Package org.hibernate.loader.custom
Class CustomLoader
- java.lang.Object
-
- org.hibernate.loader.Loader
-
- org.hibernate.loader.custom.CustomLoader
-
public class CustomLoader extends Loader
Extension point for loaders which use a SQL result set with "unexpected" column aliases.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.hibernate.loader.Loader
Loader.SqlStatementWrapper
-
-
Field Summary
-
Fields inherited from class org.hibernate.loader.Loader
DEBUG_ENABLED, LOG, SELECT, SELECT_DISTINCT
-
-
Constructor Summary
Constructors Constructor Description CustomLoader(CustomQuery customQuery, SessionFactoryImplementor factory)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected java.lang.String
applyLocks(java.lang.String sql, QueryParameters parameters, Dialect dialect, java.util.List<AfterLoadAction> afterLoadActions)
Append FOR UPDATE OF clause, if necessary.protected void
autoDiscoverTypes(java.sql.ResultSet rs)
protected int
bindParameterValues(java.sql.PreparedStatement statement, QueryParameters queryParameters, int startIndex, SharedSessionContractImplementor session)
Bind all parameter values into the prepared statement in preparation for execution.protected CollectionAliases[]
getCollectionAliases()
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 valueprotected EntityAliases[]
getEntityAliases()
Get the result set descriptorprotected Loadable[]
getEntityPersisters()
An array of persisters of entity classes contained in each row of results; implemented by all subclassesprotected LockMode[]
getLockModes(LockOptions lockOptions)
What lock options does this load entities with?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 java.lang.String
getQueryIdentifier()
Identifies the query for statistics reporting, if null, no statistics will be reportedjava.util.Set
getQuerySpaces()
protected java.lang.Object
getResultColumnOrRow(java.lang.Object[] row, ResultTransformer transformer, java.sql.ResultSet rs, SharedSessionContractImplementor session)
Get the actual object that is returned in the user-visible result list.protected java.util.List
getResultList(java.util.List results, ResultTransformer resultTransformer)
protected java.lang.Object[]
getResultRow(java.lang.Object[] row, java.sql.ResultSet rs, SharedSessionContractImplementor session)
protected java.lang.String[]
getResultRowAliases()
Returns the aliases that corresponding to a result row.java.lang.String
getSQLString()
The SQL query string to be called; implemented by all subclassesprotected boolean[]
includeInResultRow()
java.util.List
list(SharedSessionContractImplementor session, QueryParameters queryParameters)
protected void
putResultInQueryCache(SharedSessionContractImplementor session, QueryParameters queryParameters, Type[] resultTypes, QueryResultsCache queryCache, QueryKey key, java.util.List result)
resultTypes
can be overridden byautoDiscoverTypes(ResultSet)
, *after*list(SharedSessionContractImplementor, QueryParameters)
has already been called.protected ResultTransformer
resolveResultTransformer(ResultTransformer resultTransformer)
Determine the actual ResultTransformer that will be used to transform query results.ScrollableResultsImplementor
scroll(QueryParameters queryParameters, SharedSessionContractImplementor session)
protected void
validateAlias(java.lang.String alias)
-
Methods inherited from class org.hibernate.loader.Loader
applyPostLoadLocks, areResultSetRowsTransformedImmediately, bindNamedParameters, bindPositionalParameters, checkScrollability, determineFollowOnLockMode, doList, doQueryAndInitializeNonLazyCollections, doQueryAndInitializeNonLazyCollections, executeQueryStatement, executeQueryStatement, extractKeysFromResultSet, getAliases, getCompositeKeyManyToOneTargetIndices, getEntityEagerPropertyFetches, getFactory, getLimitHandler, getNamedParameterLocs, getOwnerAssociationTypes, getResultSet, getResultSet, hasSubselectLoadableCollections, isSingleRowLoader, isSubselectLoadingEnabled, list, loadCollection, loadCollectionBatch, loadCollectionSubselect, loadEntity, loadEntity, loadEntityBatch, loadSequentialRowsForward, loadSequentialRowsReverse, loadSingleRow, needsFetchingScroll, postInstantiate, prepareQueryStatement, preprocessSQL, processDistinctKeyword, processResultSet, scroll, shouldUseFollowOnLocking, toString, upgradeLocks
-
-
-
-
Constructor Detail
-
CustomLoader
public CustomLoader(CustomQuery customQuery, SessionFactoryImplementor factory)
-
-
Method Detail
-
getQueryIdentifier
protected java.lang.String getQueryIdentifier()
Description copied from class:Loader
Identifies the query for statistics reporting, if null, no statistics will be reported- Overrides:
getQueryIdentifier
in classLoader
-
getSQLString
public java.lang.String getSQLString()
Description copied from class:Loader
The SQL query string to be called; implemented by all subclasses- Specified by:
getSQLString
in classLoader
- Returns:
- The sql command this loader should use to get its
ResultSet
.
-
getQuerySpaces
public java.util.Set getQuerySpaces()
-
getLockModes
protected LockMode[] getLockModes(LockOptions lockOptions)
Description copied from class:Loader
What lock options does this load entities with?- Specified by:
getLockModes
in classLoader
- Parameters:
lockOptions
- a collection of lock options specified dynamically via the Query interface
-
getEntityPersisters
protected 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 classLoader
- Returns:
- The entity persisters.
-
getCollectionPersisters
protected 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 classLoader
-
getCollectionOwners
protected 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 classLoader
-
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"). The indexes contained here are relative to the result ofLoader.getEntityPersisters()
.
-
list
public java.util.List list(SharedSessionContractImplementor session, QueryParameters queryParameters) throws HibernateException
- Throws:
HibernateException
-
applyLocks
protected java.lang.String applyLocks(java.lang.String sql, QueryParameters parameters, Dialect dialect, java.util.List<AfterLoadAction> afterLoadActions) throws QueryException
Description copied from class:Loader
Append FOR UPDATE OF clause, if necessary. This empty superclass implementation merely returns its first argument.- Overrides:
applyLocks
in classLoader
- Throws:
QueryException
-
scroll
public ScrollableResultsImplementor scroll(QueryParameters queryParameters, SharedSessionContractImplementor session) throws HibernateException
- Throws:
HibernateException
-
getResultRowAliases
protected java.lang.String[] getResultRowAliases()
Description copied from class:Loader
Returns the aliases that corresponding to a result row.- Overrides:
getResultRowAliases
in classLoader
- Returns:
- Returns the aliases that corresponding to a result row.
-
resolveResultTransformer
protected ResultTransformer resolveResultTransformer(ResultTransformer resultTransformer)
Description copied from class:Loader
Determine the actual ResultTransformer that will be used to transform query results.- Overrides:
resolveResultTransformer
in classLoader
- Parameters:
resultTransformer
- the specified result transformer- Returns:
- the actual result transformer
-
includeInResultRow
protected boolean[] includeInResultRow()
- Overrides:
includeInResultRow
in classLoader
-
getResultColumnOrRow
protected java.lang.Object getResultColumnOrRow(java.lang.Object[] row, ResultTransformer transformer, java.sql.ResultSet rs, SharedSessionContractImplementor session) throws java.sql.SQLException, HibernateException
Description copied from class:Loader
Get the actual object that is returned in the user-visible result list. This empty implementation merely returns its first argument. This is overridden by some subclasses.- Overrides:
getResultColumnOrRow
in classLoader
- Throws:
java.sql.SQLException
HibernateException
-
getResultRow
protected java.lang.Object[] getResultRow(java.lang.Object[] row, java.sql.ResultSet rs, SharedSessionContractImplementor session) throws java.sql.SQLException, HibernateException
- Overrides:
getResultRow
in classLoader
- Throws:
java.sql.SQLException
HibernateException
-
getResultList
protected java.util.List getResultList(java.util.List results, ResultTransformer resultTransformer) throws QueryException
- Overrides:
getResultList
in classLoader
- Throws:
QueryException
-
getEntityAliases
protected EntityAliases[] getEntityAliases()
Description copied from class:Loader
Get the result set descriptor- Specified by:
getEntityAliases
in classLoader
-
getCollectionAliases
protected CollectionAliases[] getCollectionAliases()
- Specified by:
getCollectionAliases
in classLoader
-
bindParameterValues
protected int bindParameterValues(java.sql.PreparedStatement statement, QueryParameters queryParameters, int startIndex, SharedSessionContractImplementor session) throws java.sql.SQLException
Description copied from class:Loader
Bind all parameter values into the prepared statement in preparation for execution.- Overrides:
bindParameterValues
in classLoader
- Parameters:
statement
- The JDBC prepared statementqueryParameters
- The encapsulation of the parameter values to be bound.startIndex
- The position from which to start binding parameter values.session
- The originating session.- Returns:
- The number of JDBC bind positions actually bound during this method execution.
- Throws:
java.sql.SQLException
- Indicates problems performing the binding.
-
autoDiscoverTypes
protected void autoDiscoverTypes(java.sql.ResultSet rs)
- Overrides:
autoDiscoverTypes
in classLoader
-
validateAlias
protected void validateAlias(java.lang.String alias)
-
putResultInQueryCache
protected void putResultInQueryCache(SharedSessionContractImplementor session, QueryParameters queryParameters, Type[] resultTypes, QueryResultsCache queryCache, QueryKey key, java.util.List result)
resultTypes
can be overridden byautoDiscoverTypes(ResultSet)
, *after*list(SharedSessionContractImplementor, QueryParameters)
has already been called. It's a bit of a chicken-and-the-egg issue sinceautoDiscoverTypes(ResultSet)
needs theResultSet
. As a hacky workaround, overriden here to provide theresultTypes
. see HHH-3051- Overrides:
putResultInQueryCache
in classLoader
-
-