Top Description Inners Fields Constructors Methods
org.hibernate.loader

public abstract Class Loader

extends Object
Class Inheritance
Known Direct Subclasses
org.hibernate.loader.custom.CustomLoader, org.hibernate.loader.BasicLoader
Imports
java.io.Serializable, java.sql.CallableStatement, .PreparedStatement, .ResultSet, .SQLException, .Statement, java.util.ArrayList, .Arrays, .Collections, .HashMap, .HashSet, .List, .Map, .Set, java.util.concurrent.TimeUnit, org.hibernate.AssertionFailure, .HibernateException, .LockMode, .LockOptions, .QueryException, .ScrollMode, .Session, .StaleObjectStateException, .WrongClassException, org.hibernate.bytecode.enhance.spi.interceptor.EnhancementAsProxyLazinessInterceptor, org.hibernate.cache.spi.FilterKey, .QueryKey, .QueryResultsCache, org.hibernate.cache.spi.access.EntityDataAccess, org.hibernate.cache.spi.entry.CacheEntry, .ReferenceCacheEntryImpl, org.hibernate.collection.spi.PersistentCollection, org.hibernate.dialect.Dialect, org.hibernate.dialect.pagination.LimitHandler, .LimitHelper, .NoopLimitHandler, org.hibernate.engine.internal.CacheHelper, .TwoPhaseLoad, org.hibernate.engine.jdbc.ColumnNameCache, org.hibernate.engine.jdbc.spi.JdbcCoordinator, .JdbcServices, org.hibernate.engine.loading.internal.CollectionLoadContext, org.hibernate.engine.spi.BatchFetchQueue, .EntityEntry, .EntityKey, .EntityUniqueKey, .PersistenceContext, .PersistentAttributeInterceptable, .PersistentAttributeInterceptor, .QueryParameters, .RowSelection, .SessionFactoryImplementor, .SharedSessionContractImplementor, .Status, .SubselectFetch, .TypedValue, org.hibernate.event.spi.EventSource, .PostLoadEvent, .PreLoadEvent, org.hibernate.hql.internal.HolderInstantiator, org.hibernate.internal.CoreLogging, .CoreMessageLogger, .FetchingScrollableResultsImpl, .ScrollableResultsImpl, org.hibernate.internal.util.StringHelper, org.hibernate.internal.util.collections.CollectionHelper, org.hibernate.loader.spi.AfterLoadAction, org.hibernate.persister.collection.CollectionPersister, org.hibernate.persister.entity.EntityPersister, .Loadable, .UniqueKeyLoadable, org.hibernate.pretty.MessageHelper, org.hibernate.proxy.HibernateProxy, org.hibernate.query.spi.ScrollableResultsImplementor, org.hibernate.stat.spi.StatisticsImplementor, org.hibernate.transform.CacheableResultTransformer, .ResultTransformer, org.hibernate.type.AssociationType, .EntityType, .Type, .VersionType

Abstract superclass of object loading (and querying) strategies. This class implements useful common functionality that concrete loaders delegate to. It is not intended that this functionality would be directly accessed by client code. (Hence, all methods of this class are declared protected or private.) This class relies heavily upon the Loadable interface, which is the contract between this class and EntityPersisters that may be loaded by it.

The present implementation is able to load any number of columns of entities and at most one collection role per query.
Author
Gavin King
See Also
org.hibernate.persister.entity.Loadable

Nested and Inner Type Summary

Modifier and TypeClass and Description
protected static class
Loader.SqlStatementWrapper

Wrapper class for Statement and associated ResultSet.

Field Summary

Modifier and TypeField and Description
private volatile ColumnNameCache
columnNameCache

Deprecated as a consequence of ColumnNameCache being deprecated.
private final SessionFactoryImplementor
factory

Deprecated as a consequence of SessionFactoryImplementor being deprecated.
private boolean
protected static final CoreMessageLogger
public static final String
public static final String

Constructor Summary

AccessConstructor and Description
public
Loader(SessionFactoryImplementor factory)

Deprecated as a consequence of SessionFactoryImplementor being deprecated.

Method Summary

Modifier and TypeMethod and Description
private void
advance(final ResultSet rs, final RowSelection selection)

Advance the cursor to the first required row of the ResultSet

protected String
applyLocks(String sql, QueryParameters parameters, Dialect dialect, List<AfterLoadAction> afterLoadActions)

Append FOR UPDATE OF clause, if necessary.

protected void
protected boolean

Returns:

true, if getResultColumnOrRow() transforms the results; false, otherwise
areResultSetRowsTransformedImmediately
()

Are rows transformed immediately after being read from the ResultSet?

protected void
protected int

Returns:

The number of JDBC bind positions actually bound during this method execution.
bindNamedParameters
(final PreparedStatement
The JDBC prepared statement
statement
,
final Map<String, TypedValue>
A map of parameter names to values
namedParams
,
final int
The position from which to start binding parameter values.
startIndex
,
final SharedSessionContractImplementor
The originating session.
session
)

Bind named parameters to the JDBC prepared statement.

protected int

Returns:

The number of JDBC bind positions actually bound during this method execution.
bindParameterValues
(PreparedStatement
The JDBC prepared statement
statement
,
QueryParameters
The encapsulation of the parameter values to be bound.
queryParameters
,
int
The position from which to start binding parameter values.
startIndex
,
SharedSessionContractImplementor
The originating session.
session
)

Bind all parameter values into the prepared statement in preparation for execution.

protected int

Returns:

The number of JDBC bind positions actually bound during this method execution.
bindPositionalParameters
(final PreparedStatement
The JDBC prepared statement
statement
,
final QueryParameters
The encapsulation of the parameter values to be bound.
queryParameters
,
final int
The position from which to start binding parameter values.
startIndex
,
final SharedSessionContractImplementor
The originating session.
session
)

Bind positional parameter values to the JDBC prepared statement.

protected final PreparedStatement
bindPreparedStatement(final PreparedStatement st, final QueryParameters queryParameters, final LimitHandler limitHandler, final SharedSessionContractImplementor session)

private Map<K, V>
protected void
checkScrollability()

Check whether the current loader can support returning ScrollableResults.

private void
checkVersion(final int i, final Loadable persister, final Serializable id, final Object entity, final ResultSet rs, final SharedSessionContractImplementor session)

Check the version of the object in the ResultSet against the object version in the session cache, throwing an exception if the version numbers are different

protected CacheableResultTransformer
protected void
protected LockMode
protected List<E>
doList(final SharedSessionContractImplementor session, final QueryParameters queryParameters)

Actually execute a query, ignoring the query cache

private List<E>
doList(final SharedSessionContractImplementor session, final QueryParameters queryParameters, final ResultTransformer forcedResultTransformer)

private List<E>
doQuery(final SharedSessionContractImplementor session, final QueryParameters queryParameters, final boolean returnProxies, final ResultTransformer forcedResultTransformer)

public List<E>
doQueryAndInitializeNonLazyCollections(final SharedSessionContractImplementor session, final QueryParameters queryParameters, final boolean returnProxies)

Execute an SQL query and attempt to instantiate instances of the class mapped by the given persister from each row of the ResultSet.

public List<E>
doQueryAndInitializeNonLazyCollections(final SharedSessionContractImplementor session, final QueryParameters queryParameters, final boolean returnProxies, final ResultTransformer forcedResultTransformer)

protected void
endCollectionLoad(final Object resultSetId, final SharedSessionContractImplementor session, final CollectionPersister collectionPersister)

protected Loader.SqlStatementWrapper
executeQueryStatement(final QueryParameters queryParameters, final boolean scroll, List<AfterLoadAction> afterLoadActions, final SharedSessionContractImplementor session)

Process query string by applying filters, LIMIT clause, locks and comments if necessary.

protected Loader.SqlStatementWrapper
executeQueryStatement(String sqlStatement, QueryParameters queryParameters, boolean scroll, List<AfterLoadAction> afterLoadActions, SharedSessionContractImplementor session)

protected void
extractKeysFromResultSet(Loadable[] persisters, QueryParameters queryParameters, ResultSet resultSet, SharedSessionContractImplementor session, EntityKey[] keys, LockMode[] lockModes, List<E> hydratedObjects)

protected QueryKey
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 abstract CollectionAliases[]
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 int[][]
protected abstract EntityAliases[]
getEntityAliases()

Get the result set descriptor

protected boolean[][]

Returns:

Eager property fetching indicators.
getEntityEagerPerPropertyFetches
()

An array indicating for each entity which specific properties must have eager fetching enabled.

protected boolean[]

Returns:

Eager property fetching indicators.
getEntityEagerPropertyFetches
()

An array indicating whether the entities have eager property fetching enabled for all of their properties.

protected EntityPersister
protected abstract Loadable[]

Returns:

The entity persisters.
getEntityPersisters
()

An array of persisters of entity classes contained in each row of results; implemented by all subclasses

public final SessionFactoryImplementor
getFactory()

Deprecated as a consequence of SessionFactoryImplementor being deprecated.
private String
getInstanceClass(final ResultSet rs, final int i, final Loadable persister, final Serializable id, final SharedSessionContractImplementor session)

Determine the concrete class of an instance in the ResultSet

private EntityKey
getKeyFromResultSet(final int i, final Loadable persister, final Serializable id, final ResultSet rs, final SharedSessionContractImplementor session)

Read a row of Keys from the ResultSet into the given array.

protected LimitHandler

Returns:

LIMIT clause delegate.
getLimitHandler
(RowSelection
Selection criteria.
selection
)

Build LIMIT clause handler applicable for given selection criteria.

protected abstract LockMode[]
getLockModes(LockOptions
a collection of lock options specified dynamically via the Query interface
lockOptions
)

What lock options does this load entities with?

public int[]
protected static EntityKey
protected EntityType[]

Returns:

The types for the owners.
getOwnerAssociationTypes
()

An array of the owner types corresponding to the getOwners() returns.

protected int[]

Returns:

The owner indicators (see discussion above).
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").

private boolean[]
protected String
getQueryIdentifier()

Identifies the query for statistics reporting, if null, no statistics will be reported

protected Object
getResultColumnOrRow(Object[] row, ResultTransformer transformer, ResultSet rs, SharedSessionContractImplementor session)

Get the actual object that is returned in the user-visible result list.

protected List<E>
getResultFromQueryCache(final SharedSessionContractImplementor session, final QueryParameters queryParameters, final Set<Serializable> querySpaces, final Type[] resultTypes, final QueryResultsCache queryCache, final QueryKey key)

Deprecated as a consequence of QueryResultsCache being deprecated.
protected List<E>
getResultList(List<E> results, ResultTransformer resultTransformer)

protected Object[]
protected String[]

Returns:

Returns the aliases that corresponding to a result row.
getResultRowAliases
()

Returns the aliases that corresponding to a result row.

protected final ResultSet
getResultSet(final PreparedStatement st, final RowSelection selection, final LimitHandler limitHandler, final boolean autodiscovertypes, final SharedSessionContractImplementor session)

Execute given PreparedStatement, advance to the first result and return SQL ResultSet.

protected final ResultSet
getResultSet(final CallableStatement st, final RowSelection selection, final LimitHandler limitHandler, final boolean autodiscovertypes, final SharedSessionContractImplementor session)

Execute given CallableStatement, advance to the first result and return SQL ResultSet.

private Object[]
getRow(final ResultSet rs, final Loadable[] persisters, final EntityKey[] keys, final Object optionalObject, final EntityKey optionalObjectKey, final LockMode[] lockModes, final List<E> hydratedObjects, final SharedSessionContractImplementor session)

Resolve any IDs for currently loaded objects, duplications within the ResultSet, etc. Instantiate empty objects to be initialized from the ResultSet.

private Object
getRowFromResultSet(final ResultSet resultSet, final SharedSessionContractImplementor session, final QueryParameters queryParameters, final LockMode[] lockModesArray, final EntityKey optionalObjectKey, final List<E> hydratedObjects, final EntityKey[] keys, boolean returnProxies)

private Object
getRowFromResultSet(final ResultSet resultSet, final SharedSessionContractImplementor session, final QueryParameters queryParameters, final LockMode[] lockModesArray, final EntityKey optionalObjectKey, final List<E> hydratedObjects, final EntityKey[] keys, boolean returnProxies, ResultTransformer forcedResultTransformer)

protected List<Object>
getRowsFromResultSet(ResultSet rs, QueryParameters queryParameters, SharedSessionContractImplementor session, boolean returnProxies, ResultTransformer forcedResultTransformer, int maxRows, List<Object> hydratedObjects, List<EntityKey[]> subselectResultKeys)

private ScrollMode
getScrollMode(boolean scroll, LimitHandler limitHandler, QueryParameters queryParameters)

public abstract String

Returns:

The sql command this loader should use to get its ResultSet.
getSQLString
()

The SQL query string to be called; implemented by all subclasses

protected void
handleEmptyCollections(final Serializable[] keys, final Object resultSetId, final SharedSessionContractImplementor session)

If this is a collection initializer, we need to tell the session that a collection is being initialized, to account for the possibility of the collection having no elements (hence no rows in the result set).

protected boolean
private void
hydrateEntityState(ResultSet rs, int i, Loadable persister, String rowIdAlias, EntityKey key, List<E> hydratedObjects, SharedSessionContractImplementor session, String instanceClass, Object object, LockMode acquiredLockMode)

protected boolean[]
private void
initializeEntitiesAndCollections(final List<E> hydratedObjects, final Object resultSetId, final SharedSessionContractImplementor session, final boolean readOnly)

private void
initializeEntitiesAndCollections(final List<E> hydratedObjects, final Object resultSetId, final SharedSessionContractImplementor session, final boolean readOnly, List<AfterLoadAction> afterLoadActions)

protected void
instanceAlreadyLoaded(final ResultSet rs, final int i, final Loadable persister, final EntityKey key, final Object object, final LockMode requestedLockMode, List<E> hydratedObjects, final SharedSessionContractImplementor session)

The entity instance is already in the session cache

protected Object
instanceNotYetLoaded(final ResultSet rs, final int i, final Loadable persister, final String rowIdAlias, final EntityKey key, final LockMode lockMode, final EntityKey optionalObjectKey, final Object optionalObject, final List<E> hydratedObjects, final SharedSessionContractImplementor session)

The entity instance is not in the session cache

private boolean
private boolean
isCurrentRowForSameEntity(final EntityKey keyToRead, final int persisterIndex, final ResultSet resultSet, final SharedSessionContractImplementor session)

protected boolean
isSingleRowLoader()

Return false is this loader is a batch entity loader

protected boolean
private boolean
isTypeOf(final Statement statement, final Class<? extends Statement> type)

protected List<E>
list(final SharedSessionContractImplementor session, final QueryParameters queryParameters, final Set<Serializable> querySpaces, final Type[] resultTypes)

Return the query results, using the query cache, called by subclasses that implement cacheable queries

private List<E>
private List<E>
listUsingQueryCache(final SharedSessionContractImplementor session, final QueryParameters queryParameters, final Set<Serializable> querySpaces, final Type[] resultTypes)

public final void
loadCollection(final SharedSessionContractImplementor session, final Serializable id, final Type type)

Called by subclasses that initialize collections

public final void
loadCollectionBatch(final SharedSessionContractImplementor session, final Serializable[] ids, final Type type)

Called by wrappers that batch initialize collections

protected final void
loadCollectionSubselect(final SharedSessionContractImplementor session, final Serializable[] ids, final Object[] parameterValues, final Type[] parameterTypes, final Map<String, TypedValue> namedParameters, final Type type)

Called by subclasses that batch initialize collections

protected final List<E>
loadEntity(final SharedSessionContractImplementor session, final Object id, final Type identifierType, final Object optionalObject, final String optionalEntityName, final Serializable optionalIdentifier, final EntityPersister persister, final LockOptions lockOptions, final Boolean readOnly)

Called by subclasses that load entities

protected final List<E>
loadEntity(final SharedSessionContractImplementor session, final Object key, final Object index, final Type keyType, final Type indexType, final EntityPersister
only needed for logging
persister
)

Called by subclasses that load entities

public final List<E>
loadEntityBatch(final SharedSessionContractImplementor session, final Serializable[] ids, final Type idType, final Object optionalObject, final String optionalEntityName, final Serializable optionalId, final EntityPersister persister, LockOptions lockOptions)

Called by wrappers that batch load entities

public final List<E>
loadEntityBatch(final SharedSessionContractImplementor session, final Serializable[] ids, final Type idType, final Object optionalObject, final String optionalEntityName, final Serializable optionalId, final EntityPersister persister, final LockOptions lockOptions, final Boolean readOnly)

Called by wrappers that batch load entities

private void
loadFromResultSet(final ResultSet rs, final int i, final Object object, final String instanceEntityName, final EntityKey key, final String rowIdAlias, final LockMode lockMode, final Loadable rootPersister, final SharedSessionContractImplementor session)

Hydrate the state an object from the SQL ResultSet, into an array or "hydrated" values (do not resolve associations yet), and pass the hydrates state to the session.

public Object

Returns:

The loaded "row".
loadSequentialRowsForward
(final ResultSet
The result set from which to do the load.
resultSet
,
final SharedSessionContractImplementor
The session from which the request originated.
session
,
final QueryParameters
The query parameters specified by the user.
queryParameters
,
final boolean
Should proxies be generated
returnProxies
)

Loads a single logical row from the result set moving forward.

public Object

Returns:

The loaded "row".
loadSequentialRowsReverse
(final ResultSet
The result set from which to do the load.
resultSet
,
final SharedSessionContractImplementor
The session from which the request originated.
session
,
final QueryParameters
The query parameters specified by the user.
queryParameters
,
final boolean
Should proxies be generated
returnProxies
,
final boolean isLogicallyAfterLast)

Loads a single logical row from the result set moving forward.

public Object

Returns:

The loaded "row".
loadSingleRow
(final ResultSet
The result set from which to do the load.
resultSet
,
final SharedSessionContractImplementor
The session from which the request originated.
session
,
final QueryParameters
The query parameters specified by the user.
queryParameters
,
final boolean
Should proxies be generated
returnProxies
)

Loads a single row from the result set.

protected boolean

Returns:

True if it does, and thus needs the special fetching scroll functionality; false otherwise.
needsFetchingScroll
()

Does the result set to be scrolled contain collection fetches?

protected void
postInstantiate()

Calculate and cache select-clause suffixes.

protected final PreparedStatement
prepareQueryStatement(String sql, final QueryParameters queryParameters, final LimitHandler limitHandler, final boolean scroll, final SharedSessionContractImplementor session)

Obtain a PreparedStatement with all parameters pre-bound.

protected ResultSet
preprocessResultSet(ResultSet rs, final RowSelection selection, final LimitHandler limitHandler, final boolean autodiscovertypes, final SharedSessionContractImplementor session)

protected String
preprocessSQL(String sql, QueryParameters parameters, SessionFactoryImplementor sessionFactory, List<AfterLoadAction> afterLoadActions)

Deprecated as a consequence of SessionFactoryImplementor being deprecated.
Modify the SQL, adding lock hints and comments, if necessary
protected String

Returns:

SQL string
processDistinctKeyword
(String
SQL string
sql
,
QueryParameters
SQL parameters
parameters
)

Remove distinct keyword from SQL statement if the query should not pass it through.

protected List<E>
processResultSet(ResultSet rs, QueryParameters queryParameters, SharedSessionContractImplementor session, boolean returnProxies, ResultTransformer forcedResultTransformer, int maxRows, List<AfterLoadAction> afterLoadActions)

protected void
putResultInQueryCache(final SharedSessionContractImplementor session, final QueryParameters queryParameters, final Type[] resultTypes, final QueryResultsCache queryCache, final QueryKey key, final List<E> result)

Deprecated as a consequence of QueryResultsCache being deprecated.
private void
readCollectionElement(final Object optionalOwner, final Serializable optionalKey, final CollectionPersister persister, final CollectionAliases descriptor, final ResultSet rs, final SharedSessionContractImplementor session)

Read one collection element from the current row of the JDBC result set

private void
readCollectionElements(Object[] row, ResultSet resultSet, SharedSessionContractImplementor session)

Read any collection elements contained in a single row of the result set

protected void
registerNonExists(final EntityKey[] keys, final Loadable[] persisters, final SharedSessionContractImplementor session)

For missing objects associated by one-to-one with another object in the result set, register the fact that the the object is missing with the session.

protected ResultTransformer

Returns:

the actual result transformer
resolveResultTransformer
(ResultTransformer
the specified result transformer
resultTransformer
)

Determine the actual ResultTransformer that will be used to transform query results.

private ColumnNameCache
retrieveColumnNameToIndexCache(final ResultSet rs)

Deprecated as a consequence of ColumnNameCache being deprecated.
protected ScrollableResultsImplementor

Returns:

The ScrollableResults instance.
scroll
(final QueryParameters
The parameters with which the query should be executed.
queryParameters
,
final Type[]
The expected return types of the query
returnTypes
,
final HolderInstantiator
If the return values are expected to be wrapped in a holder, this is the thing that knows how to wrap them.
holderInstantiator
,
final SharedSessionContractImplementor
The session from which the scroll request originated.
session
)

Return the query results, as an instance of ScrollableResults

private Object
sequentialLoad(final ResultSet resultSet, final SharedSessionContractImplementor session, final QueryParameters queryParameters, final boolean returnProxies, final EntityKey keyToRead)

protected boolean
shouldUseFollowOnLocking(QueryParameters parameters, Dialect dialect, List<AfterLoadAction> afterLoadActions)

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
private static Set<E>[]
transpose(List<E> keys)

protected boolean
upgradeLocks()

Does this query return objects that might be already cached by the session, whose lock mode may need upgrading

private ResultSet
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait