Package org.hibernate.sql.ast.tree.from
Class LazyTableGroup
- java.lang.Object
-
- org.hibernate.sql.ast.tree.from.DelegatingTableGroup
-
- org.hibernate.sql.ast.tree.from.LazyTableGroup
-
- All Implemented Interfaces:
DomainResultProducer
,SqmPathInterpretation
,SqlSelectionProducer
,Expression
,ColumnReferenceQualifier
,TableGroup
,SqlAstNode
public class LazyTableGroup extends DelegatingTableGroup
The purpose of this table group is to defer creating the actual table group until it is really needed. If it is not needed, we can safely skip rendering it. This is useful for ToOneAttributeMapping and EntityCollectionPart, where we need a table group for the association, but aren't sure which columns are needed yet. Deferring initialization enables getting away with fewer joins in case only foreign key columns are used.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
LazyTableGroup.ParentTableGroupUseChecker
-
Constructor Summary
Constructors Constructor Description LazyTableGroup(boolean canUseInnerJoins, NavigablePath navigablePath, boolean fetched, Supplier<TableGroup> tableGroupSupplier, LazyTableGroup.ParentTableGroupUseChecker parentTableGroupUseChecker, TableGroupProducer tableGroupProducer, String sourceAlias, SqlAliasBase sqlAliasBase, SessionFactoryImplementor sessionFactory, TableGroup parentTableGroup)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addNestedTableGroupJoin(TableGroupJoin join)
A nested table group join is a join against a table group, that is ensured to be joined against the primary table reference and table reference joins in isolation, prior to doing other table group joins e.g.void
addTableGroupJoin(TableGroupJoin join)
void
applyAffectedTableNames(Consumer<String> nameCollector)
boolean
canUseInnerJoins()
ModelPart
getExpressionType()
The type for this expressionString
getGroupAlias()
If we want to use CTE for TableGroup rendering we will need to know the alias we can use for the groupTableGroupProducer
getModelPart()
NavigablePath
getNavigablePath()
List<TableGroupJoin>
getNestedTableGroupJoins()
String
getSourceAlias()
TableGroup
getTableGroup()
List<TableGroupJoin>
getTableGroupJoins()
TableReference
getTableReference(NavigablePath navigablePath, String tableExpression, boolean resolve)
Returns the table reference for the table expression, or null if not found.TableReference
getTableReference(NavigablePath navigablePath, ValuedModelPart modelPart, String tableExpression, boolean resolve)
List<TableReferenceJoin>
getTableReferenceJoins()
TableGroup
getUnderlyingTableGroup()
boolean
isFetched()
boolean
isInitialized()
If this is a lazy table group, it may report that it is not initialized, which would also mean that a join referring to this table group should not be rendered.boolean
isLateral()
boolean
isRealTableGroup()
void
setTableGroupInitializerCallback(Consumer<TableGroup> tableGroupConsumer)
void
visitNestedTableGroupJoins(Consumer<TableGroupJoin> consumer)
void
visitTableGroupJoins(Consumer<TableGroupJoin> consumer)
-
Methods inherited from class org.hibernate.sql.ast.tree.from.DelegatingTableGroup
accept, applySqlSelections, createDomainResult, createSqlSelection, createSqlSelection, getColumnReference, getPrimaryTableReference, getSqlExpression, prependTableGroupJoin
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.hibernate.sql.ast.tree.from.ColumnReferenceQualifier
getTableReference, getTableReference, resolveTableReference, resolveTableReference, resolveTableReference
-
Methods inherited from interface org.hibernate.sql.ast.tree.expression.Expression
createDomainResultSqlSelection, createDomainResultSqlSelection
-
Methods inherited from interface org.hibernate.sql.ast.tree.from.TableGroup
findCompatibleJoin, findCompatibleJoinedGroup, findTableGroupJoin, hasRealJoins, isVirtual
-
-
-
-
Constructor Detail
-
LazyTableGroup
public LazyTableGroup(boolean canUseInnerJoins, NavigablePath navigablePath, boolean fetched, Supplier<TableGroup> tableGroupSupplier, LazyTableGroup.ParentTableGroupUseChecker parentTableGroupUseChecker, TableGroupProducer tableGroupProducer, String sourceAlias, SqlAliasBase sqlAliasBase, SessionFactoryImplementor sessionFactory, TableGroup parentTableGroup)
-
-
Method Detail
-
isInitialized
public boolean isInitialized()
Description copied from interface:TableGroup
If this is a lazy table group, it may report that it is not initialized, which would also mean that a join referring to this table group should not be rendered.- Specified by:
isInitialized
in interfaceTableGroup
- Overrides:
isInitialized
in classDelegatingTableGroup
-
getUnderlyingTableGroup
public TableGroup getUnderlyingTableGroup()
-
getTableGroup
public TableGroup getTableGroup()
- Specified by:
getTableGroup
in classDelegatingTableGroup
-
setTableGroupInitializerCallback
public void setTableGroupInitializerCallback(Consumer<TableGroup> tableGroupConsumer)
-
applyAffectedTableNames
public void applyAffectedTableNames(Consumer<String> nameCollector)
- Specified by:
applyAffectedTableNames
in interfaceTableGroup
- Overrides:
applyAffectedTableNames
in classDelegatingTableGroup
-
getTableReferenceJoins
public List<TableReferenceJoin> getTableReferenceJoins()
- Specified by:
getTableReferenceJoins
in interfaceTableGroup
- Overrides:
getTableReferenceJoins
in classDelegatingTableGroup
-
getTableGroupJoins
public List<TableGroupJoin> getTableGroupJoins()
- Specified by:
getTableGroupJoins
in interfaceTableGroup
- Overrides:
getTableGroupJoins
in classDelegatingTableGroup
-
getNestedTableGroupJoins
public List<TableGroupJoin> getNestedTableGroupJoins()
- Specified by:
getNestedTableGroupJoins
in interfaceTableGroup
- Overrides:
getNestedTableGroupJoins
in classDelegatingTableGroup
-
addTableGroupJoin
public void addTableGroupJoin(TableGroupJoin join)
- Specified by:
addTableGroupJoin
in interfaceTableGroup
- Overrides:
addTableGroupJoin
in classDelegatingTableGroup
-
addNestedTableGroupJoin
public void addNestedTableGroupJoin(TableGroupJoin join)
Description copied from interface:TableGroup
A nested table group join is a join against a table group, that is ensured to be joined against the primary table reference and table reference joins in isolation, prior to doing other table group joins e.g.select * from entity1 e left join ( collection_table c1 join association a on a.id = c1.target_id ) on c1.entity_id = e.id and c1.key = 1
is modeled asTableGroup( primaryTableReference = TableReference(entity1, e), tableGroupJoins = [ TableGroupJoin( TableGroup( primaryTableReference = TableReference(collection_table, c1), nestedTableGroupJoins = [ TableGroupJoin( TableGroup( primaryTableReference = TableReference(association, a) ) ) ] ) ) ] )
This is necessary to correctly retain the cardinality of an HQL join like e.g.from Entity1 e left join e.collectionAssociation c on key(c) = 1
- Specified by:
addNestedTableGroupJoin
in interfaceTableGroup
- Overrides:
addNestedTableGroupJoin
in classDelegatingTableGroup
-
visitTableGroupJoins
public void visitTableGroupJoins(Consumer<TableGroupJoin> consumer)
- Specified by:
visitTableGroupJoins
in interfaceTableGroup
- Overrides:
visitTableGroupJoins
in classDelegatingTableGroup
-
visitNestedTableGroupJoins
public void visitNestedTableGroupJoins(Consumer<TableGroupJoin> consumer)
- Specified by:
visitNestedTableGroupJoins
in interfaceTableGroup
- Overrides:
visitNestedTableGroupJoins
in classDelegatingTableGroup
-
canUseInnerJoins
public boolean canUseInnerJoins()
- Specified by:
canUseInnerJoins
in interfaceTableGroup
- Overrides:
canUseInnerJoins
in classDelegatingTableGroup
-
getNavigablePath
public NavigablePath getNavigablePath()
- Specified by:
getNavigablePath
in interfaceSqmPathInterpretation
- Specified by:
getNavigablePath
in interfaceTableGroup
- Overrides:
getNavigablePath
in classDelegatingTableGroup
-
getGroupAlias
public String getGroupAlias()
Description copied from interface:TableGroup
If we want to use CTE for TableGroup rendering we will need to know the alias we can use for the group- Specified by:
getGroupAlias
in interfaceTableGroup
- Overrides:
getGroupAlias
in classDelegatingTableGroup
-
getModelPart
public TableGroupProducer getModelPart()
- Specified by:
getModelPart
in interfaceTableGroup
- Overrides:
getModelPart
in classDelegatingTableGroup
-
getExpressionType
public ModelPart getExpressionType()
Description copied from interface:Expression
The type for this expression- Specified by:
getExpressionType
in interfaceExpression
- Specified by:
getExpressionType
in interfaceSqmPathInterpretation
- Overrides:
getExpressionType
in classDelegatingTableGroup
-
getSourceAlias
public String getSourceAlias()
- Specified by:
getSourceAlias
in interfaceTableGroup
- Overrides:
getSourceAlias
in classDelegatingTableGroup
-
isRealTableGroup
public boolean isRealTableGroup()
- Specified by:
isRealTableGroup
in interfaceTableGroup
- Overrides:
isRealTableGroup
in classDelegatingTableGroup
-
isFetched
public boolean isFetched()
- Specified by:
isFetched
in interfaceTableGroup
- Overrides:
isFetched
in classDelegatingTableGroup
-
isLateral
public boolean isLateral()
- Specified by:
isLateral
in interfaceTableGroup
- Overrides:
isLateral
in classDelegatingTableGroup
-
getTableReference
public TableReference getTableReference(NavigablePath navigablePath, String tableExpression, boolean resolve)
Description copied from interface:ColumnReferenceQualifier
Returns the table reference for the table expression, or null if not found.- Specified by:
getTableReference
in interfaceColumnReferenceQualifier
- Overrides:
getTableReference
in classDelegatingTableGroup
- Parameters:
navigablePath
- The path for which to look up the table reference, may be nulltableExpression
- The table expression for which to look up the table referenceresolve
- Whether to potentially create table reference joins for this table group
-
getTableReference
public TableReference getTableReference(NavigablePath navigablePath, ValuedModelPart modelPart, String tableExpression, boolean resolve)
- Specified by:
getTableReference
in interfaceColumnReferenceQualifier
- Overrides:
getTableReference
in classDelegatingTableGroup
-
-