HHH-16592 minor refactor
This commit is contained in:
parent
b1116c8b71
commit
38f761daca
|
@ -375,58 +375,58 @@ public class AnnotatedJoinColumns extends AnnotatedColumns {
|
|||
|
||||
String buildDefaultColumnName(PersistentClass referencedEntity, String logicalReferencedColumn) {
|
||||
final MetadataBuildingOptions options = getBuildingContext().getBuildingOptions();
|
||||
final ImplicitNamingStrategy implicitNamingStrategy = options.getImplicitNamingStrategy();
|
||||
final PhysicalNamingStrategy physicalNamingStrategy = options.getPhysicalNamingStrategy();
|
||||
|
||||
boolean mappedBySide = getMappedByTableName() != null || getMappedByPropertyName() != null;
|
||||
boolean ownerSide = getPropertyName() != null;
|
||||
boolean isRefColumnQuoted = isQuoted( logicalReferencedColumn );
|
||||
|
||||
final InFlightMetadataCollector collector = getBuildingContext().getMetadataCollector();
|
||||
final Database database = collector.getDatabase();
|
||||
final JdbcEnvironment jdbcEnvironment = database.getJdbcEnvironment();
|
||||
final Identifier columnIdentifier = columnIdentifier(
|
||||
referencedEntity,
|
||||
logicalReferencedColumn,
|
||||
options.getImplicitNamingStrategy(),
|
||||
collector,
|
||||
database
|
||||
);
|
||||
return options.getPhysicalNamingStrategy()
|
||||
.toPhysicalColumnName( columnIdentifier, jdbcEnvironment )
|
||||
.render( jdbcEnvironment.getDialect() );
|
||||
}
|
||||
|
||||
Identifier columnIdentifier;
|
||||
if ( mappedBySide ) {
|
||||
// NOTE : While it is completely misleading here to allow for the combination
|
||||
// of a "JPA ElementCollection" to be mappedBy, the code that uses this
|
||||
// class relies on this behavior for handling the inverse side of
|
||||
// many-to-many mappings
|
||||
columnIdentifier = implicitNamingStrategy.determineJoinColumnName(
|
||||
private Identifier columnIdentifier(
|
||||
PersistentClass referencedEntity,
|
||||
String logicalReferencedColumn,
|
||||
ImplicitNamingStrategy implicitNamingStrategy,
|
||||
InFlightMetadataCollector collector,
|
||||
Database database) {
|
||||
boolean isRefColumnQuoted = isQuoted( logicalReferencedColumn );
|
||||
|
||||
if ( isMappedBySide() ) {
|
||||
// NOTE: An @ElementCollection can't be mappedBy, but the client code
|
||||
// also handles the inverse side of many-to-many mappings
|
||||
final Identifier columnIdentifier = implicitNamingStrategy.determineJoinColumnName(
|
||||
new UnownedImplicitJoinColumnNameSource( referencedEntity, logicalReferencedColumn )
|
||||
);
|
||||
|
||||
//one element was quoted so we quote
|
||||
if ( isRefColumnQuoted || isQuoted( getMappedByTableName() ) ) {
|
||||
columnIdentifier = Identifier.quote( columnIdentifier );
|
||||
return quoteIfNecessary( isRefColumnQuoted, getMappedByTableName(), columnIdentifier );
|
||||
}
|
||||
}
|
||||
else if ( ownerSide ) {
|
||||
else if ( isOwnerSide() ) {
|
||||
final String logicalTableName = collector.getLogicalTableName( referencedEntity.getTable() );
|
||||
|
||||
columnIdentifier = implicitNamingStrategy.determineJoinColumnName(
|
||||
Identifier columnIdentifier = implicitNamingStrategy.determineJoinColumnName(
|
||||
new OwnedImplicitJoinColumnNameSource(referencedEntity, logicalTableName, logicalReferencedColumn)
|
||||
);
|
||||
|
||||
// HHH-11826 magic. See Ejb3Column and the HHH-6005 comments
|
||||
// HHH-11826 magic. See AnnotatedColumn and the HHH-6005 comments
|
||||
if ( columnIdentifier.getText().contains( "_collection&&element_" ) ) {
|
||||
columnIdentifier = Identifier.toIdentifier(
|
||||
columnIdentifier.getText().replace( "_collection&&element_", "_" ),
|
||||
columnIdentifier.isQuoted()
|
||||
);
|
||||
}
|
||||
|
||||
//one element was quoted so we quote
|
||||
if ( isRefColumnQuoted || isQuoted( logicalTableName ) ) {
|
||||
columnIdentifier = Identifier.quote( columnIdentifier );
|
||||
}
|
||||
return quoteIfNecessary( isRefColumnQuoted, logicalTableName, columnIdentifier );
|
||||
}
|
||||
else {
|
||||
final Identifier logicalTableName = database.toIdentifier(
|
||||
collector.getLogicalTableName( referencedEntity.getTable() )
|
||||
);
|
||||
|
||||
// is an intra-entity hierarchy table join so copy the name by default
|
||||
columnIdentifier = implicitNamingStrategy.determinePrimaryKeyJoinColumnName(
|
||||
final Identifier columnIdentifier = implicitNamingStrategy.determinePrimaryKeyJoinColumnName(
|
||||
new ImplicitPrimaryKeyJoinColumnNameSource() {
|
||||
@Override
|
||||
public MetadataBuildingContext getBuildingContext() {
|
||||
|
@ -444,15 +444,32 @@ public class AnnotatedJoinColumns extends AnnotatedColumns {
|
|||
}
|
||||
}
|
||||
);
|
||||
|
||||
if ( !columnIdentifier.isQuoted() && ( isRefColumnQuoted || logicalTableName.isQuoted() ) ) {
|
||||
columnIdentifier = Identifier.quote( columnIdentifier );
|
||||
return quoteIfNecessary( isRefColumnQuoted, logicalTableName, columnIdentifier );
|
||||
}
|
||||
}
|
||||
|
||||
final JdbcEnvironment jdbcEnvironment = database.getJdbcEnvironment();
|
||||
return physicalNamingStrategy.toPhysicalColumnName( columnIdentifier, jdbcEnvironment )
|
||||
.render( jdbcEnvironment.getDialect() );
|
||||
private static Identifier quoteIfNecessary(
|
||||
boolean isRefColumnQuoted, Identifier logicalTableName, Identifier columnIdentifier) {
|
||||
return !columnIdentifier.isQuoted() && ( isRefColumnQuoted || logicalTableName.isQuoted() )
|
||||
? Identifier.quote( columnIdentifier )
|
||||
: columnIdentifier;
|
||||
}
|
||||
|
||||
private static Identifier quoteIfNecessary(
|
||||
boolean isRefColumnQuoted, String logicalTableName, Identifier columnIdentifier) {
|
||||
//one element was quoted so we quote
|
||||
return isRefColumnQuoted || isQuoted( logicalTableName )
|
||||
? Identifier.quote( columnIdentifier )
|
||||
: columnIdentifier;
|
||||
}
|
||||
|
||||
private boolean isOwnerSide() {
|
||||
return getPropertyName() != null;
|
||||
}
|
||||
|
||||
private boolean isMappedBySide() {
|
||||
return getMappedByTableName() != null
|
||||
|| getMappedByPropertyName() != null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue