org.hibernate.loader
Class OuterJoinLoader

java.lang.Object
  extended byorg.hibernate.loader.Loader
      extended byorg.hibernate.loader.BasicLoader
          extended byorg.hibernate.loader.OuterJoinLoader
Direct Known Subclasses:
AbstractEntityLoader, CollectionLoader, OneToManyLoader

public abstract class OuterJoinLoader
extends BasicLoader

Implements logic for walking a tree of associated classes. Generates an SQL select string containing all properties of those classes. Tables are joined using an ANSI-style left outer join.

Author:
Gavin King, Jon Lipsky

Field Summary
protected  String[] aliases
           
protected  int[] collectionOwners
           
protected  CollectionPersister[] collectionPersisters
           
protected  String[] collectionSuffixes
           
protected  LockMode[] lockModeArray
           
protected  EntityType[] ownerAssociationType
           
protected  int[] owners
           
protected  Loadable[] persisters
           
protected  String sql
           
protected  String[] suffixes
           
 
Fields inherited from class org.hibernate.loader.BasicLoader
NO_SUFFIX
 
Constructor Summary
OuterJoinLoader(SessionFactoryImplementor factory, Map enabledFilters)
           
 
Method Summary
protected static int countCollectionPersisters(List associations)
          Count the number of instances of Joinable which are actually also instances of PersistentCollection which are being fetched by outer join
protected static int countEntityPersisters(List associations)
          Count the number of instances of Joinable which are actually also instances of Loadable, or are one-to-many associations
protected  String generateRootAlias(String description)
           
protected  String generateTableAlias(int n, String path, Joinable joinable)
           
protected  String[] getAliases()
          Get the SQL table aliases of entities whose associations are subselect-loadable, returning null if this loader does not support subselect loading
protected  int[] getCollectionOwners()
          Get the index of the entity that owns the collection, or -1 if there is no owner in the query results (ie.
protected  CollectionPersister[] getCollectionPersisters()
          An (optional) persister for a collection to be initialized; only collection loaders return a non-null value
protected  String[] getCollectionSuffixes()
           
protected  Dialect getDialect()
           
 Map getEnabledFilters()
           
protected  Loadable[] getEntityPersisters()
          An array of persisters of entity classes contained in each row of results; implemented by all subclasses
protected  int getJoinType(AssociationType type, FetchMode config, String path, Set visitedAssociations, String lhsTable, String[] lhsColumns, boolean nullable, int currentDepth)
          Get the join type (inner, outer, etc) or -1 if the association should not be joined.
protected  int 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
protected  LockMode[] getLockModes(Map lockModes)
          What lock mode does this load entities with?
protected  EntityType[] getOwnerAssociationTypes()
          An array of unique key property names by which the corresponding entities are referenced by other entities in the result set
protected  int[] getOwners()
          An array of indexes of the entity that owns a one-to-one association to the entity at the given index (-1 if there is no "owner")
protected  String getSQLString()
          The SQL query string to be called; implemented by all subclasses
protected  String[] getSuffixes()
           
protected  void initPersisters(List associations, LockMode lockMode)
           
protected  boolean isDuplicateAssociation(Set visitedAssociationKeys, String foreignKeyTable, String[] foreignKeyColumns)
          Used to detect circularities in the joined graph
protected  boolean isDuplicateAssociation(Set visitedAssociationKeys, String lhsTable, String[] lhsColumnNames, AssociationType type)
          Used to detect circularities in the joined graph
protected  boolean isJoinable(int joinType, Set visitedAssociationKeys, String lhsTable, String[] lhsColumnNames, AssociationType type, int depth)
          Should we join this association?
protected  boolean isJoinedFetchEnabled(AssociationType type, FetchMode config)
          Override on subclasses to enable or suppress joining of certain association types
protected  boolean isJoinedFetchEnabledInMapping(FetchMode config, AssociationType type)
          Does the mapping, and Hibernate default semantics, specify that this association should be fetched by outer joining
protected  boolean isTooDeep(int currentDepth)
           
protected  JoinFragment mergeOuterJoins(List associations)
          Generate a sequence of LEFT OUTER JOIN clauses for the given associations.
protected static String orderBy(List associations)
          Get the order by string required for collection fetching
protected  String orderBy(List associations, String orderBy)
           
protected  String selectString(List associations)
          Generate a select list of columns containing all properties of the entity classes
protected  List walkCollectionTree(QueryableCollection persister, String alias)
          For a collection role, return a list of associations to be fetched by outerjoin
protected  List walkEntityTree(OuterJoinLoadable persister, String alias)
          For an entity class, return a list of associations to be fetched by outerjoin
protected  StringBuffer whereString(String alias, String[] columnNames, int batchSize, String subquery)
          Render the where condition for a (batch) load by identifier / collection key
 
Methods inherited from class org.hibernate.loader.BasicLoader
generateSuffixes, generateSuffixes, getCollectionAliases, getEntityAliases, postInstantiate
 
Methods inherited from class org.hibernate.loader.Loader
applyLocks, bindNamedParameters, bindPositionalParameters, doList, getEntityEagerPropertyFetches, getFactory, getQueryIdentifier, getResultColumnOrRow, getResultList, getResultSet, getResultSet, hasSubselectLoadableCollections, isSingleRowLoader, isSubselectLoadingEnabled, list, loadCollection, loadCollectionBatch, loadCollectionSubselect, loadEntity, loadEntityBatch, loadSingleRow, prepareQueryStatement, preprocessSQL, scroll, toString, upgradeLocks
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

persisters

protected Loadable[] persisters

collectionPersisters

protected CollectionPersister[] collectionPersisters

collectionOwners

protected int[] collectionOwners

aliases

protected String[] aliases

lockModeArray

protected LockMode[] lockModeArray

owners

protected int[] owners

ownerAssociationType

protected EntityType[] ownerAssociationType

sql

protected String sql

suffixes

protected String[] suffixes

collectionSuffixes

protected String[] collectionSuffixes
Constructor Detail

OuterJoinLoader

public OuterJoinLoader(SessionFactoryImplementor factory,
                       Map enabledFilters)
Method Detail

getDialect

protected final Dialect getDialect()

isJoinedFetchEnabled

protected boolean isJoinedFetchEnabled(AssociationType type,
                                       FetchMode config)
Override on subclasses to enable or suppress joining of certain association types


isDuplicateAssociation

protected boolean isDuplicateAssociation(Set visitedAssociationKeys,
                                         String lhsTable,
                                         String[] lhsColumnNames,
                                         AssociationType type)
Used to detect circularities in the joined graph


isJoinable

protected boolean isJoinable(int joinType,
                             Set visitedAssociationKeys,
                             String lhsTable,
                             String[] lhsColumnNames,
                             AssociationType type,
                             int depth)
Should we join this association?


isDuplicateAssociation

protected boolean isDuplicateAssociation(Set visitedAssociationKeys,
                                         String foreignKeyTable,
                                         String[] foreignKeyColumns)
Used to detect circularities in the joined graph


isTooDeep

protected boolean isTooDeep(int currentDepth)

getJoinType

protected int getJoinType(AssociationType type,
                          FetchMode config,
                          String path,
                          Set visitedAssociations,
                          String lhsTable,
                          String[] lhsColumns,
                          boolean nullable,
                          int currentDepth)
                   throws MappingException
Get the join type (inner, outer, etc) or -1 if the association should not be joined. Override on subclasses.

Throws:
MappingException

getJoinType

protected int 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


walkEntityTree

protected final List walkEntityTree(OuterJoinLoadable persister,
                                    String alias)
                             throws MappingException
For an entity class, return a list of associations to be fetched by outerjoin

Throws:
MappingException

walkCollectionTree

protected final List walkCollectionTree(QueryableCollection persister,
                                        String alias)
                                 throws MappingException
For a collection role, return a list of associations to be fetched by outerjoin

Throws:
MappingException

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

selectString

protected final String selectString(List associations)
                             throws MappingException
Generate a select list of columns containing all properties of the entity classes

Throws:
MappingException

getSuffixes

protected String[] getSuffixes()
Specified by:
getSuffixes in class BasicLoader

getCollectionSuffixes

protected String[] getCollectionSuffixes()
Specified by:
getCollectionSuffixes in class BasicLoader

generateTableAlias

protected String generateTableAlias(int n,
                                    String path,
                                    Joinable joinable)

generateRootAlias

protected String generateRootAlias(String description)

mergeOuterJoins

protected final JoinFragment mergeOuterJoins(List associations)
                                      throws MappingException
Generate a sequence of LEFT OUTER JOIN clauses for the given associations.

Throws:
MappingException

countEntityPersisters

protected static final int countEntityPersisters(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 final int countCollectionPersisters(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 final String orderBy(List associations)
                               throws MappingException
Get the order by string required for collection fetching

Throws:
MappingException

whereString

protected StringBuffer whereString(String alias,
                                   String[] columnNames,
                                   int batchSize,
                                   String subquery)
Render the where condition for a (batch) load by identifier / collection key


getSQLString

protected final String getSQLString()
Description copied from class: Loader
The SQL query string to be called; implemented by all subclasses

Specified by:
getSQLString in class Loader

getEntityPersisters

protected final Loadable[] getEntityPersisters()
Description copied from class: Loader
An array of persisters of entity classes contained in each row of results; implemented by all subclasses

Specified by:
getEntityPersisters in class Loader

getOwners

protected int[] getOwners()
Description copied from class: Loader
An array of indexes of the entity that owns a one-to-one association to the entity at the given index (-1 if there is no "owner")

Overrides:
getOwners in class Loader

getOwnerAssociationTypes

protected EntityType[] getOwnerAssociationTypes()
Description copied from class: Loader
An array of unique key property names by which the corresponding entities are referenced by other entities in the result set

Overrides:
getOwnerAssociationTypes in class Loader

getLockModes

protected LockMode[] getLockModes(Map lockModes)
Description copied from class: Loader
What lock mode does this load entities with?

Specified by:
getLockModes in class Loader
Parameters:
lockModes - a collection of lock modes specified dynamically via the Query interface

getEnabledFilters

public Map getEnabledFilters()

initPersisters

protected void initPersisters(List associations,
                              LockMode lockMode)
                       throws MappingException
Throws:
MappingException

getAliases

protected final String[] getAliases()
Description copied from class: Loader
Get the SQL table aliases of entities whose associations are subselect-loadable, returning null if this loader does not support subselect loading

Overrides:
getAliases in class Loader

getCollectionPersisters

protected final CollectionPersister[] getCollectionPersisters()
Description copied from class: Loader
An (optional) persister for a collection to be initialized; only collection loaders return a non-null value

Overrides:
getCollectionPersisters in class Loader

getCollectionOwners

protected final int[] getCollectionOwners()
Description copied from class: Loader
Get the index of the entity that owns the collection, or -1 if there is no owner in the query results (ie. in the case of a collection initializer) or no collection.

Overrides:
getCollectionOwners in class Loader

orderBy

protected String orderBy(List associations,
                         String orderBy)