minor change to code
This commit is contained in:
parent
c718a46285
commit
abb89a32b1
|
@ -620,17 +620,7 @@ public class EntityBinder {
|
|||
|
||||
final InFlightMetadataCollector collector = context.getMetadataCollector();
|
||||
if ( inheritanceState.hasTable() ) {
|
||||
final Check check = getOverridableAnnotation( annotatedClass, Check.class, context );
|
||||
bindTable(
|
||||
schema,
|
||||
catalog,
|
||||
table,
|
||||
uniqueConstraints,
|
||||
check == null ? null : check.constraints(),
|
||||
inheritanceState.hasDenormalizedTable()
|
||||
? collector.getEntityTableXref( superEntity.getEntityName() )
|
||||
: null
|
||||
);
|
||||
createTable( inheritanceState, superEntity, schema, table, catalog, uniqueConstraints, collector );
|
||||
}
|
||||
else {
|
||||
if ( hasTableAnnotation ) {
|
||||
|
@ -645,6 +635,29 @@ public class EntityBinder {
|
|||
}
|
||||
}
|
||||
|
||||
private void createTable(
|
||||
InheritanceState inheritanceState,
|
||||
PersistentClass superEntity,
|
||||
String schema,
|
||||
String table,
|
||||
String catalog,
|
||||
List<UniqueConstraintHolder> uniqueConstraints,
|
||||
InFlightMetadataCollector collector) {
|
||||
final Check check = getOverridableAnnotation( annotatedClass, Check.class, context );
|
||||
final RowId rowId = annotatedClass.getAnnotation( RowId.class );
|
||||
bindTable(
|
||||
schema,
|
||||
catalog,
|
||||
table,
|
||||
uniqueConstraints,
|
||||
check == null ? null : check.constraints(),
|
||||
rowId == null ? null : rowId.value(),
|
||||
inheritanceState.hasDenormalizedTable()
|
||||
? collector.getEntityTableXref( superEntity.getEntityName() )
|
||||
: null
|
||||
);
|
||||
}
|
||||
|
||||
private void handleInheritance(
|
||||
InheritanceState inheritanceState,
|
||||
PersistentClass superEntity,
|
||||
|
@ -1649,7 +1662,8 @@ public class EntityBinder {
|
|||
String catalog,
|
||||
String tableName,
|
||||
List<UniqueConstraintHolder> uniqueConstraints,
|
||||
String constraints,
|
||||
String checkConstraint,
|
||||
String rowId,
|
||||
InFlightMetadataCollector.EntityTableXref denormalizedSuperTableXref) {
|
||||
|
||||
final EntityTableNamingStrategyHelper namingStrategyHelper = new EntityTableNamingStrategyHelper(
|
||||
|
@ -1667,16 +1681,16 @@ public class EntityBinder {
|
|||
logicalName,
|
||||
persistentClass.isAbstract(),
|
||||
uniqueConstraints,
|
||||
null,
|
||||
constraints,
|
||||
context,
|
||||
subselect,
|
||||
denormalizedSuperTableXref
|
||||
);
|
||||
final RowId rowId = annotatedClass.getAnnotation( RowId.class );
|
||||
if ( rowId != null ) {
|
||||
table.setRowId( rowId.value() );
|
||||
|
||||
table.setRowId( rowId );
|
||||
if ( checkConstraint != null ) {
|
||||
table.addCheckConstraint( checkConstraint );
|
||||
}
|
||||
|
||||
// final Comment comment = annotatedClass.getAnnotation( Comment.class );
|
||||
// if ( comment != null ) {
|
||||
// table.setComment( comment.value() );
|
||||
|
@ -1964,8 +1978,8 @@ public class EntityBinder {
|
|||
Object joinColumns,
|
||||
UniqueConstraint[] uniqueConstraints) {
|
||||
final QualifiedTableName logicalName = new QualifiedTableName(
|
||||
Identifier.toIdentifier(catalog),
|
||||
Identifier.toIdentifier(schema),
|
||||
Identifier.toIdentifier( catalog ),
|
||||
Identifier.toIdentifier( schema ),
|
||||
context.getMetadataCollector()
|
||||
.getDatabase()
|
||||
.getJdbcEnvironment()
|
||||
|
@ -1984,11 +1998,7 @@ public class EntityBinder {
|
|||
logicalName.getTableName(),
|
||||
false,
|
||||
TableBinder.buildUniqueConstraintHolders( uniqueConstraints ),
|
||||
null,
|
||||
null,
|
||||
context,
|
||||
null,
|
||||
null
|
||||
context
|
||||
)
|
||||
);
|
||||
}
|
||||
|
|
|
@ -23,7 +23,6 @@ import org.hibernate.boot.spi.InFlightMetadataCollector;
|
|||
import org.hibernate.boot.spi.MetadataBuildingContext;
|
||||
import org.hibernate.dialect.Dialect;
|
||||
import org.hibernate.internal.CoreMessageLogger;
|
||||
import org.hibernate.internal.util.collections.CollectionHelper;
|
||||
import org.hibernate.mapping.Collection;
|
||||
import org.hibernate.mapping.Column;
|
||||
import org.hibernate.mapping.Component;
|
||||
|
@ -44,11 +43,13 @@ import org.jboss.logging.Logger;
|
|||
import jakarta.persistence.Index;
|
||||
import jakarta.persistence.UniqueConstraint;
|
||||
|
||||
import static java.util.Collections.emptyList;
|
||||
import static org.hibernate.internal.util.StringHelper.isNotEmpty;
|
||||
import static org.hibernate.internal.util.StringHelper.isQuoted;
|
||||
import static org.hibernate.internal.util.StringHelper.nullIfEmpty;
|
||||
import static org.hibernate.internal.util.StringHelper.unquote;
|
||||
import static org.hibernate.internal.util.collections.CollectionHelper.arrayList;
|
||||
import static org.hibernate.internal.util.collections.CollectionHelper.isNotEmpty;
|
||||
|
||||
/**
|
||||
* Stateful binder responsible for producing instances of {@link Table}.
|
||||
|
@ -59,14 +60,13 @@ public class TableBinder {
|
|||
//TODO move it to a getter/setter strategy
|
||||
private static final CoreMessageLogger LOG = Logger.getMessageLogger( CoreMessageLogger.class, TableBinder.class.getName() );
|
||||
|
||||
MetadataBuildingContext buildingContext;
|
||||
private MetadataBuildingContext buildingContext;
|
||||
|
||||
private String schema;
|
||||
private String catalog;
|
||||
private String name;
|
||||
private boolean isAbstract;
|
||||
private List<UniqueConstraintHolder> uniqueConstraints;
|
||||
String constraints;
|
||||
private String ownerEntityTable;
|
||||
private String associatedEntityTable;
|
||||
private String propertyName;
|
||||
|
@ -111,10 +111,6 @@ public class TableBinder {
|
|||
this.jpaIndexHolders = buildJpaIndexHolder( jpaIndex );
|
||||
}
|
||||
|
||||
public void setConstraints(String constraints) {
|
||||
this.constraints = constraints;
|
||||
}
|
||||
|
||||
public void setJPA2ElementCollection(boolean isJPA2ElementCollection) {
|
||||
this.isJPA2ElementCollection = isJPA2ElementCollection;
|
||||
}
|
||||
|
@ -292,12 +288,12 @@ public class TableBinder {
|
|||
return buildAndFillTable(
|
||||
schema,
|
||||
catalog,
|
||||
nameSource,
|
||||
namingStrategyHelper,
|
||||
isNotEmpty( nameSource.getExplicitName() )
|
||||
? namingStrategyHelper.handleExplicitName( nameSource.getExplicitName(), buildingContext )
|
||||
: namingStrategyHelper.determineImplicitName( buildingContext ),
|
||||
isAbstract,
|
||||
uniqueConstraints,
|
||||
jpaIndexHolders,
|
||||
constraints,
|
||||
buildingContext,
|
||||
null,
|
||||
null
|
||||
|
@ -437,54 +433,63 @@ public class TableBinder {
|
|||
public static Table buildAndFillTable(
|
||||
String schema,
|
||||
String catalog,
|
||||
ObjectNameSource nameSource,
|
||||
NamingStrategyHelper namingStrategyHelper,
|
||||
Identifier logicalName,
|
||||
boolean isAbstract,
|
||||
List<UniqueConstraintHolder> uniqueConstraints,
|
||||
List<JPAIndexHolder> jpaIndexHolders,
|
||||
String constraints,
|
||||
MetadataBuildingContext buildingContext,
|
||||
String subselect,
|
||||
InFlightMetadataCollector.EntityTableXref denormalizedSuperTableXref) {
|
||||
final Identifier logicalName;
|
||||
if ( isNotEmpty( nameSource.getExplicitName() ) ) {
|
||||
logicalName = namingStrategyHelper.handleExplicitName( nameSource.getExplicitName(), buildingContext );
|
||||
}
|
||||
else {
|
||||
logicalName = namingStrategyHelper.determineImplicitName( buildingContext );
|
||||
}
|
||||
|
||||
MetadataBuildingContext buildingContext) {
|
||||
return buildAndFillTable(
|
||||
schema,
|
||||
catalog,
|
||||
logicalName,
|
||||
isAbstract,
|
||||
uniqueConstraints,
|
||||
jpaIndexHolders,
|
||||
constraints,
|
||||
null,
|
||||
buildingContext,
|
||||
subselect,
|
||||
denormalizedSuperTableXref
|
||||
null,
|
||||
null
|
||||
);
|
||||
}
|
||||
|
||||
public static Table buildAndFillTable(
|
||||
String schema,
|
||||
String catalog,
|
||||
Identifier logicalName,
|
||||
boolean isAbstract,
|
||||
List<UniqueConstraintHolder> uniqueConstraints,
|
||||
MetadataBuildingContext buildingContext,
|
||||
String subselect,
|
||||
InFlightMetadataCollector.EntityTableXref denormalizedSuperTableXref) {
|
||||
return buildAndFillTable(
|
||||
schema,
|
||||
catalog,
|
||||
logicalName,
|
||||
isAbstract,
|
||||
uniqueConstraints,
|
||||
null,
|
||||
buildingContext,
|
||||
subselect,
|
||||
denormalizedSuperTableXref
|
||||
);
|
||||
}
|
||||
|
||||
private static Table buildAndFillTable(
|
||||
String schema,
|
||||
String catalog,
|
||||
Identifier logicalName,
|
||||
boolean isAbstract,
|
||||
List<UniqueConstraintHolder> uniqueConstraints,
|
||||
List<JPAIndexHolder> jpaIndexHolders,
|
||||
String constraints,
|
||||
MetadataBuildingContext buildingContext,
|
||||
String subselect,
|
||||
InFlightMetadataCollector.EntityTableXref denormalizedSuperTableXref) {
|
||||
schema = nullIfEmpty( schema );
|
||||
catalog = nullIfEmpty( catalog );
|
||||
|
||||
InFlightMetadataCollector metadataCollector = buildingContext.getMetadataCollector();
|
||||
|
||||
final Table table;
|
||||
if ( denormalizedSuperTableXref != null ) {
|
||||
table = buildingContext.getMetadataCollector().addDenormalizedTable(
|
||||
table = metadataCollector.addDenormalizedTable(
|
||||
schema,
|
||||
catalog,
|
||||
logicalName.render(),
|
||||
|
@ -495,7 +500,7 @@ public class TableBinder {
|
|||
);
|
||||
}
|
||||
else {
|
||||
table = buildingContext.getMetadataCollector().addTable(
|
||||
table = metadataCollector.addTable(
|
||||
schema,
|
||||
catalog,
|
||||
logicalName.render(),
|
||||
|
@ -505,19 +510,15 @@ public class TableBinder {
|
|||
);
|
||||
}
|
||||
|
||||
if ( CollectionHelper.isNotEmpty( uniqueConstraints ) ) {
|
||||
buildingContext.getMetadataCollector().addUniqueConstraintHolders( table, uniqueConstraints );
|
||||
if ( isNotEmpty( uniqueConstraints ) ) {
|
||||
metadataCollector.addUniqueConstraintHolders( table, uniqueConstraints );
|
||||
}
|
||||
|
||||
if ( CollectionHelper.isNotEmpty( jpaIndexHolders ) ) {
|
||||
buildingContext.getMetadataCollector().addJpaIndexHolders( table, jpaIndexHolders );
|
||||
if ( isNotEmpty( jpaIndexHolders ) ) {
|
||||
metadataCollector.addJpaIndexHolders( table, jpaIndexHolders );
|
||||
}
|
||||
|
||||
if ( constraints != null ) {
|
||||
table.addCheckConstraint( constraints );
|
||||
}
|
||||
|
||||
buildingContext.getMetadataCollector().addTableNameBinding( logicalName, table );
|
||||
metadataCollector.addTableNameBinding( logicalName, table );
|
||||
|
||||
return table;
|
||||
}
|
||||
|
@ -813,7 +814,7 @@ public class TableBinder {
|
|||
public static List<UniqueConstraintHolder> buildUniqueConstraintHolders(UniqueConstraint[] annotations) {
|
||||
List<UniqueConstraintHolder> result;
|
||||
if ( annotations == null || annotations.length == 0 ) {
|
||||
result = java.util.Collections.emptyList();
|
||||
result = emptyList();
|
||||
}
|
||||
else {
|
||||
result = arrayList( annotations.length );
|
||||
|
|
|
@ -10,7 +10,6 @@ import java.io.Serializable;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
|
@ -36,6 +35,7 @@ import org.hibernate.tool.schema.extract.spi.TableInformation;
|
|||
import org.hibernate.tool.schema.internal.StandardTableMigrator;
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
import static java.util.Collections.emptyList;
|
||||
import static java.util.Collections.unmodifiableList;
|
||||
import static java.util.Collections.unmodifiableMap;
|
||||
|
||||
|
@ -185,10 +185,9 @@ public class Table implements Serializable, ContributableDatabaseObject {
|
|||
}
|
||||
|
||||
public void setQuoted(boolean quoted) {
|
||||
if ( quoted == name.isQuoted() ) {
|
||||
return;
|
||||
if ( quoted != name.isQuoted() ) {
|
||||
name = new Identifier( name.getText(), quoted );
|
||||
}
|
||||
this.name = new Identifier( name.getText(), quoted );
|
||||
}
|
||||
|
||||
public void setSchema(String schema) {
|
||||
|
@ -611,17 +610,17 @@ public class Table implements Serializable, ContributableDatabaseObject {
|
|||
}
|
||||
|
||||
public String toString() {
|
||||
final StringBuilder buf = new StringBuilder()
|
||||
final StringBuilder string = new StringBuilder()
|
||||
.append( getClass().getSimpleName() )
|
||||
.append( '(' );
|
||||
if ( getCatalog() != null ) {
|
||||
buf.append( getCatalog() ).append( "." );
|
||||
string.append( getCatalog() ).append( "." );
|
||||
}
|
||||
if ( getSchema() != null ) {
|
||||
buf.append( getSchema() ).append( "." );
|
||||
string.append( getSchema() ).append( "." );
|
||||
}
|
||||
buf.append( getName() ).append( ')' );
|
||||
return buf.toString();
|
||||
string.append( getName() ).append( ')' );
|
||||
return string.toString();
|
||||
}
|
||||
|
||||
public String getSubselect() {
|
||||
|
@ -706,7 +705,7 @@ public class Table implements Serializable, ContributableDatabaseObject {
|
|||
this.referencedClassName = referencedClassName;
|
||||
this.columns = columns.toArray( EMPTY_COLUMN_ARRAY );
|
||||
this.referencedColumns = referencedColumns != null
|
||||
? referencedColumns.toArray(EMPTY_COLUMN_ARRAY)
|
||||
? referencedColumns.toArray( EMPTY_COLUMN_ARRAY )
|
||||
: EMPTY_COLUMN_ARRAY;
|
||||
}
|
||||
|
||||
|
@ -747,7 +746,7 @@ public class Table implements Serializable, ContributableDatabaseObject {
|
|||
|
||||
public List<InitCommand> getInitCommands(SqlStringGenerationContext context) {
|
||||
if ( initCommandProducers == null ) {
|
||||
return Collections.emptyList();
|
||||
return emptyList();
|
||||
}
|
||||
else {
|
||||
final List<InitCommand> initCommands = new ArrayList<>();
|
||||
|
|
Loading…
Reference in New Issue