Cleanup embeddable expression handling and resolving of column references

This commit is contained in:
Christian Beikov 2022-11-22 18:37:11 +01:00
parent c6fa10de6e
commit 67d751d81d
77 changed files with 792 additions and 999 deletions

View File

@ -358,9 +358,10 @@ public class SybaseASELegacySqlAstTranslator<T extends JdbcOperation> extends Ab
);
}
else {
appendSql( getCurrentDmlStatement().getTargetTable().getTableExpression() );
appendSql( '.' );
appendSql( columnReference.getColumnExpression() );
columnReference.appendReadExpression(
this,
getCurrentDmlStatement().getTargetTable().getTableExpression()
);
}
}
else {

View File

@ -344,9 +344,10 @@ public class SybaseASESqlAstTranslator<T extends JdbcOperation> extends Abstract
);
}
else {
appendSql( getCurrentDmlStatement().getTargetTable().getTableExpression() );
appendSql( '.' );
appendSql( columnReference.getColumnExpression() );
columnReference.appendReadExpression(
this,
getCurrentDmlStatement().getTargetTable().getTableExpression()
);
}
}
else {

View File

@ -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()
)
);
}

View File

@ -290,14 +290,7 @@ public abstract class AbstractNaturalIdLoader<T> implements NaturalIdLoader<T> {
)
);
}
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<T> implements NaturalIdLoader<T> {
private static List<Fetch> visitFetches(
FetchParent fetchParent,
QuerySpec querySpec,
LoaderSqlAstCreationState creationState) {
final FetchableContainer fetchableContainer = fetchParent.getReferencedMappingContainer();
final int size = fetchableContainer.getNumberOfFetchables();

View File

@ -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(

View File

@ -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<Fetch> visitFetches(
FetchParent fetchParent,
QuerySpec querySpec,
LoaderSqlAstCreationState creationState) {
private List<Fetch> 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<Fetch> fetches = new ArrayList<>();
final BiConsumer<Fetchable, Boolean> processor = createFetchableBiConsumer(
fetchParent,
querySpec,
creationState,
fetches
);
@ -688,7 +676,6 @@ public class LoaderSelectBuilder {
private BiConsumer<Fetchable, Boolean> createFetchableBiConsumer(
FetchParent fetchParent,
QuerySpec querySpec,
LoaderSqlAstCreationState creationState,
List<Fetch> 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(

View File

@ -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<Fetch> visitFetches(FetchParent fetchParent, QuerySpec querySpec, LoaderSqlAstCreationState creationState);
List<Fetch> 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<Fetch> visitFetches(FetchParent fetchParent) {
return fetchProcessor.visitFetches( fetchParent, processingState.getInflightQueryPart().getFirstQuerySpec(), this );
return fetchProcessor.visitFetches( fetchParent, this );
}
@Override

View File

@ -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 );
}

View File

@ -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
)
);
}

View File

@ -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

View File

@ -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,

View File

@ -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(

View File

@ -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,

View File

@ -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(

View File

@ -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,

View File

@ -149,8 +149,7 @@ public class CaseStatementDiscriminatorMappingImpl extends AbstractDiscriminator
false,
null,
null,
getJdbcMapping(),
getSessionFactory()
getJdbcMapping()
),
true
);

View File

@ -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,

View File

@ -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() );

View File

@ -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
)
);
}

View File

@ -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 );

View File

@ -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

View File

@ -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()

View File

@ -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

View File

@ -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 );
}

View File

@ -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 );
}

View File

@ -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()
)
);
}

View File

@ -68,8 +68,7 @@ public class ColumnReference implements OrderingExpression, SequencePart {
// is no need for the JdbcMapping
null,
null,
null,
creationState.getCreationContext().getSessionFactory()
null
)
);
}

View File

@ -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()
);

View File

@ -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<Fetch> fetchProcessor(FetchParent fetchParent, QuerySpec querySpec, LoaderSqlAstCreationState creationState) {
private List<Fetch> fetchProcessor(FetchParent fetchParent, LoaderSqlAstCreationState creationState) {
final FetchableContainer fetchableContainer = fetchParent.getReferencedMappingContainer();
final int size = fetchableContainer.getNumberOfFetchables();
final List<Fetch> fetches = new ArrayList<>( size );

View File

@ -754,8 +754,7 @@ public class SingleTableEntityPersister extends AbstractEntityPersister {
isDiscriminatorFormula(),
null,
null,
discriminatorType.getJdbcMapping(),
getFactory()
discriminatorType.getJdbcMapping()
)
);

View File

@ -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_" );

View File

@ -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(),

View File

@ -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() );
}

View File

@ -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
)
)
);

View File

@ -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() {
}

View File

@ -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<String> getColumnAliases();
}

View File

@ -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<String> getColumnAliases() {
return Collections.singletonList( selectionAlias );
}
@Override
public BasicFetch<?> buildFetch(
FetchParent parent,
@ -69,12 +77,11 @@ public class CompleteFetchBuilderBasicPart implements CompleteFetchBuilder, Basi
JdbcValuesMetadata jdbcResultsMetadata,
BiFunction<String, String, DynamicFetchBuilderLegacy> 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 )
);

View File

@ -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<String> 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,

View File

@ -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<String> 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,

View File

@ -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,

View File

@ -82,39 +82,9 @@ public class CompleteResultBuilderBasicValuedConverted<O,R> 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,

View File

@ -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

View File

@ -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,

View File

@ -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<String> getColumnAliases() {
return Collections.emptyList();
}
@Override
public boolean equals(Object o) {
if ( this == o ) {

View File

@ -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<String, String, DynamicFetchBuilderLegacy> 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()
);
}

View File

@ -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,

View File

@ -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<String, String, DynamicFetchBuilderLegacy> 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 );
}
),

View File

@ -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> T buildResultOrFetch(
Function<TableGroup, T> 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<String> idColumnAliases;
final FetchBuilder idFetchBuilder;
final List<String> 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<String> 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()
);
}

View File

@ -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(

View File

@ -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(

View File

@ -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()
)
)
);

View File

@ -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
)
)
);

View File

@ -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()
)
)
);

View File

@ -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
)
)
);

View File

@ -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() );

View File

@ -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 )
)
)
);

View File

@ -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<>(

View File

@ -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

View File

@ -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<Assignment> 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
)
)
);

View File

@ -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
)
);
}

View File

@ -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

View File

@ -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
)
);
}

View File

@ -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<T extends Statement> 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<T extends Statement> 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<T extends Statement> 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<T extends Statement> 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<T extends Statement> 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<T extends Statement> 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<T extends Statement> 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<T extends Statement> 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<T extends Statement> 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<T extends Statement> extends Base
final List<Expression> 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<T extends Statement> extends Base
navigablePath,
selectionMapping.getContainingTableExpression()
),
selectionMapping,
creationContext.getSessionFactory()
selectionMapping
)
)
);
@ -4489,8 +4479,7 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
navigablePath,
selectionMapping.getContainingTableExpression()
),
selectionMapping,
creationContext.getSessionFactory()
selectionMapping
);
final String columnName;
if ( selectionMapping.isFormula() ) {
@ -4528,8 +4517,7 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
false,
null,
null,
subQueryColumns.get( i ).getJdbcMapping(),
creationContext.getSessionFactory()
subQueryColumns.get( i ).getJdbcMapping()
)
);
}
@ -4572,8 +4560,7 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> 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<T extends Statement> 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<T extends Statement> extends Base
false,
null,
null,
selectionMapping.getJdbcMapping(),
creationContext.getSessionFactory()
selectionMapping.getJdbcMapping()
)
)
);
@ -5865,38 +5850,9 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> 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 )
);
}
}

View File

@ -94,15 +94,8 @@ public class BasicValuedPathInterpretation<T> 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;

View File

@ -45,12 +45,8 @@ public class DiscriminatedAssociationPathInterpretation<T> 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 );
}

View File

@ -51,15 +51,8 @@ public class DiscriminatedAssociationTypePathInterpretation<T> 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 );
}

View File

@ -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<T> implements Expression, DomainResultProducer<T>, 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<T> 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<ColumnReference> columnReferenceConsumer) {
for ( Expression expression : sqlExpression.getExpressions() ) {
if ( !( expression instanceof ColumnReference ) ) {
throw new IllegalArgumentException( "Expecting ColumnReference, found : " + expression );
}
columnReferenceConsumer.accept( (ColumnReference) expression );
}
}
@Override
public List<ColumnReference> getColumnReferences() {
final List<ColumnReference> results = new ArrayList<>();
visitColumnReferences( results::add );
return results;
}
@Override
public SqlTuple getSqlTuple() {
return sqlExpression;
}
@Override
public void accept(SqlAstWalker sqlTreeWalker) {
sqlExpression.accept( sqlTreeWalker );
}
}

View File

@ -242,6 +242,11 @@ public class EntityValuedPathInterpretation<T> 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<T> 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<T> 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<Expression> expressions = new ArrayList<>( resultModelPart.getJdbcTypeCount() );
@ -357,19 +345,7 @@ public class EntityValuedPathInterpretation<T> 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 );

View File

@ -1006,6 +1006,12 @@ public abstract class AbstractSqlAstTranslator<T extends JdbcOperation> implemen
clauseStack.pop();
}
renderSetClause( statement, clauseStack );
visitWhereClause( statement.getRestriction() );
visitReturningColumns( statement );
}
protected void renderSetClause(UpdateStatement statement, Stack<Clause> clauseStack) {
appendSql( " set " );
boolean firstPass = true;
try {
@ -1020,7 +1026,7 @@ public abstract class AbstractSqlAstTranslator<T extends JdbcOperation> implemen
final List<ColumnReference> 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<T extends JdbcOperation> 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<T extends JdbcOperation> 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<T extends JdbcOperation> implemen
false,
null,
null,
integerType,
sessionFactory
integerType
);
visitColumnReference( depthColumnReference );
appendSql( "+1" );
@ -2003,8 +2008,7 @@ public abstract class AbstractSqlAstTranslator<T extends JdbcOperation> implemen
false,
null,
null,
currentCteStatement.getSearchColumn().getJdbcMapping(),
sessionFactory
currentCteStatement.getSearchColumn().getJdbcMapping()
)
);
appendSql( "||" );
@ -2116,8 +2120,7 @@ public abstract class AbstractSqlAstTranslator<T extends JdbcOperation> implemen
false,
null,
null,
integerType,
sessionFactory
integerType
);
visitColumnReference( depthColumnReference );
appendSql( "+1" );
@ -2161,8 +2164,7 @@ public abstract class AbstractSqlAstTranslator<T extends JdbcOperation> implemen
false,
null,
null,
currentCteStatement.getSearchColumn().getJdbcMapping(),
sessionFactory
currentCteStatement.getSearchColumn().getJdbcMapping()
)
);
for ( SearchClauseSpecification searchBySpecification : currentCteStatement.getSearchBySpecifications() ) {
@ -2307,8 +2309,7 @@ public abstract class AbstractSqlAstTranslator<T extends JdbcOperation> implemen
false,
null,
null,
stringType,
sessionFactory
stringType
);
if ( !supportsRecursiveCycleClause() ) {
@ -2455,8 +2456,7 @@ public abstract class AbstractSqlAstTranslator<T extends JdbcOperation> 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<T extends JdbcOperation> implemen
false,
null,
null,
getIntegerType(),
null
getIntegerType()
)
)
);
@ -3101,8 +3100,7 @@ public abstract class AbstractSqlAstTranslator<T extends JdbcOperation> implemen
false,
null,
null,
expression.getExpressionType().getJdbcMappings().get( 0 ),
sessionFactory
expression.getExpressionType().getJdbcMappings().get( 0 )
);
}
@ -5565,8 +5563,7 @@ public abstract class AbstractSqlAstTranslator<T extends JdbcOperation> implemen
false,
null,
null,
null,
sessionFactory
null
)
);
}
@ -5636,8 +5633,7 @@ public abstract class AbstractSqlAstTranslator<T extends JdbcOperation> implemen
false,
null,
null,
null,
sessionFactory
null
)
);
}
@ -5762,8 +5758,7 @@ public abstract class AbstractSqlAstTranslator<T extends JdbcOperation> implemen
false,
null,
null,
null,
sessionFactory
null
);
sortExpression = sortSpecification.getSortExpression();
}
@ -6018,11 +6013,7 @@ public abstract class AbstractSqlAstTranslator<T extends JdbcOperation> implemen
);
}
else {
if ( qualifyColumn ) {
appendSql( tableExpression );
appendSql( '.' );
}
appendSql( columnReference.getColumnExpression() );
columnReference.appendReadExpression( this, qualifyColumn ? tableExpression : null );
}
}
else {

View File

@ -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.

View File

@ -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 );
}

View File

@ -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

View File

@ -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<String> nameCollector) {
}
@Override
public TableReference getPrimaryTableReference() {
return syntheticTableReference;
}
@Override
public List<TableReferenceJoin> 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;
}
}

View File

@ -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<String, Boolean> nameCollector);

View File

@ -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<String, Boolean> nameCollector) {
for ( String expression : subclassTableSpaceExpressions ) {
final Boolean result = nameCollector.apply( expression );
if ( result != null ) {
return result;
}
}
return null;
}
}

View File

@ -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<T> extends AbstractFetchParent implements EmbeddableResultGraphNode, DomainResult<T>, EmbeddableResult<T> {
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<Fetch> 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<Fetch> 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<T> createResultAssembler(
FetchParentAccess parentAccess,
AssemblerCreationState creationState) {
final EmbeddableInitializer initializer = (EmbeddableInitializer) creationState.resolveInitializer(
getNavigablePath(),
getReferencedModePart(),
() -> new EmbeddableResultInitializer(
this,
parentAccess,
creationState
)
);
//noinspection unchecked
return new EmbeddableAssembler( initializer );
}
}

View File

@ -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" );