From 67d751d81df2445656ff0a451929ce5c33c9e7c3 Mon Sep 17 00:00:00 2001 From: Christian Beikov Date: Tue, 22 Nov 2022 18:37:11 +0100 Subject: [PATCH] Cleanup embeddable expression handling and resolving of column references --- .../SybaseASELegacySqlAstTranslator.java | 7 +- .../dialect/SybaseASESqlAstTranslator.java | 7 +- ...regateWindowEmulationQueryTransformer.java | 15 +- .../ast/internal/AbstractNaturalIdLoader.java | 10 +- .../internal/DatabaseSnapshotExecutor.java | 11 +- .../ast/internal/LoaderSelectBuilder.java | 58 ++----- .../internal/LoaderSqlAstCreationState.java | 13 +- .../AbstractCompositeIdentifierMapping.java | 12 +- .../metamodel/mapping/MappingModelHelper.java | 16 +- .../mapping/internal/AbstractDomainPath.java | 22 +-- .../internal/AnyDiscriminatorPart.java | 12 +- .../mapping/internal/AnyKeyPart.java | 12 +- .../internal/BasicAttributeMapping.java | 11 +- .../BasicEntityIdentifierMappingImpl.java | 12 +- .../internal/BasicValuedCollectionPart.java | 11 +- ...CaseStatementDiscriminatorMappingImpl.java | 3 +- .../CollectionIdentifierDescriptorImpl.java | 30 +--- .../internal/EmbeddedAttributeMapping.java | 11 +- .../internal/EmbeddedCollectionPart.java | 8 +- .../EmbeddedForeignKeyDescriptor.java | 7 +- .../internal/EntityRowIdMappingImpl.java | 22 +-- .../internal/EntityVersionMappingImpl.java | 26 +--- ...xplicitColumnDiscriminatorMappingImpl.java | 15 +- ...InverseNonAggregatedIdentifierMapping.java | 12 +- .../NonAggregatedIdentifierMappingImpl.java | 12 +- .../internal/SimpleForeignKeyDescriptor.java | 21 +-- .../mapping/ordering/ast/ColumnReference.java | 3 +- .../AbstractCollectionPersister.java | 3 +- .../entity/AbstractEntityPersister.java | 8 +- .../entity/SingleTableEntityPersister.java | 3 +- .../entity/UnionSubclassEntityPersister.java | 2 +- .../AnonymousTupleBasicValuedModelPart.java | 9 +- ...onymousTupleEmbeddableValuedModelPart.java | 12 +- .../AnonymousTupleEntityValuedModelPart.java | 15 +- .../query/results/ResultsHelper.java | 26 ++++ .../complete/CompleteFetchBuilder.java | 4 + .../CompleteFetchBuilderBasicPart.java | 21 ++- ...FetchBuilderEmbeddableValuedModelPart.java | 21 ++- ...leteFetchBuilderEntityValuedModelPart.java | 17 +- .../CompleteResultBuilderBasicModelPart.java | 15 +- ...leteResultBuilderBasicValuedConverted.java | 32 +--- ...pleteResultBuilderBasicValuedStandard.java | 46 +----- ...mpleteResultBuilderCollectionStandard.java | 18 +-- .../DelayedFetchBuilderBasicPart.java | 7 + .../dynamic/DynamicFetchBuilderLegacy.java | 41 ++--- .../dynamic/DynamicFetchBuilderStandard.java | 13 +- .../DynamicResultBuilderAttribute.java | 19 ++- .../DynamicResultBuilderEntityStandard.java | 121 +++++++++++---- .../implicit/ImplicitFetchBuilderBasic.java | 16 +- .../internal/MatchingIdSelectionHelper.java | 10 +- .../cte/AbstractCteMutationHandler.java | 6 +- .../internal/cte/CteDeleteHandler.java | 6 +- .../internal/cte/CteInsertHandler.java | 57 +++---- .../internal/cte/CteUpdateHandler.java | 6 +- .../InPredicateRestrictionProducer.java | 6 +- .../internal/inline/InlineUpdateHandler.java | 18 +-- .../ExecuteWithTemporaryTableHelper.java | 24 +-- .../ExecuteWithoutIdTableHelper.java | 8 +- .../temptable/InsertExecutionDelegate.java | 36 ++--- .../RestrictedDeleteExecutionDelegate.java | 11 +- .../temptable/TableBasedInsertHandler.java | 17 +- .../temptable/UpdateExecutionDelegate.java | 6 +- .../sqm/sql/BaseSqmToSqlAstConverter.java | 112 ++++---------- .../BasicValuedPathInterpretation.java | 11 +- ...iminatedAssociationPathInterpretation.java | 8 +- ...atedAssociationTypePathInterpretation.java | 11 +- .../internal/EmbeddableValuedExpression.java | 117 ++++++++++++++ .../EntityValuedPathInterpretation.java | 40 +---- .../sql/ast/spi/AbstractSqlAstTranslator.java | 55 +++---- .../sql/ast/spi/SqlExpressionResolver.java | 21 ++- .../ast/tree/expression/ColumnReference.java | 38 ++--- .../ast/tree/from/NamedTableReference.java | 4 +- .../tree/from/SyntheticVirtualTableGroup.java | 92 ----------- .../sql/ast/tree/from/TableReference.java | 4 +- .../ast/tree/from/UnionTableReference.java | 19 +++ .../EmbeddableExpressionResultImpl.java | 145 ++++++++++++++++++ .../orm/test/query/QueryTimeOutTest.java | 35 +---- 77 files changed, 792 insertions(+), 999 deletions(-) create mode 100644 hibernate-core/src/main/java/org/hibernate/query/sqm/sql/internal/EmbeddableValuedExpression.java delete mode 100644 hibernate-core/src/main/java/org/hibernate/sql/ast/tree/from/SyntheticVirtualTableGroup.java create mode 100644 hibernate-core/src/main/java/org/hibernate/sql/results/graph/embeddable/internal/EmbeddableExpressionResultImpl.java diff --git a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/SybaseASELegacySqlAstTranslator.java b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/SybaseASELegacySqlAstTranslator.java index 9cdba28296..de6d137234 100644 --- a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/SybaseASELegacySqlAstTranslator.java +++ b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/SybaseASELegacySqlAstTranslator.java @@ -358,9 +358,10 @@ public class SybaseASELegacySqlAstTranslator extends Ab ); } else { - appendSql( getCurrentDmlStatement().getTargetTable().getTableExpression() ); - appendSql( '.' ); - appendSql( columnReference.getColumnExpression() ); + columnReference.appendReadExpression( + this, + getCurrentDmlStatement().getTargetTable().getTableExpression() + ); } } else { diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/SybaseASESqlAstTranslator.java b/hibernate-core/src/main/java/org/hibernate/dialect/SybaseASESqlAstTranslator.java index 83ecde4ee6..7eae387ee5 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/SybaseASESqlAstTranslator.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/SybaseASESqlAstTranslator.java @@ -344,9 +344,10 @@ public class SybaseASESqlAstTranslator extends Abstract ); } else { - appendSql( getCurrentDmlStatement().getTargetTable().getTableExpression() ); - appendSql( '.' ); - appendSql( columnReference.getColumnExpression() ); + columnReference.appendReadExpression( + this, + getCurrentDmlStatement().getTargetTable().getTableExpression() + ); } } else { diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/function/AggregateWindowEmulationQueryTransformer.java b/hibernate-core/src/main/java/org/hibernate/dialect/function/AggregateWindowEmulationQueryTransformer.java index 0a5441f427..ba36b35126 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/function/AggregateWindowEmulationQueryTransformer.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/function/AggregateWindowEmulationQueryTransformer.java @@ -123,8 +123,7 @@ public class AggregateWindowEmulationQueryTransformer implements QueryTransforme false, null, null, - mapping.getJdbcMapping(), - factory + mapping.getJdbcMapping() ); final Expression expression = subSelections.get( i ).getExpression(); final Expression finalExpression; @@ -194,8 +193,7 @@ public class AggregateWindowEmulationQueryTransformer implements QueryTransforme false, null, null, - jdbcMapping, - factory + jdbcMapping ); final int subValuesPosition = subSelectClause.getSqlSelections().size(); final SqlSelection subSelection = new ResolvedSqlSelection( @@ -259,8 +257,7 @@ public class AggregateWindowEmulationQueryTransformer implements QueryTransforme false, null, null, - jdbcMapping, - factory + jdbcMapping ); final int subValuesPosition = subSelectClause.getSqlSelections().size(); final SqlSelection subSelection = new ResolvedSqlSelection( @@ -321,8 +318,7 @@ public class AggregateWindowEmulationQueryTransformer implements QueryTransforme false, null, null, - jdbcMapping, - factory + jdbcMapping ); final int subValuesPosition = subSelectClause.getSqlSelections().size(); final SqlSelection subSelection = new ResolvedSqlSelection( @@ -379,8 +375,7 @@ public class AggregateWindowEmulationQueryTransformer implements QueryTransforme false, null, null, - mapping.getJdbcMapping(), - factory + mapping.getJdbcMapping() ) ); } diff --git a/hibernate-core/src/main/java/org/hibernate/loader/ast/internal/AbstractNaturalIdLoader.java b/hibernate-core/src/main/java/org/hibernate/loader/ast/internal/AbstractNaturalIdLoader.java index 0f042d3fae..df4183a8ef 100644 --- a/hibernate-core/src/main/java/org/hibernate/loader/ast/internal/AbstractNaturalIdLoader.java +++ b/hibernate-core/src/main/java/org/hibernate/loader/ast/internal/AbstractNaturalIdLoader.java @@ -290,14 +290,7 @@ public abstract class AbstractNaturalIdLoader implements NaturalIdLoader { ) ); } - return sqlExpressionResolver.resolveSqlExpression( - SqlExpressionResolver.createColumnReferenceKey( tableReference, selectableMapping.getSelectionExpression() ), - (processingState) -> new ColumnReference( - tableReference, - selectableMapping, - sessionFactory - ) - ); + return sqlExpressionResolver.resolveSqlExpression( tableReference, selectableMapping ); } @Override @@ -423,7 +416,6 @@ public abstract class AbstractNaturalIdLoader implements NaturalIdLoader { private static List visitFetches( FetchParent fetchParent, - QuerySpec querySpec, LoaderSqlAstCreationState creationState) { final FetchableContainer fetchableContainer = fetchParent.getReferencedMappingContainer(); final int size = fetchableContainer.getNumberOfFetchables(); diff --git a/hibernate-core/src/main/java/org/hibernate/loader/ast/internal/DatabaseSnapshotExecutor.java b/hibernate-core/src/main/java/org/hibernate/loader/ast/internal/DatabaseSnapshotExecutor.java index 7de5d1ff1f..9b3f08f219 100644 --- a/hibernate-core/src/main/java/org/hibernate/loader/ast/internal/DatabaseSnapshotExecutor.java +++ b/hibernate-core/src/main/java/org/hibernate/loader/ast/internal/DatabaseSnapshotExecutor.java @@ -77,7 +77,7 @@ class DatabaseSnapshotExecutor { sqlAliasBaseManager, new FromClauseIndex( null ), LockOptions.NONE, - (fetchParent, ast, creationState) -> Collections.emptyList(), + (fetchParent, creationState) -> Collections.emptyList(), true, sessionFactory ); @@ -122,14 +122,7 @@ class DatabaseSnapshotExecutor { jdbcParameters.add( jdbcParameter ); final ColumnReference columnReference = (ColumnReference) sqlExpressionResolver - .resolveSqlExpression( - createColumnReferenceKey( tableReference, selection.getSelectionExpression() ), - s -> new ColumnReference( - tableReference, - selection, - sessionFactory - ) - ); + .resolveSqlExpression( tableReference, selection ); rootQuerySpec.applyPredicate( new ComparisonPredicate( diff --git a/hibernate-core/src/main/java/org/hibernate/loader/ast/internal/LoaderSelectBuilder.java b/hibernate-core/src/main/java/org/hibernate/loader/ast/internal/LoaderSelectBuilder.java index efdb8e53f9..480aed4224 100644 --- a/hibernate-core/src/main/java/org/hibernate/loader/ast/internal/LoaderSelectBuilder.java +++ b/hibernate-core/src/main/java/org/hibernate/loader/ast/internal/LoaderSelectBuilder.java @@ -56,6 +56,7 @@ import org.hibernate.sql.ast.spi.SimpleFromClauseAccessImpl; import org.hibernate.sql.ast.spi.SqlAliasBaseManager; import org.hibernate.sql.ast.spi.SqlAstCreationContext; import org.hibernate.sql.ast.spi.SqlAstCreationState; +import org.hibernate.sql.ast.spi.SqlAstQueryPartProcessingState; import org.hibernate.sql.ast.spi.SqlExpressionResolver; import org.hibernate.sql.ast.tree.expression.ColumnReference; import org.hibernate.sql.ast.tree.expression.Expression; @@ -513,13 +514,8 @@ public class LoaderSelectBuilder { navigablePath, selection.getContainingTableExpression() ); final ColumnReference columnRef = (ColumnReference) sqlExpressionResolver.resolveSqlExpression( - createColumnReferenceKey( tableReference, selection.getSelectionExpression() ), - p -> new ColumnReference( - tableReference, - selection, - creationContext.getSessionFactory() - ) - + tableReference, + selection ); if ( numberOfKeysToLoad == 1 ) { final JdbcParameter jdbcParameter = new JdbcParameterImpl( selection.getJdbcMapping() ); @@ -552,12 +548,8 @@ public class LoaderSelectBuilder { final TableReference tableReference = rootTableGroup.resolveTableReference( navigablePath, selection.getContainingTableExpression() ); columnReferences.add( (ColumnReference) sqlExpressionResolver.resolveSqlExpression( - createColumnReferenceKey( tableReference, selection.getSelectionExpression() ), - p -> new ColumnReference( - tableReference, - selection, - creationContext.getSessionFactory() - ) + tableReference, + selection ) ); } @@ -656,10 +648,7 @@ public class LoaderSelectBuilder { orderByFragments.add( new AbstractMap.SimpleEntry<>( orderByFragment, tableGroup ) ); } - private List visitFetches( - FetchParent fetchParent, - QuerySpec querySpec, - LoaderSqlAstCreationState creationState) { + private List visitFetches(FetchParent fetchParent, LoaderSqlAstCreationState creationState) { if ( log.isTraceEnabled() ) { log.tracef( "Starting visitation of FetchParent's Fetchables : %s", fetchParent.getNavigablePath() ); } @@ -667,7 +656,6 @@ public class LoaderSelectBuilder { final List fetches = new ArrayList<>(); final BiConsumer processor = createFetchableBiConsumer( fetchParent, - querySpec, creationState, fetches ); @@ -688,7 +676,6 @@ public class LoaderSelectBuilder { private BiConsumer createFetchableBiConsumer( FetchParent fetchParent, - QuerySpec querySpec, LoaderSqlAstCreationState creationState, List fetches) { return (fetchable, isKeyFetchable) -> { @@ -858,6 +845,7 @@ public class LoaderSelectBuilder { hasCollectionJoinFetches = true; final TableGroup joinTableGroup = creationState.getFromClauseAccess() .getTableGroup( fetchablePath ); + final QuerySpec querySpec = creationState.getInflightQueryPart().getFirstQuerySpec(); applyFiltering( querySpec, joinTableGroup, @@ -1038,16 +1026,8 @@ public class LoaderSelectBuilder { simpleFkDescriptor.getContainingTableExpression() ); fkExpression = sqlAstCreationState.getSqlExpressionResolver().resolveSqlExpression( - createColumnReferenceKey( tableReference, simpleFkDescriptor.getSelectionExpression() ), - sqlAstProcessingState -> new ColumnReference( - tableReference, - simpleFkDescriptor.getSelectionExpression(), - false, - null, - null, - simpleFkDescriptor.getJdbcMapping(), - this.creationContext.getSessionFactory() - ) + tableReference, + simpleFkDescriptor ); } else { @@ -1060,17 +1040,7 @@ public class LoaderSelectBuilder { ); columnReferences.add( (ColumnReference) sqlAstCreationState.getSqlExpressionResolver() - .resolveSqlExpression( - createColumnReferenceKey( - tableReference, - selection.getSelectionExpression() - ), - sqlAstProcessingState -> new ColumnReference( - tableReference, - selection, - this.creationContext.getSessionFactory() - ) - ) + .resolveSqlExpression( tableReference, selection ) ); } ); @@ -1121,12 +1091,8 @@ public class LoaderSelectBuilder { // for each column, resolve a SqlSelection and add it to the sub-query select-clause final TableReference tableReference = ownerTableGroup.resolveTableReference( navigablePath, selection.getContainingTableExpression() ); final Expression expression = sqlExpressionResolver.resolveSqlExpression( - createColumnReferenceKey( tableReference, selection.getSelectionExpression() ), - sqlAstProcessingState -> new ColumnReference( - tableReference, - selection, - sessionFactory - ) + tableReference, + selection ); subQuery.getSelectClause().addSqlSelection( new SqlSelectionImpl( diff --git a/hibernate-core/src/main/java/org/hibernate/loader/ast/internal/LoaderSqlAstCreationState.java b/hibernate-core/src/main/java/org/hibernate/loader/ast/internal/LoaderSqlAstCreationState.java index 65111bcfb5..f16ceccb96 100644 --- a/hibernate-core/src/main/java/org/hibernate/loader/ast/internal/LoaderSqlAstCreationState.java +++ b/hibernate-core/src/main/java/org/hibernate/loader/ast/internal/LoaderSqlAstCreationState.java @@ -32,9 +32,9 @@ import org.hibernate.sql.ast.spi.SqlAliasBaseManager; import org.hibernate.sql.ast.spi.SqlAstCreationContext; import org.hibernate.sql.ast.spi.SqlAstCreationState; import org.hibernate.sql.ast.spi.SqlAstProcessingState; +import org.hibernate.sql.ast.spi.SqlAstQueryPartProcessingState; import org.hibernate.sql.ast.spi.SqlExpressionResolver; import org.hibernate.sql.ast.tree.select.QueryPart; -import org.hibernate.sql.ast.tree.select.QuerySpec; import org.hibernate.sql.results.graph.DomainResultCreationState; import org.hibernate.sql.results.graph.Fetch; import org.hibernate.sql.results.graph.FetchParent; @@ -43,9 +43,9 @@ import org.hibernate.sql.results.graph.FetchParent; * Helper used when generating the database-snapshot select query */ public class LoaderSqlAstCreationState - implements SqlAstProcessingState, SqlAstCreationState, DomainResultCreationState, QueryOptions { + implements SqlAstQueryPartProcessingState, SqlAstCreationState, DomainResultCreationState, QueryOptions { public interface FetchProcessor { - List visitFetches(FetchParent fetchParent, QuerySpec querySpec, LoaderSqlAstCreationState creationState); + List visitFetches(FetchParent fetchParent, LoaderSqlAstCreationState creationState); } private final SqlAliasBaseManager sqlAliasBaseManager; @@ -93,6 +93,11 @@ public class LoaderSqlAstCreationState return this; } + @Override + public QueryPart getInflightQueryPart() { + return processingState.getInflightQueryPart(); + } + @Override public SqlExpressionResolver getSqlExpressionResolver() { return processingState; @@ -115,7 +120,7 @@ public class LoaderSqlAstCreationState @Override public List visitFetches(FetchParent fetchParent) { - return fetchProcessor.visitFetches( fetchParent, processingState.getInflightQueryPart().getFirstQuerySpec(), this ); + return fetchProcessor.visitFetches( fetchParent, this ); } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/AbstractCompositeIdentifierMapping.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/AbstractCompositeIdentifierMapping.java index b792b4ac6e..0127cec8f9 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/AbstractCompositeIdentifierMapping.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/AbstractCompositeIdentifierMapping.java @@ -238,17 +238,7 @@ public abstract class AbstractCompositeIdentifierMapping ? defaultTableReference : tableGroup.resolveTableReference( navigablePath, selection.getContainingTableExpression() ); final Expression columnReference = sqlAstCreationState.getSqlExpressionResolver() - .resolveSqlExpression( - SqlExpressionResolver.createColumnReferenceKey( - tableReference, - selection.getSelectionExpression() - ), - sqlAstProcessingState -> new ColumnReference( - tableReference.getIdentificationVariable(), - selection, - sqlAstCreationState.getCreationContext().getSessionFactory() - ) - ); + .resolveSqlExpression( tableReference, selection ); columnReferences.add( (ColumnReference) columnReference ); } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/MappingModelHelper.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/MappingModelHelper.java index 99b0efdd29..cc1a2ba170 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/MappingModelHelper.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/MappingModelHelper.java @@ -57,17 +57,15 @@ public class MappingModelHelper { if ( sqlExpressionResolver == null ) { colRef = new ColumnReference( qualifier, - selection, - sessionFactory + selection ); } else { colRef = (ColumnReference) sqlExpressionResolver.resolveSqlExpression( - createColumnReferenceKey( qualifier, selection.getSelectionExpression() ), + createColumnReferenceKey( qualifier, selection ), sqlAstProcessingState -> new ColumnReference( qualifier, - selection, - sessionFactory + selection ) ); } @@ -89,17 +87,15 @@ public class MappingModelHelper { if ( sqlExpressionResolver == null ) { return new ColumnReference( qualifier, - basicPart, - sessionFactory + basicPart ); } else { return sqlExpressionResolver.resolveSqlExpression( - createColumnReferenceKey( qualifier, basicPart.getSelectionExpression() ), + createColumnReferenceKey( qualifier, basicPart ), sqlAstProcessingState -> new ColumnReference( qualifier, - basicPart, - sessionFactory + basicPart ) ); } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/AbstractDomainPath.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/AbstractDomainPath.java index d1e7b76735..d7f64661ee 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/AbstractDomainPath.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/AbstractDomainPath.java @@ -31,6 +31,8 @@ import org.hibernate.sql.ast.tree.select.QuerySpec; import org.hibernate.sql.ast.tree.select.SortSpecification; import org.hibernate.sql.results.graph.Fetchable; +import static org.hibernate.sql.ast.spi.SqlExpressionResolver.createColumnReferenceKey; + /** * @author Andrea Boriero */ @@ -62,14 +64,10 @@ public abstract class AbstractDomainPath implements DomainPath { final BasicValuedModelPart selection = (BasicValuedModelPart) referenceModelPart; final TableReference tableReference = tableGroup.resolveTableReference( getNavigablePath(), selection.getContainingTableExpression() ); return creationState.getSqlExpressionResolver().resolveSqlExpression( - SqlExpressionResolver.createColumnReferenceKey( + createColumnReferenceKey( tableReference, selection.getSelectionExpression() ), + processingState -> new ColumnReference( tableReference, - selection.getSelectionExpression() - ), - sqlAstProcessingState -> new ColumnReference( - tableReference, - selection, - creationState.getCreationContext().getSessionFactory() + selection ) ); } @@ -247,14 +245,10 @@ public abstract class AbstractDomainPath implements DomainPath { SqlAstCreationState creationState) { final TableReference tableReference = tableGroup.resolveTableReference( getNavigablePath(), selection.getContainingTableExpression() ); final Expression expression = creationState.getSqlExpressionResolver().resolveSqlExpression( - SqlExpressionResolver.createColumnReferenceKey( + createColumnReferenceKey( tableReference, selection.getSelectionExpression() ), + processingState -> new ColumnReference( tableReference, - selection.getSelectionExpression() - ), - sqlAstProcessingState -> new ColumnReference( - tableReference, - selection, - creationState.getCreationContext().getSessionFactory() + selection ) ); // It makes no sense to order by an expression multiple times diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/AnyDiscriminatorPart.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/AnyDiscriminatorPart.java index 2446ec41bc..9ab26ca262 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/AnyDiscriminatorPart.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/AnyDiscriminatorPart.java @@ -260,16 +260,8 @@ public class AnyDiscriminatorPart implements BasicValuedModelPart, FetchOptions, final TableGroup tableGroup = fromClauseAccess.getTableGroup( fetchablePath.getParent().getParent() ); final TableReference tableReference = tableGroup.resolveTableReference( fetchablePath, table ); final Expression columnReference = sqlExpressionResolver.resolveSqlExpression( - createColumnReferenceKey( tableReference, column ), - processingState -> new ColumnReference( - tableReference, - column, - false, - null, - null, - jdbcMapping(), - sessionFactory - ) + tableReference, + this ); final SqlSelection sqlSelection = sqlExpressionResolver.resolveSqlSelection( columnReference, diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/AnyKeyPart.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/AnyKeyPart.java index eedacda4c7..8f6ceff73e 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/AnyKeyPart.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/AnyKeyPart.java @@ -184,16 +184,8 @@ public class AnyKeyPart implements BasicValuedModelPart, FetchOptions { final TableReference tableReference = tableGroup.resolveTableReference( fetchablePath, table ); final Expression columnReference = sqlExpressionResolver.resolveSqlExpression( - SqlExpressionResolver.createColumnReferenceKey( tableReference, column ), - processingState -> new ColumnReference( - tableReference, - column, - false, - null, - null, - jdbcMapping, - sessionFactory - ) + tableReference, + this ); final SqlSelection sqlSelection = sqlExpressionResolver.resolveSqlSelection( diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/BasicAttributeMapping.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/BasicAttributeMapping.java index 67f3dd9a36..3482cff490 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/BasicAttributeMapping.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/BasicAttributeMapping.java @@ -262,15 +262,8 @@ public class BasicAttributeMapping return expressionResolver.resolveSqlSelection( expressionResolver.resolveSqlExpression( - SqlExpressionResolver.createColumnReferenceKey( - tableReference, - mappedColumnExpression - ), - sqlAstProcessingState -> new ColumnReference( - tableReference, - this, - creationState.getSqlAstCreationState().getCreationContext().getSessionFactory() - ) + tableReference, + this ), jdbcMapping.getJdbcJavaType(), fetchParent, diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/BasicEntityIdentifierMappingImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/BasicEntityIdentifierMappingImpl.java index 4055d77f08..b4c6981ae2 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/BasicEntityIdentifierMappingImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/BasicEntityIdentifierMappingImpl.java @@ -260,16 +260,8 @@ public class BasicEntityIdentifierMappingImpl implements BasicEntityIdentifierMa } final Expression expression = expressionResolver.resolveSqlExpression( - SqlExpressionResolver.createColumnReferenceKey( rootTableReference, pkColumnName ), - sqlAstProcessingState -> new ColumnReference( - rootTableReference, - pkColumnName, - false, - null, - null, - ( (BasicValuedMapping) entityPersister.getIdentifierType() ).getJdbcMapping(), - sessionFactory - ) + rootTableReference, + this ); return expressionResolver.resolveSqlSelection( diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/BasicValuedCollectionPart.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/BasicValuedCollectionPart.java index b45953ec19..ac36a12f9b 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/BasicValuedCollectionPart.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/BasicValuedCollectionPart.java @@ -175,15 +175,8 @@ public class BasicValuedCollectionPart ); return exprResolver.resolveSqlSelection( exprResolver.resolveSqlExpression( - SqlExpressionResolver.createColumnReferenceKey( - tableReference, - selectableMapping.getSelectionExpression() - ), - sqlAstProcessingState -> new ColumnReference( - tableReference, - selectableMapping, - creationState.getSqlAstCreationState().getCreationContext().getSessionFactory() - ) + tableReference, + selectableMapping ), getJdbcMapping().getJdbcJavaType(), fetchParent, diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/CaseStatementDiscriminatorMappingImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/CaseStatementDiscriminatorMappingImpl.java index 4072ed7843..fb32b597d5 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/CaseStatementDiscriminatorMappingImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/CaseStatementDiscriminatorMappingImpl.java @@ -149,8 +149,7 @@ public class CaseStatementDiscriminatorMappingImpl extends AbstractDiscriminator false, null, null, - getJdbcMapping(), - getSessionFactory() + getJdbcMapping() ), true ); diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/CollectionIdentifierDescriptorImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/CollectionIdentifierDescriptorImpl.java index bf113fb260..2244fcbc40 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/CollectionIdentifierDescriptorImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/CollectionIdentifierDescriptorImpl.java @@ -216,19 +216,8 @@ public class CollectionIdentifierDescriptorImpl implements CollectionIdentifierD final SqlSelection sqlSelection = sqlExpressionResolver.resolveSqlSelection( sqlExpressionResolver.resolveSqlExpression( - SqlExpressionResolver.createColumnReferenceKey( - tableGroup.getPrimaryTableReference(), - columnName - ), - p -> new ColumnReference( - tableGroup.getPrimaryTableReference().getIdentificationVariable(), - columnName, - false, - null, - null, - type, - sessionFactory - ) + tableGroup.getPrimaryTableReference(), + this ), type.getJdbcJavaType(), fetchParent, @@ -256,19 +245,8 @@ public class CollectionIdentifierDescriptorImpl implements CollectionIdentifierD final SqlSelection sqlSelection = sqlExpressionResolver.resolveSqlSelection( sqlExpressionResolver.resolveSqlExpression( - SqlExpressionResolver.createColumnReferenceKey( - tableGroup.getPrimaryTableReference(), - columnName - ), - p -> new ColumnReference( - tableGroup.getPrimaryTableReference().getIdentificationVariable(), - columnName, - false, - null, - null, - type, - sessionFactory - ) + tableGroup.getPrimaryTableReference(), + this ), type.getJdbcJavaType(), null, diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/EmbeddedAttributeMapping.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/EmbeddedAttributeMapping.java index 2e74923f9d..1d10ad22f4 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/EmbeddedAttributeMapping.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/EmbeddedAttributeMapping.java @@ -260,15 +260,8 @@ public class EmbeddedAttributeMapping ? defaultTableReference : tableGroup.resolveTableReference( navigablePath, selection.getContainingTableExpression() ); final Expression columnReference = sqlAstCreationState.getSqlExpressionResolver().resolveSqlExpression( - SqlExpressionResolver.createColumnReferenceKey( - tableReference, - selection.getSelectionExpression() - ), - sqlAstProcessingState -> new ColumnReference( - tableReference.getIdentificationVariable(), - selection, - sqlAstCreationState.getCreationContext().getSessionFactory() - ) + tableReference, + selection ); columnReferences.add( columnReference.getColumnReference() ); diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/EmbeddedCollectionPart.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/EmbeddedCollectionPart.java index e57f4acd4b..f3197f731a 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/EmbeddedCollectionPart.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/EmbeddedCollectionPart.java @@ -207,12 +207,8 @@ public class EmbeddedCollectionPart implements CollectionPart, EmbeddableValuedF ); expressions.add( sqlExpressionResolver.resolveSqlExpression( - SqlExpressionResolver.createColumnReferenceKey( tableReference, selection.getSelectionExpression() ), - sqlAstProcessingState -> new ColumnReference( - tableReference, - selection, - sqlAstCreationState.getCreationContext().getSessionFactory() - ) + tableReference, + selection ) ); } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/EmbeddedForeignKeyDescriptor.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/EmbeddedForeignKeyDescriptor.java index 56e1449632..b96a2740a9 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/EmbeddedForeignKeyDescriptor.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/EmbeddedForeignKeyDescriptor.java @@ -14,7 +14,6 @@ import java.util.function.IntFunction; import org.hibernate.engine.spi.SharedSessionContractImplementor; import org.hibernate.mapping.IndexedConsumer; import org.hibernate.metamodel.mapping.AssociationKey; -import org.hibernate.metamodel.mapping.AttributeMapping; import org.hibernate.metamodel.mapping.CompositeIdentifierMapping; import org.hibernate.metamodel.mapping.EmbeddableValuedModelPart; import org.hibernate.metamodel.mapping.EntityMappingType; @@ -369,14 +368,12 @@ public class EmbeddedForeignKeyDescriptor implements ForeignKeyDescriptor { final ComparisonPredicate comparisonPredicate = new ComparisonPredicate( new ColumnReference( targetSideReference, - selection, - creationContext.getSessionFactory() + selection ), ComparisonOperator.EQUAL, new ColumnReference( keySideReference, - keySelectableMappings.getSelectable( i ), - creationContext.getSessionFactory() + keySelectableMappings.getSelectable( i ) ) ); predicate.add( comparisonPredicate ); diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/EntityRowIdMappingImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/EntityRowIdMappingImpl.java index 114c066f76..3f34e3b341 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/EntityRowIdMappingImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/EntityRowIdMappingImpl.java @@ -21,7 +21,6 @@ import org.hibernate.sql.ast.Clause; import org.hibernate.sql.ast.spi.SqlAstCreationState; import org.hibernate.sql.ast.spi.SqlExpressionResolver; import org.hibernate.sql.ast.spi.SqlSelection; -import org.hibernate.sql.ast.tree.expression.ColumnReference; import org.hibernate.sql.ast.tree.from.TableGroup; import org.hibernate.sql.ast.tree.from.TableReference; import org.hibernate.sql.results.graph.DomainResult; @@ -89,22 +88,7 @@ public class EntityRowIdMappingImpl implements EntityRowIdMapping, SelectableMap final TableReference columnTableReference = tableGroup.resolveTableReference( navigablePath, tableExpression ); final SqlSelection sqlSelection = sqlExpressionResolver.resolveSqlSelection( - sqlExpressionResolver.resolveSqlExpression( - SqlExpressionResolver.createColumnReferenceKey( columnTableReference, rowIdName ), - sqlAstProcessingState -> new ColumnReference( - columnTableReference, - rowIdName, - false, - // todo (6.0) : allowing custom read / write transformers on ROW_ID might - // be an easy way to allow customization of the how ROW_ID is rendered - // - e.g. quickly testing whether that syntax works for a db without - // having to write a Dialect - null, - null, - rowIdType, - sqlAstCreationState.getCreationContext().getSessionFactory() - ) - ), + sqlExpressionResolver.resolveSqlExpression( columnTableReference, this ), rowIdType.getJdbcJavaType(), null, sqlAstCreationState.getCreationContext().getSessionFactory().getTypeConfiguration() @@ -174,7 +158,7 @@ public class EntityRowIdMappingImpl implements EntityRowIdMapping, SelectableMap @Override public String getCustomReadExpression() { - return rowIdName; + return null; } @Override @@ -204,7 +188,7 @@ public class EntityRowIdMappingImpl implements EntityRowIdMapping, SelectableMap @Override public boolean isFormula() { - return true; + return false; } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/EntityVersionMappingImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/EntityVersionMappingImpl.java index f263b86ea3..28c0855f90 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/EntityVersionMappingImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/EntityVersionMappingImpl.java @@ -214,18 +214,7 @@ public class EntityVersionMappingImpl implements EntityVersionMapping, FetchOpti final TableReference columnTableReference = tableGroup.resolveTableReference( fetchablePath, columnTableExpression ); final SqlSelection sqlSelection = sqlExpressionResolver.resolveSqlSelection( - sqlExpressionResolver.resolveSqlExpression( - SqlExpressionResolver.createColumnReferenceKey( columnTableReference, columnExpression ), - sqlAstProcessingState -> new ColumnReference( - columnTableReference, - columnExpression, - false, - null, - null, - versionBasicType, - sqlAstCreationState.getCreationContext().getSessionFactory() - ) - ), + sqlExpressionResolver.resolveSqlExpression( columnTableReference, this ), versionBasicType.getJdbcJavaType(), fetchParent, sqlAstCreationState.getCreationContext().getSessionFactory().getTypeConfiguration() @@ -288,18 +277,7 @@ public class EntityVersionMappingImpl implements EntityVersionMapping, FetchOpti ); return sqlExpressionResolver.resolveSqlSelection( - sqlExpressionResolver.resolveSqlExpression( - SqlExpressionResolver.createColumnReferenceKey( columnTableReference, columnExpression ), - sqlAstProcessingState -> new ColumnReference( - columnTableReference, - columnExpression, - false, - null, - null, - versionBasicType, - sqlAstCreationState.getCreationContext().getSessionFactory() - ) - ), + sqlExpressionResolver.resolveSqlExpression( columnTableReference, this ), versionBasicType.getJdbcJavaType(), null, sqlAstCreationState.getCreationContext().getSessionFactory().getTypeConfiguration() diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/ExplicitColumnDiscriminatorMappingImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/ExplicitColumnDiscriminatorMappingImpl.java index b063b37a67..66119bd0cd 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/ExplicitColumnDiscriminatorMappingImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/ExplicitColumnDiscriminatorMappingImpl.java @@ -69,20 +69,7 @@ public class ExplicitColumnDiscriminatorMappingImpl extends AbstractDiscriminato SqlAstCreationState creationState) { final SqlExpressionResolver expressionResolver = creationState.getSqlExpressionResolver(); final TableReference tableReference = tableGroup.resolveTableReference( navigablePath, tableExpression ); - final String selectionExpression = getSelectionExpression(); - return expressionResolver.resolveSqlExpression( - createColumnReferenceKey( tableReference, selectionExpression ), - sqlAstProcessingState -> new ColumnReference( - tableReference, - selectionExpression, - columnFormula != null, - null, - null, - getJdbcMapping(), - getSessionFactory() - - ) - ); + return expressionResolver.resolveSqlExpression( tableReference, this ); } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/InverseNonAggregatedIdentifierMapping.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/InverseNonAggregatedIdentifierMapping.java index cb8090ae1d..d3ed696010 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/InverseNonAggregatedIdentifierMapping.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/InverseNonAggregatedIdentifierMapping.java @@ -164,17 +164,7 @@ public class InverseNonAggregatedIdentifierMapping extends EmbeddedAttributeMapp selection.getContainingTableExpression() ); final Expression columnReference = sqlAstCreationState.getSqlExpressionResolver() - .resolveSqlExpression( - SqlExpressionResolver.createColumnReferenceKey( - tableReference, - selection.getSelectionExpression() - ), - sqlAstProcessingState -> new ColumnReference( - tableReference.getIdentificationVariable(), - selection, - sqlAstCreationState.getCreationContext().getSessionFactory() - ) - ); + .resolveSqlExpression( tableReference, selection ); columnReferences.add( (ColumnReference) columnReference ); } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/NonAggregatedIdentifierMappingImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/NonAggregatedIdentifierMappingImpl.java index b10cb567ae..3b55d781a6 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/NonAggregatedIdentifierMappingImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/NonAggregatedIdentifierMappingImpl.java @@ -190,17 +190,7 @@ public class NonAggregatedIdentifierMappingImpl extends AbstractCompositeIdentif selection.getContainingTableExpression() ); final Expression columnReference = sqlAstCreationState.getSqlExpressionResolver() - .resolveSqlExpression( - SqlExpressionResolver.createColumnReferenceKey( - tableReference, - selection.getSelectionExpression() - ), - sqlAstProcessingState -> new ColumnReference( - tableReference.getIdentificationVariable(), - selection, - sqlAstCreationState.getCreationContext().getSessionFactory() - ) - ); + .resolveSqlExpression( tableReference, selection ); columnReferences.add( (ColumnReference) columnReference ); } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/SimpleForeignKeyDescriptor.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/SimpleForeignKeyDescriptor.java index e70dda6d87..7447f6ee25 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/SimpleForeignKeyDescriptor.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/SimpleForeignKeyDescriptor.java @@ -259,21 +259,8 @@ public class SimpleForeignKeyDescriptor implements ForeignKeyDescriptor, BasicVa ); } - final String identificationVariable = tableReference.getIdentificationVariable(); - final SqlSelection sqlSelection = sqlExpressionResolver.resolveSqlSelection( - sqlExpressionResolver.resolveSqlExpression( - SqlExpressionResolver.createColumnReferenceKey( - tableReference, - selectableMapping.getSelectionExpression() - ), - s -> - new ColumnReference( - identificationVariable, - selectableMapping, - creationState.getSqlAstCreationState().getCreationContext().getSessionFactory() - ) - ), + sqlExpressionResolver.resolveSqlExpression( tableReference, selectableMapping ), selectableMapping.getJdbcMapping().getJdbcJavaType(), fetchParent, sqlAstCreationState.getCreationContext().getSessionFactory().getTypeConfiguration() @@ -295,14 +282,12 @@ public class SimpleForeignKeyDescriptor implements ForeignKeyDescriptor, BasicVa return new ComparisonPredicate( new ColumnReference( targetSideReference, - targetSide.getModelPart(), - creationContext.getSessionFactory() + targetSide.getModelPart() ), ComparisonOperator.EQUAL, new ColumnReference( keySideReference, - keySide.getModelPart(), - creationContext.getSessionFactory() + keySide.getModelPart() ) ); } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/ordering/ast/ColumnReference.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/ordering/ast/ColumnReference.java index deb26004bf..f54335ad62 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/ordering/ast/ColumnReference.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/ordering/ast/ColumnReference.java @@ -68,8 +68,7 @@ public class ColumnReference implements OrderingExpression, SequencePart { // is no need for the JdbcMapping null, null, - null, - creationState.getCreationContext().getSessionFactory() + null ) ); } diff --git a/hibernate-core/src/main/java/org/hibernate/persister/collection/AbstractCollectionPersister.java b/hibernate-core/src/main/java/org/hibernate/persister/collection/AbstractCollectionPersister.java index 57836d9835..941641d152 100644 --- a/hibernate-core/src/main/java/org/hibernate/persister/collection/AbstractCollectionPersister.java +++ b/hibernate-core/src/main/java/org/hibernate/persister/collection/AbstractCollectionPersister.java @@ -65,7 +65,6 @@ import org.hibernate.loader.ast.internal.CollectionLoaderSingleKey; import org.hibernate.loader.ast.internal.CollectionLoaderSubSelectFetch; import org.hibernate.loader.ast.internal.LoaderSqlAstCreationState; import org.hibernate.loader.ast.spi.CollectionLoader; -import org.hibernate.mapping.BasicValue; import org.hibernate.mapping.Collection; import org.hibernate.mapping.Column; import org.hibernate.mapping.Formula; @@ -1126,7 +1125,7 @@ public abstract class AbstractCollectionPersister new SqlAliasBaseManager(), new SimpleFromClauseAccessImpl(), LockOptions.NONE, - (fetchParent, querySpec, creationState) -> new ArrayList<>(), + (fetchParent, creationState) -> new ArrayList<>(), true, getFactory() ); diff --git a/hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java b/hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java index 73934ea4c9..49c71632fe 100644 --- a/hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java +++ b/hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java @@ -1489,8 +1489,7 @@ public abstract class AbstractEntityPersister false, null, null, - selection.getJdbcMapping(), - getFactory() + selection.getJdbcMapping() ) ); @@ -1506,8 +1505,7 @@ public abstract class AbstractEntityPersister false, null, null, - selection.getJdbcMapping(), - getFactory() + selection.getJdbcMapping() ) ); @@ -1970,7 +1968,7 @@ public abstract class AbstractEntityPersister return expression; } - private List fetchProcessor(FetchParent fetchParent, QuerySpec querySpec, LoaderSqlAstCreationState creationState) { + private List fetchProcessor(FetchParent fetchParent, LoaderSqlAstCreationState creationState) { final FetchableContainer fetchableContainer = fetchParent.getReferencedMappingContainer(); final int size = fetchableContainer.getNumberOfFetchables(); final List fetches = new ArrayList<>( size ); 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 a731be2aa2..ed89822e35 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 @@ -754,8 +754,7 @@ public class SingleTableEntityPersister extends AbstractEntityPersister { isDiscriminatorFormula(), null, null, - discriminatorType.getJdbcMapping(), - getFactory() + discriminatorType.getJdbcMapping() ) ); 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 9329624baf..47709045ed 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 @@ -538,7 +538,7 @@ public class UnionSubclassEntityPersister extends AbstractEntityPersister { buf.append( dialect.getSelectClauseNullString( sqlType, getFactory().getTypeConfiguration() ) ) .append( " as " ); } - new ColumnReference( (String) null, selectableMapping, getFactory() ).appendReadExpression( sqlAppender ); + new ColumnReference( (String) null, selectableMapping ).appendReadExpression( sqlAppender ); buf.append( ", " ); } buf.append( persister.getDiscriminatorSQLValue() ).append( " as clazz_" ); diff --git a/hibernate-core/src/main/java/org/hibernate/query/derived/AnonymousTupleBasicValuedModelPart.java b/hibernate-core/src/main/java/org/hibernate/query/derived/AnonymousTupleBasicValuedModelPart.java index 1813197bac..cf52a621ce 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/derived/AnonymousTupleBasicValuedModelPart.java +++ b/hibernate-core/src/main/java/org/hibernate/query/derived/AnonymousTupleBasicValuedModelPart.java @@ -189,14 +189,7 @@ public class AnonymousTupleBasicValuedModelPart implements ModelPart, MappingTyp navigablePath, getContainingTableExpression() ); - final Expression expression = expressionResolver.resolveSqlExpression( - createColumnReferenceKey( tableReference, getSelectionExpression() ), - sqlAstProcessingState -> new ColumnReference( - tableReference, - this, - creationState.getCreationContext().getSessionFactory() - ) - ); + final Expression expression = expressionResolver.resolveSqlExpression( tableReference, this ); return expressionResolver.resolveSqlSelection( expression, getJdbcMapping().getJdbcJavaType(), diff --git a/hibernate-core/src/main/java/org/hibernate/query/derived/AnonymousTupleEmbeddableValuedModelPart.java b/hibernate-core/src/main/java/org/hibernate/query/derived/AnonymousTupleEmbeddableValuedModelPart.java index 7e80c82fd1..9cbbd53e2f 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/derived/AnonymousTupleEmbeddableValuedModelPart.java +++ b/hibernate-core/src/main/java/org/hibernate/query/derived/AnonymousTupleEmbeddableValuedModelPart.java @@ -236,17 +236,7 @@ public class AnonymousTupleEmbeddableValuedModelPart implements EmbeddableValued modelPart.forEachSelectable( (columnIndex, selection) -> { final Expression columnReference = sqlAstCreationState.getSqlExpressionResolver() - .resolveSqlExpression( - SqlExpressionResolver.createColumnReferenceKey( - tableReference, - selection.getSelectionExpression() - ), - sqlAstProcessingState -> new ColumnReference( - tableReference.getIdentificationVariable(), - selection, - sqlAstCreationState.getCreationContext().getSessionFactory() - ) - ); + .resolveSqlExpression( tableReference, selection ); columnReferences.add( columnReference.getColumnReference() ); } diff --git a/hibernate-core/src/main/java/org/hibernate/query/derived/AnonymousTupleEntityValuedModelPart.java b/hibernate-core/src/main/java/org/hibernate/query/derived/AnonymousTupleEntityValuedModelPart.java index 21b068462d..0ab840e717 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/derived/AnonymousTupleEntityValuedModelPart.java +++ b/hibernate-core/src/main/java/org/hibernate/query/derived/AnonymousTupleEntityValuedModelPart.java @@ -10,7 +10,6 @@ import java.util.ArrayList; import java.util.Collection; import java.util.HashSet; import java.util.List; -import java.util.Locale; import java.util.Set; import java.util.function.BiConsumer; import java.util.function.Consumer; @@ -102,6 +101,11 @@ public class AnonymousTupleEntityValuedModelPart implements EntityValuedModelPar this.targetKeyPropertyNames = targetKeyPropertyNames; } + public ModelPart getForeignKeyPart() { + // todo: naming? + return identifierMapping; + } + @Override public ModelPart findSubPart(String name, EntityMappingType treatTargetType) { if ( identifierMapping instanceof SingleAttributeIdentifierMapping ) { @@ -310,8 +314,7 @@ public class AnonymousTupleEntityValuedModelPart implements EntityValuedModelPar ), state -> new ColumnReference( tableReference, - selectableMapping, - sessionFactory + selectableMapping ) ) ); @@ -331,8 +334,7 @@ public class AnonymousTupleEntityValuedModelPart implements EntityValuedModelPar ), state -> new ColumnReference( tableReference, - selectableMapping, - sessionFactory + selectableMapping ) ); } @@ -353,8 +355,7 @@ public class AnonymousTupleEntityValuedModelPart implements EntityValuedModelPar ComparisonOperator.EQUAL, new ColumnReference( targetTableReference, - targetMapping, - sessionFactory + targetMapping ) ) ); diff --git a/hibernate-core/src/main/java/org/hibernate/query/results/ResultsHelper.java b/hibernate-core/src/main/java/org/hibernate/query/results/ResultsHelper.java index aedf711cec..75803be62a 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/results/ResultsHelper.java +++ b/hibernate-core/src/main/java/org/hibernate/query/results/ResultsHelper.java @@ -7,14 +7,21 @@ package org.hibernate.query.results; import org.hibernate.metamodel.mapping.EntityIdentifierMapping; +import org.hibernate.metamodel.mapping.JdbcMapping; import org.hibernate.metamodel.mapping.ModelPart; +import org.hibernate.metamodel.mapping.SelectableMapping; import org.hibernate.metamodel.mapping.internal.SingleAttributeIdentifierMapping; import org.hibernate.spi.EntityIdentifierNavigablePath; +import org.hibernate.sql.ast.tree.expression.Expression; import org.hibernate.sql.ast.tree.from.TableGroup; +import org.hibernate.sql.ast.tree.from.TableReference; import org.hibernate.sql.results.graph.DomainResult; import org.hibernate.sql.results.graph.DomainResultCreationState; import org.hibernate.sql.results.graph.Fetch; import org.hibernate.sql.results.graph.basic.BasicFetch; +import org.hibernate.sql.results.jdbc.spi.JdbcValuesMetadata; + +import static org.hibernate.sql.ast.spi.SqlExpressionResolver.createColumnReferenceKey; /** * @author Steve Ebersole @@ -42,6 +49,25 @@ public class ResultsHelper { ); } + public static Expression resolveSqlExpression( + DomainResultCreationStateImpl resolver, + JdbcValuesMetadata jdbcValuesMetadata, + TableReference tableReference, + SelectableMapping selectableMapping, + String columnAlias) { + return resolver.resolveSqlExpression( + createColumnReferenceKey( + tableReference, + selectableMapping + ), + processingState -> { + final int jdbcPosition = jdbcValuesMetadata.resolveColumnPosition( columnAlias ); + final int valuesArrayPosition = jdbcPositionToValuesArrayPosition( jdbcPosition ); + return new ResultSetMappingSqlSelection( valuesArrayPosition, selectableMapping.getJdbcMapping() ); + } + ); + } + private ResultsHelper() { } diff --git a/hibernate-core/src/main/java/org/hibernate/query/results/complete/CompleteFetchBuilder.java b/hibernate-core/src/main/java/org/hibernate/query/results/complete/CompleteFetchBuilder.java index 26647c3cc4..74da9c395a 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/results/complete/CompleteFetchBuilder.java +++ b/hibernate-core/src/main/java/org/hibernate/query/results/complete/CompleteFetchBuilder.java @@ -6,6 +6,8 @@ */ package org.hibernate.query.results.complete; +import java.util.List; + import org.hibernate.query.results.FetchBuilder; import org.hibernate.sql.results.graph.Fetchable; @@ -15,4 +17,6 @@ import org.hibernate.sql.results.graph.Fetchable; public interface CompleteFetchBuilder extends FetchBuilder, ModelPartReference { @Override Fetchable getReferencedPart(); + + List getColumnAliases(); } diff --git a/hibernate-core/src/main/java/org/hibernate/query/results/complete/CompleteFetchBuilderBasicPart.java b/hibernate-core/src/main/java/org/hibernate/query/results/complete/CompleteFetchBuilderBasicPart.java index 205c197d67..f9673185f5 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/results/complete/CompleteFetchBuilderBasicPart.java +++ b/hibernate-core/src/main/java/org/hibernate/query/results/complete/CompleteFetchBuilderBasicPart.java @@ -6,11 +6,14 @@ */ package org.hibernate.query.results.complete; +import java.util.Collections; +import java.util.List; import java.util.Objects; import java.util.function.BiFunction; import org.hibernate.engine.FetchTiming; import org.hibernate.metamodel.mapping.BasicValuedModelPart; +import org.hibernate.query.results.ResultsHelper; import org.hibernate.spi.NavigablePath; import org.hibernate.query.results.BasicValuedFetchBuilder; import org.hibernate.query.results.DomainResultCreationStateImpl; @@ -62,6 +65,11 @@ public class CompleteFetchBuilderBasicPart implements CompleteFetchBuilder, Basi return referencedModelPart; } + @Override + public List getColumnAliases() { + return Collections.singletonList( selectionAlias ); + } + @Override public BasicFetch buildFetch( FetchParent parent, @@ -69,12 +77,11 @@ public class CompleteFetchBuilderBasicPart implements CompleteFetchBuilder, Basi JdbcValuesMetadata jdbcResultsMetadata, BiFunction legacyFetchResolver, DomainResultCreationState domainResultCreationState) { - final DomainResultCreationStateImpl creationState = impl( domainResultCreationState ); + final DomainResultCreationStateImpl creationStateImpl = impl( domainResultCreationState ); final String mappedTable = referencedModelPart.getContainingTableExpression(); - final String mappedColumn = referencedModelPart.getSelectionExpression(); - final TableGroup tableGroup = creationState.getFromClauseAccess().getTableGroup( parent.getNavigablePath() ); + final TableGroup tableGroup = creationStateImpl.getFromClauseAccess().getTableGroup( parent.getNavigablePath() ); final TableReference tableReference = tableGroup.resolveTableReference( navigablePath, mappedTable ); final String selectedAlias; @@ -94,20 +101,20 @@ public class CompleteFetchBuilderBasicPart implements CompleteFetchBuilder, Basi selectedAlias = selectionAlias; } else { - if ( ! creationState.arePositionalSelectionsAllowed() ) { + if ( ! creationStateImpl.arePositionalSelectionsAllowed() ) { throw new PositionalSelectionsNotAllowedException( "Positional SQL selection resolution not allowed" ); } - jdbcPosition = creationState.getNumberOfProcessedSelections(); + jdbcPosition = creationStateImpl.getNumberOfProcessedSelections() + 1; selectedAlias = jdbcResultsMetadata.resolveColumnName( jdbcPosition ); } final int valuesArrayPosition = jdbcPositionToValuesArrayPosition( jdbcPosition ); // we just care about the registration here. The ModelPart will find it later - creationState.resolveSqlExpression( - createColumnReferenceKey( tableReference, mappedColumn ), + creationStateImpl.resolveSqlExpression( + createColumnReferenceKey( tableReference, referencedModelPart ), processingState -> new ResultSetMappingSqlSelection( valuesArrayPosition, referencedModelPart ) ); diff --git a/hibernate-core/src/main/java/org/hibernate/query/results/complete/CompleteFetchBuilderEmbeddableValuedModelPart.java b/hibernate-core/src/main/java/org/hibernate/query/results/complete/CompleteFetchBuilderEmbeddableValuedModelPart.java index 71a5274326..ab3de15a98 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/results/complete/CompleteFetchBuilderEmbeddableValuedModelPart.java +++ b/hibernate-core/src/main/java/org/hibernate/query/results/complete/CompleteFetchBuilderEmbeddableValuedModelPart.java @@ -6,6 +6,7 @@ */ package org.hibernate.query.results.complete; +import java.util.Collections; import java.util.List; import java.util.function.BiFunction; @@ -14,6 +15,7 @@ import org.hibernate.metamodel.mapping.EmbeddableValuedModelPart; import org.hibernate.query.results.DomainResultCreationStateImpl; import org.hibernate.query.results.FetchBuilder; import org.hibernate.query.results.ResultSetMappingSqlSelection; +import org.hibernate.query.results.ResultsHelper; import org.hibernate.query.results.dynamic.DynamicFetchBuilderLegacy; import org.hibernate.spi.NavigablePath; import org.hibernate.sql.ast.spi.SqlExpressionResolver; @@ -66,6 +68,11 @@ public class CompleteFetchBuilderEmbeddableValuedModelPart return modelPart; } + @Override + public List getColumnAliases() { + return columnAliases; + } + @Override public Fetch buildFetch( FetchParent parent, @@ -80,16 +87,14 @@ public class CompleteFetchBuilderEmbeddableValuedModelPart modelPart.forEachSelectable( (selectionIndex, selectableMapping) -> { final TableReference tableReference = tableGroup.resolveTableReference( navigablePath, selectableMapping.getContainingTableExpression() ); - final String mappedColumn = selectableMapping.getSelectionExpression(); final String columnAlias = columnAliases.get( selectionIndex ); creationStateImpl.resolveSqlSelection( - creationStateImpl.resolveSqlExpression( - SqlExpressionResolver.createColumnReferenceKey( tableReference, mappedColumn ), - processingState -> { - final int jdbcPosition = jdbcResultsMetadata.resolveColumnPosition( columnAlias ); - final int valuesArrayPosition = jdbcPositionToValuesArrayPosition( jdbcPosition ); - return new ResultSetMappingSqlSelection( valuesArrayPosition, selectableMapping.getJdbcMapping() ); - } + ResultsHelper.resolveSqlExpression( + creationStateImpl, + jdbcResultsMetadata, + tableReference, + selectableMapping, + columnAlias ), selectableMapping.getJdbcMapping().getJdbcJavaType(), null, diff --git a/hibernate-core/src/main/java/org/hibernate/query/results/complete/CompleteFetchBuilderEntityValuedModelPart.java b/hibernate-core/src/main/java/org/hibernate/query/results/complete/CompleteFetchBuilderEntityValuedModelPart.java index 96b4d3ffe8..bbe8bbb5df 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/results/complete/CompleteFetchBuilderEntityValuedModelPart.java +++ b/hibernate-core/src/main/java/org/hibernate/query/results/complete/CompleteFetchBuilderEntityValuedModelPart.java @@ -6,10 +6,12 @@ */ package org.hibernate.query.results.complete; +import java.util.Collections; import java.util.List; import java.util.function.BiFunction; import org.hibernate.engine.FetchTiming; +import org.hibernate.query.results.ResultsHelper; import org.hibernate.spi.NavigablePath; import org.hibernate.query.results.DomainResultCreationStateImpl; import org.hibernate.query.results.FetchBuilder; @@ -66,6 +68,7 @@ public class CompleteFetchBuilderEntityValuedModelPart return modelPart; } + @Override public List getColumnAliases() { return columnAliases; } @@ -84,16 +87,14 @@ public class CompleteFetchBuilderEntityValuedModelPart modelPart.forEachSelectable( (selectionIndex, selectableMapping) -> { final TableReference tableReference = tableGroup.resolveTableReference( navigablePath, selectableMapping.getContainingTableExpression() ); - final String mappedColumn = selectableMapping.getSelectionExpression(); final String columnAlias = columnAliases.get( selectionIndex ); creationStateImpl.resolveSqlSelection( - creationStateImpl.resolveSqlExpression( - SqlExpressionResolver.createColumnReferenceKey( tableReference, mappedColumn ), - processingState -> { - final int jdbcPosition = jdbcResultsMetadata.resolveColumnPosition( columnAlias ); - final int valuesArrayPosition = jdbcPositionToValuesArrayPosition( jdbcPosition ); - return new ResultSetMappingSqlSelection( valuesArrayPosition, selectableMapping.getJdbcMapping() ); - } + ResultsHelper.resolveSqlExpression( + creationStateImpl, + jdbcResultsMetadata, + tableReference, + selectableMapping, + columnAlias ), selectableMapping.getJdbcMapping().getJdbcJavaType(), null, diff --git a/hibernate-core/src/main/java/org/hibernate/query/results/complete/CompleteResultBuilderBasicModelPart.java b/hibernate-core/src/main/java/org/hibernate/query/results/complete/CompleteResultBuilderBasicModelPart.java index 4242c17efe..44cfc57aae 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/results/complete/CompleteResultBuilderBasicModelPart.java +++ b/hibernate-core/src/main/java/org/hibernate/query/results/complete/CompleteResultBuilderBasicModelPart.java @@ -9,6 +9,7 @@ package org.hibernate.query.results.complete; import java.util.function.BiFunction; import org.hibernate.metamodel.mapping.BasicValuedModelPart; +import org.hibernate.query.results.ResultsHelper; import org.hibernate.spi.NavigablePath; import org.hibernate.query.results.DomainResultCreationStateImpl; import org.hibernate.query.results.ResultBuilder; @@ -75,16 +76,14 @@ public class CompleteResultBuilderBasicModelPart final TableGroup tableGroup = creationStateImpl.getFromClauseAccess().getTableGroup( navigablePath.getParent() ); final TableReference tableReference = tableGroup.resolveTableReference( navigablePath, modelPart.getContainingTableExpression() ); - final String mappedColumn = modelPart.getSelectionExpression(); final SqlSelection sqlSelection = creationStateImpl.resolveSqlSelection( - creationStateImpl.resolveSqlExpression( - SqlExpressionResolver.createColumnReferenceKey( tableReference, mappedColumn ), - processingState -> { - final int jdbcPosition = jdbcResultsMetadata.resolveColumnPosition( columnAlias ); - final int valuesArrayPosition = jdbcPositionToValuesArrayPosition( jdbcPosition ); - return new ResultSetMappingSqlSelection( valuesArrayPosition, modelPart ); - } + ResultsHelper.resolveSqlExpression( + creationStateImpl, + jdbcResultsMetadata, + tableReference, + modelPart, + columnAlias ), modelPart.getJdbcMapping().getJdbcJavaType(), null, diff --git a/hibernate-core/src/main/java/org/hibernate/query/results/complete/CompleteResultBuilderBasicValuedConverted.java b/hibernate-core/src/main/java/org/hibernate/query/results/complete/CompleteResultBuilderBasicValuedConverted.java index 0f27c89ba3..21044b6f12 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/results/complete/CompleteResultBuilderBasicValuedConverted.java +++ b/hibernate-core/src/main/java/org/hibernate/query/results/complete/CompleteResultBuilderBasicValuedConverted.java @@ -82,39 +82,9 @@ public class CompleteResultBuilderBasicValuedConverted implements CompleteR columnName = explicitColumnName; } else { - columnName = jdbcResultsMetadata.resolveColumnName( resultPosition + 1 ); + columnName = jdbcResultsMetadata.resolveColumnName( creationStateImpl.getNumberOfProcessedSelections() + 1 ); } - -// final int jdbcPosition; -// if ( explicitColumnName != null ) { -// jdbcPosition = jdbcResultsMetadata.resolveColumnPosition( explicitColumnName ); -// } -// else { -// jdbcPosition = resultPosition + 1; -// } -// -// final BasicValuedMapping basicType; -// if ( explicitType != null ) { -// basicType = explicitType; -// } -// else { -// basicType = jdbcResultsMetadata.resolveType( jdbcPosition, explicitJavaType ); -// } -// -// final SqlSelection sqlSelection = creationStateImpl.resolveSqlSelection( -// creationStateImpl.resolveSqlExpression( -// columnName, -// processingState -> { -// final int valuesArrayPosition = ResultsHelper.jdbcPositionToValuesArrayPosition( jdbcPosition ); -// return new SqlSelectionImpl( valuesArrayPosition, basicType ); -// } -// ), -// basicType.getExpressibleJavaType(), -// sessionFactory.getTypeConfiguration() -// ); - - final SqlSelection sqlSelection = creationStateImpl.resolveSqlSelection( creationStateImpl.resolveSqlExpression( columnName, diff --git a/hibernate-core/src/main/java/org/hibernate/query/results/complete/CompleteResultBuilderBasicValuedStandard.java b/hibernate-core/src/main/java/org/hibernate/query/results/complete/CompleteResultBuilderBasicValuedStandard.java index 7585f588ad..5e58acabb9 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/results/complete/CompleteResultBuilderBasicValuedStandard.java +++ b/hibernate-core/src/main/java/org/hibernate/query/results/complete/CompleteResultBuilderBasicValuedStandard.java @@ -72,56 +72,20 @@ public class CompleteResultBuilderBasicValuedStandard implements CompleteResultB DomainResultCreationState domainResultCreationState) { final DomainResultCreationStateImpl creationStateImpl = impl( domainResultCreationState ); final SessionFactoryImplementor sessionFactory = creationStateImpl.getSessionFactory(); - + final int jdbcPosition; final String columnName; if ( explicitColumnName != null ) { + jdbcPosition = jdbcResultsMetadata.resolveColumnPosition( explicitColumnName ); columnName = explicitColumnName; } else { - columnName = jdbcResultsMetadata.resolveColumnName( resultPosition + 1 ); + jdbcPosition = creationStateImpl.getNumberOfProcessedSelections() + 1; + columnName = jdbcResultsMetadata.resolveColumnName( jdbcPosition ); } - -// final int jdbcPosition; -// if ( explicitColumnName != null ) { -// jdbcPosition = jdbcResultsMetadata.resolveColumnPosition( explicitColumnName ); -// } -// else { -// jdbcPosition = resultPosition + 1; -// } -// -// final BasicValuedMapping basicType; -// if ( explicitType != null ) { -// basicType = explicitType; -// } -// else { -// basicType = jdbcResultsMetadata.resolveType( jdbcPosition, explicitJavaType ); -// } -// -// final SqlSelection sqlSelection = creationStateImpl.resolveSqlSelection( -// creationStateImpl.resolveSqlExpression( -// columnName, -// processingState -> { -// final int valuesArrayPosition = ResultsHelper.jdbcPositionToValuesArrayPosition( jdbcPosition ); -// return new SqlSelectionImpl( valuesArrayPosition, basicType ); -// } -// ), -// basicType.getExpressibleJavaType(), -// sessionFactory.getTypeConfiguration() -// ); - - final SqlSelection sqlSelection = creationStateImpl.resolveSqlSelection( creationStateImpl.resolveSqlExpression( columnName, processingState -> { - final int jdbcPosition; - if ( explicitColumnName != null ) { - jdbcPosition = jdbcResultsMetadata.resolveColumnPosition( explicitColumnName ); - } - else { - jdbcPosition = resultPosition + 1; - } - final BasicValuedMapping basicType; if ( explicitType != null ) { basicType = explicitType; @@ -144,7 +108,7 @@ public class CompleteResultBuilderBasicValuedStandard implements CompleteResultB ); final JdbcMapping jdbcMapping = sqlSelection.getExpressionType().getJdbcMappings().get( 0 ); - return new BasicResult( + return new BasicResult<>( sqlSelection.getValuesArrayPosition(), columnName, jdbcMapping diff --git a/hibernate-core/src/main/java/org/hibernate/query/results/complete/CompleteResultBuilderCollectionStandard.java b/hibernate-core/src/main/java/org/hibernate/query/results/complete/CompleteResultBuilderCollectionStandard.java index fc57cac181..502d2a5dea 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/results/complete/CompleteResultBuilderCollectionStandard.java +++ b/hibernate-core/src/main/java/org/hibernate/query/results/complete/CompleteResultBuilderCollectionStandard.java @@ -154,18 +154,12 @@ public class CompleteResultBuilderCollectionStandard implements CompleteResultBu final SelectableConsumer consumer = (selectionIndex, selectableMapping) -> { final String columnName = columnNames[selectionIndex]; creationStateImpl.resolveSqlSelection( - creationStateImpl.resolveSqlExpression( - SqlExpressionResolver.createColumnReferenceKey( - tableGroup.resolveTableReference( selectableMapping.getContainingTableExpression() ), - selectableMapping.getSelectionExpression() - ), - processingState -> { - final int jdbcPosition = jdbcResultsMetadata.resolveColumnPosition( columnName ); - final BasicValuedMapping basicType = (BasicValuedMapping) selectableMapping.getJdbcMapping(); - final int valuesArrayPosition = ResultsHelper.jdbcPositionToValuesArrayPosition( - jdbcPosition ); - return new ResultSetMappingSqlSelection( valuesArrayPosition, basicType ); - } + ResultsHelper.resolveSqlExpression( + creationStateImpl, + jdbcResultsMetadata, + tableGroup.resolveTableReference( selectableMapping.getContainingTableExpression() ), + selectableMapping, + columnName ), selectableMapping.getJdbcMapping().getJdbcJavaType(), null, diff --git a/hibernate-core/src/main/java/org/hibernate/query/results/complete/DelayedFetchBuilderBasicPart.java b/hibernate-core/src/main/java/org/hibernate/query/results/complete/DelayedFetchBuilderBasicPart.java index c8ed9199bd..62dfaa8624 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/results/complete/DelayedFetchBuilderBasicPart.java +++ b/hibernate-core/src/main/java/org/hibernate/query/results/complete/DelayedFetchBuilderBasicPart.java @@ -6,6 +6,8 @@ */ package org.hibernate.query.results.complete; +import java.util.Collections; +import java.util.List; import java.util.function.BiFunction; import org.hibernate.engine.FetchTiming; @@ -71,6 +73,11 @@ public class DelayedFetchBuilderBasicPart ); } + @Override + public List getColumnAliases() { + return Collections.emptyList(); + } + @Override public boolean equals(Object o) { if ( this == o ) { diff --git a/hibernate-core/src/main/java/org/hibernate/query/results/dynamic/DynamicFetchBuilderLegacy.java b/hibernate-core/src/main/java/org/hibernate/query/results/dynamic/DynamicFetchBuilderLegacy.java index 28c333fae3..8d15e93db6 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/results/dynamic/DynamicFetchBuilderLegacy.java +++ b/hibernate-core/src/main/java/org/hibernate/query/results/dynamic/DynamicFetchBuilderLegacy.java @@ -20,6 +20,7 @@ import org.hibernate.metamodel.mapping.CollectionPart; import org.hibernate.metamodel.mapping.ForeignKeyDescriptor; import org.hibernate.metamodel.mapping.JdbcMapping; import org.hibernate.metamodel.mapping.PluralAttributeMapping; +import org.hibernate.metamodel.mapping.SelectableMapping; import org.hibernate.metamodel.mapping.internal.ToOneAttributeMapping; import org.hibernate.query.NativeQuery; import org.hibernate.spi.NavigablePath; @@ -34,11 +35,14 @@ import org.hibernate.sql.ast.spi.SqlExpressionResolver; import org.hibernate.sql.ast.tree.from.TableGroup; import org.hibernate.sql.ast.tree.from.TableGroupJoin; import org.hibernate.sql.ast.tree.from.TableGroupJoinProducer; +import org.hibernate.sql.ast.tree.from.TableReference; import org.hibernate.sql.results.graph.DomainResultCreationState; import org.hibernate.sql.results.graph.Fetch; import org.hibernate.sql.results.graph.FetchParent; +import org.hibernate.sql.results.graph.Fetchable; import org.hibernate.sql.results.jdbc.spi.JdbcValuesMetadata; +import static org.hibernate.query.results.ResultsHelper.impl; import static org.hibernate.sql.ast.spi.SqlExpressionResolver.createColumnReferenceKey; /** @@ -129,7 +133,7 @@ public class DynamicFetchBuilderLegacy implements DynamicFetchBuilder, NativeQue JdbcValuesMetadata jdbcResultsMetadata, BiFunction legacyFetchResolver, DomainResultCreationState domainResultCreationState) { - final DomainResultCreationStateImpl creationState = ResultsHelper.impl( domainResultCreationState ); + final DomainResultCreationStateImpl creationState = impl( domainResultCreationState ); final TableGroup ownerTableGroup = creationState.getFromClauseAccess().findByAlias( ownerTableAlias ); final AttributeMapping attributeMapping = parent.getReferencedMappingContainer() .findContainingEntityMapping() @@ -175,11 +179,8 @@ public class DynamicFetchBuilderLegacy implements DynamicFetchBuilder, NativeQue (selectionIndex, selectableMapping) -> { resolveSqlSelection( columnNames.get( selectionIndex ), - createColumnReferenceKey( - tableGroup.resolveTableReference( selectableMapping.getContainingTableExpression() ), - selectableMapping.getSelectionExpression() - ), - selectableMapping.getJdbcMapping(), + tableGroup.resolveTableReference( selectableMapping.getContainingTableExpression() ), + selectableMapping, jdbcResultsMetadata, domainResultCreationState ); @@ -232,23 +233,25 @@ public class DynamicFetchBuilderLegacy implements DynamicFetchBuilder, NativeQue private void resolveSqlSelection( String columnAlias, - String columnKey, - JdbcMapping jdbcMapping, + TableReference tableReference, + SelectableMapping selectableMapping, JdbcValuesMetadata jdbcResultsMetadata, DomainResultCreationState domainResultCreationState) { - final SqlExpressionResolver sqlExpressionResolver = domainResultCreationState.getSqlAstCreationState().getSqlExpressionResolver(); - sqlExpressionResolver.resolveSqlSelection( - sqlExpressionResolver.resolveSqlExpression( - columnKey, - state -> { - final int jdbcPosition = jdbcResultsMetadata.resolveColumnPosition( columnAlias ); - final int valuesArrayPosition = jdbcPosition - 1; - return new ResultSetMappingSqlSelection( valuesArrayPosition, jdbcMapping ); - } + final DomainResultCreationStateImpl creationStateImpl = impl( domainResultCreationState ); + creationStateImpl.resolveSqlSelection( + ResultsHelper.resolveSqlExpression( + creationStateImpl, + jdbcResultsMetadata, + tableReference, + selectableMapping, + columnAlias ), - jdbcMapping.getJdbcJavaType(), + selectableMapping.getJdbcMapping().getJdbcJavaType(), null, - domainResultCreationState.getSqlAstCreationState().getCreationContext().getSessionFactory().getTypeConfiguration() + domainResultCreationState.getSqlAstCreationState() + .getCreationContext() + .getSessionFactory() + .getTypeConfiguration() ); } diff --git a/hibernate-core/src/main/java/org/hibernate/query/results/dynamic/DynamicFetchBuilderStandard.java b/hibernate-core/src/main/java/org/hibernate/query/results/dynamic/DynamicFetchBuilderStandard.java index 733988bb7c..544b97271c 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/results/dynamic/DynamicFetchBuilderStandard.java +++ b/hibernate-core/src/main/java/org/hibernate/query/results/dynamic/DynamicFetchBuilderStandard.java @@ -88,13 +88,12 @@ public class DynamicFetchBuilderStandard ); final String columnAlias = columnNames.get( selectionIndex ); sqlExpressionResolver.resolveSqlSelection( - sqlExpressionResolver.resolveSqlExpression( - createColumnReferenceKey( tableReference, selectableMapping.getSelectionExpression() ), - state -> { - final int resultSetPosition = jdbcResultsMetadata.resolveColumnPosition( columnAlias ); - final int valuesArrayPosition = resultSetPosition - 1; - return new ResultSetMappingSqlSelection( valuesArrayPosition, selectableMapping.getJdbcMapping() ); - } + ResultsHelper.resolveSqlExpression( + creationStateImpl, + jdbcResultsMetadata, + tableReference, + selectableMapping, + columnAlias ), selectableMapping.getJdbcMapping().getJdbcJavaType(), null, diff --git a/hibernate-core/src/main/java/org/hibernate/query/results/dynamic/DynamicResultBuilderAttribute.java b/hibernate-core/src/main/java/org/hibernate/query/results/dynamic/DynamicResultBuilderAttribute.java index bb4808fea8..f974e7292a 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/results/dynamic/DynamicResultBuilderAttribute.java +++ b/hibernate-core/src/main/java/org/hibernate/query/results/dynamic/DynamicResultBuilderAttribute.java @@ -12,14 +12,18 @@ import java.util.function.BiFunction; import org.hibernate.metamodel.mapping.SingularAttributeMapping; import org.hibernate.metamodel.mapping.internal.BasicAttributeMapping; import org.hibernate.query.NativeQuery; +import org.hibernate.query.results.DomainResultCreationStateImpl; import org.hibernate.query.results.ResultSetMappingSqlSelection; -import org.hibernate.sql.ast.spi.SqlExpressionResolver; +import org.hibernate.query.results.ResultsHelper; import org.hibernate.sql.ast.spi.SqlSelection; import org.hibernate.sql.results.graph.DomainResult; import org.hibernate.sql.results.graph.DomainResultCreationState; import org.hibernate.sql.results.graph.basic.BasicResult; import org.hibernate.sql.results.jdbc.spi.JdbcValuesMetadata; +import static org.hibernate.query.results.ResultsHelper.impl; +import static org.hibernate.query.results.ResultsHelper.jdbcPositionToValuesArrayPosition; + /** * DynamicResultBuilder based on a named mapped attribute * @@ -76,15 +80,14 @@ public class DynamicResultBuilderAttribute implements DynamicResultBuilder, Nati int resultPosition, BiFunction legacyFetchResolver, DomainResultCreationState domainResultCreationState) { - // todo (6.0) : TableGroups + `attributeMapping#buldResult` + final DomainResultCreationStateImpl domainResultCreationStateImpl = impl( domainResultCreationState ); - final SqlExpressionResolver sqlExpressionResolver = domainResultCreationState.getSqlAstCreationState().getSqlExpressionResolver(); - final SqlSelection sqlSelection = sqlExpressionResolver.resolveSqlSelection( - sqlExpressionResolver.resolveSqlExpression( + final SqlSelection sqlSelection = domainResultCreationStateImpl.resolveSqlSelection( + domainResultCreationStateImpl.resolveSqlExpression( columnAlias, - state -> { - final int resultSetPosition = jdbcResultsMetadata.resolveColumnPosition( columnAlias ); - final int valuesArrayPosition = resultSetPosition - 1; + processingState -> { + final int jdbcPosition = jdbcResultsMetadata.resolveColumnPosition( columnAlias ); + final int valuesArrayPosition = jdbcPositionToValuesArrayPosition( jdbcPosition ); return new ResultSetMappingSqlSelection( valuesArrayPosition, attributeMapping ); } ), diff --git a/hibernate-core/src/main/java/org/hibernate/query/results/dynamic/DynamicResultBuilderEntityStandard.java b/hibernate-core/src/main/java/org/hibernate/query/results/dynamic/DynamicResultBuilderEntityStandard.java index 137da588ae..1c1ea74051 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/results/dynamic/DynamicResultBuilderEntityStandard.java +++ b/hibernate-core/src/main/java/org/hibernate/query/results/dynamic/DynamicResultBuilderEntityStandard.java @@ -19,16 +19,24 @@ import org.hibernate.metamodel.mapping.CollectionPart; import org.hibernate.metamodel.mapping.EntityIdentifierMapping; import org.hibernate.metamodel.mapping.EntityMappingType; import org.hibernate.metamodel.mapping.JdbcMapping; +import org.hibernate.metamodel.mapping.ModelPart; +import org.hibernate.metamodel.mapping.PluralAttributeMapping; +import org.hibernate.metamodel.mapping.SelectableMapping; +import org.hibernate.metamodel.mapping.internal.EntityCollectionPart; import org.hibernate.metamodel.mapping.internal.SingleAttributeIdentifierMapping; import org.hibernate.query.NativeQuery; import org.hibernate.query.results.FetchBuilder; +import org.hibernate.query.results.ResultsHelper; +import org.hibernate.query.results.complete.CompleteFetchBuilder; import org.hibernate.spi.NavigablePath; import org.hibernate.query.results.DomainResultCreationStateImpl; import org.hibernate.query.results.ResultSetMappingSqlSelection; import org.hibernate.query.results.TableGroupImpl; import org.hibernate.sql.ast.spi.FromClauseAccess; import org.hibernate.sql.ast.spi.SqlAliasBaseConstant; +import org.hibernate.sql.ast.spi.SqlAstCreationState; import org.hibernate.sql.ast.spi.SqlExpressionResolver; +import org.hibernate.sql.ast.tree.expression.Expression; import org.hibernate.sql.ast.tree.from.TableGroup; import org.hibernate.sql.ast.tree.from.TableReference; import org.hibernate.sql.results.graph.DomainResultCreationState; @@ -147,6 +155,7 @@ public class DynamicResultBuilderEntityStandard tableAlias, domainResultCreationState ), + null, jdbcResultsMetadata, domainResultCreationState ); @@ -166,6 +175,7 @@ public class DynamicResultBuilderEntityStandard null, domainResultCreationState ), + fetchable, jdbcResultsMetadata, domainResultCreationState ); @@ -173,12 +183,23 @@ public class DynamicResultBuilderEntityStandard private T buildResultOrFetch( Function resultOrFetchBuilder, + Fetchable fetchable, JdbcValuesMetadata jdbcResultsMetadata, DomainResultCreationState domainResultCreationState) { final DomainResultCreationStateImpl creationState = impl( domainResultCreationState ); final FromClauseAccess fromClauseAccess = domainResultCreationState.getSqlAstCreationState().getFromClauseAccess(); + final TableGroup collectionTableGroup; + final NavigablePath elementNavigablePath; + if ( fetchable instanceof PluralAttributeMapping ) { + collectionTableGroup = fromClauseAccess.getTableGroup( navigablePath ); + elementNavigablePath = navigablePath.append( fetchable.getPartName() ); + } + else { + collectionTableGroup = null; + elementNavigablePath = navigablePath; + } final TableGroup tableGroup = fromClauseAccess.resolveTableGroup( - navigablePath, + elementNavigablePath, np -> { final TableReference tableReference = entityMapping.createPrimaryTableReference( new SqlAliasBaseConstant( tableAlias ), @@ -189,29 +210,66 @@ public class DynamicResultBuilderEntityStandard if ( lockMode != null ) { domainResultCreationState.getSqlAstCreationState().registerLockMode( tableAlias, lockMode ); } - return new TableGroupImpl( navigablePath, tableAlias, tableReference, entityMapping ); + return new TableGroupImpl( elementNavigablePath, tableAlias, tableReference, entityMapping ); } ); final TableReference tableReference = tableGroup.getPrimaryTableReference(); - final List idColumnAliases; - final FetchBuilder idFetchBuilder; + final List keyColumnAliases; + final FetchBuilder idFetchBuilder = findIdFetchBuilder(); if ( this.idColumnNames != null ) { - idColumnAliases = this.idColumnNames; + keyColumnAliases = this.idColumnNames; } - else if ( ( idFetchBuilder = findIdFetchBuilder() ) != null ) { - idColumnAliases = ( (DynamicFetchBuilder) idFetchBuilder ).getColumnAliases(); + else if ( idFetchBuilder != null ) { + keyColumnAliases = ( (DynamicFetchBuilder) idFetchBuilder ).getColumnAliases(); } else { - idColumnAliases = null; + keyColumnAliases = null; } - if ( idColumnAliases != null ) { - final EntityIdentifierMapping identifierMapping = entityMapping.getIdentifierMapping(); - identifierMapping.forEachSelectable( + if ( keyColumnAliases != null ) { + final ModelPart keyPart; + final TableGroup keyTableGroup; + if ( fetchable instanceof PluralAttributeMapping ) { + final PluralAttributeMapping pluralAttributeMapping = (PluralAttributeMapping) fetchable; + final EntityCollectionPart elementDescriptor = (EntityCollectionPart) pluralAttributeMapping.getElementDescriptor(); + if ( pluralAttributeMapping.getCollectionDescriptor().isOneToMany() ) { + keyPart = entityMapping.getIdentifierMapping(); + keyTableGroup = tableGroup; + } + else { + // In here, we know that the idColumnNames refer to the columns of the join table, + // so we also need to resolve selections for the element identifier columns + keyPart = elementDescriptor.getForeignKeyDescriptor().getKeyPart(); + keyTableGroup = collectionTableGroup; + final List idColumnAliases; + if ( idFetchBuilder instanceof DynamicFetchBuilder ) { + idColumnAliases = ( (DynamicFetchBuilder) idFetchBuilder ).getColumnAliases(); + } + else { + idColumnAliases = ( (CompleteFetchBuilder) idFetchBuilder ).getColumnAliases(); + } + entityMapping.getIdentifierMapping().forEachSelectable( + (selectionIndex, selectableMapping) -> { + resolveSqlSelection( + idColumnAliases.get( selectionIndex ), + tableReference, + selectableMapping, + jdbcResultsMetadata, + domainResultCreationState + ); + } + ); + } + } + else { + keyPart = entityMapping.getIdentifierMapping(); + keyTableGroup = tableGroup; + } + keyPart.forEachSelectable( (selectionIndex, selectableMapping) -> { resolveSqlSelection( - idColumnAliases.get( selectionIndex ), - createColumnReferenceKey( tableReference, selectableMapping.getSelectionExpression() ), - selectableMapping.getJdbcMapping(), + keyColumnAliases.get( selectionIndex ), + keyTableGroup.resolveTableReference( selectableMapping.getContainingTableExpression() ), + selectableMapping, jdbcResultsMetadata, domainResultCreationState ); @@ -222,11 +280,8 @@ public class DynamicResultBuilderEntityStandard if ( discriminatorColumnName != null ) { resolveSqlSelection( discriminatorColumnName, - createColumnReferenceKey( - tableReference, - entityMapping.getDiscriminatorMapping().getSelectionExpression() - ), - entityMapping.getDiscriminatorMapping().getJdbcMapping(), + tableReference, + entityMapping.getDiscriminatorMapping(), jdbcResultsMetadata, domainResultCreationState ); @@ -275,23 +330,25 @@ public class DynamicResultBuilderEntityStandard private void resolveSqlSelection( String columnAlias, - String columnKey, - JdbcMapping jdbcMapping, + TableReference tableReference, + SelectableMapping selectableMapping, JdbcValuesMetadata jdbcResultsMetadata, DomainResultCreationState domainResultCreationState) { - final SqlExpressionResolver sqlExpressionResolver = domainResultCreationState.getSqlAstCreationState().getSqlExpressionResolver(); - sqlExpressionResolver.resolveSqlSelection( - sqlExpressionResolver.resolveSqlExpression( - columnKey, - state -> { - final int jdbcPosition = jdbcResultsMetadata.resolveColumnPosition( columnAlias ); - final int valuesArrayPosition = jdbcPosition - 1; - return new ResultSetMappingSqlSelection( valuesArrayPosition, jdbcMapping ); - } + final DomainResultCreationStateImpl creationStateImpl = impl( domainResultCreationState ); + creationStateImpl.resolveSqlSelection( + ResultsHelper.resolveSqlExpression( + creationStateImpl, + jdbcResultsMetadata, + tableReference, + selectableMapping, + columnAlias ), - jdbcMapping.getJdbcJavaType(), + selectableMapping.getJdbcMapping().getJdbcJavaType(), null, - domainResultCreationState.getSqlAstCreationState().getCreationContext().getSessionFactory().getTypeConfiguration() + domainResultCreationState.getSqlAstCreationState() + .getCreationContext() + .getSessionFactory() + .getTypeConfiguration() ); } diff --git a/hibernate-core/src/main/java/org/hibernate/query/results/implicit/ImplicitFetchBuilderBasic.java b/hibernate-core/src/main/java/org/hibernate/query/results/implicit/ImplicitFetchBuilderBasic.java index 6c3daea1e5..787779d3e8 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/results/implicit/ImplicitFetchBuilderBasic.java +++ b/hibernate-core/src/main/java/org/hibernate/query/results/implicit/ImplicitFetchBuilderBasic.java @@ -94,16 +94,12 @@ public class ImplicitFetchBuilderBasic implements ImplicitFetchBuilder, BasicVal column = fetchable.getSelectionExpression(); } - final Expression expression = creationStateImpl.resolveSqlExpression( - createColumnReferenceKey( - parentTableGroup.resolveTableReference( fetchPath, table ), - fetchable.getSelectionExpression() - ), - processingState -> { - final int jdbcPosition = jdbcResultsMetadata.resolveColumnPosition( column ); - final int valuesArrayPosition = jdbcPositionToValuesArrayPosition( jdbcPosition ); - return new ResultSetMappingSqlSelection( valuesArrayPosition, fetchable ); - } + final Expression expression = ResultsHelper.resolveSqlExpression( + creationStateImpl, + jdbcResultsMetadata, + parentTableGroup.resolveTableReference( fetchPath, table ), + fetchable, + column ); final SqlSelection sqlSelection = creationStateImpl.resolveSqlSelection( diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/MatchingIdSelectionHelper.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/MatchingIdSelectionHelper.java index 2d22fec67f..1bd4edebed 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/MatchingIdSelectionHelper.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/MatchingIdSelectionHelper.java @@ -33,8 +33,6 @@ import org.hibernate.query.sqm.tree.delete.SqmDeleteStatement; import org.hibernate.query.sqm.tree.expression.SqmParameter; import org.hibernate.sql.ast.SqlAstJoinType; import org.hibernate.sql.ast.SqlAstTranslator; -import org.hibernate.sql.ast.spi.SqlExpressionResolver; -import org.hibernate.sql.ast.tree.expression.ColumnReference; import org.hibernate.sql.ast.tree.expression.Expression; import org.hibernate.sql.ast.tree.expression.JdbcParameter; import org.hibernate.sql.ast.tree.from.TableGroup; @@ -165,12 +163,8 @@ public class MatchingIdSelectionHelper { selection.getContainingTableExpression() ); final Expression expression = sqmConverter.getSqlExpressionResolver().resolveSqlExpression( - SqlExpressionResolver.createColumnReferenceKey( tableReference, selection.getSelectionExpression() ), - sqlAstProcessingState -> new ColumnReference( - tableReference, - selection, - sessionFactory - ) + tableReference, + selection ); idSelectionQuery.getSelectClause().addSqlSelection( new SqlSelectionImpl( diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/cte/AbstractCteMutationHandler.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/cte/AbstractCteMutationHandler.java index 1fdb6fc451..d7bd7398db 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/cte/AbstractCteMutationHandler.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/cte/AbstractCteMutationHandler.java @@ -287,8 +287,7 @@ public abstract class AbstractCteMutationHandler extends AbstractMutationHandler new ColumnReference( idSelectTableReference, cteColumn.getColumnExpression(), - cteColumn.getJdbcMapping(), - factory + cteColumn.getJdbcMapping() ) ) ); @@ -304,8 +303,7 @@ public abstract class AbstractCteMutationHandler extends AbstractMutationHandler new ColumnReference( idSelectTableReference, selectableMapping.getSelectionExpression(), - selectableMapping.getJdbcMapping(), - factory + selectableMapping.getJdbcMapping() ) ) ); diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/cte/CteDeleteHandler.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/cte/CteDeleteHandler.java index e844f80fd2..c5e03833a1 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/cte/CteDeleteHandler.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/cte/CteDeleteHandler.java @@ -123,8 +123,7 @@ public class CteDeleteHandler extends AbstractCteMutationHandler implements Dele (index, selectable) -> columnReferences.add( new ColumnReference( dmlTableReference, - selectable, - factory + selectable ) ) ); @@ -171,8 +170,7 @@ public class CteDeleteHandler extends AbstractCteMutationHandler implements Dele (index, selectable) -> columnReferences.add( new ColumnReference( dmlTableReference, - selectable, - factory + selectable ) ) ); diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/cte/CteInsertHandler.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/cte/CteInsertHandler.java index bd3e15016f..65bb94b584 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/cte/CteInsertHandler.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/cte/CteInsertHandler.java @@ -8,7 +8,6 @@ package org.hibernate.query.sqm.mutation.internal.cte; import java.util.AbstractMap; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collections; import java.util.IdentityHashMap; import java.util.LinkedHashMap; @@ -45,7 +44,6 @@ import org.hibernate.query.SemanticException; import org.hibernate.query.sqm.SortOrder; import org.hibernate.query.results.TableGroupImpl; import org.hibernate.query.spi.DomainQueryExecutionContext; -import org.hibernate.query.sqm.function.SelfRenderingFunctionSqlAstExpression; import org.hibernate.query.sqm.internal.DomainParameterXref; import org.hibernate.query.sqm.internal.SqmJdbcExecutionContextAdapter; import org.hibernate.query.sqm.internal.SqmUtil; @@ -74,7 +72,6 @@ import org.hibernate.sql.ast.tree.expression.BinaryArithmeticExpression; import org.hibernate.sql.ast.tree.expression.ColumnReference; import org.hibernate.sql.ast.tree.expression.Expression; import org.hibernate.sql.ast.tree.expression.JdbcParameter; -import org.hibernate.sql.ast.tree.expression.Over; import org.hibernate.sql.ast.tree.expression.QueryLiteral; import org.hibernate.sql.ast.tree.expression.SelfRenderingSqlFragmentExpression; import org.hibernate.sql.ast.tree.from.NamedTableReference; @@ -98,7 +95,6 @@ import org.hibernate.sql.results.graph.DomainResult; import org.hibernate.sql.results.graph.basic.BasicResult; import org.hibernate.sql.results.internal.SqlSelectionImpl; import org.hibernate.sql.results.spi.ListResultsConsumer; -import org.hibernate.type.BasicType; import org.hibernate.type.spi.TypeConfiguration; /** @@ -267,8 +263,7 @@ public class CteInsertHandler implements InsertHandler { false, null, null, - rowNumberColumn.getJdbcMapping(), - sessionFactory + rowNumberColumn.getJdbcMapping() ); insertStatement.getTargetColumnReferences().set( insertStatement.getTargetColumnReferences().size() - 1, @@ -322,9 +317,8 @@ public class CteInsertHandler implements InsertHandler { false, null, null, - columnReference.getJdbcMapping(), - null - ) + columnReference.getJdbcMapping() + ) ) ); } @@ -354,8 +348,7 @@ public class CteInsertHandler implements InsertHandler { false, null, null, - rowNumberColumn.getJdbcMapping(), - sessionFactory + rowNumberColumn.getJdbcMapping() ); insertStatement.getTargetColumnReferences().add( columnReference ); targetPathCteColumns.add( rowNumberColumn ); @@ -393,8 +386,7 @@ public class CteInsertHandler implements InsertHandler { false, null, null, - rowNumberColumn.getJdbcMapping(), - factory + rowNumberColumn.getJdbcMapping() ); final CteColumn idColumn = fullEntityCteTable.getCteColumns().get( 0 ); final BasicValuedMapping idType = (BasicValuedMapping) idColumn.getJdbcMapping(); @@ -515,8 +507,7 @@ public class CteInsertHandler implements InsertHandler { false, null, null, - rowNumberColumn.getJdbcMapping(), - factory + rowNumberColumn.getJdbcMapping() ) ) ) @@ -533,8 +524,7 @@ public class CteInsertHandler implements InsertHandler { false, null, null, - idColumn.getJdbcMapping(), - factory + idColumn.getJdbcMapping() ), BinaryArithmeticOperator.ADD, new BinaryArithmeticExpression( @@ -546,8 +536,7 @@ public class CteInsertHandler implements InsertHandler { false, null, null, - rowNumberColumn.getJdbcMapping(), - factory + rowNumberColumn.getJdbcMapping() ), integerType ), @@ -580,8 +569,7 @@ public class CteInsertHandler implements InsertHandler { false, null, null, - cteColumn.getJdbcMapping(), - factory + cteColumn.getJdbcMapping() ) ) ); @@ -849,8 +837,7 @@ public class CteInsertHandler implements InsertHandler { false, null, null, - rowNumberColumn.getJdbcMapping(), - factory + rowNumberColumn.getJdbcMapping() ); // Insert in the same order as the original tuples came insertSelectSpec.addSortSpecification( @@ -871,8 +858,7 @@ public class CteInsertHandler implements InsertHandler { false, null, null, - null, - factory + null ) ); } @@ -914,8 +900,7 @@ public class CteInsertHandler implements InsertHandler { false, null, null, - rowNumberColumn.getJdbcMapping(), - factory + rowNumberColumn.getJdbcMapping() ) ) ) @@ -934,8 +919,7 @@ public class CteInsertHandler implements InsertHandler { false, null, null, - idCteColumn.getJdbcMapping(), - factory + idCteColumn.getJdbcMapping() ) ) ); @@ -952,8 +936,7 @@ public class CteInsertHandler implements InsertHandler { false, null, null, - cteColumn.getJdbcMapping(), - factory + cteColumn.getJdbcMapping() ) ) ); @@ -985,8 +968,7 @@ public class CteInsertHandler implements InsertHandler { false, null, null, - idCteColumn.getJdbcMapping(), - factory + idCteColumn.getJdbcMapping() ); finalResultQuery.getSelectClause().addSqlSelection( new SqlSelectionImpl( @@ -1042,8 +1024,7 @@ public class CteInsertHandler implements InsertHandler { false, null, null, - null, - factory + null ) ); insertSelectSpec.getSelectClause().addSqlSelection( @@ -1056,8 +1037,7 @@ public class CteInsertHandler implements InsertHandler { false, null, null, - null, - factory + null ) ) ); @@ -1092,8 +1072,7 @@ public class CteInsertHandler implements InsertHandler { columnReference.isColumnExpressionFormula(), null, null, - columnReference.getJdbcMapping(), - factory + columnReference.getJdbcMapping() ) ) ); diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/cte/CteUpdateHandler.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/cte/CteUpdateHandler.java index 87b19afe76..922cd9952b 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/cte/CteUpdateHandler.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/cte/CteUpdateHandler.java @@ -193,8 +193,7 @@ public class CteUpdateHandler extends AbstractCteMutationHandler implements Upda new ColumnReference( existsTableReference, keyColumns[selectionIndex], - selectableMapping.getJdbcMapping(), - factory + selectableMapping.getJdbcMapping() ) ); } @@ -291,8 +290,7 @@ public class CteUpdateHandler extends AbstractCteMutationHandler implements Upda (index, selectable) -> columnReferences.add( new ColumnReference( dmlTableReference, - selectable, - factory + selectable ) ) ); diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/inline/InPredicateRestrictionProducer.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/inline/InPredicateRestrictionProducer.java index 6da2c40662..bc625b2093 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/inline/InPredicateRestrictionProducer.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/inline/InPredicateRestrictionProducer.java @@ -75,8 +75,7 @@ public class InPredicateRestrictionProducer implements MatchingIdRestrictionProd false, null, null, - basicIdMapping.getJdbcMapping(), - sessionFactory + basicIdMapping.getJdbcMapping() ); predicate = new InListPredicate( inFixture ); @@ -92,8 +91,7 @@ public class InPredicateRestrictionProducer implements MatchingIdRestrictionProd columnReferences.add( new ColumnReference( mutatingTableReference, - selection, - sessionFactory + selection ) ); jdbcMappings.add( selection.getJdbcMapping() ); diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/inline/InlineUpdateHandler.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/inline/InlineUpdateHandler.java index 880c277fb7..9fa34d1f9a 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/inline/InlineUpdateHandler.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/inline/InlineUpdateHandler.java @@ -359,8 +359,7 @@ public class InlineUpdateHandler implements UpdateHandler { keyColumnCollector.apply( new ColumnReference( (String) null, - selection, - sessionFactory + selection ) ); } @@ -454,8 +453,7 @@ public class InlineUpdateHandler implements UpdateHandler { false, null, null, - columnReference.getJdbcMapping(), - null + columnReference.getJdbcMapping() ); columnNames.add( columnReference.getColumnExpression() ); lhs.add( valuesColumnReference ); @@ -466,8 +464,7 @@ public class InlineUpdateHandler implements UpdateHandler { false, null, null, - columnReference.getJdbcMapping(), - null + columnReference.getJdbcMapping() ) ); querySpec.getSelectClause().addSqlSelection( @@ -489,8 +486,7 @@ public class InlineUpdateHandler implements UpdateHandler { false, null, null, - columnReference.getJdbcMapping(), - null + columnReference.getJdbcMapping() ); columnNames = Collections.singletonList( columnReference.getColumnExpression() ); joinPredicate = new ComparisonPredicate( @@ -502,8 +498,7 @@ public class InlineUpdateHandler implements UpdateHandler { false, null, null, - columnReference.getJdbcMapping(), - null + columnReference.getJdbcMapping() ) ); querySpec.getSelectClause().addSqlSelection( @@ -534,8 +529,7 @@ public class InlineUpdateHandler implements UpdateHandler { new ColumnReference( rootTableGroup.resolveTableReference( tableExpression ), columnNames.get( 0 ), - entityDescriptor.getIdentifierMapping().getJdbcMappings().get( 0 ), - null + entityDescriptor.getIdentifierMapping().getJdbcMappings().get( 0 ) ) ) ); diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/temptable/ExecuteWithTemporaryTableHelper.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/temptable/ExecuteWithTemporaryTableHelper.java index ed872bd7d4..58177505cb 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/temptable/ExecuteWithTemporaryTableHelper.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/temptable/ExecuteWithTemporaryTableHelper.java @@ -29,7 +29,6 @@ import org.hibernate.spi.NavigablePath; import org.hibernate.query.sqm.mutation.internal.MultiTableSqmMutationConverter; import org.hibernate.sql.ast.SqlAstJoinType; import org.hibernate.sql.ast.SqlAstTranslatorFactory; -import org.hibernate.sql.ast.spi.SqlExpressionResolver; import org.hibernate.sql.ast.tree.expression.ColumnReference; import org.hibernate.sql.ast.tree.expression.QueryLiteral; import org.hibernate.sql.ast.tree.from.NamedTableReference; @@ -84,8 +83,7 @@ public final class ExecuteWithTemporaryTableHelper { false, null, null, - column.getJdbcMapping(), - factory + column.getJdbcMapping() ) ); } @@ -106,15 +104,8 @@ public final class ExecuteWithTemporaryTableHelper { jdbcPosition, jdbcPosition + 1, sqmConverter.getSqlExpressionResolver().resolveSqlExpression( - SqlExpressionResolver.createColumnReferenceKey( - tableReference, - selection.getSelectionExpression() - ), - sqlAstProcessingState -> new ColumnReference( - tableReference, - selection, - factory - ) + tableReference, + selection ) ) ); @@ -243,8 +234,7 @@ public final class ExecuteWithTemporaryTableHelper { false, null, null, - temporaryTableColumn.getJdbcMapping(), - executionContext.getSession().getFactory() + temporaryTableColumn.getJdbcMapping() ) ) ); @@ -264,8 +254,7 @@ public final class ExecuteWithTemporaryTableHelper { false, null, null, - selectableMapping.getJdbcMapping(), - executionContext.getSession().getFactory() + selectableMapping.getJdbcMapping() ) ) ); @@ -289,8 +278,7 @@ public final class ExecuteWithTemporaryTableHelper { false, null, null, - idTable.getSessionUidColumn().getJdbcMapping(), - executionContext.getSession().getFactory() + idTable.getSessionUidColumn().getJdbcMapping() ), ComparisonOperator.EQUAL, new QueryLiteral<>( diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/temptable/ExecuteWithoutIdTableHelper.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/temptable/ExecuteWithoutIdTableHelper.java index a452694ecd..f3c2892086 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/temptable/ExecuteWithoutIdTableHelper.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/temptable/ExecuteWithoutIdTableHelper.java @@ -52,12 +52,8 @@ public final class ExecuteWithoutIdTableHelper { rootEntityPersister.getIdentifierMapping().forEachSelectable( (columnIndex, selection) -> { final ColumnReference columnReference = (ColumnReference) sqlExpressionResolver.resolveSqlExpression( - SqlExpressionResolver.createColumnReferenceKey( rootTableReference, selection.getSelectionExpression() ), - sqlAstProcessingState -> new ColumnReference( - rootTableReference, - selection, - sessionFactory - ) + rootTableReference, + selection ); final SqlSelection sqlSelection = new SqlSelectionImpl( // irrelevant diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/temptable/InsertExecutionDelegate.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/temptable/InsertExecutionDelegate.java index 177e9fec07..93a3392fa8 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/temptable/InsertExecutionDelegate.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/temptable/InsertExecutionDelegate.java @@ -344,8 +344,7 @@ public class InsertExecutionDelegate implements TableBasedInsertHandler.Executio false, null, null, - columnReference.getJdbcMapping(), - sessionFactory + columnReference.getJdbcMapping() ) ) ); @@ -364,8 +363,7 @@ public class InsertExecutionDelegate implements TableBasedInsertHandler.Executio false, null, null, - identifierMapping.getJdbcMapping(), - sessionFactory + identifierMapping.getJdbcMapping() ); idSelectQuerySpec.getSelectClause().addSqlSelection( new SqlSelectionImpl( 1, 0, columnReference ) ); idSelectQuerySpec.addSortSpecification( @@ -427,8 +425,7 @@ public class InsertExecutionDelegate implements TableBasedInsertHandler.Executio final List temporaryTableAssignments = new ArrayList<>( 1 ); final ColumnReference idColumnReference = new ColumnReference( (String) null, - identifierMapping, - sessionFactory + identifierMapping ); temporaryTableAssignments.add( new Assignment( @@ -458,8 +455,7 @@ public class InsertExecutionDelegate implements TableBasedInsertHandler.Executio false, null, null, - sessionUidColumn.getJdbcMapping(), - sessionFactory + sessionUidColumn.getJdbcMapping() ), ComparisonOperator.EQUAL, sessionUidParameter @@ -476,8 +472,7 @@ public class InsertExecutionDelegate implements TableBasedInsertHandler.Executio false, null, null, - rowNumberColumn.getJdbcMapping(), - sessionFactory + rowNumberColumn.getJdbcMapping() ), ComparisonOperator.EQUAL, rowNumber @@ -539,8 +534,7 @@ public class InsertExecutionDelegate implements TableBasedInsertHandler.Executio false, null, null, - identifierMapping.getJdbcMapping(), - sessionFactory + identifierMapping.getJdbcMapping() ) ); querySpec.getSelectClause().addSqlSelection( @@ -553,8 +547,7 @@ public class InsertExecutionDelegate implements TableBasedInsertHandler.Executio false, null, null, - idColumnReference.getJdbcMapping(), - sessionFactory + idColumnReference.getJdbcMapping() ) ) ); @@ -603,8 +596,7 @@ public class InsertExecutionDelegate implements TableBasedInsertHandler.Executio new Assignment( new ColumnReference( (String) null, - identifierMapping, - sessionFactory + identifierMapping ), rootIdentity ) @@ -619,8 +611,7 @@ public class InsertExecutionDelegate implements TableBasedInsertHandler.Executio false, null, null, - identifierMapping.getJdbcMapping(), - sessionFactory + identifierMapping.getJdbcMapping() ), ComparisonOperator.EQUAL, entityIdentity @@ -723,8 +714,7 @@ public class InsertExecutionDelegate implements TableBasedInsertHandler.Executio false, null, null, - columnReference.getJdbcMapping(), - sessionFactory + columnReference.getJdbcMapping() ) ) ); @@ -757,8 +747,7 @@ public class InsertExecutionDelegate implements TableBasedInsertHandler.Executio false, null, null, - identifierMapping.getJdbcMapping(), - sessionFactory + identifierMapping.getJdbcMapping() ) ); querySpec.getSelectClause().addSqlSelection( @@ -767,8 +756,7 @@ public class InsertExecutionDelegate implements TableBasedInsertHandler.Executio 0, new ColumnReference( updatingTableReference.getIdentificationVariable(), - identifierMapping, - sessionFactory + identifierMapping ) ) ); diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/temptable/RestrictedDeleteExecutionDelegate.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/temptable/RestrictedDeleteExecutionDelegate.java index 65a37a35ce..bfdf83f9f3 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/temptable/RestrictedDeleteExecutionDelegate.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/temptable/RestrictedDeleteExecutionDelegate.java @@ -408,12 +408,8 @@ public class RestrictedDeleteExecutionDelegate implements TableBasedDeleteHandle assert deleteTableReference.getTableReference( selection.getContainingTableExpression() ) != null; final Expression expression = sqlExpressionResolver.resolveSqlExpression( - SqlExpressionResolver.createColumnReferenceKey( deleteTableReference, selection.getSelectionExpression() ), - sqlAstProcessingState -> new ColumnReference( - deleteTableReference, - selection, - sessionFactory - ) + deleteTableReference, + selection ); deletingTableColumnRefs.add( (ColumnReference) expression ); @@ -604,8 +600,7 @@ public class RestrictedDeleteExecutionDelegate implements TableBasedDeleteHandle keyColumnCollector.apply( new ColumnReference( targetTable, - selection, - factory + selection ) ); } diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/temptable/TableBasedInsertHandler.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/temptable/TableBasedInsertHandler.java index a5d09a8348..cdb33fc761 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/temptable/TableBasedInsertHandler.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/temptable/TableBasedInsertHandler.java @@ -27,7 +27,6 @@ import org.hibernate.internal.util.collections.CollectionHelper; import org.hibernate.metamodel.mapping.MappingModelExpressible; import org.hibernate.persister.entity.EntityPersister; import org.hibernate.query.spi.DomainQueryExecutionContext; -import org.hibernate.query.sqm.function.SelfRenderingFunctionSqlAstExpression; import org.hibernate.query.sqm.internal.DomainParameterXref; import org.hibernate.query.sqm.internal.SqmJdbcExecutionContextAdapter; import org.hibernate.query.sqm.mutation.internal.InsertHandler; @@ -42,7 +41,6 @@ import org.hibernate.query.sqm.tree.insert.SqmValues; import org.hibernate.sql.ast.tree.expression.ColumnReference; import org.hibernate.sql.ast.tree.expression.Expression; import org.hibernate.sql.ast.tree.expression.JdbcParameter; -import org.hibernate.sql.ast.tree.expression.Over; import org.hibernate.sql.ast.tree.expression.QueryLiteral; import org.hibernate.sql.ast.tree.from.NamedTableReference; import org.hibernate.sql.ast.tree.from.TableGroup; @@ -198,8 +196,7 @@ public class TableBasedInsertHandler implements InsertHandler { false, null, null, - rowNumberColumn.getJdbcMapping(), - sessionFactory + rowNumberColumn.getJdbcMapping() ); insertStatement.getTargetColumnReferences().set( insertStatement.getTargetColumnReferences().size() - 1, @@ -224,8 +221,7 @@ public class TableBasedInsertHandler implements InsertHandler { false, null, null, - rowNumberColumn.getJdbcMapping(), - sessionFactory + rowNumberColumn.getJdbcMapping() ); insertStatement.getTargetColumnReferences().add( columnReference ); targetPathColumns.add( new Assignment( columnReference, columnReference ) ); @@ -248,8 +244,7 @@ public class TableBasedInsertHandler implements InsertHandler { false, null, null, - sessionUidColumn.getJdbcMapping(), - sessionFactory + sessionUidColumn.getJdbcMapping() ); insertStatement.getTargetColumnReferences().add( sessionUidColumnReference @@ -285,8 +280,7 @@ public class TableBasedInsertHandler implements InsertHandler { false, null, null, - rowNumberColumn.getJdbcMapping(), - sessionFactory + rowNumberColumn.getJdbcMapping() ); insertStatement.getTargetColumnReferences().add( columnReference ); targetPathColumns.add( new Assignment( columnReference, columnReference ) ); @@ -305,8 +299,7 @@ public class TableBasedInsertHandler implements InsertHandler { false, null, null, - sessionUidColumn.getJdbcMapping(), - sessionFactory + sessionUidColumn.getJdbcMapping() ); insertStatement.getTargetColumnReferences().add( sessionUidColumnReference diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/temptable/UpdateExecutionDelegate.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/temptable/UpdateExecutionDelegate.java index 73e3fbb338..86238efd44 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/temptable/UpdateExecutionDelegate.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/temptable/UpdateExecutionDelegate.java @@ -269,8 +269,7 @@ public class UpdateExecutionDelegate implements TableBasedUpdateHandler.Executio keyColumnCollector.apply( new ColumnReference( (String) null, - selection, - sessionFactory + selection ) ); } @@ -369,8 +368,7 @@ public class UpdateExecutionDelegate implements TableBasedUpdateHandler.Executio existsKeyColumnCollector.apply( new ColumnReference( existsTableReference, - selection, - sessionFactory + selection ) ); } diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/BaseSqmToSqlAstConverter.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/BaseSqmToSqlAstConverter.java index b3b27693f2..9e978f5986 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/BaseSqmToSqlAstConverter.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/BaseSqmToSqlAstConverter.java @@ -96,6 +96,7 @@ import org.hibernate.metamodel.model.domain.internal.AnyDiscriminatorSqmPath; import org.hibernate.metamodel.model.domain.internal.AnyDiscriminatorSqmPathSource; import org.hibernate.query.criteria.JpaCteCriteriaAttribute; import org.hibernate.query.criteria.JpaSearchOrder; +import org.hibernate.query.derived.AnonymousTupleEntityValuedModelPart; import org.hibernate.query.derived.AnonymousTupleTableGroupProducer; import org.hibernate.query.derived.AnonymousTupleType; import org.hibernate.metamodel.model.domain.internal.BasicSqmPathSource; @@ -141,6 +142,7 @@ import org.hibernate.query.sqm.sql.internal.BasicValuedPathInterpretation; import org.hibernate.query.sqm.sql.internal.DiscriminatedAssociationPathInterpretation; import org.hibernate.query.sqm.sql.internal.DiscriminatedAssociationTypePathInterpretation; import org.hibernate.query.sqm.sql.internal.DomainResultProducer; +import org.hibernate.query.sqm.sql.internal.EmbeddableValuedExpression; import org.hibernate.query.sqm.sql.internal.EmbeddableValuedPathInterpretation; import org.hibernate.query.sqm.sql.internal.EntityValuedPathInterpretation; import org.hibernate.query.sqm.sql.internal.NonAggregatedCompositeValuedPathInterpretation; @@ -331,7 +333,6 @@ import org.hibernate.sql.ast.tree.from.NamedTableReference; import org.hibernate.sql.ast.tree.from.PluralTableGroup; import org.hibernate.sql.ast.tree.from.QueryPartTableGroup; import org.hibernate.sql.ast.tree.from.QueryPartTableReference; -import org.hibernate.sql.ast.tree.from.SyntheticVirtualTableGroup; import org.hibernate.sql.ast.tree.from.TableGroup; import org.hibernate.sql.ast.tree.from.TableGroupJoin; import org.hibernate.sql.ast.tree.from.TableGroupJoinProducer; @@ -408,7 +409,6 @@ import static org.hibernate.query.sqm.TemporalUnit.EPOCH; import static org.hibernate.query.sqm.TemporalUnit.NATIVE; import static org.hibernate.query.sqm.TemporalUnit.SECOND; import static org.hibernate.query.sqm.UnaryArithmeticOperator.UNARY_MINUS; -import static org.hibernate.sql.ast.spi.SqlExpressionResolver.createColumnReferenceKey; import static org.hibernate.type.spi.TypeConfiguration.isDuration; /** @@ -1275,8 +1275,7 @@ public abstract class BaseSqmToSqlAstConverter extends Base final BasicValuedPathInterpretation discriminatorPath = new BasicValuedPathInterpretation<>( new ColumnReference( rootTableGroup.resolveTableReference( discriminatorMapping.getContainingTableExpression() ), - discriminatorMapping, - getCreationContext().getSessionFactory() + discriminatorMapping ), rootTableGroup.getNavigablePath().append( discriminatorMapping.getPartName() ), discriminatorMapping, @@ -1328,8 +1327,7 @@ public abstract class BaseSqmToSqlAstConverter extends Base final BasicValuedPathInterpretation identifierPath = new BasicValuedPathInterpretation<>( new ColumnReference( rootTableGroup.resolveTableReference( identifierMapping.getContainingTableExpression() ), - identifierMapping, - getCreationContext().getSessionFactory() + identifierMapping ), rootTableGroup.getNavigablePath().append( identifierMapping.getPartName() ), identifierMapping, @@ -2605,14 +2603,12 @@ public abstract class BaseSqmToSqlAstConverter extends Base new ComparisonPredicate( new ColumnReference( parentTableGroup.resolveTableReference( navigablePath, selectable.getContainingTableExpression() ), - selectable, - sessionFactory + selectable ), ComparisonOperator.EQUAL, new ColumnReference( tableGroup.resolveTableReference( navigablePath, selectable.getContainingTableExpression() ), - selectable, - sessionFactory + selectable ) ) ) @@ -2626,15 +2622,13 @@ public abstract class BaseSqmToSqlAstConverter extends Base lhs.add( new ColumnReference( parentTableGroup.resolveTableReference( navigablePath, selectable.getContainingTableExpression() ), - selectable, - sessionFactory + selectable ) ); rhs.add( new ColumnReference( tableGroup.resolveTableReference( navigablePath, selectable.getContainingTableExpression() ), - selectable, - sessionFactory + selectable ) ); } @@ -3697,6 +3691,10 @@ public abstract class BaseSqmToSqlAstConverter extends Base resultModelPart = entityValuedModelPart.findSubPart( targetPart.getPartName(), null ); } } + else if ( entityValuedModelPart instanceof AnonymousTupleEntityValuedModelPart ) { + // The FK of AnonymousTupleEntityValuedModelParts always refers to the PK, so we can safely use the FK + resultModelPart = ( (AnonymousTupleEntityValuedModelPart) entityValuedModelPart ).getForeignKeyPart(); + } else { // Otherwise, we use the identifier mapping of the target entity type resultModelPart = entityValuedModelPart.getEntityMappingType().getIdentifierMapping(); @@ -3758,6 +3756,9 @@ public abstract class BaseSqmToSqlAstConverter extends Base resultModelPart = collectionPart.getAssociatedEntityMappingType().getIdentifierMapping(); } } + else if ( entityValuedModelPart instanceof AnonymousTupleEntityValuedModelPart ) { + resultModelPart = ( (AnonymousTupleEntityValuedModelPart) entityValuedModelPart ).getForeignKeyPart(); + } else { // Since the table group model part is an EntityMappingType, // we can render the FK target model part of the inferred collection part, @@ -3777,6 +3778,11 @@ public abstract class BaseSqmToSqlAstConverter extends Base interpretationModelPart = inferredEntityMapping; tableGroupToUse = collectionTableGroup; } + else if ( entityValuedModelPart instanceof AnonymousTupleEntityValuedModelPart ) { + resultModelPart = ( (AnonymousTupleEntityValuedModelPart) entityValuedModelPart ).getForeignKeyPart(); + interpretationModelPart = inferredEntityMapping; + tableGroupToUse = null; + } else { // Render the identifier mapping if the inferred mapping is an EntityMappingType assert inferredEntityMapping instanceof EntityMappingType; @@ -3839,15 +3845,8 @@ public abstract class BaseSqmToSqlAstConverter extends Base ); final Expression expression = getSqlExpressionResolver().resolveSqlExpression( - createColumnReferenceKey( - tableReference, - mapping.getSelectionExpression() - ), - sacs -> new ColumnReference( - tableReference.getIdentificationVariable(), - mapping, - getCreationContext().getSessionFactory() - ) + tableReference, + mapping ); final ColumnReference columnReference; if ( expression instanceof ColumnReference ) { @@ -4055,12 +4054,8 @@ public abstract class BaseSqmToSqlAstConverter extends Base final BasicValuedModelPart basicFkPart = (BasicValuedModelPart) fkKeyPart; return getSqlExpressionResolver().resolveSqlExpression( - createColumnReferenceKey( tableReference, basicFkPart.getSelectionExpression() ), - (sqlAstProcessingState) -> new ColumnReference( - tableReference, - basicFkPart, - creationContext.getSessionFactory() - ) + tableReference, + basicFkPart ); } else { @@ -4070,12 +4065,8 @@ public abstract class BaseSqmToSqlAstConverter extends Base final List tupleElements = new ArrayList<>( jdbcMappings.size() ); compositeFkPart.forEachSelectable( (position, selectable) -> tupleElements.add( getSqlExpressionResolver().resolveSqlExpression( - createColumnReferenceKey( tableReference, selectable.getSelectionExpression() ), - (sqlAstProcessingState) -> new ColumnReference( - tableReference, - selectable, - creationContext.getSessionFactory() - ) + tableReference, + selectable ) ) ); @@ -4371,8 +4362,7 @@ public abstract class BaseSqmToSqlAstConverter extends Base navigablePath, selectionMapping.getContainingTableExpression() ), - selectionMapping, - creationContext.getSessionFactory() + selectionMapping ) ) ); @@ -4489,8 +4479,7 @@ public abstract class BaseSqmToSqlAstConverter extends Base navigablePath, selectionMapping.getContainingTableExpression() ), - selectionMapping, - creationContext.getSessionFactory() + selectionMapping ); final String columnName; if ( selectionMapping.isFormula() ) { @@ -4528,8 +4517,7 @@ public abstract class BaseSqmToSqlAstConverter extends Base false, null, null, - subQueryColumns.get( i ).getJdbcMapping(), - creationContext.getSessionFactory() + subQueryColumns.get( i ).getJdbcMapping() ) ); } @@ -4572,8 +4560,7 @@ public abstract class BaseSqmToSqlAstConverter extends Base false, null, null, - expression.getExpressionType().getJdbcMappings().get( 0 ), - creationContext.getSessionFactory() + expression.getExpressionType().getJdbcMappings().get( 0 ) ) ); } @@ -4676,8 +4663,7 @@ public abstract class BaseSqmToSqlAstConverter extends Base false, null, null, - sqlSelections.get( 0 ).getExpressionType().getJdbcMappings().get( 0 ), - creationContext.getSessionFactory() + sqlSelections.get( 0 ).getExpressionType().getJdbcMappings().get( 0 ) ) ), (ReturnableType) sqlSelections.get( 0 ).getExpressionType().getJdbcMappings().get( 0 ), @@ -4694,8 +4680,7 @@ public abstract class BaseSqmToSqlAstConverter extends Base false, null, null, - selectionMapping.getJdbcMapping(), - creationContext.getSessionFactory() + selectionMapping.getJdbcMapping() ) ) ); @@ -5865,38 +5850,9 @@ public abstract class BaseSqmToSqlAstConverter extends Base } else { final EmbeddableValuedModelPart valueMapping = (EmbeddableValuedModelPart) determineValueMapping( expression ); - final SqmPath path = SqmExpressionHelper.findPath( expression, expression.getNodeType() ); - final FromClauseIndex fromClauseIndex = fromClauseIndexStack.getCurrent(); - final TableGroup parentTableGroup = fromClauseIndex.findTableGroup( - path.getLhs().getNavigablePath() - ); - final NavigablePath navigablePath = parentTableGroup.getNavigablePath().append( - path.getNavigablePath().getLocalName(), - Long.toString( System.nanoTime() ) - ); - final TableGroup tableGroup = new SyntheticVirtualTableGroup( - navigablePath, + return new EmbeddableValuedExpression<>( valueMapping, - parentTableGroup - ); - fromClauseIndex.registerTableGroup( navigablePath, tableGroup ); - // Register the expressions under the column reference key - final SqlExpressionResolver resolver = getSqlAstCreationState().getSqlExpressionResolver(); - final TableReference tableReference = tableGroup.getPrimaryTableReference(); - valueMapping.forEachSelectable( - (selectionIndex, selection) -> resolver.resolveSqlExpression( - SqlExpressionResolver.createColumnReferenceKey( - tableReference, - selection.getSelectionExpression() - ), - processingState -> (Expression) (selectionIndex == 0 ? result : offset) - ) - ); - return new EmbeddableValuedPathInterpretation<>( - new SqlTuple( List.of( (Expression) result, (Expression) offset ), valueMapping ), - navigablePath, - valueMapping, - tableGroup + new SqlTuple( List.of( (Expression) result, (Expression) offset ), valueMapping ) ); } } diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/internal/BasicValuedPathInterpretation.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/internal/BasicValuedPathInterpretation.java index 1fadf68a00..8a5292d66f 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/internal/BasicValuedPathInterpretation.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/internal/BasicValuedPathInterpretation.java @@ -94,15 +94,8 @@ public class BasicValuedPathInterpretation extends AbstractSqmPathInterpretat ); final Expression expression = sqlAstCreationState.getSqlExpressionResolver().resolveSqlExpression( - SqlExpressionResolver.createColumnReferenceKey( - tableReference, - mapping.getSelectionExpression() - ), - sacs -> new ColumnReference( - tableReference.getIdentificationVariable(), - mapping, - sqlAstCreationState.getCreationContext().getSessionFactory() - ) + tableReference, + mapping ); final ColumnReference columnReference; diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/internal/DiscriminatedAssociationPathInterpretation.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/internal/DiscriminatedAssociationPathInterpretation.java index 6681479e84..4985dcf5e5 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/internal/DiscriminatedAssociationPathInterpretation.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/internal/DiscriminatedAssociationPathInterpretation.java @@ -45,12 +45,8 @@ public class DiscriminatedAssociationPathInterpretation extends AbstractSqmPa (selectionIndex, selectableMapping) -> { final TableReference tableReference = tableGroup.resolveTableReference( sqmPath.getNavigablePath(), selectableMapping.getContainingTableExpression() ); final Expression expression = converter.getSqlExpressionResolver().resolveSqlExpression( - SqlExpressionResolver.createColumnReferenceKey( tableReference, selectableMapping.getSelectionExpression() ), - processingState -> new ColumnReference( - tableReference, - selectableMapping, - converter.getCreationContext().getSessionFactory() - ) + tableReference, + selectableMapping ); tupleExpressions.add( expression ); } diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/internal/DiscriminatedAssociationTypePathInterpretation.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/internal/DiscriminatedAssociationTypePathInterpretation.java index b85c664159..b2da863277 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/internal/DiscriminatedAssociationTypePathInterpretation.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/internal/DiscriminatedAssociationTypePathInterpretation.java @@ -51,15 +51,8 @@ public class DiscriminatedAssociationTypePathInterpretation extends AbstractS if ( selectableMapping instanceof AnyDiscriminatorPart ) { final TableReference tableReference = tableGroup.getPrimaryTableReference(); final Expression expression = converter.getSqlExpressionResolver().resolveSqlExpression( - SqlExpressionResolver.createColumnReferenceKey( - tableReference, - selectableMapping.getSelectionExpression() - ), - processingState -> new ColumnReference( - tableReference, - selectableMapping, - converter.getCreationContext().getSessionFactory() - ) + tableReference, + selectableMapping ); tupleExpressions.add( expression ); } diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/internal/EmbeddableValuedExpression.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/internal/EmbeddableValuedExpression.java new file mode 100644 index 0000000000..60eb6b86c5 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/internal/EmbeddableValuedExpression.java @@ -0,0 +1,117 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html + */ +package org.hibernate.query.sqm.sql.internal; + +import java.util.ArrayList; +import java.util.List; +import java.util.function.Consumer; + +import org.hibernate.metamodel.mapping.AttributeMapping; +import org.hibernate.metamodel.mapping.EmbeddableMappingType; +import org.hibernate.metamodel.mapping.EmbeddableValuedModelPart; +import org.hibernate.metamodel.mapping.ModelPart; +import org.hibernate.metamodel.mapping.internal.BasicAttributeMapping; +import org.hibernate.spi.NavigablePath; +import org.hibernate.sql.ast.SqlAstWalker; +import org.hibernate.sql.ast.spi.SqlAstCreationState; +import org.hibernate.sql.ast.spi.SqlExpressionResolver; +import org.hibernate.sql.ast.spi.SqlSelection; +import org.hibernate.sql.ast.tree.expression.ColumnReference; +import org.hibernate.sql.ast.tree.expression.Expression; +import org.hibernate.sql.ast.tree.expression.SqlTuple; +import org.hibernate.sql.ast.tree.expression.SqlTupleContainer; +import org.hibernate.sql.ast.tree.update.Assignable; +import org.hibernate.sql.results.graph.DomainResult; +import org.hibernate.sql.results.graph.DomainResultCreationState; +import org.hibernate.sql.results.graph.embeddable.internal.EmbeddableExpressionResultImpl; +import org.hibernate.type.spi.TypeConfiguration; + +/** + * A computed expression that produces an embeddable valued model part. + * It may only be composed of basic attribute mappings. + */ +public class EmbeddableValuedExpression implements Expression, DomainResultProducer, Assignable, SqlTupleContainer { + + private final NavigablePath navigablePath; + private final EmbeddableValuedModelPart mapping; + private final SqlTuple sqlExpression; + + public EmbeddableValuedExpression(EmbeddableValuedModelPart mapping, SqlTuple sqlExpression) { + assert mapping != null; + assert sqlExpression != null; + assert mapping.getEmbeddableTypeDescriptor().getNumberOfAttributeMappings() == sqlExpression.getExpressions().size(); + this.navigablePath = new NavigablePath( mapping.getPartName(), Long.toString( System.nanoTime() ) ); + this.mapping = mapping; + this.sqlExpression = sqlExpression; + } + + @Override + public ModelPart getExpressionType() { + return mapping; + } + + @Override + public DomainResult createDomainResult( + String resultVariable, + DomainResultCreationState creationState) { + return new EmbeddableExpressionResultImpl<>( + navigablePath, + mapping, + sqlExpression, + resultVariable, + creationState + ); + } + + @Override + public void applySqlSelections(DomainResultCreationState creationState) { + final EmbeddableMappingType mappingType = mapping.getEmbeddableTypeDescriptor(); + final int numberOfAttributeMappings = mappingType.getNumberOfAttributeMappings(); + final SqlAstCreationState sqlAstCreationState = creationState.getSqlAstCreationState(); + final TypeConfiguration typeConfiguration = sqlAstCreationState.getCreationContext() + .getSessionFactory() + .getTypeConfiguration(); + final SqlExpressionResolver sqlExpressionResolver = sqlAstCreationState.getSqlExpressionResolver(); + for ( int i = 0; i < numberOfAttributeMappings; i++ ) { + final AttributeMapping attributeMapping = mappingType.getAttributeMapping( i ); + assert attributeMapping instanceof BasicAttributeMapping; + sqlExpressionResolver.resolveSqlSelection( + sqlExpression.getExpressions().get( i ), + attributeMapping.getJavaType(), + null, + typeConfiguration + ); + } + } + + @Override + public void visitColumnReferences(Consumer columnReferenceConsumer) { + for ( Expression expression : sqlExpression.getExpressions() ) { + if ( !( expression instanceof ColumnReference ) ) { + throw new IllegalArgumentException( "Expecting ColumnReference, found : " + expression ); + } + columnReferenceConsumer.accept( (ColumnReference) expression ); + } + } + + @Override + public List getColumnReferences() { + final List results = new ArrayList<>(); + visitColumnReferences( results::add ); + return results; + } + + @Override + public SqlTuple getSqlTuple() { + return sqlExpression; + } + + @Override + public void accept(SqlAstWalker sqlTreeWalker) { + sqlExpression.accept( sqlTreeWalker ); + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/internal/EntityValuedPathInterpretation.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/internal/EntityValuedPathInterpretation.java index 9f9d842be7..7128c91c3a 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/internal/EntityValuedPathInterpretation.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/internal/EntityValuedPathInterpretation.java @@ -242,6 +242,11 @@ public class EntityValuedPathInterpretation extends AbstractSqmPathInterpreta allowFkOptimization = false; } } + else if ( mapping instanceof AnonymousTupleEntityValuedModelPart ) { + resultModelPart = ( (AnonymousTupleEntityValuedModelPart) mapping ).getForeignKeyPart(); + resultTableGroup = tableGroup; + allowFkOptimization = true; + } else { // If the mapping is not an association, use the PK and disallow FK optimizations resultModelPart = mapping.getEntityMappingType().getIdentifierMapping(); @@ -311,17 +316,7 @@ public class EntityValuedPathInterpretation extends AbstractSqmPathInterpreta false ); expressions.add( - sqlExprResolver.resolveSqlExpression( - createColumnReferenceKey( - tableReference, - selectableMapping.getSelectionExpression() - ), - processingState -> new ColumnReference( - tableReference, - selectableMapping, - sessionFactory - ) - ) + sqlExprResolver.resolveSqlExpression( tableReference, selectableMapping ) ); }; identifierMapping.forEachSelectable( selectableConsumer ); @@ -339,14 +334,7 @@ public class EntityValuedPathInterpretation extends AbstractSqmPathInterpreta basicValuedModelPart.getContainingTableExpression(), allowFkOptimization ); - sqlExpression = sqlExprResolver.resolveSqlExpression( - createColumnReferenceKey( tableReference, basicValuedModelPart.getSelectionExpression() ), - processingState -> new ColumnReference( - tableReference, - basicValuedModelPart, - sessionFactory - ) - ); + sqlExpression = sqlExprResolver.resolveSqlExpression( tableReference, basicValuedModelPart ); } else { final List expressions = new ArrayList<>( resultModelPart.getJdbcTypeCount() ); @@ -357,19 +345,7 @@ public class EntityValuedPathInterpretation extends AbstractSqmPathInterpreta selectableMapping.getContainingTableExpression(), allowFkOptimization ); - expressions.add( - sqlExprResolver.resolveSqlExpression( - createColumnReferenceKey( - tableReference, - selectableMapping.getSelectionExpression() - ), - processingState -> new ColumnReference( - tableReference, - selectableMapping, - sessionFactory - ) - ) - ); + expressions.add( sqlExprResolver.resolveSqlExpression( tableReference, selectableMapping ) ); } ); sqlExpression = new SqlTuple( expressions, resultModelPart ); diff --git a/hibernate-core/src/main/java/org/hibernate/sql/ast/spi/AbstractSqlAstTranslator.java b/hibernate-core/src/main/java/org/hibernate/sql/ast/spi/AbstractSqlAstTranslator.java index 40732311ff..c2b307df2b 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/ast/spi/AbstractSqlAstTranslator.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/ast/spi/AbstractSqlAstTranslator.java @@ -1006,6 +1006,12 @@ public abstract class AbstractSqlAstTranslator implemen clauseStack.pop(); } + renderSetClause( statement, clauseStack ); + visitWhereClause( statement.getRestriction() ); + visitReturningColumns( statement ); + } + + protected void renderSetClause(UpdateStatement statement, Stack clauseStack) { appendSql( " set " ); boolean firstPass = true; try { @@ -1020,7 +1026,7 @@ public abstract class AbstractSqlAstTranslator implemen final List columnReferences = assignment.getAssignable().getColumnReferences(); if ( columnReferences.size() == 1 ) { - columnReferences.get( 0 ).accept( this ); + visitSetClauseTarget( columnReferences.get( 0 ) ); appendSql( '=' ); final Expression assignedValue = assignment.getAssignedValue(); final SqlTuple sqlTuple = SqlTupleContainer.getSqlTuple( assignedValue ); @@ -1047,9 +1053,10 @@ public abstract class AbstractSqlAstTranslator implemen finally { clauseStack.pop(); } + } - visitWhereClause( statement.getRestriction() ); - visitReturningColumns( statement ); + protected void visitSetClauseTarget(ColumnReference columnReference) { + appendSql( columnReference.getColumnExpression() ); } protected void visitInsertStatementOnly(InsertStatement statement) { @@ -1926,8 +1933,7 @@ public abstract class AbstractSqlAstTranslator implemen false, null, null, - currentCteStatement.getCycleMarkColumn().getJdbcMapping(), - sessionFactory + currentCteStatement.getCycleMarkColumn().getJdbcMapping() ); if ( currentCteStatement.getCycleValue().getJdbcMapping() == getBooleanType() && currentCteStatement.getCycleValue().getLiteralValue() == Boolean.TRUE @@ -1970,8 +1976,7 @@ public abstract class AbstractSqlAstTranslator implemen false, null, null, - integerType, - sessionFactory + integerType ); visitColumnReference( depthColumnReference ); appendSql( "+1" ); @@ -2003,8 +2008,7 @@ public abstract class AbstractSqlAstTranslator implemen false, null, null, - currentCteStatement.getSearchColumn().getJdbcMapping(), - sessionFactory + currentCteStatement.getSearchColumn().getJdbcMapping() ) ); appendSql( "||" ); @@ -2116,8 +2120,7 @@ public abstract class AbstractSqlAstTranslator implemen false, null, null, - integerType, - sessionFactory + integerType ); visitColumnReference( depthColumnReference ); appendSql( "+1" ); @@ -2161,8 +2164,7 @@ public abstract class AbstractSqlAstTranslator implemen false, null, null, - currentCteStatement.getSearchColumn().getJdbcMapping(), - sessionFactory + currentCteStatement.getSearchColumn().getJdbcMapping() ) ); for ( SearchClauseSpecification searchBySpecification : currentCteStatement.getSearchBySpecifications() ) { @@ -2307,8 +2309,7 @@ public abstract class AbstractSqlAstTranslator implemen false, null, null, - stringType, - sessionFactory + stringType ); if ( !supportsRecursiveCycleClause() ) { @@ -2455,8 +2456,7 @@ public abstract class AbstractSqlAstTranslator implemen false, null, null, - stringType, - sessionFactory + stringType ); arguments.add( new QueryLiteral<>( "%", stringType ) ); for ( CteColumn cycleColumn : currentCteStatement.getCycleColumns() ) { @@ -2875,8 +2875,7 @@ public abstract class AbstractSqlAstTranslator implemen false, null, null, - getIntegerType(), - null + getIntegerType() ) ) ); @@ -3101,8 +3100,7 @@ public abstract class AbstractSqlAstTranslator implemen false, null, null, - expression.getExpressionType().getJdbcMappings().get( 0 ), - sessionFactory + expression.getExpressionType().getJdbcMappings().get( 0 ) ); } @@ -5565,8 +5563,7 @@ public abstract class AbstractSqlAstTranslator implemen false, null, null, - null, - sessionFactory + null ) ); } @@ -5636,8 +5633,7 @@ public abstract class AbstractSqlAstTranslator implemen false, null, null, - null, - sessionFactory + null ) ); } @@ -5762,8 +5758,7 @@ public abstract class AbstractSqlAstTranslator implemen false, null, null, - null, - sessionFactory + null ); sortExpression = sortSpecification.getSortExpression(); } @@ -6018,11 +6013,7 @@ public abstract class AbstractSqlAstTranslator implemen ); } else { - if ( qualifyColumn ) { - appendSql( tableExpression ); - appendSql( '.' ); - } - appendSql( columnReference.getColumnExpression() ); + columnReference.appendReadExpression( this, qualifyColumn ? tableExpression : null ); } } else { diff --git a/hibernate-core/src/main/java/org/hibernate/sql/ast/spi/SqlExpressionResolver.java b/hibernate-core/src/main/java/org/hibernate/sql/ast/spi/SqlExpressionResolver.java index b977457f10..4fe36df313 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/ast/spi/SqlExpressionResolver.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/ast/spi/SqlExpressionResolver.java @@ -10,6 +10,7 @@ import java.util.Objects; import java.util.function.Function; import org.hibernate.metamodel.mapping.SelectableMapping; +import org.hibernate.sql.ast.tree.expression.ColumnReference; import org.hibernate.sql.ast.tree.expression.Expression; import org.hibernate.sql.ast.tree.from.TableReference; import org.hibernate.sql.results.graph.FetchParent; @@ -57,15 +58,33 @@ public interface SqlExpressionResolver { return qualifier + columnExpression; } + /** + * Convenience form for creating a key from table expression and SelectableMapping + */ + static String createColumnReferenceKey(String tableExpression, SelectableMapping selectable) { + return createColumnReferenceKey( tableExpression, selectable.getSelectionExpression() ); + } + /** * Convenience form for creating a key from TableReference and SelectableMapping */ static String createColumnReferenceKey(TableReference tableReference, SelectableMapping selectable) { - assert Objects.equals( selectable.getContainingTableExpression(), tableReference.getTableId() ) + assert tableReference.containsAffectedTableName( selectable.getContainingTableExpression() ) : String.format( ROOT, "Expecting tables to match between TableReference (%s) and SelectableMapping (%s)", tableReference.getTableId(), selectable.getContainingTableExpression() ); return createColumnReferenceKey( tableReference, selectable.getSelectionExpression() ); } + default Expression resolveSqlExpression(TableReference tableReference, SelectableMapping selectableMapping) { + return resolveSqlExpression( + createColumnReferenceKey( tableReference, selectableMapping ), + processingState -> new ColumnReference( + tableReference, + selectableMapping + ) + ); + } + + /** * Given a qualifier + a qualifiable {@link org.hibernate.metamodel.mapping.SqlExpressible}, * resolve the (Sql)Expression reference. diff --git a/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/expression/ColumnReference.java b/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/expression/ColumnReference.java index 083abc376b..0ac8f066e1 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/expression/ColumnReference.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/expression/ColumnReference.java @@ -12,7 +12,6 @@ import java.util.Locale; import java.util.Objects; import java.util.function.Consumer; -import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.internal.util.StringHelper; import org.hibernate.metamodel.mapping.SelectableMapping; import org.hibernate.metamodel.mapping.JdbcMapping; @@ -42,32 +41,28 @@ public class ColumnReference implements Expression, Assignable { public ColumnReference( String qualifier, - SelectableMapping selectableMapping, - SessionFactoryImplementor sessionFactory) { + SelectableMapping selectableMapping) { this( qualifier, selectableMapping.getSelectionExpression(), selectableMapping.isFormula(), selectableMapping.getCustomReadExpression(), selectableMapping.getCustomWriteExpression(), - selectableMapping.getJdbcMapping(), - sessionFactory + selectableMapping.getJdbcMapping() ); } public ColumnReference( String qualifier, SelectableMapping selectableMapping, - JdbcMapping jdbcMapping, - SessionFactoryImplementor sessionFactory) { + JdbcMapping jdbcMapping) { this( qualifier, selectableMapping.getSelectionExpression(), selectableMapping.isFormula(), selectableMapping.getCustomReadExpression(), selectableMapping.getCustomWriteExpression(), - jdbcMapping, - sessionFactory + jdbcMapping ); } @@ -77,8 +72,7 @@ public class ColumnReference implements Expression, Assignable { boolean isFormula, String customReadExpression, String customWriteExpression, - JdbcMapping jdbcMapping, - SessionFactoryImplementor sessionFactory) { + JdbcMapping jdbcMapping) { this.qualifier = StringHelper.nullIfEmpty( qualifier ); if ( isFormula ) { @@ -112,28 +106,24 @@ public class ColumnReference implements Expression, Assignable { public ColumnReference( TableReference tableReference, - SelectableMapping selectableMapping, - SessionFactoryImplementor sessionFactory) { + SelectableMapping selectableMapping) { this( tableReference.getIdentificationVariable(), - selectableMapping, - sessionFactory + selectableMapping ); } public ColumnReference( TableReference tableReference, String mapping, - JdbcMapping jdbcMapping, - SessionFactoryImplementor sessionFactory) { + JdbcMapping jdbcMapping) { this( tableReference.getIdentificationVariable(), mapping, false, null, null, - jdbcMapping, - sessionFactory + jdbcMapping ); } @@ -143,16 +133,14 @@ public class ColumnReference implements Expression, Assignable { boolean isFormula, String customReadExpression, String customWriteExpression, - JdbcMapping jdbcMapping, - SessionFactoryImplementor sessionFactory) { + JdbcMapping jdbcMapping) { this( tableReference.getIdentificationVariable(), columnExpression, isFormula, customReadExpression, customWriteExpression, - jdbcMapping, - sessionFactory + jdbcMapping ); } @@ -180,6 +168,10 @@ public class ColumnReference implements Expression, Assignable { } public void appendReadExpression(SqlAppender appender) { + appendReadExpression( appender, qualifier ); + } + + public void appendReadExpression(SqlAppender appender, String qualifier) { if ( isFormula ) { appender.append( columnExpression ); } diff --git a/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/from/NamedTableReference.java b/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/from/NamedTableReference.java index 8d0ff6526e..3d6a320dae 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/from/NamedTableReference.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/from/NamedTableReference.java @@ -16,6 +16,8 @@ import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.spi.NavigablePath; import org.hibernate.sql.ast.SqlAstWalker; +import static org.hibernate.internal.util.StringHelper.isEmpty; + /** * Represents a reference to a "named" table in a query's from clause. * @@ -66,7 +68,7 @@ public class NamedTableReference extends AbstractTableReference { @Override public boolean containsAffectedTableName(String requestedName) { - return getTableExpression().equals( requestedName ); + return isEmpty( requestedName ) || getTableExpression().equals( requestedName ); } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/from/SyntheticVirtualTableGroup.java b/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/from/SyntheticVirtualTableGroup.java deleted file mode 100644 index 7be4a22c9f..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/from/SyntheticVirtualTableGroup.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later - * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html - */ -package org.hibernate.sql.ast.tree.from; - -import java.util.Collections; -import java.util.List; -import java.util.function.Consumer; - -import org.hibernate.metamodel.mapping.ModelPartContainer; -import org.hibernate.spi.NavigablePath; - -/** - * @author Christian Beikov - */ -public class SyntheticVirtualTableGroup extends AbstractTableGroup implements VirtualTableGroup { - private final TableGroup underlyingTableGroup; - private final TableReference syntheticTableReference; - - public SyntheticVirtualTableGroup( - NavigablePath navigablePath, - ModelPartContainer modelPart, - TableGroup underlyingTableGroup) { - super( - underlyingTableGroup.canUseInnerJoins(), - navigablePath, - modelPart, - underlyingTableGroup.getSourceAlias(), - null, - null - ); - this.underlyingTableGroup = underlyingTableGroup; - this.syntheticTableReference = new NamedTableReference( - navigablePath.getFullPath(), - navigablePath.getLocalName(), - false, - null - ); - } - - @Override - public ModelPartContainer getExpressionType() { - return getModelPart(); - } - - @Override - public boolean isFetched() { - return false; - } - - @Override - public String getSourceAlias() { - return underlyingTableGroup.getSourceAlias(); - } - - @Override - public boolean canUseInnerJoins() { - return underlyingTableGroup.canUseInnerJoins(); - } - - @Override - public void applyAffectedTableNames(Consumer nameCollector) { - } - - @Override - public TableReference getPrimaryTableReference() { - return syntheticTableReference; - } - - @Override - public List getTableReferenceJoins() { - return Collections.emptyList(); - } - - @Override - public TableReference getTableReferenceInternal( - NavigablePath navigablePath, - String tableExpression, - boolean allowFkOptimization, - boolean resolve) { - final TableReference tableReference = underlyingTableGroup.getPrimaryTableReference() - .getTableReference( navigablePath, tableExpression, allowFkOptimization, resolve ); - if ( tableReference != null ) { - return syntheticTableReference; - } - return null; - } - -} diff --git a/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/from/TableReference.java b/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/from/TableReference.java index 7821b5ac2c..f487880b7b 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/from/TableReference.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/from/TableReference.java @@ -15,6 +15,8 @@ import org.hibernate.spi.NavigablePath; import org.hibernate.sql.ast.SqlAstWalker; import org.hibernate.sql.ast.tree.SqlAstNode; +import static org.hibernate.internal.util.StringHelper.isEmpty; + /** * Represents a reference to a table (derived or physical) in a query's from clause. * @@ -55,7 +57,7 @@ public interface TableReference extends SqlAstNode, ColumnReferenceQualifier { } default boolean containsAffectedTableName(String requestedName) { - return visitAffectedTableNames( requestedName::equals ); + return isEmpty( requestedName ) || Boolean.TRUE.equals( visitAffectedTableNames( requestedName::equals ) ); } Boolean visitAffectedTableNames(Function nameCollector); diff --git a/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/from/UnionTableReference.java b/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/from/UnionTableReference.java index 8efdc2ef68..f48745a062 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/from/UnionTableReference.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/from/UnionTableReference.java @@ -7,10 +7,13 @@ package org.hibernate.sql.ast.tree.from; import java.util.Locale; +import java.util.function.Function; import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.spi.NavigablePath; +import static org.hibernate.internal.util.StringHelper.isEmpty; + /** * @author Andrea Boriero */ @@ -71,4 +74,20 @@ public class UnionTableReference extends NamedTableReference { } return false; } + + @Override + public boolean containsAffectedTableName(String requestedName) { + return isEmpty( requestedName ) || hasTableExpression( requestedName ); + } + + @Override + public Boolean visitAffectedTableNames(Function nameCollector) { + for ( String expression : subclassTableSpaceExpressions ) { + final Boolean result = nameCollector.apply( expression ); + if ( result != null ) { + return result; + } + } + return null; + } } diff --git a/hibernate-core/src/main/java/org/hibernate/sql/results/graph/embeddable/internal/EmbeddableExpressionResultImpl.java b/hibernate-core/src/main/java/org/hibernate/sql/results/graph/embeddable/internal/EmbeddableExpressionResultImpl.java new file mode 100644 index 0000000000..8485995982 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/sql/results/graph/embeddable/internal/EmbeddableExpressionResultImpl.java @@ -0,0 +1,145 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html + */ +package org.hibernate.sql.results.graph.embeddable.internal; + +import java.util.ArrayList; +import java.util.List; + +import org.hibernate.engine.FetchTiming; +import org.hibernate.metamodel.mapping.AttributeMapping; +import org.hibernate.metamodel.mapping.EmbeddableMappingType; +import org.hibernate.metamodel.mapping.EmbeddableValuedModelPart; +import org.hibernate.metamodel.mapping.internal.BasicAttributeMapping; +import org.hibernate.spi.NavigablePath; +import org.hibernate.sql.ast.SqlAstJoinType; +import org.hibernate.sql.ast.spi.FromClauseAccess; +import org.hibernate.sql.ast.spi.SqlAstCreationState; +import org.hibernate.sql.ast.spi.SqlExpressionResolver; +import org.hibernate.sql.ast.spi.SqlSelection; +import org.hibernate.sql.ast.tree.expression.SqlTuple; +import org.hibernate.sql.ast.tree.from.TableGroup; +import org.hibernate.sql.ast.tree.from.TableGroupJoin; +import org.hibernate.sql.results.graph.AbstractFetchParent; +import org.hibernate.sql.results.graph.AssemblerCreationState; +import org.hibernate.sql.results.graph.DomainResult; +import org.hibernate.sql.results.graph.DomainResultAssembler; +import org.hibernate.sql.results.graph.DomainResultCreationState; +import org.hibernate.sql.results.graph.Fetch; +import org.hibernate.sql.results.graph.FetchParentAccess; +import org.hibernate.sql.results.graph.basic.BasicFetch; +import org.hibernate.sql.results.graph.embeddable.EmbeddableInitializer; +import org.hibernate.sql.results.graph.embeddable.EmbeddableResult; +import org.hibernate.sql.results.graph.embeddable.EmbeddableResultGraphNode; +import org.hibernate.type.descriptor.java.JavaType; +import org.hibernate.type.spi.TypeConfiguration; + +/** + * @author Steve Ebersole + */ +public class EmbeddableExpressionResultImpl extends AbstractFetchParent implements EmbeddableResultGraphNode, DomainResult, EmbeddableResult { + private final String resultVariable; + private final boolean containsAnyNonScalars; + + public EmbeddableExpressionResultImpl( + NavigablePath navigablePath, + EmbeddableValuedModelPart modelPart, + SqlTuple sqlExpression, + String resultVariable, + DomainResultCreationState creationState) { + super( modelPart.getEmbeddableTypeDescriptor(), navigablePath ); + this.resultVariable = resultVariable; + + final List fetches = new ArrayList<>(); + final EmbeddableMappingType mappingType = modelPart.getEmbeddableTypeDescriptor(); + final int numberOfAttributeMappings = mappingType.getNumberOfAttributeMappings(); + final SqlAstCreationState sqlAstCreationState = creationState.getSqlAstCreationState(); + final TypeConfiguration typeConfiguration = sqlAstCreationState.getCreationContext() + .getSessionFactory() + .getTypeConfiguration(); + final SqlExpressionResolver sqlExpressionResolver = sqlAstCreationState.getSqlExpressionResolver(); + for ( int i = 0; i < numberOfAttributeMappings; i++ ) { + final BasicAttributeMapping attribute = (BasicAttributeMapping) mappingType.getAttributeMapping( i ); + final SqlSelection sqlSelection = sqlExpressionResolver.resolveSqlSelection( + sqlExpression.getExpressions().get( i ), + attribute.getJavaType(), + this, + typeConfiguration + ); + fetches.add( + new BasicFetch<>( + sqlSelection.getValuesArrayPosition(), + this, + resolveNavigablePath( attribute ), + attribute, + FetchTiming.IMMEDIATE, + creationState + ) + ); + } + + this.fetches = fetches; + this.containsAnyNonScalars = determineIfContainedAnyScalars( fetches ); + } + + private static boolean determineIfContainedAnyScalars(List fetches) { + for ( int i = 0; i < fetches.size(); i++ ) { + if ( fetches.get( i ).containsAnyNonScalarResults() ) { + return true; + } + } + + return false; + } + + @Override + public String getResultVariable() { + return resultVariable; + } + + @Override + public boolean containsAnyNonScalarResults() { + return containsAnyNonScalars; + } + + @Override + public EmbeddableMappingType getFetchContainer() { + return (EmbeddableMappingType) super.getFetchContainer(); + } + + @Override + public JavaType getResultJavaType() { + return getReferencedMappingType().getJavaType(); + } + + @Override + public EmbeddableMappingType getReferencedMappingType() { + return getFetchContainer(); + } + + @Override + public EmbeddableValuedModelPart getReferencedMappingContainer() { + return getFetchContainer().getEmbeddedValueMapping(); + } + + @Override + public DomainResultAssembler createResultAssembler( + FetchParentAccess parentAccess, + AssemblerCreationState creationState) { + final EmbeddableInitializer initializer = (EmbeddableInitializer) creationState.resolveInitializer( + getNavigablePath(), + getReferencedModePart(), + () -> new EmbeddableResultInitializer( + this, + parentAccess, + creationState + ) + ); + + //noinspection unchecked + return new EmbeddableAssembler( initializer ); + } +} diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/query/QueryTimeOutTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/query/QueryTimeOutTest.java index bb64cbdda1..50f2465022 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/query/QueryTimeOutTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/query/QueryTimeOutTest.java @@ -11,7 +11,6 @@ import java.sql.Types; import java.util.Map; import org.hibernate.cfg.AvailableSettings; -import org.hibernate.dialect.SybaseDialect; import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider; import org.hibernate.query.NativeQuery; import org.hibernate.query.Query; @@ -85,19 +84,10 @@ public class QueryTimeOutTest extends BaseNonConfigCoreFunctionalTestCase { query.executeUpdate(); try { - if ( getDialect() instanceof SybaseDialect ) { - verify( - CONNECTION_PROVIDER.getPreparedStatement( - "update AnEntity set AnEntity.name='abc'" ), - times( 1 ) - ).setQueryTimeout( 123 ); - } - else { - verify( - CONNECTION_PROVIDER.getPreparedStatement( expectedSqlQuery ), - times( 1 ) - ).setQueryTimeout( 123 ); - } + verify( + CONNECTION_PROVIDER.getPreparedStatement( expectedSqlQuery ), + times( 1 ) + ).setQueryTimeout( 123 ); } catch (SQLException ex) { fail( "should not have thrown exception" ); @@ -116,19 +106,10 @@ public class QueryTimeOutTest extends BaseNonConfigCoreFunctionalTestCase { query.executeUpdate(); try { - if ( getDialect() instanceof SybaseDialect ) { - verify( - CONNECTION_PROVIDER.getPreparedStatement( - "update AnEntity set AnEntity.name='abc'" ), - times( 1 ) - ).setQueryTimeout( 123 ); - } - else { - verify( - CONNECTION_PROVIDER.getPreparedStatement( expectedSqlQuery ), - times( 1 ) - ).setQueryTimeout( 123 ); - } + verify( + CONNECTION_PROVIDER.getPreparedStatement( expectedSqlQuery ), + times( 1 ) + ).setQueryTimeout( 123 ); } catch (SQLException ex) { fail( "should not have thrown exception" );