misc code style cleanups
This commit is contained in:
parent
f5062fca66
commit
539e270d5c
|
@ -85,7 +85,6 @@ import org.hibernate.engine.spi.FilterDefinition;
|
||||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||||
import org.hibernate.internal.CoreLogging;
|
import org.hibernate.internal.CoreLogging;
|
||||||
import org.hibernate.internal.CoreMessageLogger;
|
import org.hibernate.internal.CoreMessageLogger;
|
||||||
import org.hibernate.internal.util.collections.CollectionHelper;
|
|
||||||
import org.hibernate.mapping.Collection;
|
import org.hibernate.mapping.Collection;
|
||||||
import org.hibernate.mapping.Column;
|
import org.hibernate.mapping.Column;
|
||||||
import org.hibernate.mapping.Component;
|
import org.hibernate.mapping.Component;
|
||||||
|
@ -126,6 +125,7 @@ import static org.hibernate.boot.model.naming.Identifier.toIdentifier;
|
||||||
import static org.hibernate.boot.model.relational.internal.SqlStringGenerationContextImpl.fromExplicit;
|
import static org.hibernate.boot.model.relational.internal.SqlStringGenerationContextImpl.fromExplicit;
|
||||||
import static org.hibernate.cfg.MappingSettings.DEFAULT_CATALOG;
|
import static org.hibernate.cfg.MappingSettings.DEFAULT_CATALOG;
|
||||||
import static org.hibernate.cfg.MappingSettings.DEFAULT_SCHEMA;
|
import static org.hibernate.cfg.MappingSettings.DEFAULT_SCHEMA;
|
||||||
|
import static org.hibernate.internal.util.collections.CollectionHelper.isEmpty;
|
||||||
import static org.hibernate.internal.util.collections.CollectionHelper.mapOfSize;
|
import static org.hibernate.internal.util.collections.CollectionHelper.mapOfSize;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -409,7 +409,7 @@ public class InFlightMetadataCollectorImpl
|
||||||
throw new DuplicateMappingException( DuplicateMappingException.Type.ENTITY, entityName );
|
throw new DuplicateMappingException( DuplicateMappingException.Type.ENTITY, entityName );
|
||||||
}
|
}
|
||||||
|
|
||||||
PersistentClass matchingPersistentClass = entityBindingMap.values()
|
final PersistentClass matchingPersistentClass = entityBindingMap.values()
|
||||||
.stream()
|
.stream()
|
||||||
.filter( existingPersistentClass -> existingPersistentClass.getJpaEntityName().equals( jpaEntityName ) )
|
.filter( existingPersistentClass -> existingPersistentClass.getJpaEntityName().equals( jpaEntityName ) )
|
||||||
.findFirst()
|
.findFirst()
|
||||||
|
@ -503,11 +503,8 @@ public class InFlightMetadataCollectorImpl
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Class<? extends EmbeddableInstantiator> findRegisteredEmbeddableInstantiator(Class<?> embeddableType) {
|
public Class<? extends EmbeddableInstantiator> findRegisteredEmbeddableInstantiator(Class<?> embeddableType) {
|
||||||
if ( registeredInstantiators == null ) {
|
return registeredInstantiators == null ? null : registeredInstantiators.get( embeddableType );
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return registeredInstantiators.get( embeddableType );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Map<Class<?>, Class<? extends CompositeUserType<?>>> registeredCompositeUserTypes;
|
private Map<Class<?>, Class<? extends CompositeUserType<?>>> registeredCompositeUserTypes;
|
||||||
|
@ -522,11 +519,8 @@ public class InFlightMetadataCollectorImpl
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Class<? extends CompositeUserType<?>> findRegisteredCompositeUserType(Class<?> embeddableType) {
|
public Class<? extends CompositeUserType<?>> findRegisteredCompositeUserType(Class<?> embeddableType) {
|
||||||
if ( registeredCompositeUserTypes == null ) {
|
return registeredCompositeUserTypes == null ? null : registeredCompositeUserTypes.get( embeddableType );
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return registeredCompositeUserTypes.get( embeddableType );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Map<Class<?>, Class<? extends UserType<?>>> registeredUserTypes;
|
private Map<Class<?>, Class<? extends UserType<?>>> registeredUserTypes;
|
||||||
|
@ -540,11 +534,8 @@ public class InFlightMetadataCollectorImpl
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Class<? extends UserType<?>> findRegisteredUserType(Class<?> basicType) {
|
public Class<? extends UserType<?>> findRegisteredUserType(Class<?> basicType) {
|
||||||
if ( registeredUserTypes == null ) {
|
return registeredUserTypes == null ? null : registeredUserTypes.get( basicType );
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return registeredUserTypes.get( basicType );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Map<CollectionClassification, CollectionTypeRegistrationDescriptor> collectionTypeRegistrations;
|
private Map<CollectionClassification, CollectionTypeRegistrationDescriptor> collectionTypeRegistrations;
|
||||||
|
@ -582,15 +573,16 @@ public class InFlightMetadataCollectorImpl
|
||||||
}
|
}
|
||||||
|
|
||||||
private Map<String,String> extractParameters(Parameter[] annotationUsages) {
|
private Map<String,String> extractParameters(Parameter[] annotationUsages) {
|
||||||
if ( CollectionHelper.isEmpty( annotationUsages ) ) {
|
if ( isEmpty( annotationUsages ) ) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
final Map<String,String> result = mapOfSize( annotationUsages.length );
|
final Map<String, String> result = mapOfSize( annotationUsages.length );
|
||||||
for ( Parameter parameter : annotationUsages ) {
|
for ( Parameter parameter : annotationUsages ) {
|
||||||
result.put( parameter.name(), parameter.value() );
|
result.put( parameter.name(), parameter.value() );
|
||||||
|
}
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -703,7 +695,7 @@ public class InFlightMetadataCollectorImpl
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public java.util.Collection<Table> collectTableMappings() {
|
public java.util.Collection<Table> collectTableMappings() {
|
||||||
ArrayList<Table> tables = new ArrayList<>();
|
final ArrayList<Table> tables = new ArrayList<>();
|
||||||
for ( Namespace namespace : getDatabase().getNamespaces() ) {
|
for ( Namespace namespace : getDatabase().getNamespaces() ) {
|
||||||
tables.addAll( namespace.getTables() );
|
tables.addAll( namespace.getTables() );
|
||||||
}
|
}
|
||||||
|
@ -715,29 +707,27 @@ public class InFlightMetadataCollectorImpl
|
||||||
if ( generator == null || generator.getName() == null ) {
|
if ( generator == null || generator.getName() == null ) {
|
||||||
throw new IllegalArgumentException( "ID generator object or name is null." );
|
throw new IllegalArgumentException( "ID generator object or name is null." );
|
||||||
}
|
}
|
||||||
|
else if ( !generator.getName().isEmpty()
|
||||||
if ( generator.getName().isEmpty() ) {
|
&& !defaultIdentifierGeneratorNames.contains( generator.getName() ) ) {
|
||||||
return;
|
final IdentifierGeneratorDefinition old =
|
||||||
}
|
idGeneratorDefinitionMap.put( generator.getName(), generator );
|
||||||
|
if ( old != null && !old.equals( generator ) ) {
|
||||||
if ( defaultIdentifierGeneratorNames.contains( generator.getName() ) ) {
|
if ( bootstrapContext.getJpaCompliance().isGlobalGeneratorScopeEnabled() ) {
|
||||||
return;
|
throw new IllegalArgumentException( "Duplicate generator name " + old.getName()
|
||||||
}
|
+ "; you will likely want to set the property "
|
||||||
|
+ AvailableSettings.JPA_ID_GENERATOR_GLOBAL_SCOPE_COMPLIANCE + " to false " );
|
||||||
final IdentifierGeneratorDefinition old = idGeneratorDefinitionMap.put( generator.getName(), generator );
|
}
|
||||||
if ( old != null && !old.equals( generator ) ) {
|
else {
|
||||||
if ( bootstrapContext.getJpaCompliance().isGlobalGeneratorScopeEnabled() ) {
|
log.duplicateGeneratorName( old.getName() );
|
||||||
throw new IllegalArgumentException( "Duplicate generator name " + old.getName() + "; you will likely want to set the property " + AvailableSettings.JPA_ID_GENERATOR_GLOBAL_SCOPE_COMPLIANCE + " to false " );
|
}
|
||||||
}
|
|
||||||
else {
|
|
||||||
log.duplicateGeneratorName( old.getName() );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addDefaultIdentifierGenerator(IdentifierGeneratorDefinition generator) {
|
public void addDefaultIdentifierGenerator(IdentifierGeneratorDefinition generator) {
|
||||||
this.addIdentifierGenerator( generator );
|
addIdentifierGenerator( generator );
|
||||||
defaultIdentifierGeneratorNames.add( generator.getName() );
|
defaultIdentifierGeneratorNames.add( generator.getName() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -761,8 +751,7 @@ public class InFlightMetadataCollectorImpl
|
||||||
final String name = definition.getRegisteredName();
|
final String name = definition.getRegisteredName();
|
||||||
final NamedEntityGraphDefinition previous = namedEntityGraphMap.put( name, definition );
|
final NamedEntityGraphDefinition previous = namedEntityGraphMap.put( name, definition );
|
||||||
if ( previous != null ) {
|
if ( previous != null ) {
|
||||||
throw new DuplicateMappingException(
|
throw new DuplicateMappingException( DuplicateMappingException.Type.NAMED_ENTITY_GRAPH, name );
|
||||||
DuplicateMappingException.Type.NAMED_ENTITY_GRAPH, name );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -790,12 +779,9 @@ public class InFlightMetadataCollectorImpl
|
||||||
else if ( def.getRegistrationName() == null ) {
|
else if ( def.getRegistrationName() == null ) {
|
||||||
throw new IllegalArgumentException( "Named query definition name is null: " + def.getHqlString() );
|
throw new IllegalArgumentException( "Named query definition name is null: " + def.getHqlString() );
|
||||||
}
|
}
|
||||||
|
else if ( !defaultNamedQueryNames.contains( def.getRegistrationName() ) ) {
|
||||||
if ( defaultNamedQueryNames.contains( def.getRegistrationName() ) ) {
|
applyNamedQuery( def.getRegistrationName(), def );
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
applyNamedQuery( def.getRegistrationName(), def );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void applyNamedQuery(String name, NamedHqlQueryDefinition<?> query) {
|
private void applyNamedQuery(String name, NamedHqlQueryDefinition<?> query) {
|
||||||
|
@ -833,15 +819,12 @@ public class InFlightMetadataCollectorImpl
|
||||||
if ( def == null ) {
|
if ( def == null ) {
|
||||||
throw new IllegalArgumentException( "Named native query definition object is null" );
|
throw new IllegalArgumentException( "Named native query definition object is null" );
|
||||||
}
|
}
|
||||||
if ( def.getRegistrationName() == null ) {
|
else if ( def.getRegistrationName() == null ) {
|
||||||
throw new IllegalArgumentException( "Named native query definition name is null: " + def.getSqlQueryString() );
|
throw new IllegalArgumentException( "Named native query definition name is null: " + def.getSqlQueryString() );
|
||||||
}
|
}
|
||||||
|
else if ( !defaultNamedNativeQueryNames.contains( def.getRegistrationName() ) ) {
|
||||||
if ( defaultNamedNativeQueryNames.contains( def.getRegistrationName() ) ) {
|
applyNamedNativeQuery( def.getRegistrationName(), def );
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
applyNamedNativeQuery( def.getRegistrationName(), def );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void applyNamedNativeQuery(String name, NamedNativeQueryDefinition<?> query) {
|
private void applyNamedNativeQuery(String name, NamedNativeQueryDefinition<?> query) {
|
||||||
|
@ -877,14 +860,11 @@ public class InFlightMetadataCollectorImpl
|
||||||
}
|
}
|
||||||
|
|
||||||
final String name = definition.getRegistrationName();
|
final String name = definition.getRegistrationName();
|
||||||
|
if ( !defaultNamedProcedureNames.contains( name ) ) {
|
||||||
if ( defaultNamedProcedureNames.contains( name ) ) {
|
final NamedProcedureCallDefinition previous = namedProcedureCallMap.put( name, definition );
|
||||||
return;
|
if ( previous != null ) {
|
||||||
}
|
throw new DuplicateMappingException( DuplicateMappingException.Type.PROCEDURE, name );
|
||||||
|
}
|
||||||
final NamedProcedureCallDefinition previous = namedProcedureCallMap.put( name, definition );
|
|
||||||
if ( previous != null ) {
|
|
||||||
throw new DuplicateMappingException( DuplicateMappingException.Type.PROCEDURE, name );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -918,12 +898,9 @@ public class InFlightMetadataCollectorImpl
|
||||||
if ( name == null ) {
|
if ( name == null ) {
|
||||||
throw new IllegalArgumentException( "Result-set mapping name is null: " + resultSetMappingDescriptor );
|
throw new IllegalArgumentException( "Result-set mapping name is null: " + resultSetMappingDescriptor );
|
||||||
}
|
}
|
||||||
|
else if ( !defaultSqlResultSetMappingNames.contains( name ) ) {
|
||||||
if ( defaultSqlResultSetMappingNames.contains( name ) ) {
|
applyResultSetMapping( resultSetMappingDescriptor );
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
applyResultSetMapping( resultSetMappingDescriptor );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void applyResultSetMapping(NamedResultSetMappingDescriptor resultSetMappingDescriptor) {
|
public void applyResultSetMapping(NamedResultSetMappingDescriptor resultSetMappingDescriptor) {
|
||||||
|
@ -1879,32 +1856,26 @@ public class InFlightMetadataCollectorImpl
|
||||||
}
|
}
|
||||||
|
|
||||||
private void processValueResolvers(MetadataBuildingContext buildingContext) {
|
private void processValueResolvers(MetadataBuildingContext buildingContext) {
|
||||||
if ( valueResolvers == null ) {
|
if ( valueResolvers != null ) {
|
||||||
return;
|
while ( !valueResolvers.isEmpty() ) {
|
||||||
}
|
final boolean anyRemoved = valueResolvers.removeIf(
|
||||||
|
resolver -> resolver.apply( buildingContext )
|
||||||
|
);
|
||||||
|
|
||||||
|
if ( !anyRemoved ) {
|
||||||
while ( ! valueResolvers.isEmpty() ) {
|
throw new MappingException( "Unable to complete initialization of boot meta-model" );
|
||||||
final boolean anyRemoved = valueResolvers.removeIf(
|
}
|
||||||
resolver -> resolver.apply( buildingContext )
|
|
||||||
);
|
|
||||||
|
|
||||||
if ( ! anyRemoved ) {
|
|
||||||
throw new MappingException( "Unable to complete initialization of boot meta-model" );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void processSecondPasses(ArrayList<? extends SecondPass> secondPasses) {
|
private void processSecondPasses(ArrayList<? extends SecondPass> secondPasses) {
|
||||||
if ( secondPasses == null ) {
|
if ( secondPasses != null ) {
|
||||||
return;
|
for ( SecondPass secondPass : secondPasses ) {
|
||||||
|
secondPass.doSecondPass( getEntityBindingMap() );
|
||||||
|
}
|
||||||
|
secondPasses.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
for ( SecondPass secondPass : secondPasses ) {
|
|
||||||
secondPass.doSecondPass( getEntityBindingMap() );
|
|
||||||
}
|
|
||||||
|
|
||||||
secondPasses.clear();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void processFkSecondPassesInOrder() {
|
private void processFkSecondPassesInOrder() {
|
||||||
|
@ -1915,8 +1886,8 @@ public class InFlightMetadataCollectorImpl
|
||||||
|
|
||||||
// split FkSecondPass instances into primary key and non primary key FKs.
|
// split FkSecondPass instances into primary key and non primary key FKs.
|
||||||
// While doing so build a map of class names to FkSecondPass instances depending on this class.
|
// While doing so build a map of class names to FkSecondPass instances depending on this class.
|
||||||
Map<String, Set<FkSecondPass>> isADependencyOf = new HashMap<>();
|
final Map<String, Set<FkSecondPass>> isADependencyOf = new HashMap<>();
|
||||||
List<FkSecondPass> endOfQueueFkSecondPasses = new ArrayList<>( fkSecondPassList.size() );
|
final List<FkSecondPass> endOfQueueFkSecondPasses = new ArrayList<>( fkSecondPassList.size() );
|
||||||
for ( FkSecondPass sp : fkSecondPassList ) {
|
for ( FkSecondPass sp : fkSecondPassList ) {
|
||||||
if ( sp.isInPrimaryKey() ) {
|
if ( sp.isInPrimaryKey() ) {
|
||||||
final String referenceEntityName = sp.getReferencedEntityName();
|
final String referenceEntityName = sp.getReferencedEntityName();
|
||||||
|
@ -1933,7 +1904,7 @@ public class InFlightMetadataCollectorImpl
|
||||||
}
|
}
|
||||||
|
|
||||||
// using the isADependencyOf map we order the FkSecondPass recursively instances into the right order for processing
|
// using the isADependencyOf map we order the FkSecondPass recursively instances into the right order for processing
|
||||||
List<FkSecondPass> orderedFkSecondPasses = new ArrayList<>( fkSecondPassList.size() );
|
final List<FkSecondPass> orderedFkSecondPasses = new ArrayList<>( fkSecondPassList.size() );
|
||||||
for ( String tableName : isADependencyOf.keySet() ) {
|
for ( String tableName : isADependencyOf.keySet() ) {
|
||||||
buildRecursiveOrderedFkSecondPasses( orderedFkSecondPasses, isADependencyOf, tableName, tableName );
|
buildRecursiveOrderedFkSecondPasses( orderedFkSecondPasses, isADependencyOf, tableName, tableName );
|
||||||
}
|
}
|
||||||
|
@ -1968,7 +1939,7 @@ public class InFlightMetadataCollectorImpl
|
||||||
Map<String, Set<FkSecondPass>> isADependencyOf,
|
Map<String, Set<FkSecondPass>> isADependencyOf,
|
||||||
String startTable,
|
String startTable,
|
||||||
String currentTable) {
|
String currentTable) {
|
||||||
Set<FkSecondPass> dependencies = isADependencyOf.get( currentTable );
|
final Set<FkSecondPass> dependencies = isADependencyOf.get( currentTable );
|
||||||
if ( dependencies != null ) {
|
if ( dependencies != null ) {
|
||||||
for ( FkSecondPass pass : dependencies ) {
|
for ( FkSecondPass pass : dependencies ) {
|
||||||
String dependentTable = pass.getValue().getTable().getQualifiedTableName().render();
|
String dependentTable = pass.getValue().getTable().getQualifiedTableName().render();
|
||||||
|
@ -2016,7 +1987,7 @@ public class InFlightMetadataCollectorImpl
|
||||||
|
|
||||||
private void secondPassCompileForeignKeys(MetadataBuildingContext buildingContext) {
|
private void secondPassCompileForeignKeys(MetadataBuildingContext buildingContext) {
|
||||||
int uniqueInteger = 0;
|
int uniqueInteger = 0;
|
||||||
Set<ForeignKey> done = new HashSet<>();
|
final Set<ForeignKey> done = new HashSet<>();
|
||||||
for ( Table table : collectTableMappings() ) {
|
for ( Table table : collectTableMappings() ) {
|
||||||
table.setUniqueInteger( uniqueInteger++ );
|
table.setUniqueInteger( uniqueInteger++ );
|
||||||
secondPassCompileForeignKeys( table, done, buildingContext );
|
secondPassCompileForeignKeys( table, done, buildingContext );
|
||||||
|
@ -2052,26 +2023,22 @@ public class InFlightMetadataCollectorImpl
|
||||||
}
|
}
|
||||||
|
|
||||||
private void processPropertyReferences() {
|
private void processPropertyReferences() {
|
||||||
if ( delayedPropertyReferenceHandlers == null ) {
|
if ( delayedPropertyReferenceHandlers != null ) {
|
||||||
return;
|
log.debug( "Processing association property references" );
|
||||||
}
|
|
||||||
log.debug( "Processing association property references" );
|
|
||||||
|
|
||||||
for ( DelayedPropertyReferenceHandler delayedPropertyReferenceHandler : delayedPropertyReferenceHandlers ) {
|
for ( DelayedPropertyReferenceHandler delayedPropertyReferenceHandler : delayedPropertyReferenceHandlers ) {
|
||||||
delayedPropertyReferenceHandler.process( this );
|
delayedPropertyReferenceHandler.process( this );
|
||||||
}
|
}
|
||||||
|
|
||||||
delayedPropertyReferenceHandlers.clear();
|
delayedPropertyReferenceHandlers.clear();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Map<String,NaturalIdUniqueKeyBinder> naturalIdUniqueKeyBinderMap;
|
private Map<String,NaturalIdUniqueKeyBinder> naturalIdUniqueKeyBinderMap;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public NaturalIdUniqueKeyBinder locateNaturalIdUniqueKeyBinder(String entityName) {
|
public NaturalIdUniqueKeyBinder locateNaturalIdUniqueKeyBinder(String entityName) {
|
||||||
if ( naturalIdUniqueKeyBinderMap == null ) {
|
return naturalIdUniqueKeyBinderMap == null ? null : naturalIdUniqueKeyBinderMap.get( entityName );
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return naturalIdUniqueKeyBinderMap.get( entityName );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -2086,15 +2053,12 @@ public class InFlightMetadataCollectorImpl
|
||||||
}
|
}
|
||||||
|
|
||||||
private void processNaturalIdUniqueKeyBinders() {
|
private void processNaturalIdUniqueKeyBinders() {
|
||||||
if ( naturalIdUniqueKeyBinderMap == null ) {
|
if ( naturalIdUniqueKeyBinderMap != null ) {
|
||||||
return;
|
for ( NaturalIdUniqueKeyBinder naturalIdUniqueKeyBinder : naturalIdUniqueKeyBinderMap.values() ) {
|
||||||
|
naturalIdUniqueKeyBinder.process();
|
||||||
|
}
|
||||||
|
naturalIdUniqueKeyBinderMap.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
for ( NaturalIdUniqueKeyBinder naturalIdUniqueKeyBinder : naturalIdUniqueKeyBinderMap.values() ) {
|
|
||||||
naturalIdUniqueKeyBinder.process();
|
|
||||||
}
|
|
||||||
|
|
||||||
naturalIdUniqueKeyBinderMap.clear();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void processCachingOverrides() {
|
private void processCachingOverrides() {
|
||||||
|
|
|
@ -450,10 +450,10 @@ public class AnnotatedColumn {
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
final Table table = value.getTable();
|
final Table table = value.getTable();
|
||||||
getParent().setTable( table );
|
parent.setTable( table );
|
||||||
getMappingColumn().setValue( value );
|
mappingColumn.setValue( value );
|
||||||
value.addColumn( getMappingColumn(), insertable, updatable );
|
value.addColumn( mappingColumn, insertable, updatable );
|
||||||
table.addColumn( getMappingColumn() );
|
table.addColumn( mappingColumn );
|
||||||
addColumnBinding( value );
|
addColumnBinding( value );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,6 @@ import org.hibernate.internal.util.MutableInteger;
|
||||||
import org.hibernate.mapping.BasicValue;
|
import org.hibernate.mapping.BasicValue;
|
||||||
import org.hibernate.mapping.Column;
|
import org.hibernate.mapping.Column;
|
||||||
import org.hibernate.mapping.Component;
|
import org.hibernate.mapping.Component;
|
||||||
import org.hibernate.mapping.KeyValue;
|
|
||||||
import org.hibernate.mapping.PersistentClass;
|
import org.hibernate.mapping.PersistentClass;
|
||||||
import org.hibernate.mapping.Property;
|
import org.hibernate.mapping.Property;
|
||||||
import org.hibernate.mapping.Selectable;
|
import org.hibernate.mapping.Selectable;
|
||||||
|
@ -114,8 +113,10 @@ public class CopyIdentifierComponentSecondPass extends FkSecondPass {
|
||||||
// TODO: much better error message if this is something that can really happen!
|
// TODO: much better error message if this is something that can really happen!
|
||||||
throw new AnnotationException( "Unknown entity name '" + referencedEntityName + "'");
|
throw new AnnotationException( "Unknown entity name '" + referencedEntityName + "'");
|
||||||
}
|
}
|
||||||
final KeyValue identifier = referencedPersistentClass.getIdentifier();
|
if ( referencedPersistentClass.getIdentifier() instanceof Component id ) {
|
||||||
if ( !(identifier instanceof Component) ) {
|
return id;
|
||||||
|
}
|
||||||
|
else {
|
||||||
// The entity with the @MapsId annotation has a composite
|
// The entity with the @MapsId annotation has a composite
|
||||||
// id type, but the referenced entity has a basic-typed id.
|
// id type, but the referenced entity has a basic-typed id.
|
||||||
// Therefore, the @MapsId annotation should have specified
|
// Therefore, the @MapsId annotation should have specified
|
||||||
|
@ -128,7 +129,6 @@ public class CopyIdentifierComponentSecondPass extends FkSecondPass {
|
||||||
+ referencedEntityName + "')"
|
+ referencedEntityName + "')"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return (Component) identifier;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Property createComponentProperty(
|
private Property createComponentProperty(
|
||||||
|
@ -136,7 +136,7 @@ public class CopyIdentifierComponentSecondPass extends FkSecondPass {
|
||||||
Map<String, AnnotatedJoinColumn> columnByReferencedName,
|
Map<String, AnnotatedJoinColumn> columnByReferencedName,
|
||||||
MutableInteger index,
|
MutableInteger index,
|
||||||
Property referencedProperty ) {
|
Property referencedProperty ) {
|
||||||
Property property = new Property();
|
final Property property = new Property();
|
||||||
property.setName( referencedProperty.getName() );
|
property.setName( referencedProperty.getName() );
|
||||||
//FIXME set optional?
|
//FIXME set optional?
|
||||||
//property.setOptional( property.isOptional() );
|
//property.setOptional( property.isOptional() );
|
||||||
|
@ -181,13 +181,13 @@ public class CopyIdentifierComponentSecondPass extends FkSecondPass {
|
||||||
Map<String, AnnotatedJoinColumn> columnByReferencedName,
|
Map<String, AnnotatedJoinColumn> columnByReferencedName,
|
||||||
MutableInteger index,
|
MutableInteger index,
|
||||||
Property referencedProperty ) {
|
Property referencedProperty ) {
|
||||||
Property property = new Property();
|
final Property property = new Property();
|
||||||
property.setName( referencedProperty.getName() );
|
property.setName( referencedProperty.getName() );
|
||||||
//FIXME set optional?
|
//FIXME set optional?
|
||||||
//property.setOptional( property.isOptional() );
|
//property.setOptional( property.isOptional() );
|
||||||
property.setPersistentClass( component.getOwner() );
|
property.setPersistentClass( component.getOwner() );
|
||||||
property.setPropertyAccessorName( referencedProperty.getPropertyAccessorName() );
|
property.setPropertyAccessorName( referencedProperty.getPropertyAccessorName() );
|
||||||
SimpleValue value = new BasicValue( buildingContext, component.getTable() );
|
final SimpleValue value = new BasicValue( buildingContext, component.getTable() );
|
||||||
property.setValue( value );
|
property.setValue( value );
|
||||||
final SimpleValue referencedValue = (SimpleValue) referencedProperty.getValue();
|
final SimpleValue referencedValue = (SimpleValue) referencedProperty.getValue();
|
||||||
value.copyTypeFrom( referencedValue );
|
value.copyTypeFrom( referencedValue );
|
||||||
|
@ -202,48 +202,50 @@ public class CopyIdentifierComponentSecondPass extends FkSecondPass {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
//FIXME take care of Formula
|
|
||||||
for ( Selectable selectable : referencedValue.getSelectables() ) {
|
for ( Selectable selectable : referencedValue.getSelectables() ) {
|
||||||
if ( !(selectable instanceof Column) ) {
|
if ( selectable instanceof Column column ) {
|
||||||
log.debug( "Encountered formula definition; skipping" );
|
final AnnotatedJoinColumn joinColumn;
|
||||||
continue;
|
final String logicalColumnName;
|
||||||
}
|
if ( isExplicitReference ) {
|
||||||
final Column column = (Column) selectable;
|
logicalColumnName = column.getName();
|
||||||
final AnnotatedJoinColumn joinColumn;
|
//JPA 2 requires referencedColumnNames to be case-insensitive
|
||||||
final String logicalColumnName;
|
joinColumn = columnByReferencedName.get( logicalColumnName.toLowerCase( Locale.ROOT ) );
|
||||||
if ( isExplicitReference ) {
|
}
|
||||||
logicalColumnName = column.getName();
|
else {
|
||||||
//JPA 2 requires referencedColumnNames to be case-insensitive
|
logicalColumnName = null;
|
||||||
joinColumn = columnByReferencedName.get( logicalColumnName.toLowerCase(Locale.ROOT ) );
|
joinColumn = columnByReferencedName.get( String.valueOf( index.get() ) );
|
||||||
|
index.getAndIncrement();
|
||||||
|
}
|
||||||
|
if ( joinColumn == null && !firstColumn.isNameDeferred() ) {
|
||||||
|
throw new AnnotationException(
|
||||||
|
"Property '" + propertyName
|
||||||
|
+ "' of entity '" + component.getOwner().getEntityName()
|
||||||
|
+ "' must have a '@JoinColumn' which references the foreign key column '"
|
||||||
|
+ logicalColumnName + "'"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
final String columnName =
|
||||||
|
joinColumn == null || joinColumn.isNameDeferred()
|
||||||
|
? "tata_" + column.getName()
|
||||||
|
: joinColumn.getName();
|
||||||
|
|
||||||
|
final Database database = buildingContext.getMetadataCollector().getDatabase();
|
||||||
|
final String physicalName =
|
||||||
|
buildingContext.getBuildingOptions().getPhysicalNamingStrategy()
|
||||||
|
.toPhysicalColumnName( database.toIdentifier( columnName ),
|
||||||
|
database.getJdbcEnvironment() )
|
||||||
|
.render( database.getDialect() );
|
||||||
|
value.addColumn( new Column( physicalName ) );
|
||||||
|
if ( joinColumn != null ) {
|
||||||
|
applyComponentColumnSizeValueToJoinColumn( column, joinColumn );
|
||||||
|
joinColumn.linkWithValue( value );
|
||||||
|
}
|
||||||
|
column.setValue( value );
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
logicalColumnName = null;
|
//FIXME take care of Formula
|
||||||
joinColumn = columnByReferencedName.get( String.valueOf( index.get() ) );
|
log.debug( "Encountered formula definition; skipping" );
|
||||||
index.getAndIncrement();
|
|
||||||
}
|
}
|
||||||
if ( joinColumn == null && !firstColumn.isNameDeferred() ) {
|
|
||||||
throw new AnnotationException(
|
|
||||||
"Property '" + propertyName
|
|
||||||
+ "' of entity '" + component.getOwner().getEntityName()
|
|
||||||
+ "' must have a '@JoinColumn' which references the foreign key column '"
|
|
||||||
+ logicalColumnName + "'"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
final String columnName = joinColumn == null || joinColumn.isNameDeferred()
|
|
||||||
? "tata_" + column.getName()
|
|
||||||
: joinColumn.getName();
|
|
||||||
|
|
||||||
final Database database = buildingContext.getMetadataCollector().getDatabase();
|
|
||||||
final String physicalName =
|
|
||||||
buildingContext.getBuildingOptions().getPhysicalNamingStrategy()
|
|
||||||
.toPhysicalColumnName( database.toIdentifier( columnName ), database.getJdbcEnvironment() )
|
|
||||||
.render( database.getDialect() );
|
|
||||||
value.addColumn( new Column( physicalName ) );
|
|
||||||
if ( joinColumn != null ) {
|
|
||||||
applyComponentColumnSizeValueToJoinColumn( column, joinColumn );
|
|
||||||
joinColumn.linkWithValue( value );
|
|
||||||
}
|
|
||||||
column.setValue( value );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return property;
|
return property;
|
||||||
|
|
Loading…
Reference in New Issue