Package org.hibernate.loader
Class JoinWalker
- java.lang.Object
-
- org.hibernate.loader.JoinWalker
-
- Direct Known Subclasses:
AbstractEntityJoinWalker
,CollectionJoinWalker
public class JoinWalker extends java.lang.Object
Walks the metamodel, searching for joins, and collecting together information needed by OuterJoinLoader.- See Also:
OuterJoinLoader
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static interface
JoinWalker.AssociationInitCallback
-
Field Summary
Fields Modifier and Type Field Description protected java.lang.String[]
aliases
protected java.util.List
associations
protected int[]
collectionOwners
protected CollectionPersister[]
collectionPersisters
protected java.lang.String[]
collectionSuffixes
protected LockMode[]
lockModeArray
protected LockOptions
lockOptions
protected EntityType[]
ownerAssociationTypes
protected int[]
owners
protected Loadable[]
persisters
protected java.lang.String
sql
protected java.lang.String[]
suffixes
-
Constructor Summary
Constructors Modifier Constructor Description protected
JoinWalker(SessionFactoryImplementor factory, LoadQueryInfluencers loadQueryInfluencers)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected static int
countCollectionPersisters(java.util.List associations)
Count the number of instances of Joinable which are actually also instances of PersistentCollection which are being fetched by outer joinprotected static int
countEntityPersisters(java.util.List associations)
Count the number of instances of Joinable which are actually also instances of Loadable, or are one-to-many associationsprotected java.lang.String
generateRootAlias(java.lang.String description)
protected java.lang.String
generateTableAlias(int n, PropertyPath path, Joinable joinable)
java.lang.String[]
getAliases()
java.util.List
getAssociations()
int[]
getCollectionOwners()
CollectionPersister[]
getCollectionPersisters()
java.lang.String[]
getCollectionSuffixes()
protected Dialect
getDialect()
protected SessionFactoryImplementor
getFactory()
protected JoinType
getJoinType(boolean nullable, int currentDepth)
Use an inner join if it is a non-null association and this is the "first" join in a seriesprotected JoinType
getJoinType(OuterJoinLoadable persister, PropertyPath path, int propertyNumber, AssociationType associationType, FetchMode metadataFetchMode, CascadeStyle metadataCascadeStyle, java.lang.String lhsTable, java.lang.String[] lhsColumns, boolean nullable, int currentDepth)
Determine the appropriate type of join (if any) to use to fetch the given association.protected JoinType
getJoinType(AssociationType associationType, FetchMode config, PropertyPath path, java.lang.String lhsTable, java.lang.String[] lhsColumns, boolean nullable, int currentDepth, CascadeStyle cascadeStyle)
Determine the appropriate associationType of join (if any) to use to fetch the given association.LoadQueryInfluencers
getLoadQueryInfluencers()
LockMode[]
getLockModeArray()
LockOptions
getLockModeOptions()
EntityType[]
getOwnerAssociationTypes()
int[]
getOwners()
Loadable[]
getPersisters()
java.lang.String
getSQLString()
java.lang.String[]
getSuffixes()
protected java.lang.String
getWithClause(PropertyPath path)
protected boolean
hasRestriction(PropertyPath path)
protected void
initPersisters(java.util.List associations, LockMode lockMode)
protected void
initPersisters(java.util.List associations, LockOptions lockOptions)
protected void
initPersisters(java.util.List associations, LockOptions lockOptions, JoinWalker.AssociationInitCallback callback)
protected boolean
isDuplicateAssociation(java.lang.String foreignKeyTable, java.lang.String[] foreignKeyColumns)
Used to detect circularities in the joined graph, note that this method is side-effectyprotected boolean
isDuplicateAssociation(java.lang.String lhsTable, java.lang.String[] lhsColumnNames, AssociationType type)
Used to detect circularities in the joined graph, note that this method is side-effectyprotected boolean
isJoinable(JoinType joinType, java.util.Set visitedAssociationKeys, java.lang.String lhsTable, java.lang.String[] lhsColumnNames, AssociationType type, int depth)
Should we join this association?protected boolean
isJoinedFetchEnabled(AssociationType type, FetchMode config, CascadeStyle cascadeStyle)
Override on subclasses to enable or suppress joining of certain association typesprotected boolean
isJoinedFetchEnabledInMapping(FetchMode config, AssociationType type)
Does the mapping, and Hibernate default semantics, specify that this association should be fetched by outer joiningprotected boolean
isTooDeep(int currentDepth)
protected boolean
isTooManyCollections()
protected static java.lang.String
mergeOrderings(java.lang.String ordering1, java.lang.String ordering2)
protected JoinFragment
mergeOuterJoins(java.util.List associations)
Generate a sequence of LEFT OUTER JOIN clauses for the given associations.protected static java.lang.String
orderBy(java.util.List associations)
Get the order by string required for collection fetchingprotected java.lang.String
orderBy(java.util.List associations, java.lang.String orderBy)
protected java.lang.String
selectString(java.util.List associations)
Generate a select list of columns containing all properties of the entity classesvoid
setAliases(java.lang.String[] aliases)
void
setCollectionOwners(int[] collectionOwners)
void
setCollectionPersisters(CollectionPersister[] collectionPersisters)
void
setCollectionSuffixes(java.lang.String[] collectionSuffixes)
void
setOwnerAssociationTypes(EntityType[] ownerAssociationType)
void
setOwners(int[] owners)
void
setPersisters(Loadable[] persisters)
void
setSql(java.lang.String sql)
void
setSuffixes(java.lang.String[] suffixes)
protected void
walkCollectionTree(QueryableCollection persister, java.lang.String alias)
For a collection role, return a list of associations to be fetched by outerjoinprotected void
walkEntityTree(OuterJoinLoadable persister, java.lang.String alias)
Walk the association tree for an entity, adding associations which should be join fetched to theassociations
inst var.protected java.lang.StringBuilder
whereString(java.lang.String alias, java.lang.String[] columnNames, int batchSize)
Render the where condition for a (batch) load by identifier / collection key
-
-
-
Field Detail
-
associations
protected final java.util.List associations
-
suffixes
protected java.lang.String[] suffixes
-
collectionSuffixes
protected java.lang.String[] collectionSuffixes
-
persisters
protected Loadable[] persisters
-
owners
protected int[] owners
-
ownerAssociationTypes
protected EntityType[] ownerAssociationTypes
-
collectionPersisters
protected CollectionPersister[] collectionPersisters
-
collectionOwners
protected int[] collectionOwners
-
aliases
protected java.lang.String[] aliases
-
lockOptions
protected LockOptions lockOptions
-
lockModeArray
protected LockMode[] lockModeArray
-
sql
protected java.lang.String sql
-
-
Constructor Detail
-
JoinWalker
protected JoinWalker(SessionFactoryImplementor factory, LoadQueryInfluencers loadQueryInfluencers)
-
-
Method Detail
-
getAssociations
public java.util.List getAssociations()
-
getCollectionSuffixes
public java.lang.String[] getCollectionSuffixes()
-
setCollectionSuffixes
public void setCollectionSuffixes(java.lang.String[] collectionSuffixes)
-
getLockModeOptions
public LockOptions getLockModeOptions()
-
getLockModeArray
public LockMode[] getLockModeArray()
-
getSuffixes
public java.lang.String[] getSuffixes()
-
setSuffixes
public void setSuffixes(java.lang.String[] suffixes)
-
getAliases
public java.lang.String[] getAliases()
-
setAliases
public void setAliases(java.lang.String[] aliases)
-
getCollectionOwners
public int[] getCollectionOwners()
-
setCollectionOwners
public void setCollectionOwners(int[] collectionOwners)
-
getCollectionPersisters
public CollectionPersister[] getCollectionPersisters()
-
setCollectionPersisters
public void setCollectionPersisters(CollectionPersister[] collectionPersisters)
-
getOwnerAssociationTypes
public EntityType[] getOwnerAssociationTypes()
-
setOwnerAssociationTypes
public void setOwnerAssociationTypes(EntityType[] ownerAssociationType)
-
getOwners
public int[] getOwners()
-
setOwners
public void setOwners(int[] owners)
-
getPersisters
public Loadable[] getPersisters()
-
setPersisters
public void setPersisters(Loadable[] persisters)
-
getSQLString
public java.lang.String getSQLString()
-
setSql
public void setSql(java.lang.String sql)
-
getFactory
protected SessionFactoryImplementor getFactory()
-
getDialect
protected Dialect getDialect()
-
getLoadQueryInfluencers
public LoadQueryInfluencers getLoadQueryInfluencers()
-
hasRestriction
protected boolean hasRestriction(PropertyPath path)
-
getWithClause
protected java.lang.String getWithClause(PropertyPath path)
-
walkEntityTree
protected final void walkEntityTree(OuterJoinLoadable persister, java.lang.String alias) throws MappingException
Walk the association tree for an entity, adding associations which should be join fetched to theassociations
inst var. This form is the entry point into the walking for a given entity, starting the recursive calls intowalkEntityTree(org.hibernate.persister.entity.OuterJoinLoadable, String, PropertyPath, int)
.- Parameters:
persister
- The persister representing the entity to be walked.alias
- The (root) alias to use for this entity/persister.- Throws:
MappingException
- ???
-
walkCollectionTree
protected final void walkCollectionTree(QueryableCollection persister, java.lang.String alias) throws MappingException
For a collection role, return a list of associations to be fetched by outerjoin- Throws:
MappingException
-
getJoinType
protected JoinType getJoinType(OuterJoinLoadable persister, PropertyPath path, int propertyNumber, AssociationType associationType, FetchMode metadataFetchMode, CascadeStyle metadataCascadeStyle, java.lang.String lhsTable, java.lang.String[] lhsColumns, boolean nullable, int currentDepth) throws MappingException
Determine the appropriate type of join (if any) to use to fetch the given association.- Parameters:
persister
- The owner of the association.path
- The path to the associationpropertyNumber
- The property number representing the association.associationType
- The association type.metadataFetchMode
- The metadata-defined fetch mode.metadataCascadeStyle
- The metadata-defined cascade style.lhsTable
- The owner tablelhsColumns
- The owner join columnsnullable
- Is the association nullable.currentDepth
- Current join depth- Returns:
- type of join to use (
JoinType.INNER_JOIN
,JoinType.LEFT_OUTER_JOIN
, or -1 to indicate no joining. - Throws:
MappingException
- ??
-
getJoinType
protected JoinType getJoinType(AssociationType associationType, FetchMode config, PropertyPath path, java.lang.String lhsTable, java.lang.String[] lhsColumns, boolean nullable, int currentDepth, CascadeStyle cascadeStyle) throws MappingException
Determine the appropriate associationType of join (if any) to use to fetch the given association.- Parameters:
associationType
- The association associationType.config
- The metadata-defined fetch mode.path
- The path to the associationlhsTable
- The owner tablelhsColumns
- The owner join columnsnullable
- Is the association nullable.currentDepth
- Current join depthcascadeStyle
- The metadata-defined cascade style.- Returns:
- type of join to use (
JoinType.INNER_JOIN
,JoinType.LEFT_OUTER_JOIN
, or -1 to indicate no joining. - Throws:
MappingException
- ??
-
getJoinType
protected JoinType getJoinType(boolean nullable, int currentDepth)
Use an inner join if it is a non-null association and this is the "first" join in a series
-
isTooDeep
protected boolean isTooDeep(int currentDepth)
-
isTooManyCollections
protected boolean isTooManyCollections()
-
isJoinedFetchEnabledInMapping
protected boolean isJoinedFetchEnabledInMapping(FetchMode config, AssociationType type) throws MappingException
Does the mapping, and Hibernate default semantics, specify that this association should be fetched by outer joining- Throws:
MappingException
-
isJoinedFetchEnabled
protected boolean isJoinedFetchEnabled(AssociationType type, FetchMode config, CascadeStyle cascadeStyle)
Override on subclasses to enable or suppress joining of certain association types
-
generateTableAlias
protected java.lang.String generateTableAlias(int n, PropertyPath path, Joinable joinable)
-
generateRootAlias
protected java.lang.String generateRootAlias(java.lang.String description)
-
isDuplicateAssociation
protected boolean isDuplicateAssociation(java.lang.String foreignKeyTable, java.lang.String[] foreignKeyColumns)
Used to detect circularities in the joined graph, note that this method is side-effecty
-
isDuplicateAssociation
protected boolean isDuplicateAssociation(java.lang.String lhsTable, java.lang.String[] lhsColumnNames, AssociationType type)
Used to detect circularities in the joined graph, note that this method is side-effecty
-
isJoinable
protected boolean isJoinable(JoinType joinType, java.util.Set visitedAssociationKeys, java.lang.String lhsTable, java.lang.String[] lhsColumnNames, AssociationType type, int depth)
Should we join this association?
-
orderBy
protected java.lang.String orderBy(java.util.List associations, java.lang.String orderBy)
-
mergeOrderings
protected static java.lang.String mergeOrderings(java.lang.String ordering1, java.lang.String ordering2)
-
mergeOuterJoins
protected final JoinFragment mergeOuterJoins(java.util.List associations) throws MappingException
Generate a sequence of LEFT OUTER JOIN clauses for the given associations.- Throws:
MappingException
-
countEntityPersisters
protected static int countEntityPersisters(java.util.List associations) throws MappingException
Count the number of instances of Joinable which are actually also instances of Loadable, or are one-to-many associations- Throws:
MappingException
-
countCollectionPersisters
protected static int countCollectionPersisters(java.util.List associations) throws MappingException
Count the number of instances of Joinable which are actually also instances of PersistentCollection which are being fetched by outer join- Throws:
MappingException
-
orderBy
protected static java.lang.String orderBy(java.util.List associations) throws MappingException
Get the order by string required for collection fetching- Throws:
MappingException
-
whereString
protected java.lang.StringBuilder whereString(java.lang.String alias, java.lang.String[] columnNames, int batchSize)
Render the where condition for a (batch) load by identifier / collection key
-
initPersisters
protected void initPersisters(java.util.List associations, LockMode lockMode) throws MappingException
- Throws:
MappingException
-
initPersisters
protected void initPersisters(java.util.List associations, LockOptions lockOptions) throws MappingException
- Throws:
MappingException
-
initPersisters
protected void initPersisters(java.util.List associations, LockOptions lockOptions, JoinWalker.AssociationInitCallback callback) throws MappingException
- Throws:
MappingException
-
selectString
protected final java.lang.String selectString(java.util.List associations) throws MappingException
Generate a select list of columns containing all properties of the entity classes- Throws:
MappingException
-
-