Cleanup embeddable expression handling and resolving of column references
This commit is contained in:
parent
c6fa10de6e
commit
67d751d81d
|
@ -358,9 +358,10 @@ public class SybaseASELegacySqlAstTranslator<T extends JdbcOperation> extends Ab
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
appendSql( getCurrentDmlStatement().getTargetTable().getTableExpression() );
|
columnReference.appendReadExpression(
|
||||||
appendSql( '.' );
|
this,
|
||||||
appendSql( columnReference.getColumnExpression() );
|
getCurrentDmlStatement().getTargetTable().getTableExpression()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
|
@ -344,9 +344,10 @@ public class SybaseASESqlAstTranslator<T extends JdbcOperation> extends Abstract
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
appendSql( getCurrentDmlStatement().getTargetTable().getTableExpression() );
|
columnReference.appendReadExpression(
|
||||||
appendSql( '.' );
|
this,
|
||||||
appendSql( columnReference.getColumnExpression() );
|
getCurrentDmlStatement().getTargetTable().getTableExpression()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
|
@ -123,8 +123,7 @@ public class AggregateWindowEmulationQueryTransformer implements QueryTransforme
|
||||||
false,
|
false,
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
mapping.getJdbcMapping(),
|
mapping.getJdbcMapping()
|
||||||
factory
|
|
||||||
);
|
);
|
||||||
final Expression expression = subSelections.get( i ).getExpression();
|
final Expression expression = subSelections.get( i ).getExpression();
|
||||||
final Expression finalExpression;
|
final Expression finalExpression;
|
||||||
|
@ -194,8 +193,7 @@ public class AggregateWindowEmulationQueryTransformer implements QueryTransforme
|
||||||
false,
|
false,
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
jdbcMapping,
|
jdbcMapping
|
||||||
factory
|
|
||||||
);
|
);
|
||||||
final int subValuesPosition = subSelectClause.getSqlSelections().size();
|
final int subValuesPosition = subSelectClause.getSqlSelections().size();
|
||||||
final SqlSelection subSelection = new ResolvedSqlSelection(
|
final SqlSelection subSelection = new ResolvedSqlSelection(
|
||||||
|
@ -259,8 +257,7 @@ public class AggregateWindowEmulationQueryTransformer implements QueryTransforme
|
||||||
false,
|
false,
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
jdbcMapping,
|
jdbcMapping
|
||||||
factory
|
|
||||||
);
|
);
|
||||||
final int subValuesPosition = subSelectClause.getSqlSelections().size();
|
final int subValuesPosition = subSelectClause.getSqlSelections().size();
|
||||||
final SqlSelection subSelection = new ResolvedSqlSelection(
|
final SqlSelection subSelection = new ResolvedSqlSelection(
|
||||||
|
@ -321,8 +318,7 @@ public class AggregateWindowEmulationQueryTransformer implements QueryTransforme
|
||||||
false,
|
false,
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
jdbcMapping,
|
jdbcMapping
|
||||||
factory
|
|
||||||
);
|
);
|
||||||
final int subValuesPosition = subSelectClause.getSqlSelections().size();
|
final int subValuesPosition = subSelectClause.getSqlSelections().size();
|
||||||
final SqlSelection subSelection = new ResolvedSqlSelection(
|
final SqlSelection subSelection = new ResolvedSqlSelection(
|
||||||
|
@ -379,8 +375,7 @@ public class AggregateWindowEmulationQueryTransformer implements QueryTransforme
|
||||||
false,
|
false,
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
mapping.getJdbcMapping(),
|
mapping.getJdbcMapping()
|
||||||
factory
|
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -290,14 +290,7 @@ public abstract class AbstractNaturalIdLoader<T> implements NaturalIdLoader<T> {
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return sqlExpressionResolver.resolveSqlExpression(
|
return sqlExpressionResolver.resolveSqlExpression( tableReference, selectableMapping );
|
||||||
SqlExpressionResolver.createColumnReferenceKey( tableReference, selectableMapping.getSelectionExpression() ),
|
|
||||||
(processingState) -> new ColumnReference(
|
|
||||||
tableReference,
|
|
||||||
selectableMapping,
|
|
||||||
sessionFactory
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -423,7 +416,6 @@ public abstract class AbstractNaturalIdLoader<T> implements NaturalIdLoader<T> {
|
||||||
|
|
||||||
private static List<Fetch> visitFetches(
|
private static List<Fetch> visitFetches(
|
||||||
FetchParent fetchParent,
|
FetchParent fetchParent,
|
||||||
QuerySpec querySpec,
|
|
||||||
LoaderSqlAstCreationState creationState) {
|
LoaderSqlAstCreationState creationState) {
|
||||||
final FetchableContainer fetchableContainer = fetchParent.getReferencedMappingContainer();
|
final FetchableContainer fetchableContainer = fetchParent.getReferencedMappingContainer();
|
||||||
final int size = fetchableContainer.getNumberOfFetchables();
|
final int size = fetchableContainer.getNumberOfFetchables();
|
||||||
|
|
|
@ -77,7 +77,7 @@ class DatabaseSnapshotExecutor {
|
||||||
sqlAliasBaseManager,
|
sqlAliasBaseManager,
|
||||||
new FromClauseIndex( null ),
|
new FromClauseIndex( null ),
|
||||||
LockOptions.NONE,
|
LockOptions.NONE,
|
||||||
(fetchParent, ast, creationState) -> Collections.emptyList(),
|
(fetchParent, creationState) -> Collections.emptyList(),
|
||||||
true,
|
true,
|
||||||
sessionFactory
|
sessionFactory
|
||||||
);
|
);
|
||||||
|
@ -122,14 +122,7 @@ class DatabaseSnapshotExecutor {
|
||||||
jdbcParameters.add( jdbcParameter );
|
jdbcParameters.add( jdbcParameter );
|
||||||
|
|
||||||
final ColumnReference columnReference = (ColumnReference) sqlExpressionResolver
|
final ColumnReference columnReference = (ColumnReference) sqlExpressionResolver
|
||||||
.resolveSqlExpression(
|
.resolveSqlExpression( tableReference, selection );
|
||||||
createColumnReferenceKey( tableReference, selection.getSelectionExpression() ),
|
|
||||||
s -> new ColumnReference(
|
|
||||||
tableReference,
|
|
||||||
selection,
|
|
||||||
sessionFactory
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
rootQuerySpec.applyPredicate(
|
rootQuerySpec.applyPredicate(
|
||||||
new ComparisonPredicate(
|
new ComparisonPredicate(
|
||||||
|
|
|
@ -56,6 +56,7 @@ import org.hibernate.sql.ast.spi.SimpleFromClauseAccessImpl;
|
||||||
import org.hibernate.sql.ast.spi.SqlAliasBaseManager;
|
import org.hibernate.sql.ast.spi.SqlAliasBaseManager;
|
||||||
import org.hibernate.sql.ast.spi.SqlAstCreationContext;
|
import org.hibernate.sql.ast.spi.SqlAstCreationContext;
|
||||||
import org.hibernate.sql.ast.spi.SqlAstCreationState;
|
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.spi.SqlExpressionResolver;
|
||||||
import org.hibernate.sql.ast.tree.expression.ColumnReference;
|
import org.hibernate.sql.ast.tree.expression.ColumnReference;
|
||||||
import org.hibernate.sql.ast.tree.expression.Expression;
|
import org.hibernate.sql.ast.tree.expression.Expression;
|
||||||
|
@ -513,13 +514,8 @@ public class LoaderSelectBuilder {
|
||||||
navigablePath, selection.getContainingTableExpression() );
|
navigablePath, selection.getContainingTableExpression() );
|
||||||
final ColumnReference columnRef =
|
final ColumnReference columnRef =
|
||||||
(ColumnReference) sqlExpressionResolver.resolveSqlExpression(
|
(ColumnReference) sqlExpressionResolver.resolveSqlExpression(
|
||||||
createColumnReferenceKey( tableReference, selection.getSelectionExpression() ),
|
|
||||||
p -> new ColumnReference(
|
|
||||||
tableReference,
|
tableReference,
|
||||||
selection,
|
selection
|
||||||
creationContext.getSessionFactory()
|
|
||||||
)
|
|
||||||
|
|
||||||
);
|
);
|
||||||
if ( numberOfKeysToLoad == 1 ) {
|
if ( numberOfKeysToLoad == 1 ) {
|
||||||
final JdbcParameter jdbcParameter = new JdbcParameterImpl( selection.getJdbcMapping() );
|
final JdbcParameter jdbcParameter = new JdbcParameterImpl( selection.getJdbcMapping() );
|
||||||
|
@ -552,12 +548,8 @@ public class LoaderSelectBuilder {
|
||||||
final TableReference tableReference = rootTableGroup.resolveTableReference( navigablePath, selection.getContainingTableExpression() );
|
final TableReference tableReference = rootTableGroup.resolveTableReference( navigablePath, selection.getContainingTableExpression() );
|
||||||
columnReferences.add(
|
columnReferences.add(
|
||||||
(ColumnReference) sqlExpressionResolver.resolveSqlExpression(
|
(ColumnReference) sqlExpressionResolver.resolveSqlExpression(
|
||||||
createColumnReferenceKey( tableReference, selection.getSelectionExpression() ),
|
|
||||||
p -> new ColumnReference(
|
|
||||||
tableReference,
|
tableReference,
|
||||||
selection,
|
selection
|
||||||
creationContext.getSessionFactory()
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -656,10 +648,7 @@ public class LoaderSelectBuilder {
|
||||||
orderByFragments.add( new AbstractMap.SimpleEntry<>( orderByFragment, tableGroup ) );
|
orderByFragments.add( new AbstractMap.SimpleEntry<>( orderByFragment, tableGroup ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<Fetch> visitFetches(
|
private List<Fetch> visitFetches(FetchParent fetchParent, LoaderSqlAstCreationState creationState) {
|
||||||
FetchParent fetchParent,
|
|
||||||
QuerySpec querySpec,
|
|
||||||
LoaderSqlAstCreationState creationState) {
|
|
||||||
if ( log.isTraceEnabled() ) {
|
if ( log.isTraceEnabled() ) {
|
||||||
log.tracef( "Starting visitation of FetchParent's Fetchables : %s", fetchParent.getNavigablePath() );
|
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 List<Fetch> fetches = new ArrayList<>();
|
||||||
final BiConsumer<Fetchable, Boolean> processor = createFetchableBiConsumer(
|
final BiConsumer<Fetchable, Boolean> processor = createFetchableBiConsumer(
|
||||||
fetchParent,
|
fetchParent,
|
||||||
querySpec,
|
|
||||||
creationState,
|
creationState,
|
||||||
fetches
|
fetches
|
||||||
);
|
);
|
||||||
|
@ -688,7 +676,6 @@ public class LoaderSelectBuilder {
|
||||||
|
|
||||||
private BiConsumer<Fetchable, Boolean> createFetchableBiConsumer(
|
private BiConsumer<Fetchable, Boolean> createFetchableBiConsumer(
|
||||||
FetchParent fetchParent,
|
FetchParent fetchParent,
|
||||||
QuerySpec querySpec,
|
|
||||||
LoaderSqlAstCreationState creationState,
|
LoaderSqlAstCreationState creationState,
|
||||||
List<Fetch> fetches) {
|
List<Fetch> fetches) {
|
||||||
return (fetchable, isKeyFetchable) -> {
|
return (fetchable, isKeyFetchable) -> {
|
||||||
|
@ -858,6 +845,7 @@ public class LoaderSelectBuilder {
|
||||||
hasCollectionJoinFetches = true;
|
hasCollectionJoinFetches = true;
|
||||||
final TableGroup joinTableGroup = creationState.getFromClauseAccess()
|
final TableGroup joinTableGroup = creationState.getFromClauseAccess()
|
||||||
.getTableGroup( fetchablePath );
|
.getTableGroup( fetchablePath );
|
||||||
|
final QuerySpec querySpec = creationState.getInflightQueryPart().getFirstQuerySpec();
|
||||||
applyFiltering(
|
applyFiltering(
|
||||||
querySpec,
|
querySpec,
|
||||||
joinTableGroup,
|
joinTableGroup,
|
||||||
|
@ -1038,16 +1026,8 @@ public class LoaderSelectBuilder {
|
||||||
simpleFkDescriptor.getContainingTableExpression()
|
simpleFkDescriptor.getContainingTableExpression()
|
||||||
);
|
);
|
||||||
fkExpression = sqlAstCreationState.getSqlExpressionResolver().resolveSqlExpression(
|
fkExpression = sqlAstCreationState.getSqlExpressionResolver().resolveSqlExpression(
|
||||||
createColumnReferenceKey( tableReference, simpleFkDescriptor.getSelectionExpression() ),
|
|
||||||
sqlAstProcessingState -> new ColumnReference(
|
|
||||||
tableReference,
|
tableReference,
|
||||||
simpleFkDescriptor.getSelectionExpression(),
|
simpleFkDescriptor
|
||||||
false,
|
|
||||||
null,
|
|
||||||
null,
|
|
||||||
simpleFkDescriptor.getJdbcMapping(),
|
|
||||||
this.creationContext.getSessionFactory()
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -1060,17 +1040,7 @@ public class LoaderSelectBuilder {
|
||||||
);
|
);
|
||||||
columnReferences.add(
|
columnReferences.add(
|
||||||
(ColumnReference) sqlAstCreationState.getSqlExpressionResolver()
|
(ColumnReference) sqlAstCreationState.getSqlExpressionResolver()
|
||||||
.resolveSqlExpression(
|
.resolveSqlExpression( tableReference, selection )
|
||||||
createColumnReferenceKey(
|
|
||||||
tableReference,
|
|
||||||
selection.getSelectionExpression()
|
|
||||||
),
|
|
||||||
sqlAstProcessingState -> new ColumnReference(
|
|
||||||
tableReference,
|
|
||||||
selection,
|
|
||||||
this.creationContext.getSessionFactory()
|
|
||||||
)
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -1121,12 +1091,8 @@ public class LoaderSelectBuilder {
|
||||||
// for each column, resolve a SqlSelection and add it to the sub-query select-clause
|
// for each column, resolve a SqlSelection and add it to the sub-query select-clause
|
||||||
final TableReference tableReference = ownerTableGroup.resolveTableReference( navigablePath, selection.getContainingTableExpression() );
|
final TableReference tableReference = ownerTableGroup.resolveTableReference( navigablePath, selection.getContainingTableExpression() );
|
||||||
final Expression expression = sqlExpressionResolver.resolveSqlExpression(
|
final Expression expression = sqlExpressionResolver.resolveSqlExpression(
|
||||||
createColumnReferenceKey( tableReference, selection.getSelectionExpression() ),
|
|
||||||
sqlAstProcessingState -> new ColumnReference(
|
|
||||||
tableReference,
|
tableReference,
|
||||||
selection,
|
selection
|
||||||
sessionFactory
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
subQuery.getSelectClause().addSqlSelection(
|
subQuery.getSelectClause().addSqlSelection(
|
||||||
new SqlSelectionImpl(
|
new SqlSelectionImpl(
|
||||||
|
|
|
@ -32,9 +32,9 @@ import org.hibernate.sql.ast.spi.SqlAliasBaseManager;
|
||||||
import org.hibernate.sql.ast.spi.SqlAstCreationContext;
|
import org.hibernate.sql.ast.spi.SqlAstCreationContext;
|
||||||
import org.hibernate.sql.ast.spi.SqlAstCreationState;
|
import org.hibernate.sql.ast.spi.SqlAstCreationState;
|
||||||
import org.hibernate.sql.ast.spi.SqlAstProcessingState;
|
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.spi.SqlExpressionResolver;
|
||||||
import org.hibernate.sql.ast.tree.select.QueryPart;
|
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.DomainResultCreationState;
|
||||||
import org.hibernate.sql.results.graph.Fetch;
|
import org.hibernate.sql.results.graph.Fetch;
|
||||||
import org.hibernate.sql.results.graph.FetchParent;
|
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
|
* Helper used when generating the database-snapshot select query
|
||||||
*/
|
*/
|
||||||
public class LoaderSqlAstCreationState
|
public class LoaderSqlAstCreationState
|
||||||
implements SqlAstProcessingState, SqlAstCreationState, DomainResultCreationState, QueryOptions {
|
implements SqlAstQueryPartProcessingState, SqlAstCreationState, DomainResultCreationState, QueryOptions {
|
||||||
public interface FetchProcessor {
|
public interface FetchProcessor {
|
||||||
List<Fetch> visitFetches(FetchParent fetchParent, QuerySpec querySpec, LoaderSqlAstCreationState creationState);
|
List<Fetch> visitFetches(FetchParent fetchParent, LoaderSqlAstCreationState creationState);
|
||||||
}
|
}
|
||||||
|
|
||||||
private final SqlAliasBaseManager sqlAliasBaseManager;
|
private final SqlAliasBaseManager sqlAliasBaseManager;
|
||||||
|
@ -93,6 +93,11 @@ public class LoaderSqlAstCreationState
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public QueryPart getInflightQueryPart() {
|
||||||
|
return processingState.getInflightQueryPart();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SqlExpressionResolver getSqlExpressionResolver() {
|
public SqlExpressionResolver getSqlExpressionResolver() {
|
||||||
return processingState;
|
return processingState;
|
||||||
|
@ -115,7 +120,7 @@ public class LoaderSqlAstCreationState
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Fetch> visitFetches(FetchParent fetchParent) {
|
public List<Fetch> visitFetches(FetchParent fetchParent) {
|
||||||
return fetchProcessor.visitFetches( fetchParent, processingState.getInflightQueryPart().getFirstQuerySpec(), this );
|
return fetchProcessor.visitFetches( fetchParent, this );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -238,17 +238,7 @@ public abstract class AbstractCompositeIdentifierMapping
|
||||||
? defaultTableReference
|
? defaultTableReference
|
||||||
: tableGroup.resolveTableReference( navigablePath, selection.getContainingTableExpression() );
|
: tableGroup.resolveTableReference( navigablePath, selection.getContainingTableExpression() );
|
||||||
final Expression columnReference = sqlAstCreationState.getSqlExpressionResolver()
|
final Expression columnReference = sqlAstCreationState.getSqlExpressionResolver()
|
||||||
.resolveSqlExpression(
|
.resolveSqlExpression( tableReference, selection );
|
||||||
SqlExpressionResolver.createColumnReferenceKey(
|
|
||||||
tableReference,
|
|
||||||
selection.getSelectionExpression()
|
|
||||||
),
|
|
||||||
sqlAstProcessingState -> new ColumnReference(
|
|
||||||
tableReference.getIdentificationVariable(),
|
|
||||||
selection,
|
|
||||||
sqlAstCreationState.getCreationContext().getSessionFactory()
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
columnReferences.add( (ColumnReference) columnReference );
|
columnReferences.add( (ColumnReference) columnReference );
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,17 +57,15 @@ public class MappingModelHelper {
|
||||||
if ( sqlExpressionResolver == null ) {
|
if ( sqlExpressionResolver == null ) {
|
||||||
colRef = new ColumnReference(
|
colRef = new ColumnReference(
|
||||||
qualifier,
|
qualifier,
|
||||||
selection,
|
selection
|
||||||
sessionFactory
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
colRef = (ColumnReference) sqlExpressionResolver.resolveSqlExpression(
|
colRef = (ColumnReference) sqlExpressionResolver.resolveSqlExpression(
|
||||||
createColumnReferenceKey( qualifier, selection.getSelectionExpression() ),
|
createColumnReferenceKey( qualifier, selection ),
|
||||||
sqlAstProcessingState -> new ColumnReference(
|
sqlAstProcessingState -> new ColumnReference(
|
||||||
qualifier,
|
qualifier,
|
||||||
selection,
|
selection
|
||||||
sessionFactory
|
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -89,17 +87,15 @@ public class MappingModelHelper {
|
||||||
if ( sqlExpressionResolver == null ) {
|
if ( sqlExpressionResolver == null ) {
|
||||||
return new ColumnReference(
|
return new ColumnReference(
|
||||||
qualifier,
|
qualifier,
|
||||||
basicPart,
|
basicPart
|
||||||
sessionFactory
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return sqlExpressionResolver.resolveSqlExpression(
|
return sqlExpressionResolver.resolveSqlExpression(
|
||||||
createColumnReferenceKey( qualifier, basicPart.getSelectionExpression() ),
|
createColumnReferenceKey( qualifier, basicPart ),
|
||||||
sqlAstProcessingState -> new ColumnReference(
|
sqlAstProcessingState -> new ColumnReference(
|
||||||
qualifier,
|
qualifier,
|
||||||
basicPart,
|
basicPart
|
||||||
sessionFactory
|
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,6 +31,8 @@ import org.hibernate.sql.ast.tree.select.QuerySpec;
|
||||||
import org.hibernate.sql.ast.tree.select.SortSpecification;
|
import org.hibernate.sql.ast.tree.select.SortSpecification;
|
||||||
import org.hibernate.sql.results.graph.Fetchable;
|
import org.hibernate.sql.results.graph.Fetchable;
|
||||||
|
|
||||||
|
import static org.hibernate.sql.ast.spi.SqlExpressionResolver.createColumnReferenceKey;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Andrea Boriero
|
* @author Andrea Boriero
|
||||||
*/
|
*/
|
||||||
|
@ -62,14 +64,10 @@ public abstract class AbstractDomainPath implements DomainPath {
|
||||||
final BasicValuedModelPart selection = (BasicValuedModelPart) referenceModelPart;
|
final BasicValuedModelPart selection = (BasicValuedModelPart) referenceModelPart;
|
||||||
final TableReference tableReference = tableGroup.resolveTableReference( getNavigablePath(), selection.getContainingTableExpression() );
|
final TableReference tableReference = tableGroup.resolveTableReference( getNavigablePath(), selection.getContainingTableExpression() );
|
||||||
return creationState.getSqlExpressionResolver().resolveSqlExpression(
|
return creationState.getSqlExpressionResolver().resolveSqlExpression(
|
||||||
SqlExpressionResolver.createColumnReferenceKey(
|
createColumnReferenceKey( tableReference, selection.getSelectionExpression() ),
|
||||||
|
processingState -> new ColumnReference(
|
||||||
tableReference,
|
tableReference,
|
||||||
selection.getSelectionExpression()
|
selection
|
||||||
),
|
|
||||||
sqlAstProcessingState -> new ColumnReference(
|
|
||||||
tableReference,
|
|
||||||
selection,
|
|
||||||
creationState.getCreationContext().getSessionFactory()
|
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -247,14 +245,10 @@ public abstract class AbstractDomainPath implements DomainPath {
|
||||||
SqlAstCreationState creationState) {
|
SqlAstCreationState creationState) {
|
||||||
final TableReference tableReference = tableGroup.resolveTableReference( getNavigablePath(), selection.getContainingTableExpression() );
|
final TableReference tableReference = tableGroup.resolveTableReference( getNavigablePath(), selection.getContainingTableExpression() );
|
||||||
final Expression expression = creationState.getSqlExpressionResolver().resolveSqlExpression(
|
final Expression expression = creationState.getSqlExpressionResolver().resolveSqlExpression(
|
||||||
SqlExpressionResolver.createColumnReferenceKey(
|
createColumnReferenceKey( tableReference, selection.getSelectionExpression() ),
|
||||||
|
processingState -> new ColumnReference(
|
||||||
tableReference,
|
tableReference,
|
||||||
selection.getSelectionExpression()
|
selection
|
||||||
),
|
|
||||||
sqlAstProcessingState -> new ColumnReference(
|
|
||||||
tableReference,
|
|
||||||
selection,
|
|
||||||
creationState.getCreationContext().getSessionFactory()
|
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
// It makes no sense to order by an expression multiple times
|
// It makes no sense to order by an expression multiple times
|
||||||
|
|
|
@ -260,16 +260,8 @@ public class AnyDiscriminatorPart implements BasicValuedModelPart, FetchOptions,
|
||||||
final TableGroup tableGroup = fromClauseAccess.getTableGroup( fetchablePath.getParent().getParent() );
|
final TableGroup tableGroup = fromClauseAccess.getTableGroup( fetchablePath.getParent().getParent() );
|
||||||
final TableReference tableReference = tableGroup.resolveTableReference( fetchablePath, table );
|
final TableReference tableReference = tableGroup.resolveTableReference( fetchablePath, table );
|
||||||
final Expression columnReference = sqlExpressionResolver.resolveSqlExpression(
|
final Expression columnReference = sqlExpressionResolver.resolveSqlExpression(
|
||||||
createColumnReferenceKey( tableReference, column ),
|
|
||||||
processingState -> new ColumnReference(
|
|
||||||
tableReference,
|
tableReference,
|
||||||
column,
|
this
|
||||||
false,
|
|
||||||
null,
|
|
||||||
null,
|
|
||||||
jdbcMapping(),
|
|
||||||
sessionFactory
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
final SqlSelection sqlSelection = sqlExpressionResolver.resolveSqlSelection(
|
final SqlSelection sqlSelection = sqlExpressionResolver.resolveSqlSelection(
|
||||||
columnReference,
|
columnReference,
|
||||||
|
|
|
@ -184,16 +184,8 @@ public class AnyKeyPart implements BasicValuedModelPart, FetchOptions {
|
||||||
final TableReference tableReference = tableGroup.resolveTableReference( fetchablePath, table );
|
final TableReference tableReference = tableGroup.resolveTableReference( fetchablePath, table );
|
||||||
|
|
||||||
final Expression columnReference = sqlExpressionResolver.resolveSqlExpression(
|
final Expression columnReference = sqlExpressionResolver.resolveSqlExpression(
|
||||||
SqlExpressionResolver.createColumnReferenceKey( tableReference, column ),
|
|
||||||
processingState -> new ColumnReference(
|
|
||||||
tableReference,
|
tableReference,
|
||||||
column,
|
this
|
||||||
false,
|
|
||||||
null,
|
|
||||||
null,
|
|
||||||
jdbcMapping,
|
|
||||||
sessionFactory
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
|
|
||||||
final SqlSelection sqlSelection = sqlExpressionResolver.resolveSqlSelection(
|
final SqlSelection sqlSelection = sqlExpressionResolver.resolveSqlSelection(
|
||||||
|
|
|
@ -262,15 +262,8 @@ public class BasicAttributeMapping
|
||||||
|
|
||||||
return expressionResolver.resolveSqlSelection(
|
return expressionResolver.resolveSqlSelection(
|
||||||
expressionResolver.resolveSqlExpression(
|
expressionResolver.resolveSqlExpression(
|
||||||
SqlExpressionResolver.createColumnReferenceKey(
|
|
||||||
tableReference,
|
tableReference,
|
||||||
mappedColumnExpression
|
this
|
||||||
),
|
|
||||||
sqlAstProcessingState -> new ColumnReference(
|
|
||||||
tableReference,
|
|
||||||
this,
|
|
||||||
creationState.getSqlAstCreationState().getCreationContext().getSessionFactory()
|
|
||||||
)
|
|
||||||
),
|
),
|
||||||
jdbcMapping.getJdbcJavaType(),
|
jdbcMapping.getJdbcJavaType(),
|
||||||
fetchParent,
|
fetchParent,
|
||||||
|
|
|
@ -260,16 +260,8 @@ public class BasicEntityIdentifierMappingImpl implements BasicEntityIdentifierMa
|
||||||
}
|
}
|
||||||
|
|
||||||
final Expression expression = expressionResolver.resolveSqlExpression(
|
final Expression expression = expressionResolver.resolveSqlExpression(
|
||||||
SqlExpressionResolver.createColumnReferenceKey( rootTableReference, pkColumnName ),
|
|
||||||
sqlAstProcessingState -> new ColumnReference(
|
|
||||||
rootTableReference,
|
rootTableReference,
|
||||||
pkColumnName,
|
this
|
||||||
false,
|
|
||||||
null,
|
|
||||||
null,
|
|
||||||
( (BasicValuedMapping) entityPersister.getIdentifierType() ).getJdbcMapping(),
|
|
||||||
sessionFactory
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
|
|
||||||
return expressionResolver.resolveSqlSelection(
|
return expressionResolver.resolveSqlSelection(
|
||||||
|
|
|
@ -175,15 +175,8 @@ public class BasicValuedCollectionPart
|
||||||
);
|
);
|
||||||
return exprResolver.resolveSqlSelection(
|
return exprResolver.resolveSqlSelection(
|
||||||
exprResolver.resolveSqlExpression(
|
exprResolver.resolveSqlExpression(
|
||||||
SqlExpressionResolver.createColumnReferenceKey(
|
|
||||||
tableReference,
|
tableReference,
|
||||||
selectableMapping.getSelectionExpression()
|
selectableMapping
|
||||||
),
|
|
||||||
sqlAstProcessingState -> new ColumnReference(
|
|
||||||
tableReference,
|
|
||||||
selectableMapping,
|
|
||||||
creationState.getSqlAstCreationState().getCreationContext().getSessionFactory()
|
|
||||||
)
|
|
||||||
),
|
),
|
||||||
getJdbcMapping().getJdbcJavaType(),
|
getJdbcMapping().getJdbcJavaType(),
|
||||||
fetchParent,
|
fetchParent,
|
||||||
|
|
|
@ -149,8 +149,7 @@ public class CaseStatementDiscriminatorMappingImpl extends AbstractDiscriminator
|
||||||
false,
|
false,
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
getJdbcMapping(),
|
getJdbcMapping()
|
||||||
getSessionFactory()
|
|
||||||
),
|
),
|
||||||
true
|
true
|
||||||
);
|
);
|
||||||
|
|
|
@ -216,19 +216,8 @@ public class CollectionIdentifierDescriptorImpl implements CollectionIdentifierD
|
||||||
|
|
||||||
final SqlSelection sqlSelection = sqlExpressionResolver.resolveSqlSelection(
|
final SqlSelection sqlSelection = sqlExpressionResolver.resolveSqlSelection(
|
||||||
sqlExpressionResolver.resolveSqlExpression(
|
sqlExpressionResolver.resolveSqlExpression(
|
||||||
SqlExpressionResolver.createColumnReferenceKey(
|
|
||||||
tableGroup.getPrimaryTableReference(),
|
tableGroup.getPrimaryTableReference(),
|
||||||
columnName
|
this
|
||||||
),
|
|
||||||
p -> new ColumnReference(
|
|
||||||
tableGroup.getPrimaryTableReference().getIdentificationVariable(),
|
|
||||||
columnName,
|
|
||||||
false,
|
|
||||||
null,
|
|
||||||
null,
|
|
||||||
type,
|
|
||||||
sessionFactory
|
|
||||||
)
|
|
||||||
),
|
),
|
||||||
type.getJdbcJavaType(),
|
type.getJdbcJavaType(),
|
||||||
fetchParent,
|
fetchParent,
|
||||||
|
@ -256,19 +245,8 @@ public class CollectionIdentifierDescriptorImpl implements CollectionIdentifierD
|
||||||
|
|
||||||
final SqlSelection sqlSelection = sqlExpressionResolver.resolveSqlSelection(
|
final SqlSelection sqlSelection = sqlExpressionResolver.resolveSqlSelection(
|
||||||
sqlExpressionResolver.resolveSqlExpression(
|
sqlExpressionResolver.resolveSqlExpression(
|
||||||
SqlExpressionResolver.createColumnReferenceKey(
|
|
||||||
tableGroup.getPrimaryTableReference(),
|
tableGroup.getPrimaryTableReference(),
|
||||||
columnName
|
this
|
||||||
),
|
|
||||||
p -> new ColumnReference(
|
|
||||||
tableGroup.getPrimaryTableReference().getIdentificationVariable(),
|
|
||||||
columnName,
|
|
||||||
false,
|
|
||||||
null,
|
|
||||||
null,
|
|
||||||
type,
|
|
||||||
sessionFactory
|
|
||||||
)
|
|
||||||
),
|
),
|
||||||
type.getJdbcJavaType(),
|
type.getJdbcJavaType(),
|
||||||
null,
|
null,
|
||||||
|
|
|
@ -260,15 +260,8 @@ public class EmbeddedAttributeMapping
|
||||||
? defaultTableReference
|
? defaultTableReference
|
||||||
: tableGroup.resolveTableReference( navigablePath, selection.getContainingTableExpression() );
|
: tableGroup.resolveTableReference( navigablePath, selection.getContainingTableExpression() );
|
||||||
final Expression columnReference = sqlAstCreationState.getSqlExpressionResolver().resolveSqlExpression(
|
final Expression columnReference = sqlAstCreationState.getSqlExpressionResolver().resolveSqlExpression(
|
||||||
SqlExpressionResolver.createColumnReferenceKey(
|
|
||||||
tableReference,
|
tableReference,
|
||||||
selection.getSelectionExpression()
|
selection
|
||||||
),
|
|
||||||
sqlAstProcessingState -> new ColumnReference(
|
|
||||||
tableReference.getIdentificationVariable(),
|
|
||||||
selection,
|
|
||||||
sqlAstCreationState.getCreationContext().getSessionFactory()
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
|
|
||||||
columnReferences.add( columnReference.getColumnReference() );
|
columnReferences.add( columnReference.getColumnReference() );
|
||||||
|
|
|
@ -207,12 +207,8 @@ public class EmbeddedCollectionPart implements CollectionPart, EmbeddableValuedF
|
||||||
);
|
);
|
||||||
expressions.add(
|
expressions.add(
|
||||||
sqlExpressionResolver.resolveSqlExpression(
|
sqlExpressionResolver.resolveSqlExpression(
|
||||||
SqlExpressionResolver.createColumnReferenceKey( tableReference, selection.getSelectionExpression() ),
|
|
||||||
sqlAstProcessingState -> new ColumnReference(
|
|
||||||
tableReference,
|
tableReference,
|
||||||
selection,
|
selection
|
||||||
sqlAstCreationState.getCreationContext().getSessionFactory()
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,6 @@ import java.util.function.IntFunction;
|
||||||
import org.hibernate.engine.spi.SharedSessionContractImplementor;
|
import org.hibernate.engine.spi.SharedSessionContractImplementor;
|
||||||
import org.hibernate.mapping.IndexedConsumer;
|
import org.hibernate.mapping.IndexedConsumer;
|
||||||
import org.hibernate.metamodel.mapping.AssociationKey;
|
import org.hibernate.metamodel.mapping.AssociationKey;
|
||||||
import org.hibernate.metamodel.mapping.AttributeMapping;
|
|
||||||
import org.hibernate.metamodel.mapping.CompositeIdentifierMapping;
|
import org.hibernate.metamodel.mapping.CompositeIdentifierMapping;
|
||||||
import org.hibernate.metamodel.mapping.EmbeddableValuedModelPart;
|
import org.hibernate.metamodel.mapping.EmbeddableValuedModelPart;
|
||||||
import org.hibernate.metamodel.mapping.EntityMappingType;
|
import org.hibernate.metamodel.mapping.EntityMappingType;
|
||||||
|
@ -369,14 +368,12 @@ public class EmbeddedForeignKeyDescriptor implements ForeignKeyDescriptor {
|
||||||
final ComparisonPredicate comparisonPredicate = new ComparisonPredicate(
|
final ComparisonPredicate comparisonPredicate = new ComparisonPredicate(
|
||||||
new ColumnReference(
|
new ColumnReference(
|
||||||
targetSideReference,
|
targetSideReference,
|
||||||
selection,
|
selection
|
||||||
creationContext.getSessionFactory()
|
|
||||||
),
|
),
|
||||||
ComparisonOperator.EQUAL,
|
ComparisonOperator.EQUAL,
|
||||||
new ColumnReference(
|
new ColumnReference(
|
||||||
keySideReference,
|
keySideReference,
|
||||||
keySelectableMappings.getSelectable( i ),
|
keySelectableMappings.getSelectable( i )
|
||||||
creationContext.getSessionFactory()
|
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
predicate.add( comparisonPredicate );
|
predicate.add( comparisonPredicate );
|
||||||
|
|
|
@ -21,7 +21,6 @@ import org.hibernate.sql.ast.Clause;
|
||||||
import org.hibernate.sql.ast.spi.SqlAstCreationState;
|
import org.hibernate.sql.ast.spi.SqlAstCreationState;
|
||||||
import org.hibernate.sql.ast.spi.SqlExpressionResolver;
|
import org.hibernate.sql.ast.spi.SqlExpressionResolver;
|
||||||
import org.hibernate.sql.ast.spi.SqlSelection;
|
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.TableGroup;
|
||||||
import org.hibernate.sql.ast.tree.from.TableReference;
|
import org.hibernate.sql.ast.tree.from.TableReference;
|
||||||
import org.hibernate.sql.results.graph.DomainResult;
|
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 TableReference columnTableReference = tableGroup.resolveTableReference( navigablePath, tableExpression );
|
||||||
|
|
||||||
final SqlSelection sqlSelection = sqlExpressionResolver.resolveSqlSelection(
|
final SqlSelection sqlSelection = sqlExpressionResolver.resolveSqlSelection(
|
||||||
sqlExpressionResolver.resolveSqlExpression(
|
sqlExpressionResolver.resolveSqlExpression( columnTableReference, this ),
|
||||||
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()
|
|
||||||
)
|
|
||||||
),
|
|
||||||
rowIdType.getJdbcJavaType(),
|
rowIdType.getJdbcJavaType(),
|
||||||
null,
|
null,
|
||||||
sqlAstCreationState.getCreationContext().getSessionFactory().getTypeConfiguration()
|
sqlAstCreationState.getCreationContext().getSessionFactory().getTypeConfiguration()
|
||||||
|
@ -174,7 +158,7 @@ public class EntityRowIdMappingImpl implements EntityRowIdMapping, SelectableMap
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getCustomReadExpression() {
|
public String getCustomReadExpression() {
|
||||||
return rowIdName;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -204,7 +188,7 @@ public class EntityRowIdMappingImpl implements EntityRowIdMapping, SelectableMap
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isFormula() {
|
public boolean isFormula() {
|
||||||
return true;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -214,18 +214,7 @@ public class EntityVersionMappingImpl implements EntityVersionMapping, FetchOpti
|
||||||
final TableReference columnTableReference = tableGroup.resolveTableReference( fetchablePath, columnTableExpression );
|
final TableReference columnTableReference = tableGroup.resolveTableReference( fetchablePath, columnTableExpression );
|
||||||
|
|
||||||
final SqlSelection sqlSelection = sqlExpressionResolver.resolveSqlSelection(
|
final SqlSelection sqlSelection = sqlExpressionResolver.resolveSqlSelection(
|
||||||
sqlExpressionResolver.resolveSqlExpression(
|
sqlExpressionResolver.resolveSqlExpression( columnTableReference, this ),
|
||||||
SqlExpressionResolver.createColumnReferenceKey( columnTableReference, columnExpression ),
|
|
||||||
sqlAstProcessingState -> new ColumnReference(
|
|
||||||
columnTableReference,
|
|
||||||
columnExpression,
|
|
||||||
false,
|
|
||||||
null,
|
|
||||||
null,
|
|
||||||
versionBasicType,
|
|
||||||
sqlAstCreationState.getCreationContext().getSessionFactory()
|
|
||||||
)
|
|
||||||
),
|
|
||||||
versionBasicType.getJdbcJavaType(),
|
versionBasicType.getJdbcJavaType(),
|
||||||
fetchParent,
|
fetchParent,
|
||||||
sqlAstCreationState.getCreationContext().getSessionFactory().getTypeConfiguration()
|
sqlAstCreationState.getCreationContext().getSessionFactory().getTypeConfiguration()
|
||||||
|
@ -288,18 +277,7 @@ public class EntityVersionMappingImpl implements EntityVersionMapping, FetchOpti
|
||||||
);
|
);
|
||||||
|
|
||||||
return sqlExpressionResolver.resolveSqlSelection(
|
return sqlExpressionResolver.resolveSqlSelection(
|
||||||
sqlExpressionResolver.resolveSqlExpression(
|
sqlExpressionResolver.resolveSqlExpression( columnTableReference, this ),
|
||||||
SqlExpressionResolver.createColumnReferenceKey( columnTableReference, columnExpression ),
|
|
||||||
sqlAstProcessingState -> new ColumnReference(
|
|
||||||
columnTableReference,
|
|
||||||
columnExpression,
|
|
||||||
false,
|
|
||||||
null,
|
|
||||||
null,
|
|
||||||
versionBasicType,
|
|
||||||
sqlAstCreationState.getCreationContext().getSessionFactory()
|
|
||||||
)
|
|
||||||
),
|
|
||||||
versionBasicType.getJdbcJavaType(),
|
versionBasicType.getJdbcJavaType(),
|
||||||
null,
|
null,
|
||||||
sqlAstCreationState.getCreationContext().getSessionFactory().getTypeConfiguration()
|
sqlAstCreationState.getCreationContext().getSessionFactory().getTypeConfiguration()
|
||||||
|
|
|
@ -69,20 +69,7 @@ public class ExplicitColumnDiscriminatorMappingImpl extends AbstractDiscriminato
|
||||||
SqlAstCreationState creationState) {
|
SqlAstCreationState creationState) {
|
||||||
final SqlExpressionResolver expressionResolver = creationState.getSqlExpressionResolver();
|
final SqlExpressionResolver expressionResolver = creationState.getSqlExpressionResolver();
|
||||||
final TableReference tableReference = tableGroup.resolveTableReference( navigablePath, tableExpression );
|
final TableReference tableReference = tableGroup.resolveTableReference( navigablePath, tableExpression );
|
||||||
final String selectionExpression = getSelectionExpression();
|
return expressionResolver.resolveSqlExpression( tableReference, this );
|
||||||
return expressionResolver.resolveSqlExpression(
|
|
||||||
createColumnReferenceKey( tableReference, selectionExpression ),
|
|
||||||
sqlAstProcessingState -> new ColumnReference(
|
|
||||||
tableReference,
|
|
||||||
selectionExpression,
|
|
||||||
columnFormula != null,
|
|
||||||
null,
|
|
||||||
null,
|
|
||||||
getJdbcMapping(),
|
|
||||||
getSessionFactory()
|
|
||||||
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -164,17 +164,7 @@ public class InverseNonAggregatedIdentifierMapping extends EmbeddedAttributeMapp
|
||||||
selection.getContainingTableExpression()
|
selection.getContainingTableExpression()
|
||||||
);
|
);
|
||||||
final Expression columnReference = sqlAstCreationState.getSqlExpressionResolver()
|
final Expression columnReference = sqlAstCreationState.getSqlExpressionResolver()
|
||||||
.resolveSqlExpression(
|
.resolveSqlExpression( tableReference, selection );
|
||||||
SqlExpressionResolver.createColumnReferenceKey(
|
|
||||||
tableReference,
|
|
||||||
selection.getSelectionExpression()
|
|
||||||
),
|
|
||||||
sqlAstProcessingState -> new ColumnReference(
|
|
||||||
tableReference.getIdentificationVariable(),
|
|
||||||
selection,
|
|
||||||
sqlAstCreationState.getCreationContext().getSessionFactory()
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
columnReferences.add( (ColumnReference) columnReference );
|
columnReferences.add( (ColumnReference) columnReference );
|
||||||
}
|
}
|
||||||
|
|
|
@ -190,17 +190,7 @@ public class NonAggregatedIdentifierMappingImpl extends AbstractCompositeIdentif
|
||||||
selection.getContainingTableExpression()
|
selection.getContainingTableExpression()
|
||||||
);
|
);
|
||||||
final Expression columnReference = sqlAstCreationState.getSqlExpressionResolver()
|
final Expression columnReference = sqlAstCreationState.getSqlExpressionResolver()
|
||||||
.resolveSqlExpression(
|
.resolveSqlExpression( tableReference, selection );
|
||||||
SqlExpressionResolver.createColumnReferenceKey(
|
|
||||||
tableReference,
|
|
||||||
selection.getSelectionExpression()
|
|
||||||
),
|
|
||||||
sqlAstProcessingState -> new ColumnReference(
|
|
||||||
tableReference.getIdentificationVariable(),
|
|
||||||
selection,
|
|
||||||
sqlAstCreationState.getCreationContext().getSessionFactory()
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
columnReferences.add( (ColumnReference) columnReference );
|
columnReferences.add( (ColumnReference) columnReference );
|
||||||
}
|
}
|
||||||
|
|
|
@ -259,21 +259,8 @@ public class SimpleForeignKeyDescriptor implements ForeignKeyDescriptor, BasicVa
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
final String identificationVariable = tableReference.getIdentificationVariable();
|
|
||||||
|
|
||||||
final SqlSelection sqlSelection = sqlExpressionResolver.resolveSqlSelection(
|
final SqlSelection sqlSelection = sqlExpressionResolver.resolveSqlSelection(
|
||||||
sqlExpressionResolver.resolveSqlExpression(
|
sqlExpressionResolver.resolveSqlExpression( tableReference, selectableMapping ),
|
||||||
SqlExpressionResolver.createColumnReferenceKey(
|
|
||||||
tableReference,
|
|
||||||
selectableMapping.getSelectionExpression()
|
|
||||||
),
|
|
||||||
s ->
|
|
||||||
new ColumnReference(
|
|
||||||
identificationVariable,
|
|
||||||
selectableMapping,
|
|
||||||
creationState.getSqlAstCreationState().getCreationContext().getSessionFactory()
|
|
||||||
)
|
|
||||||
),
|
|
||||||
selectableMapping.getJdbcMapping().getJdbcJavaType(),
|
selectableMapping.getJdbcMapping().getJdbcJavaType(),
|
||||||
fetchParent,
|
fetchParent,
|
||||||
sqlAstCreationState.getCreationContext().getSessionFactory().getTypeConfiguration()
|
sqlAstCreationState.getCreationContext().getSessionFactory().getTypeConfiguration()
|
||||||
|
@ -295,14 +282,12 @@ public class SimpleForeignKeyDescriptor implements ForeignKeyDescriptor, BasicVa
|
||||||
return new ComparisonPredicate(
|
return new ComparisonPredicate(
|
||||||
new ColumnReference(
|
new ColumnReference(
|
||||||
targetSideReference,
|
targetSideReference,
|
||||||
targetSide.getModelPart(),
|
targetSide.getModelPart()
|
||||||
creationContext.getSessionFactory()
|
|
||||||
),
|
),
|
||||||
ComparisonOperator.EQUAL,
|
ComparisonOperator.EQUAL,
|
||||||
new ColumnReference(
|
new ColumnReference(
|
||||||
keySideReference,
|
keySideReference,
|
||||||
keySide.getModelPart(),
|
keySide.getModelPart()
|
||||||
creationContext.getSessionFactory()
|
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,8 +68,7 @@ public class ColumnReference implements OrderingExpression, SequencePart {
|
||||||
// is no need for the JdbcMapping
|
// is no need for the JdbcMapping
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
null,
|
null
|
||||||
creationState.getCreationContext().getSessionFactory()
|
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,7 +65,6 @@ import org.hibernate.loader.ast.internal.CollectionLoaderSingleKey;
|
||||||
import org.hibernate.loader.ast.internal.CollectionLoaderSubSelectFetch;
|
import org.hibernate.loader.ast.internal.CollectionLoaderSubSelectFetch;
|
||||||
import org.hibernate.loader.ast.internal.LoaderSqlAstCreationState;
|
import org.hibernate.loader.ast.internal.LoaderSqlAstCreationState;
|
||||||
import org.hibernate.loader.ast.spi.CollectionLoader;
|
import org.hibernate.loader.ast.spi.CollectionLoader;
|
||||||
import org.hibernate.mapping.BasicValue;
|
|
||||||
import org.hibernate.mapping.Collection;
|
import org.hibernate.mapping.Collection;
|
||||||
import org.hibernate.mapping.Column;
|
import org.hibernate.mapping.Column;
|
||||||
import org.hibernate.mapping.Formula;
|
import org.hibernate.mapping.Formula;
|
||||||
|
@ -1126,7 +1125,7 @@ public abstract class AbstractCollectionPersister
|
||||||
new SqlAliasBaseManager(),
|
new SqlAliasBaseManager(),
|
||||||
new SimpleFromClauseAccessImpl(),
|
new SimpleFromClauseAccessImpl(),
|
||||||
LockOptions.NONE,
|
LockOptions.NONE,
|
||||||
(fetchParent, querySpec, creationState) -> new ArrayList<>(),
|
(fetchParent, creationState) -> new ArrayList<>(),
|
||||||
true,
|
true,
|
||||||
getFactory()
|
getFactory()
|
||||||
);
|
);
|
||||||
|
|
|
@ -1489,8 +1489,7 @@ public abstract class AbstractEntityPersister
|
||||||
false,
|
false,
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
selection.getJdbcMapping(),
|
selection.getJdbcMapping()
|
||||||
getFactory()
|
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -1506,8 +1505,7 @@ public abstract class AbstractEntityPersister
|
||||||
false,
|
false,
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
selection.getJdbcMapping(),
|
selection.getJdbcMapping()
|
||||||
getFactory()
|
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -1970,7 +1968,7 @@ public abstract class AbstractEntityPersister
|
||||||
return expression;
|
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 FetchableContainer fetchableContainer = fetchParent.getReferencedMappingContainer();
|
||||||
final int size = fetchableContainer.getNumberOfFetchables();
|
final int size = fetchableContainer.getNumberOfFetchables();
|
||||||
final List<Fetch> fetches = new ArrayList<>( size );
|
final List<Fetch> fetches = new ArrayList<>( size );
|
||||||
|
|
|
@ -754,8 +754,7 @@ public class SingleTableEntityPersister extends AbstractEntityPersister {
|
||||||
isDiscriminatorFormula(),
|
isDiscriminatorFormula(),
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
discriminatorType.getJdbcMapping(),
|
discriminatorType.getJdbcMapping()
|
||||||
getFactory()
|
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -538,7 +538,7 @@ public class UnionSubclassEntityPersister extends AbstractEntityPersister {
|
||||||
buf.append( dialect.getSelectClauseNullString( sqlType, getFactory().getTypeConfiguration() ) )
|
buf.append( dialect.getSelectClauseNullString( sqlType, getFactory().getTypeConfiguration() ) )
|
||||||
.append( " as " );
|
.append( " as " );
|
||||||
}
|
}
|
||||||
new ColumnReference( (String) null, selectableMapping, getFactory() ).appendReadExpression( sqlAppender );
|
new ColumnReference( (String) null, selectableMapping ).appendReadExpression( sqlAppender );
|
||||||
buf.append( ", " );
|
buf.append( ", " );
|
||||||
}
|
}
|
||||||
buf.append( persister.getDiscriminatorSQLValue() ).append( " as clazz_" );
|
buf.append( persister.getDiscriminatorSQLValue() ).append( " as clazz_" );
|
||||||
|
|
|
@ -189,14 +189,7 @@ public class AnonymousTupleBasicValuedModelPart implements ModelPart, MappingTyp
|
||||||
navigablePath,
|
navigablePath,
|
||||||
getContainingTableExpression()
|
getContainingTableExpression()
|
||||||
);
|
);
|
||||||
final Expression expression = expressionResolver.resolveSqlExpression(
|
final Expression expression = expressionResolver.resolveSqlExpression( tableReference, this );
|
||||||
createColumnReferenceKey( tableReference, getSelectionExpression() ),
|
|
||||||
sqlAstProcessingState -> new ColumnReference(
|
|
||||||
tableReference,
|
|
||||||
this,
|
|
||||||
creationState.getCreationContext().getSessionFactory()
|
|
||||||
)
|
|
||||||
);
|
|
||||||
return expressionResolver.resolveSqlSelection(
|
return expressionResolver.resolveSqlSelection(
|
||||||
expression,
|
expression,
|
||||||
getJdbcMapping().getJdbcJavaType(),
|
getJdbcMapping().getJdbcJavaType(),
|
||||||
|
|
|
@ -236,17 +236,7 @@ public class AnonymousTupleEmbeddableValuedModelPart implements EmbeddableValued
|
||||||
modelPart.forEachSelectable(
|
modelPart.forEachSelectable(
|
||||||
(columnIndex, selection) -> {
|
(columnIndex, selection) -> {
|
||||||
final Expression columnReference = sqlAstCreationState.getSqlExpressionResolver()
|
final Expression columnReference = sqlAstCreationState.getSqlExpressionResolver()
|
||||||
.resolveSqlExpression(
|
.resolveSqlExpression( tableReference, selection );
|
||||||
SqlExpressionResolver.createColumnReferenceKey(
|
|
||||||
tableReference,
|
|
||||||
selection.getSelectionExpression()
|
|
||||||
),
|
|
||||||
sqlAstProcessingState -> new ColumnReference(
|
|
||||||
tableReference.getIdentificationVariable(),
|
|
||||||
selection,
|
|
||||||
sqlAstCreationState.getCreationContext().getSessionFactory()
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
columnReferences.add( columnReference.getColumnReference() );
|
columnReferences.add( columnReference.getColumnReference() );
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,6 @@ import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.function.BiConsumer;
|
import java.util.function.BiConsumer;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
@ -102,6 +101,11 @@ public class AnonymousTupleEntityValuedModelPart implements EntityValuedModelPar
|
||||||
this.targetKeyPropertyNames = targetKeyPropertyNames;
|
this.targetKeyPropertyNames = targetKeyPropertyNames;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ModelPart getForeignKeyPart() {
|
||||||
|
// todo: naming?
|
||||||
|
return identifierMapping;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ModelPart findSubPart(String name, EntityMappingType treatTargetType) {
|
public ModelPart findSubPart(String name, EntityMappingType treatTargetType) {
|
||||||
if ( identifierMapping instanceof SingleAttributeIdentifierMapping ) {
|
if ( identifierMapping instanceof SingleAttributeIdentifierMapping ) {
|
||||||
|
@ -310,8 +314,7 @@ public class AnonymousTupleEntityValuedModelPart implements EntityValuedModelPar
|
||||||
),
|
),
|
||||||
state -> new ColumnReference(
|
state -> new ColumnReference(
|
||||||
tableReference,
|
tableReference,
|
||||||
selectableMapping,
|
selectableMapping
|
||||||
sessionFactory
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
@ -331,8 +334,7 @@ public class AnonymousTupleEntityValuedModelPart implements EntityValuedModelPar
|
||||||
),
|
),
|
||||||
state -> new ColumnReference(
|
state -> new ColumnReference(
|
||||||
tableReference,
|
tableReference,
|
||||||
selectableMapping,
|
selectableMapping
|
||||||
sessionFactory
|
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -353,8 +355,7 @@ public class AnonymousTupleEntityValuedModelPart implements EntityValuedModelPar
|
||||||
ComparisonOperator.EQUAL,
|
ComparisonOperator.EQUAL,
|
||||||
new ColumnReference(
|
new ColumnReference(
|
||||||
targetTableReference,
|
targetTableReference,
|
||||||
targetMapping,
|
targetMapping
|
||||||
sessionFactory
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
|
@ -7,14 +7,21 @@
|
||||||
package org.hibernate.query.results;
|
package org.hibernate.query.results;
|
||||||
|
|
||||||
import org.hibernate.metamodel.mapping.EntityIdentifierMapping;
|
import org.hibernate.metamodel.mapping.EntityIdentifierMapping;
|
||||||
|
import org.hibernate.metamodel.mapping.JdbcMapping;
|
||||||
import org.hibernate.metamodel.mapping.ModelPart;
|
import org.hibernate.metamodel.mapping.ModelPart;
|
||||||
|
import org.hibernate.metamodel.mapping.SelectableMapping;
|
||||||
import org.hibernate.metamodel.mapping.internal.SingleAttributeIdentifierMapping;
|
import org.hibernate.metamodel.mapping.internal.SingleAttributeIdentifierMapping;
|
||||||
import org.hibernate.spi.EntityIdentifierNavigablePath;
|
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.TableGroup;
|
||||||
|
import org.hibernate.sql.ast.tree.from.TableReference;
|
||||||
import org.hibernate.sql.results.graph.DomainResult;
|
import org.hibernate.sql.results.graph.DomainResult;
|
||||||
import org.hibernate.sql.results.graph.DomainResultCreationState;
|
import org.hibernate.sql.results.graph.DomainResultCreationState;
|
||||||
import org.hibernate.sql.results.graph.Fetch;
|
import org.hibernate.sql.results.graph.Fetch;
|
||||||
import org.hibernate.sql.results.graph.basic.BasicFetch;
|
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
|
* @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() {
|
private ResultsHelper() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,8 @@
|
||||||
*/
|
*/
|
||||||
package org.hibernate.query.results.complete;
|
package org.hibernate.query.results.complete;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import org.hibernate.query.results.FetchBuilder;
|
import org.hibernate.query.results.FetchBuilder;
|
||||||
import org.hibernate.sql.results.graph.Fetchable;
|
import org.hibernate.sql.results.graph.Fetchable;
|
||||||
|
|
||||||
|
@ -15,4 +17,6 @@ import org.hibernate.sql.results.graph.Fetchable;
|
||||||
public interface CompleteFetchBuilder extends FetchBuilder, ModelPartReference {
|
public interface CompleteFetchBuilder extends FetchBuilder, ModelPartReference {
|
||||||
@Override
|
@Override
|
||||||
Fetchable getReferencedPart();
|
Fetchable getReferencedPart();
|
||||||
|
|
||||||
|
List<String> getColumnAliases();
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,11 +6,14 @@
|
||||||
*/
|
*/
|
||||||
package org.hibernate.query.results.complete;
|
package org.hibernate.query.results.complete;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.function.BiFunction;
|
import java.util.function.BiFunction;
|
||||||
|
|
||||||
import org.hibernate.engine.FetchTiming;
|
import org.hibernate.engine.FetchTiming;
|
||||||
import org.hibernate.metamodel.mapping.BasicValuedModelPart;
|
import org.hibernate.metamodel.mapping.BasicValuedModelPart;
|
||||||
|
import org.hibernate.query.results.ResultsHelper;
|
||||||
import org.hibernate.spi.NavigablePath;
|
import org.hibernate.spi.NavigablePath;
|
||||||
import org.hibernate.query.results.BasicValuedFetchBuilder;
|
import org.hibernate.query.results.BasicValuedFetchBuilder;
|
||||||
import org.hibernate.query.results.DomainResultCreationStateImpl;
|
import org.hibernate.query.results.DomainResultCreationStateImpl;
|
||||||
|
@ -62,6 +65,11 @@ public class CompleteFetchBuilderBasicPart implements CompleteFetchBuilder, Basi
|
||||||
return referencedModelPart;
|
return referencedModelPart;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<String> getColumnAliases() {
|
||||||
|
return Collections.singletonList( selectionAlias );
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BasicFetch<?> buildFetch(
|
public BasicFetch<?> buildFetch(
|
||||||
FetchParent parent,
|
FetchParent parent,
|
||||||
|
@ -69,12 +77,11 @@ public class CompleteFetchBuilderBasicPart implements CompleteFetchBuilder, Basi
|
||||||
JdbcValuesMetadata jdbcResultsMetadata,
|
JdbcValuesMetadata jdbcResultsMetadata,
|
||||||
BiFunction<String, String, DynamicFetchBuilderLegacy> legacyFetchResolver,
|
BiFunction<String, String, DynamicFetchBuilderLegacy> legacyFetchResolver,
|
||||||
DomainResultCreationState domainResultCreationState) {
|
DomainResultCreationState domainResultCreationState) {
|
||||||
final DomainResultCreationStateImpl creationState = impl( domainResultCreationState );
|
final DomainResultCreationStateImpl creationStateImpl = impl( domainResultCreationState );
|
||||||
|
|
||||||
final String mappedTable = referencedModelPart.getContainingTableExpression();
|
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 TableReference tableReference = tableGroup.resolveTableReference( navigablePath, mappedTable );
|
||||||
|
|
||||||
final String selectedAlias;
|
final String selectedAlias;
|
||||||
|
@ -94,20 +101,20 @@ public class CompleteFetchBuilderBasicPart implements CompleteFetchBuilder, Basi
|
||||||
selectedAlias = selectionAlias;
|
selectedAlias = selectionAlias;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if ( ! creationState.arePositionalSelectionsAllowed() ) {
|
if ( ! creationStateImpl.arePositionalSelectionsAllowed() ) {
|
||||||
throw new PositionalSelectionsNotAllowedException(
|
throw new PositionalSelectionsNotAllowedException(
|
||||||
"Positional SQL selection resolution not allowed"
|
"Positional SQL selection resolution not allowed"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
jdbcPosition = creationState.getNumberOfProcessedSelections();
|
jdbcPosition = creationStateImpl.getNumberOfProcessedSelections() + 1;
|
||||||
selectedAlias = jdbcResultsMetadata.resolveColumnName( jdbcPosition );
|
selectedAlias = jdbcResultsMetadata.resolveColumnName( jdbcPosition );
|
||||||
}
|
}
|
||||||
|
|
||||||
final int valuesArrayPosition = jdbcPositionToValuesArrayPosition( jdbcPosition );
|
final int valuesArrayPosition = jdbcPositionToValuesArrayPosition( jdbcPosition );
|
||||||
|
|
||||||
// we just care about the registration here. The ModelPart will find it later
|
// we just care about the registration here. The ModelPart will find it later
|
||||||
creationState.resolveSqlExpression(
|
creationStateImpl.resolveSqlExpression(
|
||||||
createColumnReferenceKey( tableReference, mappedColumn ),
|
createColumnReferenceKey( tableReference, referencedModelPart ),
|
||||||
processingState -> new ResultSetMappingSqlSelection( valuesArrayPosition, referencedModelPart )
|
processingState -> new ResultSetMappingSqlSelection( valuesArrayPosition, referencedModelPart )
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
*/
|
*/
|
||||||
package org.hibernate.query.results.complete;
|
package org.hibernate.query.results.complete;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.function.BiFunction;
|
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.DomainResultCreationStateImpl;
|
||||||
import org.hibernate.query.results.FetchBuilder;
|
import org.hibernate.query.results.FetchBuilder;
|
||||||
import org.hibernate.query.results.ResultSetMappingSqlSelection;
|
import org.hibernate.query.results.ResultSetMappingSqlSelection;
|
||||||
|
import org.hibernate.query.results.ResultsHelper;
|
||||||
import org.hibernate.query.results.dynamic.DynamicFetchBuilderLegacy;
|
import org.hibernate.query.results.dynamic.DynamicFetchBuilderLegacy;
|
||||||
import org.hibernate.spi.NavigablePath;
|
import org.hibernate.spi.NavigablePath;
|
||||||
import org.hibernate.sql.ast.spi.SqlExpressionResolver;
|
import org.hibernate.sql.ast.spi.SqlExpressionResolver;
|
||||||
|
@ -66,6 +68,11 @@ public class CompleteFetchBuilderEmbeddableValuedModelPart
|
||||||
return modelPart;
|
return modelPart;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<String> getColumnAliases() {
|
||||||
|
return columnAliases;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Fetch buildFetch(
|
public Fetch buildFetch(
|
||||||
FetchParent parent,
|
FetchParent parent,
|
||||||
|
@ -80,16 +87,14 @@ public class CompleteFetchBuilderEmbeddableValuedModelPart
|
||||||
modelPart.forEachSelectable(
|
modelPart.forEachSelectable(
|
||||||
(selectionIndex, selectableMapping) -> {
|
(selectionIndex, selectableMapping) -> {
|
||||||
final TableReference tableReference = tableGroup.resolveTableReference( navigablePath, selectableMapping.getContainingTableExpression() );
|
final TableReference tableReference = tableGroup.resolveTableReference( navigablePath, selectableMapping.getContainingTableExpression() );
|
||||||
final String mappedColumn = selectableMapping.getSelectionExpression();
|
|
||||||
final String columnAlias = columnAliases.get( selectionIndex );
|
final String columnAlias = columnAliases.get( selectionIndex );
|
||||||
creationStateImpl.resolveSqlSelection(
|
creationStateImpl.resolveSqlSelection(
|
||||||
creationStateImpl.resolveSqlExpression(
|
ResultsHelper.resolveSqlExpression(
|
||||||
SqlExpressionResolver.createColumnReferenceKey( tableReference, mappedColumn ),
|
creationStateImpl,
|
||||||
processingState -> {
|
jdbcResultsMetadata,
|
||||||
final int jdbcPosition = jdbcResultsMetadata.resolveColumnPosition( columnAlias );
|
tableReference,
|
||||||
final int valuesArrayPosition = jdbcPositionToValuesArrayPosition( jdbcPosition );
|
selectableMapping,
|
||||||
return new ResultSetMappingSqlSelection( valuesArrayPosition, selectableMapping.getJdbcMapping() );
|
columnAlias
|
||||||
}
|
|
||||||
),
|
),
|
||||||
selectableMapping.getJdbcMapping().getJdbcJavaType(),
|
selectableMapping.getJdbcMapping().getJdbcJavaType(),
|
||||||
null,
|
null,
|
||||||
|
|
|
@ -6,10 +6,12 @@
|
||||||
*/
|
*/
|
||||||
package org.hibernate.query.results.complete;
|
package org.hibernate.query.results.complete;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.function.BiFunction;
|
import java.util.function.BiFunction;
|
||||||
|
|
||||||
import org.hibernate.engine.FetchTiming;
|
import org.hibernate.engine.FetchTiming;
|
||||||
|
import org.hibernate.query.results.ResultsHelper;
|
||||||
import org.hibernate.spi.NavigablePath;
|
import org.hibernate.spi.NavigablePath;
|
||||||
import org.hibernate.query.results.DomainResultCreationStateImpl;
|
import org.hibernate.query.results.DomainResultCreationStateImpl;
|
||||||
import org.hibernate.query.results.FetchBuilder;
|
import org.hibernate.query.results.FetchBuilder;
|
||||||
|
@ -66,6 +68,7 @@ public class CompleteFetchBuilderEntityValuedModelPart
|
||||||
return modelPart;
|
return modelPart;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public List<String> getColumnAliases() {
|
public List<String> getColumnAliases() {
|
||||||
return columnAliases;
|
return columnAliases;
|
||||||
}
|
}
|
||||||
|
@ -84,16 +87,14 @@ public class CompleteFetchBuilderEntityValuedModelPart
|
||||||
modelPart.forEachSelectable(
|
modelPart.forEachSelectable(
|
||||||
(selectionIndex, selectableMapping) -> {
|
(selectionIndex, selectableMapping) -> {
|
||||||
final TableReference tableReference = tableGroup.resolveTableReference( navigablePath, selectableMapping.getContainingTableExpression() );
|
final TableReference tableReference = tableGroup.resolveTableReference( navigablePath, selectableMapping.getContainingTableExpression() );
|
||||||
final String mappedColumn = selectableMapping.getSelectionExpression();
|
|
||||||
final String columnAlias = columnAliases.get( selectionIndex );
|
final String columnAlias = columnAliases.get( selectionIndex );
|
||||||
creationStateImpl.resolveSqlSelection(
|
creationStateImpl.resolveSqlSelection(
|
||||||
creationStateImpl.resolveSqlExpression(
|
ResultsHelper.resolveSqlExpression(
|
||||||
SqlExpressionResolver.createColumnReferenceKey( tableReference, mappedColumn ),
|
creationStateImpl,
|
||||||
processingState -> {
|
jdbcResultsMetadata,
|
||||||
final int jdbcPosition = jdbcResultsMetadata.resolveColumnPosition( columnAlias );
|
tableReference,
|
||||||
final int valuesArrayPosition = jdbcPositionToValuesArrayPosition( jdbcPosition );
|
selectableMapping,
|
||||||
return new ResultSetMappingSqlSelection( valuesArrayPosition, selectableMapping.getJdbcMapping() );
|
columnAlias
|
||||||
}
|
|
||||||
),
|
),
|
||||||
selectableMapping.getJdbcMapping().getJdbcJavaType(),
|
selectableMapping.getJdbcMapping().getJdbcJavaType(),
|
||||||
null,
|
null,
|
||||||
|
|
|
@ -9,6 +9,7 @@ package org.hibernate.query.results.complete;
|
||||||
import java.util.function.BiFunction;
|
import java.util.function.BiFunction;
|
||||||
|
|
||||||
import org.hibernate.metamodel.mapping.BasicValuedModelPart;
|
import org.hibernate.metamodel.mapping.BasicValuedModelPart;
|
||||||
|
import org.hibernate.query.results.ResultsHelper;
|
||||||
import org.hibernate.spi.NavigablePath;
|
import org.hibernate.spi.NavigablePath;
|
||||||
import org.hibernate.query.results.DomainResultCreationStateImpl;
|
import org.hibernate.query.results.DomainResultCreationStateImpl;
|
||||||
import org.hibernate.query.results.ResultBuilder;
|
import org.hibernate.query.results.ResultBuilder;
|
||||||
|
@ -75,16 +76,14 @@ public class CompleteResultBuilderBasicModelPart
|
||||||
|
|
||||||
final TableGroup tableGroup = creationStateImpl.getFromClauseAccess().getTableGroup( navigablePath.getParent() );
|
final TableGroup tableGroup = creationStateImpl.getFromClauseAccess().getTableGroup( navigablePath.getParent() );
|
||||||
final TableReference tableReference = tableGroup.resolveTableReference( navigablePath, modelPart.getContainingTableExpression() );
|
final TableReference tableReference = tableGroup.resolveTableReference( navigablePath, modelPart.getContainingTableExpression() );
|
||||||
final String mappedColumn = modelPart.getSelectionExpression();
|
|
||||||
|
|
||||||
final SqlSelection sqlSelection = creationStateImpl.resolveSqlSelection(
|
final SqlSelection sqlSelection = creationStateImpl.resolveSqlSelection(
|
||||||
creationStateImpl.resolveSqlExpression(
|
ResultsHelper.resolveSqlExpression(
|
||||||
SqlExpressionResolver.createColumnReferenceKey( tableReference, mappedColumn ),
|
creationStateImpl,
|
||||||
processingState -> {
|
jdbcResultsMetadata,
|
||||||
final int jdbcPosition = jdbcResultsMetadata.resolveColumnPosition( columnAlias );
|
tableReference,
|
||||||
final int valuesArrayPosition = jdbcPositionToValuesArrayPosition( jdbcPosition );
|
modelPart,
|
||||||
return new ResultSetMappingSqlSelection( valuesArrayPosition, modelPart );
|
columnAlias
|
||||||
}
|
|
||||||
),
|
),
|
||||||
modelPart.getJdbcMapping().getJdbcJavaType(),
|
modelPart.getJdbcMapping().getJdbcJavaType(),
|
||||||
null,
|
null,
|
||||||
|
|
|
@ -82,39 +82,9 @@ public class CompleteResultBuilderBasicValuedConverted<O,R> implements CompleteR
|
||||||
columnName = explicitColumnName;
|
columnName = explicitColumnName;
|
||||||
}
|
}
|
||||||
else {
|
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(
|
final SqlSelection sqlSelection = creationStateImpl.resolveSqlSelection(
|
||||||
creationStateImpl.resolveSqlExpression(
|
creationStateImpl.resolveSqlExpression(
|
||||||
columnName,
|
columnName,
|
||||||
|
|
|
@ -72,56 +72,20 @@ public class CompleteResultBuilderBasicValuedStandard implements CompleteResultB
|
||||||
DomainResultCreationState domainResultCreationState) {
|
DomainResultCreationState domainResultCreationState) {
|
||||||
final DomainResultCreationStateImpl creationStateImpl = impl( domainResultCreationState );
|
final DomainResultCreationStateImpl creationStateImpl = impl( domainResultCreationState );
|
||||||
final SessionFactoryImplementor sessionFactory = creationStateImpl.getSessionFactory();
|
final SessionFactoryImplementor sessionFactory = creationStateImpl.getSessionFactory();
|
||||||
|
final int jdbcPosition;
|
||||||
final String columnName;
|
final String columnName;
|
||||||
if ( explicitColumnName != null ) {
|
if ( explicitColumnName != null ) {
|
||||||
|
jdbcPosition = jdbcResultsMetadata.resolveColumnPosition( explicitColumnName );
|
||||||
columnName = explicitColumnName;
|
columnName = explicitColumnName;
|
||||||
}
|
}
|
||||||
else {
|
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(
|
final SqlSelection sqlSelection = creationStateImpl.resolveSqlSelection(
|
||||||
creationStateImpl.resolveSqlExpression(
|
creationStateImpl.resolveSqlExpression(
|
||||||
columnName,
|
columnName,
|
||||||
processingState -> {
|
processingState -> {
|
||||||
final int jdbcPosition;
|
|
||||||
if ( explicitColumnName != null ) {
|
|
||||||
jdbcPosition = jdbcResultsMetadata.resolveColumnPosition( explicitColumnName );
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
jdbcPosition = resultPosition + 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
final BasicValuedMapping basicType;
|
final BasicValuedMapping basicType;
|
||||||
if ( explicitType != null ) {
|
if ( explicitType != null ) {
|
||||||
basicType = explicitType;
|
basicType = explicitType;
|
||||||
|
@ -144,7 +108,7 @@ public class CompleteResultBuilderBasicValuedStandard implements CompleteResultB
|
||||||
);
|
);
|
||||||
|
|
||||||
final JdbcMapping jdbcMapping = sqlSelection.getExpressionType().getJdbcMappings().get( 0 );
|
final JdbcMapping jdbcMapping = sqlSelection.getExpressionType().getJdbcMappings().get( 0 );
|
||||||
return new BasicResult(
|
return new BasicResult<>(
|
||||||
sqlSelection.getValuesArrayPosition(),
|
sqlSelection.getValuesArrayPosition(),
|
||||||
columnName,
|
columnName,
|
||||||
jdbcMapping
|
jdbcMapping
|
||||||
|
|
|
@ -154,18 +154,12 @@ public class CompleteResultBuilderCollectionStandard implements CompleteResultBu
|
||||||
final SelectableConsumer consumer = (selectionIndex, selectableMapping) -> {
|
final SelectableConsumer consumer = (selectionIndex, selectableMapping) -> {
|
||||||
final String columnName = columnNames[selectionIndex];
|
final String columnName = columnNames[selectionIndex];
|
||||||
creationStateImpl.resolveSqlSelection(
|
creationStateImpl.resolveSqlSelection(
|
||||||
creationStateImpl.resolveSqlExpression(
|
ResultsHelper.resolveSqlExpression(
|
||||||
SqlExpressionResolver.createColumnReferenceKey(
|
creationStateImpl,
|
||||||
|
jdbcResultsMetadata,
|
||||||
tableGroup.resolveTableReference( selectableMapping.getContainingTableExpression() ),
|
tableGroup.resolveTableReference( selectableMapping.getContainingTableExpression() ),
|
||||||
selectableMapping.getSelectionExpression()
|
selectableMapping,
|
||||||
),
|
columnName
|
||||||
processingState -> {
|
|
||||||
final int jdbcPosition = jdbcResultsMetadata.resolveColumnPosition( columnName );
|
|
||||||
final BasicValuedMapping basicType = (BasicValuedMapping) selectableMapping.getJdbcMapping();
|
|
||||||
final int valuesArrayPosition = ResultsHelper.jdbcPositionToValuesArrayPosition(
|
|
||||||
jdbcPosition );
|
|
||||||
return new ResultSetMappingSqlSelection( valuesArrayPosition, basicType );
|
|
||||||
}
|
|
||||||
),
|
),
|
||||||
selectableMapping.getJdbcMapping().getJdbcJavaType(),
|
selectableMapping.getJdbcMapping().getJdbcJavaType(),
|
||||||
null,
|
null,
|
||||||
|
|
|
@ -6,6 +6,8 @@
|
||||||
*/
|
*/
|
||||||
package org.hibernate.query.results.complete;
|
package org.hibernate.query.results.complete;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
import java.util.function.BiFunction;
|
import java.util.function.BiFunction;
|
||||||
|
|
||||||
import org.hibernate.engine.FetchTiming;
|
import org.hibernate.engine.FetchTiming;
|
||||||
|
@ -71,6 +73,11 @@ public class DelayedFetchBuilderBasicPart
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<String> getColumnAliases() {
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
if ( this == o ) {
|
if ( this == o ) {
|
||||||
|
|
|
@ -20,6 +20,7 @@ import org.hibernate.metamodel.mapping.CollectionPart;
|
||||||
import org.hibernate.metamodel.mapping.ForeignKeyDescriptor;
|
import org.hibernate.metamodel.mapping.ForeignKeyDescriptor;
|
||||||
import org.hibernate.metamodel.mapping.JdbcMapping;
|
import org.hibernate.metamodel.mapping.JdbcMapping;
|
||||||
import org.hibernate.metamodel.mapping.PluralAttributeMapping;
|
import org.hibernate.metamodel.mapping.PluralAttributeMapping;
|
||||||
|
import org.hibernate.metamodel.mapping.SelectableMapping;
|
||||||
import org.hibernate.metamodel.mapping.internal.ToOneAttributeMapping;
|
import org.hibernate.metamodel.mapping.internal.ToOneAttributeMapping;
|
||||||
import org.hibernate.query.NativeQuery;
|
import org.hibernate.query.NativeQuery;
|
||||||
import org.hibernate.spi.NavigablePath;
|
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.TableGroup;
|
||||||
import org.hibernate.sql.ast.tree.from.TableGroupJoin;
|
import org.hibernate.sql.ast.tree.from.TableGroupJoin;
|
||||||
import org.hibernate.sql.ast.tree.from.TableGroupJoinProducer;
|
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.DomainResultCreationState;
|
||||||
import org.hibernate.sql.results.graph.Fetch;
|
import org.hibernate.sql.results.graph.Fetch;
|
||||||
import org.hibernate.sql.results.graph.FetchParent;
|
import org.hibernate.sql.results.graph.FetchParent;
|
||||||
|
import org.hibernate.sql.results.graph.Fetchable;
|
||||||
import org.hibernate.sql.results.jdbc.spi.JdbcValuesMetadata;
|
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;
|
import static org.hibernate.sql.ast.spi.SqlExpressionResolver.createColumnReferenceKey;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -129,7 +133,7 @@ public class DynamicFetchBuilderLegacy implements DynamicFetchBuilder, NativeQue
|
||||||
JdbcValuesMetadata jdbcResultsMetadata,
|
JdbcValuesMetadata jdbcResultsMetadata,
|
||||||
BiFunction<String, String, DynamicFetchBuilderLegacy> legacyFetchResolver,
|
BiFunction<String, String, DynamicFetchBuilderLegacy> legacyFetchResolver,
|
||||||
DomainResultCreationState domainResultCreationState) {
|
DomainResultCreationState domainResultCreationState) {
|
||||||
final DomainResultCreationStateImpl creationState = ResultsHelper.impl( domainResultCreationState );
|
final DomainResultCreationStateImpl creationState = impl( domainResultCreationState );
|
||||||
final TableGroup ownerTableGroup = creationState.getFromClauseAccess().findByAlias( ownerTableAlias );
|
final TableGroup ownerTableGroup = creationState.getFromClauseAccess().findByAlias( ownerTableAlias );
|
||||||
final AttributeMapping attributeMapping = parent.getReferencedMappingContainer()
|
final AttributeMapping attributeMapping = parent.getReferencedMappingContainer()
|
||||||
.findContainingEntityMapping()
|
.findContainingEntityMapping()
|
||||||
|
@ -175,11 +179,8 @@ public class DynamicFetchBuilderLegacy implements DynamicFetchBuilder, NativeQue
|
||||||
(selectionIndex, selectableMapping) -> {
|
(selectionIndex, selectableMapping) -> {
|
||||||
resolveSqlSelection(
|
resolveSqlSelection(
|
||||||
columnNames.get( selectionIndex ),
|
columnNames.get( selectionIndex ),
|
||||||
createColumnReferenceKey(
|
|
||||||
tableGroup.resolveTableReference( selectableMapping.getContainingTableExpression() ),
|
tableGroup.resolveTableReference( selectableMapping.getContainingTableExpression() ),
|
||||||
selectableMapping.getSelectionExpression()
|
selectableMapping,
|
||||||
),
|
|
||||||
selectableMapping.getJdbcMapping(),
|
|
||||||
jdbcResultsMetadata,
|
jdbcResultsMetadata,
|
||||||
domainResultCreationState
|
domainResultCreationState
|
||||||
);
|
);
|
||||||
|
@ -232,23 +233,25 @@ public class DynamicFetchBuilderLegacy implements DynamicFetchBuilder, NativeQue
|
||||||
|
|
||||||
private void resolveSqlSelection(
|
private void resolveSqlSelection(
|
||||||
String columnAlias,
|
String columnAlias,
|
||||||
String columnKey,
|
TableReference tableReference,
|
||||||
JdbcMapping jdbcMapping,
|
SelectableMapping selectableMapping,
|
||||||
JdbcValuesMetadata jdbcResultsMetadata,
|
JdbcValuesMetadata jdbcResultsMetadata,
|
||||||
DomainResultCreationState domainResultCreationState) {
|
DomainResultCreationState domainResultCreationState) {
|
||||||
final SqlExpressionResolver sqlExpressionResolver = domainResultCreationState.getSqlAstCreationState().getSqlExpressionResolver();
|
final DomainResultCreationStateImpl creationStateImpl = impl( domainResultCreationState );
|
||||||
sqlExpressionResolver.resolveSqlSelection(
|
creationStateImpl.resolveSqlSelection(
|
||||||
sqlExpressionResolver.resolveSqlExpression(
|
ResultsHelper.resolveSqlExpression(
|
||||||
columnKey,
|
creationStateImpl,
|
||||||
state -> {
|
jdbcResultsMetadata,
|
||||||
final int jdbcPosition = jdbcResultsMetadata.resolveColumnPosition( columnAlias );
|
tableReference,
|
||||||
final int valuesArrayPosition = jdbcPosition - 1;
|
selectableMapping,
|
||||||
return new ResultSetMappingSqlSelection( valuesArrayPosition, jdbcMapping );
|
columnAlias
|
||||||
}
|
|
||||||
),
|
),
|
||||||
jdbcMapping.getJdbcJavaType(),
|
selectableMapping.getJdbcMapping().getJdbcJavaType(),
|
||||||
null,
|
null,
|
||||||
domainResultCreationState.getSqlAstCreationState().getCreationContext().getSessionFactory().getTypeConfiguration()
|
domainResultCreationState.getSqlAstCreationState()
|
||||||
|
.getCreationContext()
|
||||||
|
.getSessionFactory()
|
||||||
|
.getTypeConfiguration()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -88,13 +88,12 @@ public class DynamicFetchBuilderStandard
|
||||||
);
|
);
|
||||||
final String columnAlias = columnNames.get( selectionIndex );
|
final String columnAlias = columnNames.get( selectionIndex );
|
||||||
sqlExpressionResolver.resolveSqlSelection(
|
sqlExpressionResolver.resolveSqlSelection(
|
||||||
sqlExpressionResolver.resolveSqlExpression(
|
ResultsHelper.resolveSqlExpression(
|
||||||
createColumnReferenceKey( tableReference, selectableMapping.getSelectionExpression() ),
|
creationStateImpl,
|
||||||
state -> {
|
jdbcResultsMetadata,
|
||||||
final int resultSetPosition = jdbcResultsMetadata.resolveColumnPosition( columnAlias );
|
tableReference,
|
||||||
final int valuesArrayPosition = resultSetPosition - 1;
|
selectableMapping,
|
||||||
return new ResultSetMappingSqlSelection( valuesArrayPosition, selectableMapping.getJdbcMapping() );
|
columnAlias
|
||||||
}
|
|
||||||
),
|
),
|
||||||
selectableMapping.getJdbcMapping().getJdbcJavaType(),
|
selectableMapping.getJdbcMapping().getJdbcJavaType(),
|
||||||
null,
|
null,
|
||||||
|
|
|
@ -12,14 +12,18 @@ import java.util.function.BiFunction;
|
||||||
import org.hibernate.metamodel.mapping.SingularAttributeMapping;
|
import org.hibernate.metamodel.mapping.SingularAttributeMapping;
|
||||||
import org.hibernate.metamodel.mapping.internal.BasicAttributeMapping;
|
import org.hibernate.metamodel.mapping.internal.BasicAttributeMapping;
|
||||||
import org.hibernate.query.NativeQuery;
|
import org.hibernate.query.NativeQuery;
|
||||||
|
import org.hibernate.query.results.DomainResultCreationStateImpl;
|
||||||
import org.hibernate.query.results.ResultSetMappingSqlSelection;
|
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.ast.spi.SqlSelection;
|
||||||
import org.hibernate.sql.results.graph.DomainResult;
|
import org.hibernate.sql.results.graph.DomainResult;
|
||||||
import org.hibernate.sql.results.graph.DomainResultCreationState;
|
import org.hibernate.sql.results.graph.DomainResultCreationState;
|
||||||
import org.hibernate.sql.results.graph.basic.BasicResult;
|
import org.hibernate.sql.results.graph.basic.BasicResult;
|
||||||
import org.hibernate.sql.results.jdbc.spi.JdbcValuesMetadata;
|
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
|
* DynamicResultBuilder based on a named mapped attribute
|
||||||
*
|
*
|
||||||
|
@ -76,15 +80,14 @@ public class DynamicResultBuilderAttribute implements DynamicResultBuilder, Nati
|
||||||
int resultPosition,
|
int resultPosition,
|
||||||
BiFunction<String, String, DynamicFetchBuilderLegacy> legacyFetchResolver,
|
BiFunction<String, String, DynamicFetchBuilderLegacy> legacyFetchResolver,
|
||||||
DomainResultCreationState domainResultCreationState) {
|
DomainResultCreationState domainResultCreationState) {
|
||||||
// todo (6.0) : TableGroups + `attributeMapping#buldResult`
|
final DomainResultCreationStateImpl domainResultCreationStateImpl = impl( domainResultCreationState );
|
||||||
|
|
||||||
final SqlExpressionResolver sqlExpressionResolver = domainResultCreationState.getSqlAstCreationState().getSqlExpressionResolver();
|
final SqlSelection sqlSelection = domainResultCreationStateImpl.resolveSqlSelection(
|
||||||
final SqlSelection sqlSelection = sqlExpressionResolver.resolveSqlSelection(
|
domainResultCreationStateImpl.resolveSqlExpression(
|
||||||
sqlExpressionResolver.resolveSqlExpression(
|
|
||||||
columnAlias,
|
columnAlias,
|
||||||
state -> {
|
processingState -> {
|
||||||
final int resultSetPosition = jdbcResultsMetadata.resolveColumnPosition( columnAlias );
|
final int jdbcPosition = jdbcResultsMetadata.resolveColumnPosition( columnAlias );
|
||||||
final int valuesArrayPosition = resultSetPosition - 1;
|
final int valuesArrayPosition = jdbcPositionToValuesArrayPosition( jdbcPosition );
|
||||||
return new ResultSetMappingSqlSelection( valuesArrayPosition, attributeMapping );
|
return new ResultSetMappingSqlSelection( valuesArrayPosition, attributeMapping );
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
|
|
|
@ -19,16 +19,24 @@ import org.hibernate.metamodel.mapping.CollectionPart;
|
||||||
import org.hibernate.metamodel.mapping.EntityIdentifierMapping;
|
import org.hibernate.metamodel.mapping.EntityIdentifierMapping;
|
||||||
import org.hibernate.metamodel.mapping.EntityMappingType;
|
import org.hibernate.metamodel.mapping.EntityMappingType;
|
||||||
import org.hibernate.metamodel.mapping.JdbcMapping;
|
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.metamodel.mapping.internal.SingleAttributeIdentifierMapping;
|
||||||
import org.hibernate.query.NativeQuery;
|
import org.hibernate.query.NativeQuery;
|
||||||
import org.hibernate.query.results.FetchBuilder;
|
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.spi.NavigablePath;
|
||||||
import org.hibernate.query.results.DomainResultCreationStateImpl;
|
import org.hibernate.query.results.DomainResultCreationStateImpl;
|
||||||
import org.hibernate.query.results.ResultSetMappingSqlSelection;
|
import org.hibernate.query.results.ResultSetMappingSqlSelection;
|
||||||
import org.hibernate.query.results.TableGroupImpl;
|
import org.hibernate.query.results.TableGroupImpl;
|
||||||
import org.hibernate.sql.ast.spi.FromClauseAccess;
|
import org.hibernate.sql.ast.spi.FromClauseAccess;
|
||||||
import org.hibernate.sql.ast.spi.SqlAliasBaseConstant;
|
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.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.TableGroup;
|
||||||
import org.hibernate.sql.ast.tree.from.TableReference;
|
import org.hibernate.sql.ast.tree.from.TableReference;
|
||||||
import org.hibernate.sql.results.graph.DomainResultCreationState;
|
import org.hibernate.sql.results.graph.DomainResultCreationState;
|
||||||
|
@ -147,6 +155,7 @@ public class DynamicResultBuilderEntityStandard
|
||||||
tableAlias,
|
tableAlias,
|
||||||
domainResultCreationState
|
domainResultCreationState
|
||||||
),
|
),
|
||||||
|
null,
|
||||||
jdbcResultsMetadata,
|
jdbcResultsMetadata,
|
||||||
domainResultCreationState
|
domainResultCreationState
|
||||||
);
|
);
|
||||||
|
@ -166,6 +175,7 @@ public class DynamicResultBuilderEntityStandard
|
||||||
null,
|
null,
|
||||||
domainResultCreationState
|
domainResultCreationState
|
||||||
),
|
),
|
||||||
|
fetchable,
|
||||||
jdbcResultsMetadata,
|
jdbcResultsMetadata,
|
||||||
domainResultCreationState
|
domainResultCreationState
|
||||||
);
|
);
|
||||||
|
@ -173,12 +183,23 @@ public class DynamicResultBuilderEntityStandard
|
||||||
|
|
||||||
private <T> T buildResultOrFetch(
|
private <T> T buildResultOrFetch(
|
||||||
Function<TableGroup, T> resultOrFetchBuilder,
|
Function<TableGroup, T> resultOrFetchBuilder,
|
||||||
|
Fetchable fetchable,
|
||||||
JdbcValuesMetadata jdbcResultsMetadata,
|
JdbcValuesMetadata jdbcResultsMetadata,
|
||||||
DomainResultCreationState domainResultCreationState) {
|
DomainResultCreationState domainResultCreationState) {
|
||||||
final DomainResultCreationStateImpl creationState = impl( domainResultCreationState );
|
final DomainResultCreationStateImpl creationState = impl( domainResultCreationState );
|
||||||
final FromClauseAccess fromClauseAccess = domainResultCreationState.getSqlAstCreationState().getFromClauseAccess();
|
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(
|
final TableGroup tableGroup = fromClauseAccess.resolveTableGroup(
|
||||||
navigablePath,
|
elementNavigablePath,
|
||||||
np -> {
|
np -> {
|
||||||
final TableReference tableReference = entityMapping.createPrimaryTableReference(
|
final TableReference tableReference = entityMapping.createPrimaryTableReference(
|
||||||
new SqlAliasBaseConstant( tableAlias ),
|
new SqlAliasBaseConstant( tableAlias ),
|
||||||
|
@ -189,29 +210,66 @@ public class DynamicResultBuilderEntityStandard
|
||||||
if ( lockMode != null ) {
|
if ( lockMode != null ) {
|
||||||
domainResultCreationState.getSqlAstCreationState().registerLockMode( tableAlias, lockMode );
|
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 TableReference tableReference = tableGroup.getPrimaryTableReference();
|
||||||
final List<String> idColumnAliases;
|
final List<String> keyColumnAliases;
|
||||||
final FetchBuilder idFetchBuilder;
|
final FetchBuilder idFetchBuilder = findIdFetchBuilder();
|
||||||
if ( this.idColumnNames != null ) {
|
if ( this.idColumnNames != null ) {
|
||||||
idColumnAliases = this.idColumnNames;
|
keyColumnAliases = this.idColumnNames;
|
||||||
}
|
}
|
||||||
else if ( ( idFetchBuilder = findIdFetchBuilder() ) != null ) {
|
else if ( idFetchBuilder != null ) {
|
||||||
|
keyColumnAliases = ( (DynamicFetchBuilder) idFetchBuilder ).getColumnAliases();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
keyColumnAliases = null;
|
||||||
|
}
|
||||||
|
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();
|
idColumnAliases = ( (DynamicFetchBuilder) idFetchBuilder ).getColumnAliases();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
idColumnAliases = null;
|
idColumnAliases = ( (CompleteFetchBuilder) idFetchBuilder ).getColumnAliases();
|
||||||
}
|
}
|
||||||
if ( idColumnAliases != null ) {
|
entityMapping.getIdentifierMapping().forEachSelectable(
|
||||||
final EntityIdentifierMapping identifierMapping = entityMapping.getIdentifierMapping();
|
|
||||||
identifierMapping.forEachSelectable(
|
|
||||||
(selectionIndex, selectableMapping) -> {
|
(selectionIndex, selectableMapping) -> {
|
||||||
resolveSqlSelection(
|
resolveSqlSelection(
|
||||||
idColumnAliases.get( selectionIndex ),
|
idColumnAliases.get( selectionIndex ),
|
||||||
createColumnReferenceKey( tableReference, selectableMapping.getSelectionExpression() ),
|
tableReference,
|
||||||
selectableMapping.getJdbcMapping(),
|
selectableMapping,
|
||||||
|
jdbcResultsMetadata,
|
||||||
|
domainResultCreationState
|
||||||
|
);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
keyPart = entityMapping.getIdentifierMapping();
|
||||||
|
keyTableGroup = tableGroup;
|
||||||
|
}
|
||||||
|
keyPart.forEachSelectable(
|
||||||
|
(selectionIndex, selectableMapping) -> {
|
||||||
|
resolveSqlSelection(
|
||||||
|
keyColumnAliases.get( selectionIndex ),
|
||||||
|
keyTableGroup.resolveTableReference( selectableMapping.getContainingTableExpression() ),
|
||||||
|
selectableMapping,
|
||||||
jdbcResultsMetadata,
|
jdbcResultsMetadata,
|
||||||
domainResultCreationState
|
domainResultCreationState
|
||||||
);
|
);
|
||||||
|
@ -222,11 +280,8 @@ public class DynamicResultBuilderEntityStandard
|
||||||
if ( discriminatorColumnName != null ) {
|
if ( discriminatorColumnName != null ) {
|
||||||
resolveSqlSelection(
|
resolveSqlSelection(
|
||||||
discriminatorColumnName,
|
discriminatorColumnName,
|
||||||
createColumnReferenceKey(
|
|
||||||
tableReference,
|
tableReference,
|
||||||
entityMapping.getDiscriminatorMapping().getSelectionExpression()
|
entityMapping.getDiscriminatorMapping(),
|
||||||
),
|
|
||||||
entityMapping.getDiscriminatorMapping().getJdbcMapping(),
|
|
||||||
jdbcResultsMetadata,
|
jdbcResultsMetadata,
|
||||||
domainResultCreationState
|
domainResultCreationState
|
||||||
);
|
);
|
||||||
|
@ -275,23 +330,25 @@ public class DynamicResultBuilderEntityStandard
|
||||||
|
|
||||||
private void resolveSqlSelection(
|
private void resolveSqlSelection(
|
||||||
String columnAlias,
|
String columnAlias,
|
||||||
String columnKey,
|
TableReference tableReference,
|
||||||
JdbcMapping jdbcMapping,
|
SelectableMapping selectableMapping,
|
||||||
JdbcValuesMetadata jdbcResultsMetadata,
|
JdbcValuesMetadata jdbcResultsMetadata,
|
||||||
DomainResultCreationState domainResultCreationState) {
|
DomainResultCreationState domainResultCreationState) {
|
||||||
final SqlExpressionResolver sqlExpressionResolver = domainResultCreationState.getSqlAstCreationState().getSqlExpressionResolver();
|
final DomainResultCreationStateImpl creationStateImpl = impl( domainResultCreationState );
|
||||||
sqlExpressionResolver.resolveSqlSelection(
|
creationStateImpl.resolveSqlSelection(
|
||||||
sqlExpressionResolver.resolveSqlExpression(
|
ResultsHelper.resolveSqlExpression(
|
||||||
columnKey,
|
creationStateImpl,
|
||||||
state -> {
|
jdbcResultsMetadata,
|
||||||
final int jdbcPosition = jdbcResultsMetadata.resolveColumnPosition( columnAlias );
|
tableReference,
|
||||||
final int valuesArrayPosition = jdbcPosition - 1;
|
selectableMapping,
|
||||||
return new ResultSetMappingSqlSelection( valuesArrayPosition, jdbcMapping );
|
columnAlias
|
||||||
}
|
|
||||||
),
|
),
|
||||||
jdbcMapping.getJdbcJavaType(),
|
selectableMapping.getJdbcMapping().getJdbcJavaType(),
|
||||||
null,
|
null,
|
||||||
domainResultCreationState.getSqlAstCreationState().getCreationContext().getSessionFactory().getTypeConfiguration()
|
domainResultCreationState.getSqlAstCreationState()
|
||||||
|
.getCreationContext()
|
||||||
|
.getSessionFactory()
|
||||||
|
.getTypeConfiguration()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -94,16 +94,12 @@ public class ImplicitFetchBuilderBasic implements ImplicitFetchBuilder, BasicVal
|
||||||
column = fetchable.getSelectionExpression();
|
column = fetchable.getSelectionExpression();
|
||||||
}
|
}
|
||||||
|
|
||||||
final Expression expression = creationStateImpl.resolveSqlExpression(
|
final Expression expression = ResultsHelper.resolveSqlExpression(
|
||||||
createColumnReferenceKey(
|
creationStateImpl,
|
||||||
|
jdbcResultsMetadata,
|
||||||
parentTableGroup.resolveTableReference( fetchPath, table ),
|
parentTableGroup.resolveTableReference( fetchPath, table ),
|
||||||
fetchable.getSelectionExpression()
|
fetchable,
|
||||||
),
|
column
|
||||||
processingState -> {
|
|
||||||
final int jdbcPosition = jdbcResultsMetadata.resolveColumnPosition( column );
|
|
||||||
final int valuesArrayPosition = jdbcPositionToValuesArrayPosition( jdbcPosition );
|
|
||||||
return new ResultSetMappingSqlSelection( valuesArrayPosition, fetchable );
|
|
||||||
}
|
|
||||||
);
|
);
|
||||||
|
|
||||||
final SqlSelection sqlSelection = creationStateImpl.resolveSqlSelection(
|
final SqlSelection sqlSelection = creationStateImpl.resolveSqlSelection(
|
||||||
|
|
|
@ -33,8 +33,6 @@ import org.hibernate.query.sqm.tree.delete.SqmDeleteStatement;
|
||||||
import org.hibernate.query.sqm.tree.expression.SqmParameter;
|
import org.hibernate.query.sqm.tree.expression.SqmParameter;
|
||||||
import org.hibernate.sql.ast.SqlAstJoinType;
|
import org.hibernate.sql.ast.SqlAstJoinType;
|
||||||
import org.hibernate.sql.ast.SqlAstTranslator;
|
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.Expression;
|
||||||
import org.hibernate.sql.ast.tree.expression.JdbcParameter;
|
import org.hibernate.sql.ast.tree.expression.JdbcParameter;
|
||||||
import org.hibernate.sql.ast.tree.from.TableGroup;
|
import org.hibernate.sql.ast.tree.from.TableGroup;
|
||||||
|
@ -165,12 +163,8 @@ public class MatchingIdSelectionHelper {
|
||||||
selection.getContainingTableExpression()
|
selection.getContainingTableExpression()
|
||||||
);
|
);
|
||||||
final Expression expression = sqmConverter.getSqlExpressionResolver().resolveSqlExpression(
|
final Expression expression = sqmConverter.getSqlExpressionResolver().resolveSqlExpression(
|
||||||
SqlExpressionResolver.createColumnReferenceKey( tableReference, selection.getSelectionExpression() ),
|
|
||||||
sqlAstProcessingState -> new ColumnReference(
|
|
||||||
tableReference,
|
tableReference,
|
||||||
selection,
|
selection
|
||||||
sessionFactory
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
idSelectionQuery.getSelectClause().addSqlSelection(
|
idSelectionQuery.getSelectClause().addSqlSelection(
|
||||||
new SqlSelectionImpl(
|
new SqlSelectionImpl(
|
||||||
|
|
|
@ -287,8 +287,7 @@ public abstract class AbstractCteMutationHandler extends AbstractMutationHandler
|
||||||
new ColumnReference(
|
new ColumnReference(
|
||||||
idSelectTableReference,
|
idSelectTableReference,
|
||||||
cteColumn.getColumnExpression(),
|
cteColumn.getColumnExpression(),
|
||||||
cteColumn.getJdbcMapping(),
|
cteColumn.getJdbcMapping()
|
||||||
factory
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
@ -304,8 +303,7 @@ public abstract class AbstractCteMutationHandler extends AbstractMutationHandler
|
||||||
new ColumnReference(
|
new ColumnReference(
|
||||||
idSelectTableReference,
|
idSelectTableReference,
|
||||||
selectableMapping.getSelectionExpression(),
|
selectableMapping.getSelectionExpression(),
|
||||||
selectableMapping.getJdbcMapping(),
|
selectableMapping.getJdbcMapping()
|
||||||
factory
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
|
@ -123,8 +123,7 @@ public class CteDeleteHandler extends AbstractCteMutationHandler implements Dele
|
||||||
(index, selectable) -> columnReferences.add(
|
(index, selectable) -> columnReferences.add(
|
||||||
new ColumnReference(
|
new ColumnReference(
|
||||||
dmlTableReference,
|
dmlTableReference,
|
||||||
selectable,
|
selectable
|
||||||
factory
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
@ -171,8 +170,7 @@ public class CteDeleteHandler extends AbstractCteMutationHandler implements Dele
|
||||||
(index, selectable) -> columnReferences.add(
|
(index, selectable) -> columnReferences.add(
|
||||||
new ColumnReference(
|
new ColumnReference(
|
||||||
dmlTableReference,
|
dmlTableReference,
|
||||||
selectable,
|
selectable
|
||||||
factory
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
|
@ -8,7 +8,6 @@ package org.hibernate.query.sqm.mutation.internal.cte;
|
||||||
|
|
||||||
import java.util.AbstractMap;
|
import java.util.AbstractMap;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.IdentityHashMap;
|
import java.util.IdentityHashMap;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
|
@ -45,7 +44,6 @@ import org.hibernate.query.SemanticException;
|
||||||
import org.hibernate.query.sqm.SortOrder;
|
import org.hibernate.query.sqm.SortOrder;
|
||||||
import org.hibernate.query.results.TableGroupImpl;
|
import org.hibernate.query.results.TableGroupImpl;
|
||||||
import org.hibernate.query.spi.DomainQueryExecutionContext;
|
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.DomainParameterXref;
|
||||||
import org.hibernate.query.sqm.internal.SqmJdbcExecutionContextAdapter;
|
import org.hibernate.query.sqm.internal.SqmJdbcExecutionContextAdapter;
|
||||||
import org.hibernate.query.sqm.internal.SqmUtil;
|
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.ColumnReference;
|
||||||
import org.hibernate.sql.ast.tree.expression.Expression;
|
import org.hibernate.sql.ast.tree.expression.Expression;
|
||||||
import org.hibernate.sql.ast.tree.expression.JdbcParameter;
|
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.QueryLiteral;
|
||||||
import org.hibernate.sql.ast.tree.expression.SelfRenderingSqlFragmentExpression;
|
import org.hibernate.sql.ast.tree.expression.SelfRenderingSqlFragmentExpression;
|
||||||
import org.hibernate.sql.ast.tree.from.NamedTableReference;
|
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.graph.basic.BasicResult;
|
||||||
import org.hibernate.sql.results.internal.SqlSelectionImpl;
|
import org.hibernate.sql.results.internal.SqlSelectionImpl;
|
||||||
import org.hibernate.sql.results.spi.ListResultsConsumer;
|
import org.hibernate.sql.results.spi.ListResultsConsumer;
|
||||||
import org.hibernate.type.BasicType;
|
|
||||||
import org.hibernate.type.spi.TypeConfiguration;
|
import org.hibernate.type.spi.TypeConfiguration;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -267,8 +263,7 @@ public class CteInsertHandler implements InsertHandler {
|
||||||
false,
|
false,
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
rowNumberColumn.getJdbcMapping(),
|
rowNumberColumn.getJdbcMapping()
|
||||||
sessionFactory
|
|
||||||
);
|
);
|
||||||
insertStatement.getTargetColumnReferences().set(
|
insertStatement.getTargetColumnReferences().set(
|
||||||
insertStatement.getTargetColumnReferences().size() - 1,
|
insertStatement.getTargetColumnReferences().size() - 1,
|
||||||
|
@ -322,8 +317,7 @@ public class CteInsertHandler implements InsertHandler {
|
||||||
false,
|
false,
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
columnReference.getJdbcMapping(),
|
columnReference.getJdbcMapping()
|
||||||
null
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
@ -354,8 +348,7 @@ public class CteInsertHandler implements InsertHandler {
|
||||||
false,
|
false,
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
rowNumberColumn.getJdbcMapping(),
|
rowNumberColumn.getJdbcMapping()
|
||||||
sessionFactory
|
|
||||||
);
|
);
|
||||||
insertStatement.getTargetColumnReferences().add( columnReference );
|
insertStatement.getTargetColumnReferences().add( columnReference );
|
||||||
targetPathCteColumns.add( rowNumberColumn );
|
targetPathCteColumns.add( rowNumberColumn );
|
||||||
|
@ -393,8 +386,7 @@ public class CteInsertHandler implements InsertHandler {
|
||||||
false,
|
false,
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
rowNumberColumn.getJdbcMapping(),
|
rowNumberColumn.getJdbcMapping()
|
||||||
factory
|
|
||||||
);
|
);
|
||||||
final CteColumn idColumn = fullEntityCteTable.getCteColumns().get( 0 );
|
final CteColumn idColumn = fullEntityCteTable.getCteColumns().get( 0 );
|
||||||
final BasicValuedMapping idType = (BasicValuedMapping) idColumn.getJdbcMapping();
|
final BasicValuedMapping idType = (BasicValuedMapping) idColumn.getJdbcMapping();
|
||||||
|
@ -515,8 +507,7 @@ public class CteInsertHandler implements InsertHandler {
|
||||||
false,
|
false,
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
rowNumberColumn.getJdbcMapping(),
|
rowNumberColumn.getJdbcMapping()
|
||||||
factory
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
@ -533,8 +524,7 @@ public class CteInsertHandler implements InsertHandler {
|
||||||
false,
|
false,
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
idColumn.getJdbcMapping(),
|
idColumn.getJdbcMapping()
|
||||||
factory
|
|
||||||
),
|
),
|
||||||
BinaryArithmeticOperator.ADD,
|
BinaryArithmeticOperator.ADD,
|
||||||
new BinaryArithmeticExpression(
|
new BinaryArithmeticExpression(
|
||||||
|
@ -546,8 +536,7 @@ public class CteInsertHandler implements InsertHandler {
|
||||||
false,
|
false,
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
rowNumberColumn.getJdbcMapping(),
|
rowNumberColumn.getJdbcMapping()
|
||||||
factory
|
|
||||||
),
|
),
|
||||||
integerType
|
integerType
|
||||||
),
|
),
|
||||||
|
@ -580,8 +569,7 @@ public class CteInsertHandler implements InsertHandler {
|
||||||
false,
|
false,
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
cteColumn.getJdbcMapping(),
|
cteColumn.getJdbcMapping()
|
||||||
factory
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
@ -849,8 +837,7 @@ public class CteInsertHandler implements InsertHandler {
|
||||||
false,
|
false,
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
rowNumberColumn.getJdbcMapping(),
|
rowNumberColumn.getJdbcMapping()
|
||||||
factory
|
|
||||||
);
|
);
|
||||||
// Insert in the same order as the original tuples came
|
// Insert in the same order as the original tuples came
|
||||||
insertSelectSpec.addSortSpecification(
|
insertSelectSpec.addSortSpecification(
|
||||||
|
@ -871,8 +858,7 @@ public class CteInsertHandler implements InsertHandler {
|
||||||
false,
|
false,
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
null,
|
null
|
||||||
factory
|
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -914,8 +900,7 @@ public class CteInsertHandler implements InsertHandler {
|
||||||
false,
|
false,
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
rowNumberColumn.getJdbcMapping(),
|
rowNumberColumn.getJdbcMapping()
|
||||||
factory
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
@ -934,8 +919,7 @@ public class CteInsertHandler implements InsertHandler {
|
||||||
false,
|
false,
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
idCteColumn.getJdbcMapping(),
|
idCteColumn.getJdbcMapping()
|
||||||
factory
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
@ -952,8 +936,7 @@ public class CteInsertHandler implements InsertHandler {
|
||||||
false,
|
false,
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
cteColumn.getJdbcMapping(),
|
cteColumn.getJdbcMapping()
|
||||||
factory
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
@ -985,8 +968,7 @@ public class CteInsertHandler implements InsertHandler {
|
||||||
false,
|
false,
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
idCteColumn.getJdbcMapping(),
|
idCteColumn.getJdbcMapping()
|
||||||
factory
|
|
||||||
);
|
);
|
||||||
finalResultQuery.getSelectClause().addSqlSelection(
|
finalResultQuery.getSelectClause().addSqlSelection(
|
||||||
new SqlSelectionImpl(
|
new SqlSelectionImpl(
|
||||||
|
@ -1042,8 +1024,7 @@ public class CteInsertHandler implements InsertHandler {
|
||||||
false,
|
false,
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
null,
|
null
|
||||||
factory
|
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
insertSelectSpec.getSelectClause().addSqlSelection(
|
insertSelectSpec.getSelectClause().addSqlSelection(
|
||||||
|
@ -1056,8 +1037,7 @@ public class CteInsertHandler implements InsertHandler {
|
||||||
false,
|
false,
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
null,
|
null
|
||||||
factory
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
@ -1092,8 +1072,7 @@ public class CteInsertHandler implements InsertHandler {
|
||||||
columnReference.isColumnExpressionFormula(),
|
columnReference.isColumnExpressionFormula(),
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
columnReference.getJdbcMapping(),
|
columnReference.getJdbcMapping()
|
||||||
factory
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
|
@ -193,8 +193,7 @@ public class CteUpdateHandler extends AbstractCteMutationHandler implements Upda
|
||||||
new ColumnReference(
|
new ColumnReference(
|
||||||
existsTableReference,
|
existsTableReference,
|
||||||
keyColumns[selectionIndex],
|
keyColumns[selectionIndex],
|
||||||
selectableMapping.getJdbcMapping(),
|
selectableMapping.getJdbcMapping()
|
||||||
factory
|
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -291,8 +290,7 @@ public class CteUpdateHandler extends AbstractCteMutationHandler implements Upda
|
||||||
(index, selectable) -> columnReferences.add(
|
(index, selectable) -> columnReferences.add(
|
||||||
new ColumnReference(
|
new ColumnReference(
|
||||||
dmlTableReference,
|
dmlTableReference,
|
||||||
selectable,
|
selectable
|
||||||
factory
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
|
@ -75,8 +75,7 @@ public class InPredicateRestrictionProducer implements MatchingIdRestrictionProd
|
||||||
false,
|
false,
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
basicIdMapping.getJdbcMapping(),
|
basicIdMapping.getJdbcMapping()
|
||||||
sessionFactory
|
|
||||||
);
|
);
|
||||||
predicate = new InListPredicate( inFixture );
|
predicate = new InListPredicate( inFixture );
|
||||||
|
|
||||||
|
@ -92,8 +91,7 @@ public class InPredicateRestrictionProducer implements MatchingIdRestrictionProd
|
||||||
columnReferences.add(
|
columnReferences.add(
|
||||||
new ColumnReference(
|
new ColumnReference(
|
||||||
mutatingTableReference,
|
mutatingTableReference,
|
||||||
selection,
|
selection
|
||||||
sessionFactory
|
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
jdbcMappings.add( selection.getJdbcMapping() );
|
jdbcMappings.add( selection.getJdbcMapping() );
|
||||||
|
|
|
@ -359,8 +359,7 @@ public class InlineUpdateHandler implements UpdateHandler {
|
||||||
keyColumnCollector.apply(
|
keyColumnCollector.apply(
|
||||||
new ColumnReference(
|
new ColumnReference(
|
||||||
(String) null,
|
(String) null,
|
||||||
selection,
|
selection
|
||||||
sessionFactory
|
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -454,8 +453,7 @@ public class InlineUpdateHandler implements UpdateHandler {
|
||||||
false,
|
false,
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
columnReference.getJdbcMapping(),
|
columnReference.getJdbcMapping()
|
||||||
null
|
|
||||||
);
|
);
|
||||||
columnNames.add( columnReference.getColumnExpression() );
|
columnNames.add( columnReference.getColumnExpression() );
|
||||||
lhs.add( valuesColumnReference );
|
lhs.add( valuesColumnReference );
|
||||||
|
@ -466,8 +464,7 @@ public class InlineUpdateHandler implements UpdateHandler {
|
||||||
false,
|
false,
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
columnReference.getJdbcMapping(),
|
columnReference.getJdbcMapping()
|
||||||
null
|
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
querySpec.getSelectClause().addSqlSelection(
|
querySpec.getSelectClause().addSqlSelection(
|
||||||
|
@ -489,8 +486,7 @@ public class InlineUpdateHandler implements UpdateHandler {
|
||||||
false,
|
false,
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
columnReference.getJdbcMapping(),
|
columnReference.getJdbcMapping()
|
||||||
null
|
|
||||||
);
|
);
|
||||||
columnNames = Collections.singletonList( columnReference.getColumnExpression() );
|
columnNames = Collections.singletonList( columnReference.getColumnExpression() );
|
||||||
joinPredicate = new ComparisonPredicate(
|
joinPredicate = new ComparisonPredicate(
|
||||||
|
@ -502,8 +498,7 @@ public class InlineUpdateHandler implements UpdateHandler {
|
||||||
false,
|
false,
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
columnReference.getJdbcMapping(),
|
columnReference.getJdbcMapping()
|
||||||
null
|
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
querySpec.getSelectClause().addSqlSelection(
|
querySpec.getSelectClause().addSqlSelection(
|
||||||
|
@ -534,8 +529,7 @@ public class InlineUpdateHandler implements UpdateHandler {
|
||||||
new ColumnReference(
|
new ColumnReference(
|
||||||
rootTableGroup.resolveTableReference( tableExpression ),
|
rootTableGroup.resolveTableReference( tableExpression ),
|
||||||
columnNames.get( 0 ),
|
columnNames.get( 0 ),
|
||||||
entityDescriptor.getIdentifierMapping().getJdbcMappings().get( 0 ),
|
entityDescriptor.getIdentifierMapping().getJdbcMappings().get( 0 )
|
||||||
null
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
|
@ -29,7 +29,6 @@ import org.hibernate.spi.NavigablePath;
|
||||||
import org.hibernate.query.sqm.mutation.internal.MultiTableSqmMutationConverter;
|
import org.hibernate.query.sqm.mutation.internal.MultiTableSqmMutationConverter;
|
||||||
import org.hibernate.sql.ast.SqlAstJoinType;
|
import org.hibernate.sql.ast.SqlAstJoinType;
|
||||||
import org.hibernate.sql.ast.SqlAstTranslatorFactory;
|
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.ColumnReference;
|
||||||
import org.hibernate.sql.ast.tree.expression.QueryLiteral;
|
import org.hibernate.sql.ast.tree.expression.QueryLiteral;
|
||||||
import org.hibernate.sql.ast.tree.from.NamedTableReference;
|
import org.hibernate.sql.ast.tree.from.NamedTableReference;
|
||||||
|
@ -84,8 +83,7 @@ public final class ExecuteWithTemporaryTableHelper {
|
||||||
false,
|
false,
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
column.getJdbcMapping(),
|
column.getJdbcMapping()
|
||||||
factory
|
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -106,15 +104,8 @@ public final class ExecuteWithTemporaryTableHelper {
|
||||||
jdbcPosition,
|
jdbcPosition,
|
||||||
jdbcPosition + 1,
|
jdbcPosition + 1,
|
||||||
sqmConverter.getSqlExpressionResolver().resolveSqlExpression(
|
sqmConverter.getSqlExpressionResolver().resolveSqlExpression(
|
||||||
SqlExpressionResolver.createColumnReferenceKey(
|
|
||||||
tableReference,
|
tableReference,
|
||||||
selection.getSelectionExpression()
|
selection
|
||||||
),
|
|
||||||
sqlAstProcessingState -> new ColumnReference(
|
|
||||||
tableReference,
|
|
||||||
selection,
|
|
||||||
factory
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
@ -243,8 +234,7 @@ public final class ExecuteWithTemporaryTableHelper {
|
||||||
false,
|
false,
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
temporaryTableColumn.getJdbcMapping(),
|
temporaryTableColumn.getJdbcMapping()
|
||||||
executionContext.getSession().getFactory()
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
@ -264,8 +254,7 @@ public final class ExecuteWithTemporaryTableHelper {
|
||||||
false,
|
false,
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
selectableMapping.getJdbcMapping(),
|
selectableMapping.getJdbcMapping()
|
||||||
executionContext.getSession().getFactory()
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
@ -289,8 +278,7 @@ public final class ExecuteWithTemporaryTableHelper {
|
||||||
false,
|
false,
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
idTable.getSessionUidColumn().getJdbcMapping(),
|
idTable.getSessionUidColumn().getJdbcMapping()
|
||||||
executionContext.getSession().getFactory()
|
|
||||||
),
|
),
|
||||||
ComparisonOperator.EQUAL,
|
ComparisonOperator.EQUAL,
|
||||||
new QueryLiteral<>(
|
new QueryLiteral<>(
|
||||||
|
|
|
@ -52,12 +52,8 @@ public final class ExecuteWithoutIdTableHelper {
|
||||||
rootEntityPersister.getIdentifierMapping().forEachSelectable(
|
rootEntityPersister.getIdentifierMapping().forEachSelectable(
|
||||||
(columnIndex, selection) -> {
|
(columnIndex, selection) -> {
|
||||||
final ColumnReference columnReference = (ColumnReference) sqlExpressionResolver.resolveSqlExpression(
|
final ColumnReference columnReference = (ColumnReference) sqlExpressionResolver.resolveSqlExpression(
|
||||||
SqlExpressionResolver.createColumnReferenceKey( rootTableReference, selection.getSelectionExpression() ),
|
|
||||||
sqlAstProcessingState -> new ColumnReference(
|
|
||||||
rootTableReference,
|
rootTableReference,
|
||||||
selection,
|
selection
|
||||||
sessionFactory
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
final SqlSelection sqlSelection = new SqlSelectionImpl(
|
final SqlSelection sqlSelection = new SqlSelectionImpl(
|
||||||
// irrelevant
|
// irrelevant
|
||||||
|
|
|
@ -344,8 +344,7 @@ public class InsertExecutionDelegate implements TableBasedInsertHandler.Executio
|
||||||
false,
|
false,
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
columnReference.getJdbcMapping(),
|
columnReference.getJdbcMapping()
|
||||||
sessionFactory
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
@ -364,8 +363,7 @@ public class InsertExecutionDelegate implements TableBasedInsertHandler.Executio
|
||||||
false,
|
false,
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
identifierMapping.getJdbcMapping(),
|
identifierMapping.getJdbcMapping()
|
||||||
sessionFactory
|
|
||||||
);
|
);
|
||||||
idSelectQuerySpec.getSelectClause().addSqlSelection( new SqlSelectionImpl( 1, 0, columnReference ) );
|
idSelectQuerySpec.getSelectClause().addSqlSelection( new SqlSelectionImpl( 1, 0, columnReference ) );
|
||||||
idSelectQuerySpec.addSortSpecification(
|
idSelectQuerySpec.addSortSpecification(
|
||||||
|
@ -427,8 +425,7 @@ public class InsertExecutionDelegate implements TableBasedInsertHandler.Executio
|
||||||
final List<Assignment> temporaryTableAssignments = new ArrayList<>( 1 );
|
final List<Assignment> temporaryTableAssignments = new ArrayList<>( 1 );
|
||||||
final ColumnReference idColumnReference = new ColumnReference(
|
final ColumnReference idColumnReference = new ColumnReference(
|
||||||
(String) null,
|
(String) null,
|
||||||
identifierMapping,
|
identifierMapping
|
||||||
sessionFactory
|
|
||||||
);
|
);
|
||||||
temporaryTableAssignments.add(
|
temporaryTableAssignments.add(
|
||||||
new Assignment(
|
new Assignment(
|
||||||
|
@ -458,8 +455,7 @@ public class InsertExecutionDelegate implements TableBasedInsertHandler.Executio
|
||||||
false,
|
false,
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
sessionUidColumn.getJdbcMapping(),
|
sessionUidColumn.getJdbcMapping()
|
||||||
sessionFactory
|
|
||||||
),
|
),
|
||||||
ComparisonOperator.EQUAL,
|
ComparisonOperator.EQUAL,
|
||||||
sessionUidParameter
|
sessionUidParameter
|
||||||
|
@ -476,8 +472,7 @@ public class InsertExecutionDelegate implements TableBasedInsertHandler.Executio
|
||||||
false,
|
false,
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
rowNumberColumn.getJdbcMapping(),
|
rowNumberColumn.getJdbcMapping()
|
||||||
sessionFactory
|
|
||||||
),
|
),
|
||||||
ComparisonOperator.EQUAL,
|
ComparisonOperator.EQUAL,
|
||||||
rowNumber
|
rowNumber
|
||||||
|
@ -539,8 +534,7 @@ public class InsertExecutionDelegate implements TableBasedInsertHandler.Executio
|
||||||
false,
|
false,
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
identifierMapping.getJdbcMapping(),
|
identifierMapping.getJdbcMapping()
|
||||||
sessionFactory
|
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
querySpec.getSelectClause().addSqlSelection(
|
querySpec.getSelectClause().addSqlSelection(
|
||||||
|
@ -553,8 +547,7 @@ public class InsertExecutionDelegate implements TableBasedInsertHandler.Executio
|
||||||
false,
|
false,
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
idColumnReference.getJdbcMapping(),
|
idColumnReference.getJdbcMapping()
|
||||||
sessionFactory
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
@ -603,8 +596,7 @@ public class InsertExecutionDelegate implements TableBasedInsertHandler.Executio
|
||||||
new Assignment(
|
new Assignment(
|
||||||
new ColumnReference(
|
new ColumnReference(
|
||||||
(String) null,
|
(String) null,
|
||||||
identifierMapping,
|
identifierMapping
|
||||||
sessionFactory
|
|
||||||
),
|
),
|
||||||
rootIdentity
|
rootIdentity
|
||||||
)
|
)
|
||||||
|
@ -619,8 +611,7 @@ public class InsertExecutionDelegate implements TableBasedInsertHandler.Executio
|
||||||
false,
|
false,
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
identifierMapping.getJdbcMapping(),
|
identifierMapping.getJdbcMapping()
|
||||||
sessionFactory
|
|
||||||
),
|
),
|
||||||
ComparisonOperator.EQUAL,
|
ComparisonOperator.EQUAL,
|
||||||
entityIdentity
|
entityIdentity
|
||||||
|
@ -723,8 +714,7 @@ public class InsertExecutionDelegate implements TableBasedInsertHandler.Executio
|
||||||
false,
|
false,
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
columnReference.getJdbcMapping(),
|
columnReference.getJdbcMapping()
|
||||||
sessionFactory
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
@ -757,8 +747,7 @@ public class InsertExecutionDelegate implements TableBasedInsertHandler.Executio
|
||||||
false,
|
false,
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
identifierMapping.getJdbcMapping(),
|
identifierMapping.getJdbcMapping()
|
||||||
sessionFactory
|
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
querySpec.getSelectClause().addSqlSelection(
|
querySpec.getSelectClause().addSqlSelection(
|
||||||
|
@ -767,8 +756,7 @@ public class InsertExecutionDelegate implements TableBasedInsertHandler.Executio
|
||||||
0,
|
0,
|
||||||
new ColumnReference(
|
new ColumnReference(
|
||||||
updatingTableReference.getIdentificationVariable(),
|
updatingTableReference.getIdentificationVariable(),
|
||||||
identifierMapping,
|
identifierMapping
|
||||||
sessionFactory
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
|
@ -408,12 +408,8 @@ public class RestrictedDeleteExecutionDelegate implements TableBasedDeleteHandle
|
||||||
assert deleteTableReference.getTableReference( selection.getContainingTableExpression() ) != null;
|
assert deleteTableReference.getTableReference( selection.getContainingTableExpression() ) != null;
|
||||||
|
|
||||||
final Expression expression = sqlExpressionResolver.resolveSqlExpression(
|
final Expression expression = sqlExpressionResolver.resolveSqlExpression(
|
||||||
SqlExpressionResolver.createColumnReferenceKey( deleteTableReference, selection.getSelectionExpression() ),
|
|
||||||
sqlAstProcessingState -> new ColumnReference(
|
|
||||||
deleteTableReference,
|
deleteTableReference,
|
||||||
selection,
|
selection
|
||||||
sessionFactory
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
|
|
||||||
deletingTableColumnRefs.add( (ColumnReference) expression );
|
deletingTableColumnRefs.add( (ColumnReference) expression );
|
||||||
|
@ -604,8 +600,7 @@ public class RestrictedDeleteExecutionDelegate implements TableBasedDeleteHandle
|
||||||
keyColumnCollector.apply(
|
keyColumnCollector.apply(
|
||||||
new ColumnReference(
|
new ColumnReference(
|
||||||
targetTable,
|
targetTable,
|
||||||
selection,
|
selection
|
||||||
factory
|
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,7 +27,6 @@ import org.hibernate.internal.util.collections.CollectionHelper;
|
||||||
import org.hibernate.metamodel.mapping.MappingModelExpressible;
|
import org.hibernate.metamodel.mapping.MappingModelExpressible;
|
||||||
import org.hibernate.persister.entity.EntityPersister;
|
import org.hibernate.persister.entity.EntityPersister;
|
||||||
import org.hibernate.query.spi.DomainQueryExecutionContext;
|
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.DomainParameterXref;
|
||||||
import org.hibernate.query.sqm.internal.SqmJdbcExecutionContextAdapter;
|
import org.hibernate.query.sqm.internal.SqmJdbcExecutionContextAdapter;
|
||||||
import org.hibernate.query.sqm.mutation.internal.InsertHandler;
|
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.ColumnReference;
|
||||||
import org.hibernate.sql.ast.tree.expression.Expression;
|
import org.hibernate.sql.ast.tree.expression.Expression;
|
||||||
import org.hibernate.sql.ast.tree.expression.JdbcParameter;
|
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.QueryLiteral;
|
||||||
import org.hibernate.sql.ast.tree.from.NamedTableReference;
|
import org.hibernate.sql.ast.tree.from.NamedTableReference;
|
||||||
import org.hibernate.sql.ast.tree.from.TableGroup;
|
import org.hibernate.sql.ast.tree.from.TableGroup;
|
||||||
|
@ -198,8 +196,7 @@ public class TableBasedInsertHandler implements InsertHandler {
|
||||||
false,
|
false,
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
rowNumberColumn.getJdbcMapping(),
|
rowNumberColumn.getJdbcMapping()
|
||||||
sessionFactory
|
|
||||||
);
|
);
|
||||||
insertStatement.getTargetColumnReferences().set(
|
insertStatement.getTargetColumnReferences().set(
|
||||||
insertStatement.getTargetColumnReferences().size() - 1,
|
insertStatement.getTargetColumnReferences().size() - 1,
|
||||||
|
@ -224,8 +221,7 @@ public class TableBasedInsertHandler implements InsertHandler {
|
||||||
false,
|
false,
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
rowNumberColumn.getJdbcMapping(),
|
rowNumberColumn.getJdbcMapping()
|
||||||
sessionFactory
|
|
||||||
);
|
);
|
||||||
insertStatement.getTargetColumnReferences().add( columnReference );
|
insertStatement.getTargetColumnReferences().add( columnReference );
|
||||||
targetPathColumns.add( new Assignment( columnReference, columnReference ) );
|
targetPathColumns.add( new Assignment( columnReference, columnReference ) );
|
||||||
|
@ -248,8 +244,7 @@ public class TableBasedInsertHandler implements InsertHandler {
|
||||||
false,
|
false,
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
sessionUidColumn.getJdbcMapping(),
|
sessionUidColumn.getJdbcMapping()
|
||||||
sessionFactory
|
|
||||||
);
|
);
|
||||||
insertStatement.getTargetColumnReferences().add(
|
insertStatement.getTargetColumnReferences().add(
|
||||||
sessionUidColumnReference
|
sessionUidColumnReference
|
||||||
|
@ -285,8 +280,7 @@ public class TableBasedInsertHandler implements InsertHandler {
|
||||||
false,
|
false,
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
rowNumberColumn.getJdbcMapping(),
|
rowNumberColumn.getJdbcMapping()
|
||||||
sessionFactory
|
|
||||||
);
|
);
|
||||||
insertStatement.getTargetColumnReferences().add( columnReference );
|
insertStatement.getTargetColumnReferences().add( columnReference );
|
||||||
targetPathColumns.add( new Assignment( columnReference, columnReference ) );
|
targetPathColumns.add( new Assignment( columnReference, columnReference ) );
|
||||||
|
@ -305,8 +299,7 @@ public class TableBasedInsertHandler implements InsertHandler {
|
||||||
false,
|
false,
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
sessionUidColumn.getJdbcMapping(),
|
sessionUidColumn.getJdbcMapping()
|
||||||
sessionFactory
|
|
||||||
);
|
);
|
||||||
insertStatement.getTargetColumnReferences().add(
|
insertStatement.getTargetColumnReferences().add(
|
||||||
sessionUidColumnReference
|
sessionUidColumnReference
|
||||||
|
|
|
@ -269,8 +269,7 @@ public class UpdateExecutionDelegate implements TableBasedUpdateHandler.Executio
|
||||||
keyColumnCollector.apply(
|
keyColumnCollector.apply(
|
||||||
new ColumnReference(
|
new ColumnReference(
|
||||||
(String) null,
|
(String) null,
|
||||||
selection,
|
selection
|
||||||
sessionFactory
|
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -369,8 +368,7 @@ public class UpdateExecutionDelegate implements TableBasedUpdateHandler.Executio
|
||||||
existsKeyColumnCollector.apply(
|
existsKeyColumnCollector.apply(
|
||||||
new ColumnReference(
|
new ColumnReference(
|
||||||
existsTableReference,
|
existsTableReference,
|
||||||
selection,
|
selection
|
||||||
sessionFactory
|
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -96,6 +96,7 @@ import org.hibernate.metamodel.model.domain.internal.AnyDiscriminatorSqmPath;
|
||||||
import org.hibernate.metamodel.model.domain.internal.AnyDiscriminatorSqmPathSource;
|
import org.hibernate.metamodel.model.domain.internal.AnyDiscriminatorSqmPathSource;
|
||||||
import org.hibernate.query.criteria.JpaCteCriteriaAttribute;
|
import org.hibernate.query.criteria.JpaCteCriteriaAttribute;
|
||||||
import org.hibernate.query.criteria.JpaSearchOrder;
|
import org.hibernate.query.criteria.JpaSearchOrder;
|
||||||
|
import org.hibernate.query.derived.AnonymousTupleEntityValuedModelPart;
|
||||||
import org.hibernate.query.derived.AnonymousTupleTableGroupProducer;
|
import org.hibernate.query.derived.AnonymousTupleTableGroupProducer;
|
||||||
import org.hibernate.query.derived.AnonymousTupleType;
|
import org.hibernate.query.derived.AnonymousTupleType;
|
||||||
import org.hibernate.metamodel.model.domain.internal.BasicSqmPathSource;
|
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.DiscriminatedAssociationPathInterpretation;
|
||||||
import org.hibernate.query.sqm.sql.internal.DiscriminatedAssociationTypePathInterpretation;
|
import org.hibernate.query.sqm.sql.internal.DiscriminatedAssociationTypePathInterpretation;
|
||||||
import org.hibernate.query.sqm.sql.internal.DomainResultProducer;
|
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.EmbeddableValuedPathInterpretation;
|
||||||
import org.hibernate.query.sqm.sql.internal.EntityValuedPathInterpretation;
|
import org.hibernate.query.sqm.sql.internal.EntityValuedPathInterpretation;
|
||||||
import org.hibernate.query.sqm.sql.internal.NonAggregatedCompositeValuedPathInterpretation;
|
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.PluralTableGroup;
|
||||||
import org.hibernate.sql.ast.tree.from.QueryPartTableGroup;
|
import org.hibernate.sql.ast.tree.from.QueryPartTableGroup;
|
||||||
import org.hibernate.sql.ast.tree.from.QueryPartTableReference;
|
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.TableGroup;
|
||||||
import org.hibernate.sql.ast.tree.from.TableGroupJoin;
|
import org.hibernate.sql.ast.tree.from.TableGroupJoin;
|
||||||
import org.hibernate.sql.ast.tree.from.TableGroupJoinProducer;
|
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.NATIVE;
|
||||||
import static org.hibernate.query.sqm.TemporalUnit.SECOND;
|
import static org.hibernate.query.sqm.TemporalUnit.SECOND;
|
||||||
import static org.hibernate.query.sqm.UnaryArithmeticOperator.UNARY_MINUS;
|
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;
|
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<>(
|
final BasicValuedPathInterpretation<?> discriminatorPath = new BasicValuedPathInterpretation<>(
|
||||||
new ColumnReference(
|
new ColumnReference(
|
||||||
rootTableGroup.resolveTableReference( discriminatorMapping.getContainingTableExpression() ),
|
rootTableGroup.resolveTableReference( discriminatorMapping.getContainingTableExpression() ),
|
||||||
discriminatorMapping,
|
discriminatorMapping
|
||||||
getCreationContext().getSessionFactory()
|
|
||||||
),
|
),
|
||||||
rootTableGroup.getNavigablePath().append( discriminatorMapping.getPartName() ),
|
rootTableGroup.getNavigablePath().append( discriminatorMapping.getPartName() ),
|
||||||
discriminatorMapping,
|
discriminatorMapping,
|
||||||
|
@ -1328,8 +1327,7 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
|
||||||
final BasicValuedPathInterpretation<?> identifierPath = new BasicValuedPathInterpretation<>(
|
final BasicValuedPathInterpretation<?> identifierPath = new BasicValuedPathInterpretation<>(
|
||||||
new ColumnReference(
|
new ColumnReference(
|
||||||
rootTableGroup.resolveTableReference( identifierMapping.getContainingTableExpression() ),
|
rootTableGroup.resolveTableReference( identifierMapping.getContainingTableExpression() ),
|
||||||
identifierMapping,
|
identifierMapping
|
||||||
getCreationContext().getSessionFactory()
|
|
||||||
),
|
),
|
||||||
rootTableGroup.getNavigablePath().append( identifierMapping.getPartName() ),
|
rootTableGroup.getNavigablePath().append( identifierMapping.getPartName() ),
|
||||||
identifierMapping,
|
identifierMapping,
|
||||||
|
@ -2605,14 +2603,12 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
|
||||||
new ComparisonPredicate(
|
new ComparisonPredicate(
|
||||||
new ColumnReference(
|
new ColumnReference(
|
||||||
parentTableGroup.resolveTableReference( navigablePath, selectable.getContainingTableExpression() ),
|
parentTableGroup.resolveTableReference( navigablePath, selectable.getContainingTableExpression() ),
|
||||||
selectable,
|
selectable
|
||||||
sessionFactory
|
|
||||||
),
|
),
|
||||||
ComparisonOperator.EQUAL,
|
ComparisonOperator.EQUAL,
|
||||||
new ColumnReference(
|
new ColumnReference(
|
||||||
tableGroup.resolveTableReference( navigablePath, selectable.getContainingTableExpression() ),
|
tableGroup.resolveTableReference( navigablePath, selectable.getContainingTableExpression() ),
|
||||||
selectable,
|
selectable
|
||||||
sessionFactory
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
@ -2626,15 +2622,13 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
|
||||||
lhs.add(
|
lhs.add(
|
||||||
new ColumnReference(
|
new ColumnReference(
|
||||||
parentTableGroup.resolveTableReference( navigablePath, selectable.getContainingTableExpression() ),
|
parentTableGroup.resolveTableReference( navigablePath, selectable.getContainingTableExpression() ),
|
||||||
selectable,
|
selectable
|
||||||
sessionFactory
|
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
rhs.add(
|
rhs.add(
|
||||||
new ColumnReference(
|
new ColumnReference(
|
||||||
tableGroup.resolveTableReference( navigablePath, selectable.getContainingTableExpression() ),
|
tableGroup.resolveTableReference( navigablePath, selectable.getContainingTableExpression() ),
|
||||||
selectable,
|
selectable
|
||||||
sessionFactory
|
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -3697,6 +3691,10 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
|
||||||
resultModelPart = entityValuedModelPart.findSubPart( targetPart.getPartName(), null );
|
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 {
|
else {
|
||||||
// Otherwise, we use the identifier mapping of the target entity type
|
// Otherwise, we use the identifier mapping of the target entity type
|
||||||
resultModelPart = entityValuedModelPart.getEntityMappingType().getIdentifierMapping();
|
resultModelPart = entityValuedModelPart.getEntityMappingType().getIdentifierMapping();
|
||||||
|
@ -3758,6 +3756,9 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
|
||||||
resultModelPart = collectionPart.getAssociatedEntityMappingType().getIdentifierMapping();
|
resultModelPart = collectionPart.getAssociatedEntityMappingType().getIdentifierMapping();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if ( entityValuedModelPart instanceof AnonymousTupleEntityValuedModelPart ) {
|
||||||
|
resultModelPart = ( (AnonymousTupleEntityValuedModelPart) entityValuedModelPart ).getForeignKeyPart();
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
// Since the table group model part is an EntityMappingType,
|
// Since the table group model part is an EntityMappingType,
|
||||||
// we can render the FK target model part of the inferred collection part,
|
// 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;
|
interpretationModelPart = inferredEntityMapping;
|
||||||
tableGroupToUse = collectionTableGroup;
|
tableGroupToUse = collectionTableGroup;
|
||||||
}
|
}
|
||||||
|
else if ( entityValuedModelPart instanceof AnonymousTupleEntityValuedModelPart ) {
|
||||||
|
resultModelPart = ( (AnonymousTupleEntityValuedModelPart) entityValuedModelPart ).getForeignKeyPart();
|
||||||
|
interpretationModelPart = inferredEntityMapping;
|
||||||
|
tableGroupToUse = null;
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
// Render the identifier mapping if the inferred mapping is an EntityMappingType
|
// Render the identifier mapping if the inferred mapping is an EntityMappingType
|
||||||
assert inferredEntityMapping instanceof EntityMappingType;
|
assert inferredEntityMapping instanceof EntityMappingType;
|
||||||
|
@ -3839,15 +3845,8 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
|
||||||
);
|
);
|
||||||
|
|
||||||
final Expression expression = getSqlExpressionResolver().resolveSqlExpression(
|
final Expression expression = getSqlExpressionResolver().resolveSqlExpression(
|
||||||
createColumnReferenceKey(
|
|
||||||
tableReference,
|
tableReference,
|
||||||
mapping.getSelectionExpression()
|
mapping
|
||||||
),
|
|
||||||
sacs -> new ColumnReference(
|
|
||||||
tableReference.getIdentificationVariable(),
|
|
||||||
mapping,
|
|
||||||
getCreationContext().getSessionFactory()
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
final ColumnReference columnReference;
|
final ColumnReference columnReference;
|
||||||
if ( expression instanceof ColumnReference ) {
|
if ( expression instanceof ColumnReference ) {
|
||||||
|
@ -4055,12 +4054,8 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
|
||||||
final BasicValuedModelPart basicFkPart = (BasicValuedModelPart) fkKeyPart;
|
final BasicValuedModelPart basicFkPart = (BasicValuedModelPart) fkKeyPart;
|
||||||
|
|
||||||
return getSqlExpressionResolver().resolveSqlExpression(
|
return getSqlExpressionResolver().resolveSqlExpression(
|
||||||
createColumnReferenceKey( tableReference, basicFkPart.getSelectionExpression() ),
|
|
||||||
(sqlAstProcessingState) -> new ColumnReference(
|
|
||||||
tableReference,
|
tableReference,
|
||||||
basicFkPart,
|
basicFkPart
|
||||||
creationContext.getSessionFactory()
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -4070,12 +4065,8 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
|
||||||
final List<Expression> tupleElements = new ArrayList<>( jdbcMappings.size() );
|
final List<Expression> tupleElements = new ArrayList<>( jdbcMappings.size() );
|
||||||
compositeFkPart.forEachSelectable( (position, selectable) -> tupleElements.add(
|
compositeFkPart.forEachSelectable( (position, selectable) -> tupleElements.add(
|
||||||
getSqlExpressionResolver().resolveSqlExpression(
|
getSqlExpressionResolver().resolveSqlExpression(
|
||||||
createColumnReferenceKey( tableReference, selectable.getSelectionExpression() ),
|
|
||||||
(sqlAstProcessingState) -> new ColumnReference(
|
|
||||||
tableReference,
|
tableReference,
|
||||||
selectable,
|
selectable
|
||||||
creationContext.getSessionFactory()
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
) );
|
) );
|
||||||
|
|
||||||
|
@ -4371,8 +4362,7 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
|
||||||
navigablePath,
|
navigablePath,
|
||||||
selectionMapping.getContainingTableExpression()
|
selectionMapping.getContainingTableExpression()
|
||||||
),
|
),
|
||||||
selectionMapping,
|
selectionMapping
|
||||||
creationContext.getSessionFactory()
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
@ -4489,8 +4479,7 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
|
||||||
navigablePath,
|
navigablePath,
|
||||||
selectionMapping.getContainingTableExpression()
|
selectionMapping.getContainingTableExpression()
|
||||||
),
|
),
|
||||||
selectionMapping,
|
selectionMapping
|
||||||
creationContext.getSessionFactory()
|
|
||||||
);
|
);
|
||||||
final String columnName;
|
final String columnName;
|
||||||
if ( selectionMapping.isFormula() ) {
|
if ( selectionMapping.isFormula() ) {
|
||||||
|
@ -4528,8 +4517,7 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
|
||||||
false,
|
false,
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
subQueryColumns.get( i ).getJdbcMapping(),
|
subQueryColumns.get( i ).getJdbcMapping()
|
||||||
creationContext.getSessionFactory()
|
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -4572,8 +4560,7 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
|
||||||
false,
|
false,
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
expression.getExpressionType().getJdbcMappings().get( 0 ),
|
expression.getExpressionType().getJdbcMappings().get( 0 )
|
||||||
creationContext.getSessionFactory()
|
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -4676,8 +4663,7 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
|
||||||
false,
|
false,
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
sqlSelections.get( 0 ).getExpressionType().getJdbcMappings().get( 0 ),
|
sqlSelections.get( 0 ).getExpressionType().getJdbcMappings().get( 0 )
|
||||||
creationContext.getSessionFactory()
|
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
(ReturnableType<?>) 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,
|
false,
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
selectionMapping.getJdbcMapping(),
|
selectionMapping.getJdbcMapping()
|
||||||
creationContext.getSessionFactory()
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
@ -5865,38 +5850,9 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
final EmbeddableValuedModelPart valueMapping = (EmbeddableValuedModelPart) determineValueMapping( expression );
|
final EmbeddableValuedModelPart valueMapping = (EmbeddableValuedModelPart) determineValueMapping( expression );
|
||||||
final SqmPath<?> path = SqmExpressionHelper.findPath( expression, expression.getNodeType() );
|
return new EmbeddableValuedExpression<>(
|
||||||
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,
|
|
||||||
valueMapping,
|
valueMapping,
|
||||||
parentTableGroup
|
new SqlTuple( List.of( (Expression) result, (Expression) offset ), valueMapping )
|
||||||
);
|
|
||||||
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
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -94,15 +94,8 @@ public class BasicValuedPathInterpretation<T> extends AbstractSqmPathInterpretat
|
||||||
);
|
);
|
||||||
|
|
||||||
final Expression expression = sqlAstCreationState.getSqlExpressionResolver().resolveSqlExpression(
|
final Expression expression = sqlAstCreationState.getSqlExpressionResolver().resolveSqlExpression(
|
||||||
SqlExpressionResolver.createColumnReferenceKey(
|
|
||||||
tableReference,
|
tableReference,
|
||||||
mapping.getSelectionExpression()
|
mapping
|
||||||
),
|
|
||||||
sacs -> new ColumnReference(
|
|
||||||
tableReference.getIdentificationVariable(),
|
|
||||||
mapping,
|
|
||||||
sqlAstCreationState.getCreationContext().getSessionFactory()
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
|
|
||||||
final ColumnReference columnReference;
|
final ColumnReference columnReference;
|
||||||
|
|
|
@ -45,12 +45,8 @@ public class DiscriminatedAssociationPathInterpretation<T> extends AbstractSqmPa
|
||||||
(selectionIndex, selectableMapping) -> {
|
(selectionIndex, selectableMapping) -> {
|
||||||
final TableReference tableReference = tableGroup.resolveTableReference( sqmPath.getNavigablePath(), selectableMapping.getContainingTableExpression() );
|
final TableReference tableReference = tableGroup.resolveTableReference( sqmPath.getNavigablePath(), selectableMapping.getContainingTableExpression() );
|
||||||
final Expression expression = converter.getSqlExpressionResolver().resolveSqlExpression(
|
final Expression expression = converter.getSqlExpressionResolver().resolveSqlExpression(
|
||||||
SqlExpressionResolver.createColumnReferenceKey( tableReference, selectableMapping.getSelectionExpression() ),
|
|
||||||
processingState -> new ColumnReference(
|
|
||||||
tableReference,
|
tableReference,
|
||||||
selectableMapping,
|
selectableMapping
|
||||||
converter.getCreationContext().getSessionFactory()
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
tupleExpressions.add( expression );
|
tupleExpressions.add( expression );
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,15 +51,8 @@ public class DiscriminatedAssociationTypePathInterpretation<T> extends AbstractS
|
||||||
if ( selectableMapping instanceof AnyDiscriminatorPart ) {
|
if ( selectableMapping instanceof AnyDiscriminatorPart ) {
|
||||||
final TableReference tableReference = tableGroup.getPrimaryTableReference();
|
final TableReference tableReference = tableGroup.getPrimaryTableReference();
|
||||||
final Expression expression = converter.getSqlExpressionResolver().resolveSqlExpression(
|
final Expression expression = converter.getSqlExpressionResolver().resolveSqlExpression(
|
||||||
SqlExpressionResolver.createColumnReferenceKey(
|
|
||||||
tableReference,
|
tableReference,
|
||||||
selectableMapping.getSelectionExpression()
|
selectableMapping
|
||||||
),
|
|
||||||
processingState -> new ColumnReference(
|
|
||||||
tableReference,
|
|
||||||
selectableMapping,
|
|
||||||
converter.getCreationContext().getSessionFactory()
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
tupleExpressions.add( expression );
|
tupleExpressions.add( expression );
|
||||||
}
|
}
|
||||||
|
|
|
@ -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 );
|
||||||
|
}
|
||||||
|
}
|
|
@ -242,6 +242,11 @@ public class EntityValuedPathInterpretation<T> extends AbstractSqmPathInterpreta
|
||||||
allowFkOptimization = false;
|
allowFkOptimization = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if ( mapping instanceof AnonymousTupleEntityValuedModelPart ) {
|
||||||
|
resultModelPart = ( (AnonymousTupleEntityValuedModelPart) mapping ).getForeignKeyPart();
|
||||||
|
resultTableGroup = tableGroup;
|
||||||
|
allowFkOptimization = true;
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
// If the mapping is not an association, use the PK and disallow FK optimizations
|
// If the mapping is not an association, use the PK and disallow FK optimizations
|
||||||
resultModelPart = mapping.getEntityMappingType().getIdentifierMapping();
|
resultModelPart = mapping.getEntityMappingType().getIdentifierMapping();
|
||||||
|
@ -311,17 +316,7 @@ public class EntityValuedPathInterpretation<T> extends AbstractSqmPathInterpreta
|
||||||
false
|
false
|
||||||
);
|
);
|
||||||
expressions.add(
|
expressions.add(
|
||||||
sqlExprResolver.resolveSqlExpression(
|
sqlExprResolver.resolveSqlExpression( tableReference, selectableMapping )
|
||||||
createColumnReferenceKey(
|
|
||||||
tableReference,
|
|
||||||
selectableMapping.getSelectionExpression()
|
|
||||||
),
|
|
||||||
processingState -> new ColumnReference(
|
|
||||||
tableReference,
|
|
||||||
selectableMapping,
|
|
||||||
sessionFactory
|
|
||||||
)
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
identifierMapping.forEachSelectable( selectableConsumer );
|
identifierMapping.forEachSelectable( selectableConsumer );
|
||||||
|
@ -339,14 +334,7 @@ public class EntityValuedPathInterpretation<T> extends AbstractSqmPathInterpreta
|
||||||
basicValuedModelPart.getContainingTableExpression(),
|
basicValuedModelPart.getContainingTableExpression(),
|
||||||
allowFkOptimization
|
allowFkOptimization
|
||||||
);
|
);
|
||||||
sqlExpression = sqlExprResolver.resolveSqlExpression(
|
sqlExpression = sqlExprResolver.resolveSqlExpression( tableReference, basicValuedModelPart );
|
||||||
createColumnReferenceKey( tableReference, basicValuedModelPart.getSelectionExpression() ),
|
|
||||||
processingState -> new ColumnReference(
|
|
||||||
tableReference,
|
|
||||||
basicValuedModelPart,
|
|
||||||
sessionFactory
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
final List<Expression> expressions = new ArrayList<>( resultModelPart.getJdbcTypeCount() );
|
final List<Expression> expressions = new ArrayList<>( resultModelPart.getJdbcTypeCount() );
|
||||||
|
@ -357,19 +345,7 @@ public class EntityValuedPathInterpretation<T> extends AbstractSqmPathInterpreta
|
||||||
selectableMapping.getContainingTableExpression(),
|
selectableMapping.getContainingTableExpression(),
|
||||||
allowFkOptimization
|
allowFkOptimization
|
||||||
);
|
);
|
||||||
expressions.add(
|
expressions.add( sqlExprResolver.resolveSqlExpression( tableReference, selectableMapping ) );
|
||||||
sqlExprResolver.resolveSqlExpression(
|
|
||||||
createColumnReferenceKey(
|
|
||||||
tableReference,
|
|
||||||
selectableMapping.getSelectionExpression()
|
|
||||||
),
|
|
||||||
processingState -> new ColumnReference(
|
|
||||||
tableReference,
|
|
||||||
selectableMapping,
|
|
||||||
sessionFactory
|
|
||||||
)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
sqlExpression = new SqlTuple( expressions, resultModelPart );
|
sqlExpression = new SqlTuple( expressions, resultModelPart );
|
||||||
|
|
|
@ -1006,6 +1006,12 @@ public abstract class AbstractSqlAstTranslator<T extends JdbcOperation> implemen
|
||||||
clauseStack.pop();
|
clauseStack.pop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
renderSetClause( statement, clauseStack );
|
||||||
|
visitWhereClause( statement.getRestriction() );
|
||||||
|
visitReturningColumns( statement );
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void renderSetClause(UpdateStatement statement, Stack<Clause> clauseStack) {
|
||||||
appendSql( " set " );
|
appendSql( " set " );
|
||||||
boolean firstPass = true;
|
boolean firstPass = true;
|
||||||
try {
|
try {
|
||||||
|
@ -1020,7 +1026,7 @@ public abstract class AbstractSqlAstTranslator<T extends JdbcOperation> implemen
|
||||||
|
|
||||||
final List<ColumnReference> columnReferences = assignment.getAssignable().getColumnReferences();
|
final List<ColumnReference> columnReferences = assignment.getAssignable().getColumnReferences();
|
||||||
if ( columnReferences.size() == 1 ) {
|
if ( columnReferences.size() == 1 ) {
|
||||||
columnReferences.get( 0 ).accept( this );
|
visitSetClauseTarget( columnReferences.get( 0 ) );
|
||||||
appendSql( '=' );
|
appendSql( '=' );
|
||||||
final Expression assignedValue = assignment.getAssignedValue();
|
final Expression assignedValue = assignment.getAssignedValue();
|
||||||
final SqlTuple sqlTuple = SqlTupleContainer.getSqlTuple( assignedValue );
|
final SqlTuple sqlTuple = SqlTupleContainer.getSqlTuple( assignedValue );
|
||||||
|
@ -1047,9 +1053,10 @@ public abstract class AbstractSqlAstTranslator<T extends JdbcOperation> implemen
|
||||||
finally {
|
finally {
|
||||||
clauseStack.pop();
|
clauseStack.pop();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
visitWhereClause( statement.getRestriction() );
|
protected void visitSetClauseTarget(ColumnReference columnReference) {
|
||||||
visitReturningColumns( statement );
|
appendSql( columnReference.getColumnExpression() );
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void visitInsertStatementOnly(InsertStatement statement) {
|
protected void visitInsertStatementOnly(InsertStatement statement) {
|
||||||
|
@ -1926,8 +1933,7 @@ public abstract class AbstractSqlAstTranslator<T extends JdbcOperation> implemen
|
||||||
false,
|
false,
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
currentCteStatement.getCycleMarkColumn().getJdbcMapping(),
|
currentCteStatement.getCycleMarkColumn().getJdbcMapping()
|
||||||
sessionFactory
|
|
||||||
);
|
);
|
||||||
if ( currentCteStatement.getCycleValue().getJdbcMapping() == getBooleanType()
|
if ( currentCteStatement.getCycleValue().getJdbcMapping() == getBooleanType()
|
||||||
&& currentCteStatement.getCycleValue().getLiteralValue() == Boolean.TRUE
|
&& currentCteStatement.getCycleValue().getLiteralValue() == Boolean.TRUE
|
||||||
|
@ -1970,8 +1976,7 @@ public abstract class AbstractSqlAstTranslator<T extends JdbcOperation> implemen
|
||||||
false,
|
false,
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
integerType,
|
integerType
|
||||||
sessionFactory
|
|
||||||
);
|
);
|
||||||
visitColumnReference( depthColumnReference );
|
visitColumnReference( depthColumnReference );
|
||||||
appendSql( "+1" );
|
appendSql( "+1" );
|
||||||
|
@ -2003,8 +2008,7 @@ public abstract class AbstractSqlAstTranslator<T extends JdbcOperation> implemen
|
||||||
false,
|
false,
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
currentCteStatement.getSearchColumn().getJdbcMapping(),
|
currentCteStatement.getSearchColumn().getJdbcMapping()
|
||||||
sessionFactory
|
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
appendSql( "||" );
|
appendSql( "||" );
|
||||||
|
@ -2116,8 +2120,7 @@ public abstract class AbstractSqlAstTranslator<T extends JdbcOperation> implemen
|
||||||
false,
|
false,
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
integerType,
|
integerType
|
||||||
sessionFactory
|
|
||||||
);
|
);
|
||||||
visitColumnReference( depthColumnReference );
|
visitColumnReference( depthColumnReference );
|
||||||
appendSql( "+1" );
|
appendSql( "+1" );
|
||||||
|
@ -2161,8 +2164,7 @@ public abstract class AbstractSqlAstTranslator<T extends JdbcOperation> implemen
|
||||||
false,
|
false,
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
currentCteStatement.getSearchColumn().getJdbcMapping(),
|
currentCteStatement.getSearchColumn().getJdbcMapping()
|
||||||
sessionFactory
|
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
for ( SearchClauseSpecification searchBySpecification : currentCteStatement.getSearchBySpecifications() ) {
|
for ( SearchClauseSpecification searchBySpecification : currentCteStatement.getSearchBySpecifications() ) {
|
||||||
|
@ -2307,8 +2309,7 @@ public abstract class AbstractSqlAstTranslator<T extends JdbcOperation> implemen
|
||||||
false,
|
false,
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
stringType,
|
stringType
|
||||||
sessionFactory
|
|
||||||
);
|
);
|
||||||
|
|
||||||
if ( !supportsRecursiveCycleClause() ) {
|
if ( !supportsRecursiveCycleClause() ) {
|
||||||
|
@ -2455,8 +2456,7 @@ public abstract class AbstractSqlAstTranslator<T extends JdbcOperation> implemen
|
||||||
false,
|
false,
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
stringType,
|
stringType
|
||||||
sessionFactory
|
|
||||||
);
|
);
|
||||||
arguments.add( new QueryLiteral<>( "%", stringType ) );
|
arguments.add( new QueryLiteral<>( "%", stringType ) );
|
||||||
for ( CteColumn cycleColumn : currentCteStatement.getCycleColumns() ) {
|
for ( CteColumn cycleColumn : currentCteStatement.getCycleColumns() ) {
|
||||||
|
@ -2875,8 +2875,7 @@ public abstract class AbstractSqlAstTranslator<T extends JdbcOperation> implemen
|
||||||
false,
|
false,
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
getIntegerType(),
|
getIntegerType()
|
||||||
null
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
@ -3101,8 +3100,7 @@ public abstract class AbstractSqlAstTranslator<T extends JdbcOperation> implemen
|
||||||
false,
|
false,
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
expression.getExpressionType().getJdbcMappings().get( 0 ),
|
expression.getExpressionType().getJdbcMappings().get( 0 )
|
||||||
sessionFactory
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5565,8 +5563,7 @@ public abstract class AbstractSqlAstTranslator<T extends JdbcOperation> implemen
|
||||||
false,
|
false,
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
null,
|
null
|
||||||
sessionFactory
|
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -5636,8 +5633,7 @@ public abstract class AbstractSqlAstTranslator<T extends JdbcOperation> implemen
|
||||||
false,
|
false,
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
null,
|
null
|
||||||
sessionFactory
|
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -5762,8 +5758,7 @@ public abstract class AbstractSqlAstTranslator<T extends JdbcOperation> implemen
|
||||||
false,
|
false,
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
null,
|
null
|
||||||
sessionFactory
|
|
||||||
);
|
);
|
||||||
sortExpression = sortSpecification.getSortExpression();
|
sortExpression = sortSpecification.getSortExpression();
|
||||||
}
|
}
|
||||||
|
@ -6018,11 +6013,7 @@ public abstract class AbstractSqlAstTranslator<T extends JdbcOperation> implemen
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if ( qualifyColumn ) {
|
columnReference.appendReadExpression( this, qualifyColumn ? tableExpression : null );
|
||||||
appendSql( tableExpression );
|
|
||||||
appendSql( '.' );
|
|
||||||
}
|
|
||||||
appendSql( columnReference.getColumnExpression() );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
|
@ -10,6 +10,7 @@ import java.util.Objects;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
|
||||||
import org.hibernate.metamodel.mapping.SelectableMapping;
|
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.expression.Expression;
|
||||||
import org.hibernate.sql.ast.tree.from.TableReference;
|
import org.hibernate.sql.ast.tree.from.TableReference;
|
||||||
import org.hibernate.sql.results.graph.FetchParent;
|
import org.hibernate.sql.results.graph.FetchParent;
|
||||||
|
@ -57,15 +58,33 @@ public interface SqlExpressionResolver {
|
||||||
return qualifier + columnExpression;
|
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
|
* Convenience form for creating a key from TableReference and SelectableMapping
|
||||||
*/
|
*/
|
||||||
static String createColumnReferenceKey(TableReference tableReference, SelectableMapping selectable) {
|
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() );
|
: String.format( ROOT, "Expecting tables to match between TableReference (%s) and SelectableMapping (%s)", tableReference.getTableId(), selectable.getContainingTableExpression() );
|
||||||
return createColumnReferenceKey( tableReference, selectable.getSelectionExpression() );
|
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},
|
* Given a qualifier + a qualifiable {@link org.hibernate.metamodel.mapping.SqlExpressible},
|
||||||
* resolve the (Sql)Expression reference.
|
* resolve the (Sql)Expression reference.
|
||||||
|
|
|
@ -12,7 +12,6 @@ import java.util.Locale;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
|
||||||
import org.hibernate.internal.util.StringHelper;
|
import org.hibernate.internal.util.StringHelper;
|
||||||
import org.hibernate.metamodel.mapping.SelectableMapping;
|
import org.hibernate.metamodel.mapping.SelectableMapping;
|
||||||
import org.hibernate.metamodel.mapping.JdbcMapping;
|
import org.hibernate.metamodel.mapping.JdbcMapping;
|
||||||
|
@ -42,32 +41,28 @@ public class ColumnReference implements Expression, Assignable {
|
||||||
|
|
||||||
public ColumnReference(
|
public ColumnReference(
|
||||||
String qualifier,
|
String qualifier,
|
||||||
SelectableMapping selectableMapping,
|
SelectableMapping selectableMapping) {
|
||||||
SessionFactoryImplementor sessionFactory) {
|
|
||||||
this(
|
this(
|
||||||
qualifier,
|
qualifier,
|
||||||
selectableMapping.getSelectionExpression(),
|
selectableMapping.getSelectionExpression(),
|
||||||
selectableMapping.isFormula(),
|
selectableMapping.isFormula(),
|
||||||
selectableMapping.getCustomReadExpression(),
|
selectableMapping.getCustomReadExpression(),
|
||||||
selectableMapping.getCustomWriteExpression(),
|
selectableMapping.getCustomWriteExpression(),
|
||||||
selectableMapping.getJdbcMapping(),
|
selectableMapping.getJdbcMapping()
|
||||||
sessionFactory
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ColumnReference(
|
public ColumnReference(
|
||||||
String qualifier,
|
String qualifier,
|
||||||
SelectableMapping selectableMapping,
|
SelectableMapping selectableMapping,
|
||||||
JdbcMapping jdbcMapping,
|
JdbcMapping jdbcMapping) {
|
||||||
SessionFactoryImplementor sessionFactory) {
|
|
||||||
this(
|
this(
|
||||||
qualifier,
|
qualifier,
|
||||||
selectableMapping.getSelectionExpression(),
|
selectableMapping.getSelectionExpression(),
|
||||||
selectableMapping.isFormula(),
|
selectableMapping.isFormula(),
|
||||||
selectableMapping.getCustomReadExpression(),
|
selectableMapping.getCustomReadExpression(),
|
||||||
selectableMapping.getCustomWriteExpression(),
|
selectableMapping.getCustomWriteExpression(),
|
||||||
jdbcMapping,
|
jdbcMapping
|
||||||
sessionFactory
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,8 +72,7 @@ public class ColumnReference implements Expression, Assignable {
|
||||||
boolean isFormula,
|
boolean isFormula,
|
||||||
String customReadExpression,
|
String customReadExpression,
|
||||||
String customWriteExpression,
|
String customWriteExpression,
|
||||||
JdbcMapping jdbcMapping,
|
JdbcMapping jdbcMapping) {
|
||||||
SessionFactoryImplementor sessionFactory) {
|
|
||||||
this.qualifier = StringHelper.nullIfEmpty( qualifier );
|
this.qualifier = StringHelper.nullIfEmpty( qualifier );
|
||||||
|
|
||||||
if ( isFormula ) {
|
if ( isFormula ) {
|
||||||
|
@ -112,28 +106,24 @@ public class ColumnReference implements Expression, Assignable {
|
||||||
|
|
||||||
public ColumnReference(
|
public ColumnReference(
|
||||||
TableReference tableReference,
|
TableReference tableReference,
|
||||||
SelectableMapping selectableMapping,
|
SelectableMapping selectableMapping) {
|
||||||
SessionFactoryImplementor sessionFactory) {
|
|
||||||
this(
|
this(
|
||||||
tableReference.getIdentificationVariable(),
|
tableReference.getIdentificationVariable(),
|
||||||
selectableMapping,
|
selectableMapping
|
||||||
sessionFactory
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ColumnReference(
|
public ColumnReference(
|
||||||
TableReference tableReference,
|
TableReference tableReference,
|
||||||
String mapping,
|
String mapping,
|
||||||
JdbcMapping jdbcMapping,
|
JdbcMapping jdbcMapping) {
|
||||||
SessionFactoryImplementor sessionFactory) {
|
|
||||||
this(
|
this(
|
||||||
tableReference.getIdentificationVariable(),
|
tableReference.getIdentificationVariable(),
|
||||||
mapping,
|
mapping,
|
||||||
false,
|
false,
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
jdbcMapping,
|
jdbcMapping
|
||||||
sessionFactory
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -143,16 +133,14 @@ public class ColumnReference implements Expression, Assignable {
|
||||||
boolean isFormula,
|
boolean isFormula,
|
||||||
String customReadExpression,
|
String customReadExpression,
|
||||||
String customWriteExpression,
|
String customWriteExpression,
|
||||||
JdbcMapping jdbcMapping,
|
JdbcMapping jdbcMapping) {
|
||||||
SessionFactoryImplementor sessionFactory) {
|
|
||||||
this(
|
this(
|
||||||
tableReference.getIdentificationVariable(),
|
tableReference.getIdentificationVariable(),
|
||||||
columnExpression,
|
columnExpression,
|
||||||
isFormula,
|
isFormula,
|
||||||
customReadExpression,
|
customReadExpression,
|
||||||
customWriteExpression,
|
customWriteExpression,
|
||||||
jdbcMapping,
|
jdbcMapping
|
||||||
sessionFactory
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -180,6 +168,10 @@ public class ColumnReference implements Expression, Assignable {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void appendReadExpression(SqlAppender appender) {
|
public void appendReadExpression(SqlAppender appender) {
|
||||||
|
appendReadExpression( appender, qualifier );
|
||||||
|
}
|
||||||
|
|
||||||
|
public void appendReadExpression(SqlAppender appender, String qualifier) {
|
||||||
if ( isFormula ) {
|
if ( isFormula ) {
|
||||||
appender.append( columnExpression );
|
appender.append( columnExpression );
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,8 @@ import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||||
import org.hibernate.spi.NavigablePath;
|
import org.hibernate.spi.NavigablePath;
|
||||||
import org.hibernate.sql.ast.SqlAstWalker;
|
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.
|
* Represents a reference to a "named" table in a query's from clause.
|
||||||
*
|
*
|
||||||
|
@ -66,7 +68,7 @@ public class NamedTableReference extends AbstractTableReference {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean containsAffectedTableName(String requestedName) {
|
public boolean containsAffectedTableName(String requestedName) {
|
||||||
return getTableExpression().equals( requestedName );
|
return isEmpty( requestedName ) || getTableExpression().equals( requestedName );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -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;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -15,6 +15,8 @@ import org.hibernate.spi.NavigablePath;
|
||||||
import org.hibernate.sql.ast.SqlAstWalker;
|
import org.hibernate.sql.ast.SqlAstWalker;
|
||||||
import org.hibernate.sql.ast.tree.SqlAstNode;
|
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.
|
* 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) {
|
default boolean containsAffectedTableName(String requestedName) {
|
||||||
return visitAffectedTableNames( requestedName::equals );
|
return isEmpty( requestedName ) || Boolean.TRUE.equals( visitAffectedTableNames( requestedName::equals ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
Boolean visitAffectedTableNames(Function<String, Boolean> nameCollector);
|
Boolean visitAffectedTableNames(Function<String, Boolean> nameCollector);
|
||||||
|
|
|
@ -7,10 +7,13 @@
|
||||||
package org.hibernate.sql.ast.tree.from;
|
package org.hibernate.sql.ast.tree.from;
|
||||||
|
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
import java.util.function.Function;
|
||||||
|
|
||||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||||
import org.hibernate.spi.NavigablePath;
|
import org.hibernate.spi.NavigablePath;
|
||||||
|
|
||||||
|
import static org.hibernate.internal.util.StringHelper.isEmpty;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Andrea Boriero
|
* @author Andrea Boriero
|
||||||
*/
|
*/
|
||||||
|
@ -71,4 +74,20 @@ public class UnionTableReference extends NamedTableReference {
|
||||||
}
|
}
|
||||||
return false;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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 );
|
||||||
|
}
|
||||||
|
}
|
|
@ -11,7 +11,6 @@ import java.sql.Types;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.hibernate.cfg.AvailableSettings;
|
import org.hibernate.cfg.AvailableSettings;
|
||||||
import org.hibernate.dialect.SybaseDialect;
|
|
||||||
import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider;
|
import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider;
|
||||||
import org.hibernate.query.NativeQuery;
|
import org.hibernate.query.NativeQuery;
|
||||||
import org.hibernate.query.Query;
|
import org.hibernate.query.Query;
|
||||||
|
@ -85,20 +84,11 @@ public class QueryTimeOutTest extends BaseNonConfigCoreFunctionalTestCase {
|
||||||
query.executeUpdate();
|
query.executeUpdate();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if ( getDialect() instanceof SybaseDialect ) {
|
|
||||||
verify(
|
|
||||||
CONNECTION_PROVIDER.getPreparedStatement(
|
|
||||||
"update AnEntity set AnEntity.name='abc'" ),
|
|
||||||
times( 1 )
|
|
||||||
).setQueryTimeout( 123 );
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
verify(
|
verify(
|
||||||
CONNECTION_PROVIDER.getPreparedStatement( expectedSqlQuery ),
|
CONNECTION_PROVIDER.getPreparedStatement( expectedSqlQuery ),
|
||||||
times( 1 )
|
times( 1 )
|
||||||
).setQueryTimeout( 123 );
|
).setQueryTimeout( 123 );
|
||||||
}
|
}
|
||||||
}
|
|
||||||
catch (SQLException ex) {
|
catch (SQLException ex) {
|
||||||
fail( "should not have thrown exception" );
|
fail( "should not have thrown exception" );
|
||||||
}
|
}
|
||||||
|
@ -116,20 +106,11 @@ public class QueryTimeOutTest extends BaseNonConfigCoreFunctionalTestCase {
|
||||||
query.executeUpdate();
|
query.executeUpdate();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if ( getDialect() instanceof SybaseDialect ) {
|
|
||||||
verify(
|
|
||||||
CONNECTION_PROVIDER.getPreparedStatement(
|
|
||||||
"update AnEntity set AnEntity.name='abc'" ),
|
|
||||||
times( 1 )
|
|
||||||
).setQueryTimeout( 123 );
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
verify(
|
verify(
|
||||||
CONNECTION_PROVIDER.getPreparedStatement( expectedSqlQuery ),
|
CONNECTION_PROVIDER.getPreparedStatement( expectedSqlQuery ),
|
||||||
times( 1 )
|
times( 1 )
|
||||||
).setQueryTimeout( 123 );
|
).setQueryTimeout( 123 );
|
||||||
}
|
}
|
||||||
}
|
|
||||||
catch (SQLException ex) {
|
catch (SQLException ex) {
|
||||||
fail( "should not have thrown exception" );
|
fail( "should not have thrown exception" );
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue