From 9a11e843e678bf64c0812e9a09b57ce2e8777bf2 Mon Sep 17 00:00:00 2001 From: Gavin King Date: Sat, 29 Jan 2022 18:00:39 +0100 Subject: [PATCH] stop calling factory.getJdbcServices().getDialect() so much --- .../entity/JoinedSubclassEntityPersister.java | 37 +++++++++---------- .../entity/SingleTableEntityPersister.java | 4 +- .../entity/UnionSubclassEntityPersister.java | 10 ++--- 3 files changed, 25 insertions(+), 26 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/persister/entity/JoinedSubclassEntityPersister.java b/hibernate-core/src/main/java/org/hibernate/persister/entity/JoinedSubclassEntityPersister.java index 7c013b459e..a566c615f7 100644 --- a/hibernate-core/src/main/java/org/hibernate/persister/entity/JoinedSubclassEntityPersister.java +++ b/hibernate-core/src/main/java/org/hibernate/persister/entity/JoinedSubclassEntityPersister.java @@ -51,6 +51,7 @@ import org.hibernate.metamodel.mapping.internal.MappingModelCreationHelper; import org.hibernate.metamodel.mapping.internal.MappingModelCreationProcess; import org.hibernate.persister.spi.PersisterCreationContext; import org.hibernate.query.spi.NavigablePath; +import org.hibernate.query.sqm.function.SqmFunctionRegistry; import org.hibernate.sql.InFragment; import org.hibernate.sql.Insert; import org.hibernate.sql.ast.SqlAstJoinType; @@ -165,6 +166,10 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister { super( persistentClass, cacheAccessStrategy, naturalIdRegionAccessStrategy, creationContext ); final SessionFactoryImplementor factory = creationContext.getSessionFactory(); + final JdbcServices jdbcServices = factory.getServiceRegistry().getService( JdbcServices.class ); + final Dialect dialect = jdbcServices.getJdbcEnvironment().getDialect(); + final SqmFunctionRegistry sqmFunctionRegistry = factory.getQueryEngine().getSqmFunctionRegistry(); + // DISCRIMINATOR @@ -179,8 +184,8 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister { } else { final Column column = (Column) selectable; - explicitDiscriminatorColumnName = column.getQuotedName( factory.getJdbcServices().getDialect() ); - discriminatorAlias = column.getAlias( factory.getJdbcServices().getDialect(), persistentClass.getRootTable() ); + explicitDiscriminatorColumnName = column.getQuotedName( dialect ); + discriminatorAlias = column.getAlias( dialect, persistentClass.getRootTable() ); } discriminatorType = (BasicType) persistentClass.getDiscriminator().getType(); if ( persistentClass.isDiscriminatorValueNull() ) { @@ -199,7 +204,7 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister { .getJdbcLiteralFormatter( discriminatorType.getJavaTypeDescriptor() ); discriminatorSQLString = literalFormatter.toJdbcLiteral( discriminatorValue, - factory.getJdbcServices().getDialect(), + dialect, factory.getWrapperOptions() ); } @@ -262,17 +267,14 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister { List columns = key.getColumns(); for ( int k = 0; k < idColumnSpan; k++ ) { Column column = columns.get(k); - keyCols[k] = column.getQuotedName( factory.getJdbcServices().getDialect() ); - keyColReaders[k] = column.getReadExpr( factory.getJdbcServices().getDialect() ); - keyColReaderTemplates[k] = column.getTemplate( - factory.getJdbcServices().getDialect(), - factory.getQueryEngine().getSqmFunctionRegistry() - ); + keyCols[k] = column.getQuotedName( dialect ); + keyColReaders[k] = column.getReadExpr( dialect ); + keyColReaderTemplates[k] = column.getTemplate( dialect, sqmFunctionRegistry ); } keyColumns.add( keyCols ); keyColumnReaders.add( keyColReaders ); keyColumnReaderTemplates.add( keyColReaderTemplates ); - cascadeDeletes.add( key.isCascadeDeleteEnabled() && factory.getJdbcServices().getDialect().supportsCascadeDelete() ); + cascadeDeletes.add( key.isCascadeDeleteEnabled() && dialect.supportsCascadeDelete() ); } //Span of the tableNames directly mapped by this entity and super-classes, if any @@ -301,14 +303,14 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister { List columns = key.getColumns(); for ( int k = 0; k < joinIdColumnSpan; k++ ) { Column column = columns.get(k); - keyCols[k] = column.getQuotedName( factory.getJdbcServices().getDialect() ); - keyColReaders[k] = column.getReadExpr( factory.getJdbcServices().getDialect() ); - keyColReaderTemplates[k] = column.getTemplate( factory.getJdbcServices().getDialect(), factory.getQueryEngine().getSqmFunctionRegistry() ); + keyCols[k] = column.getQuotedName( dialect ); + keyColReaders[k] = column.getReadExpr( dialect ); + keyColReaderTemplates[k] = column.getTemplate( dialect, sqmFunctionRegistry ); } keyColumns.add( keyCols ); keyColumnReaders.add( keyColReaders ); keyColumnReaderTemplates.add( keyColReaderTemplates ); - cascadeDeletes.add( key.isCascadeDeleteEnabled() && factory.getJdbcServices().getDialect().supportsCascadeDelete() ); + cascadeDeletes.add( key.isCascadeDeleteEnabled() && dialect.supportsCascadeDelete() ); tableIndex++; } @@ -338,7 +340,7 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister { String[] key = new String[idColumnSpan]; List columns = table.getPrimaryKey().getColumns(); for ( int k = 0; k < idColumnSpan; k++ ) { - key[k] = columns.get(k).getQuotedName( factory.getJdbcServices().getDialect() ); + key[k] = columns.get(k).getQuotedName( dialect ); } keyColumns.add( key ); } @@ -358,7 +360,7 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister { String[] key = new String[idColumnSpan]; List columns = joinTable.getPrimaryKey().getColumns(); for ( int k = 0; k < idColumnSpan; k++ ) { - key[k] = columns.get(k).getQuotedName( factory.getJdbcServices().getDialect() ); + key[k] = columns.get(k).getQuotedName( dialect ); } keyColumns.add( key ); } @@ -483,9 +485,6 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister { //TODO: code duplication with SingleTableEntityPersister - final JdbcServices jdbcServices = factory.getServiceRegistry().getService( JdbcServices.class ); - final Dialect dialect = jdbcServices.getJdbcEnvironment().getDialect(); - ArrayList columnTableNumbers = new ArrayList<>(); // ArrayList formulaTableNumbers = new ArrayList<>(); ArrayList propTableNumbers = new ArrayList<>(); diff --git a/hibernate-core/src/main/java/org/hibernate/persister/entity/SingleTableEntityPersister.java b/hibernate-core/src/main/java/org/hibernate/persister/entity/SingleTableEntityPersister.java index d1b5295f65..c34bd4ed6d 100644 --- a/hibernate-core/src/main/java/org/hibernate/persister/entity/SingleTableEntityPersister.java +++ b/hibernate-core/src/main/java/org/hibernate/persister/entity/SingleTableEntityPersister.java @@ -141,6 +141,7 @@ public class SingleTableEntityPersister extends AbstractEntityPersister { super( persistentClass, cacheAccessStrategy, naturalIdRegionAccessStrategy, creationContext ); final SessionFactoryImplementor factory = creationContext.getSessionFactory(); + final Dialect dialect = factory.getJdbcServices().getDialect(); // CLASS + TABLE @@ -187,7 +188,6 @@ public class SingleTableEntityPersister extends AbstractEntityPersister { // JOINS int j = 1; - final Dialect dialect = factory.getJdbcServices().getDialect(); for ( Join join : persistentClass.getJoinClosure() ) { qualifiedTableNames[j] = determineTableName( join.getTable() ); isInverseTable[j] = join.isInverse(); @@ -327,7 +327,7 @@ public class SingleTableEntityPersister extends AbstractEntityPersister { .getJdbcLiteralFormatter( discriminatorType.getJavaTypeDescriptor() ); discriminatorSQLValue = literalFormatter.toJdbcLiteral( discriminatorValue, - factory.getJdbcServices().getDialect(), + dialect, factory.getWrapperOptions() ); } diff --git a/hibernate-core/src/main/java/org/hibernate/persister/entity/UnionSubclassEntityPersister.java b/hibernate-core/src/main/java/org/hibernate/persister/entity/UnionSubclassEntityPersister.java index 6201956991..673a902142 100644 --- a/hibernate-core/src/main/java/org/hibernate/persister/entity/UnionSubclassEntityPersister.java +++ b/hibernate-core/src/main/java/org/hibernate/persister/entity/UnionSubclassEntityPersister.java @@ -104,6 +104,7 @@ public class UnionSubclassEntityPersister extends AbstractEntityPersister { } final SessionFactoryImplementor factory = creationContext.getSessionFactory(); + final Dialect dialect = factory.getJdbcServices().getDialect(); // TABLE @@ -206,12 +207,11 @@ public class UnionSubclassEntityPersister extends AbstractEntityPersister { ArrayList keyColumns = new ArrayList<>(); for ( Table table : persistentClass.getSubclassTableClosure() ) { if ( !table.isAbstractUnionTable() ) { - final String tableName = determineTableName( table ); - tableNames.add( tableName ); + tableNames.add( determineTableName( table ) ); String[] key = new String[idColumnSpan]; List columns = table.getPrimaryKey().getColumns(); for ( int k = 0; k < idColumnSpan; k++ ) { - key[k] = columns.get(k).getQuotedName( factory.getJdbcServices().getDialect() ); + key[k] = columns.get(k).getQuotedName( dialect ); } keyColumns.add( key ); } @@ -221,8 +221,8 @@ public class UnionSubclassEntityPersister extends AbstractEntityPersister { constraintOrderedKeyColumnNames = ArrayHelper.to2DStringArray( keyColumns ); } else { - constraintOrderedTableNames = new String[] {tableName}; - constraintOrderedKeyColumnNames = new String[][] {getIdentifierColumnNames()}; + constraintOrderedTableNames = new String[] { tableName }; + constraintOrderedKeyColumnNames = new String[][] { getIdentifierColumnNames() }; } initSubclassPropertyAliasesMap( persistentClass );