站内搜索: 请输入搜索关键词
当前页面: 在线文档首页 > Hibernate 2.1.8 正式版 API 英文文档

Loader (Hibernate API Documentation) - Hibernate 2.1.8 正式版 API 英文文档


net.sf.hibernate.loader
Class Loader

java.lang.Object
  extended bynet.sf.hibernate.loader.Loader
Direct Known Subclasses:
OuterJoinLoader, QueryTranslator, SimpleEntityLoader

public abstract class Loader
extends Object

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 ClassPersisters 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:
Loadable

Field Summary
protected static String[] NO_SUFFIX
           
 
Constructor Summary
Loader()
           
 
Method Summary
protected  String applyLocks(String sql, Map lockModes, Dialect dialect)
          Append FOR UPDATE OF clause, if necessary.
protected  int bindNamedParameters(PreparedStatement st, Map namedParams, int start, SessionImplementor session)
          Bind named parameters to the PreparedStatement.
protected  int bindPositionalParameters(PreparedStatement st, QueryParameters queryParameters, int start, SessionImplementor session)
          Bind positional parameter values to the PreparedStatement (these are parameters specified by a JDBC-style ?).
protected  List doList(SessionImplementor session, QueryParameters queryParameters)
          Actually execute a query, ignoring the query cache
protected static String generateAlias(String description, int unique)
          Generate a nice alias for the given class name or collection role name and unique integer.
protected static String[] generateSuffixes(int length)
          Utility method that generate 0_, 1_ suffixes.
protected  int getCollectionOwner()
          Get the index of the entity that owns the collection, or -1 if there is no owner in the query results (ie.
protected abstract  CollectionPersister getCollectionPersister()
          An (optional) persister for a collection to be initialized; only collection loaders return a non-null value
protected abstract  LockMode[] getLockModes(Map lockModes)
          What lock mode does this load entities with?
protected abstract  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 abstract  Loadable[] getPersisters()
          An array of persisters of entity classes contained in each row of results; implemented by all subclasses
protected  Object getResultColumnOrRow(Object[] row, ResultSet rs, SessionImplementor session)
          Get the actual object that is returned in the user-visible result list.
protected  List getResultList(List results)
           
protected  ResultSet getResultSet(PreparedStatement st, RowSelection selection, SessionImplementor session)
          Fetch a PreparedStatement, call setMaxRows and then execute it, advance to the first result and return an SQL ResultSet
protected abstract  String getSQLString()
          The SQL query string to be called; implemented by all subclasses
protected abstract  String[] getSuffixes()
          The suffix identifies a particular column of results in the SQL ResultSet; implemented by all subclasses
protected  boolean isSingleRowLoader()
          Return false is this loader is a batch entity loader
protected  List list(SessionImplementor session, QueryParameters queryParameters, Set querySpaces, Type[] resultTypes)
          Return the query results, using the query cache, called by subclasses that implement cacheable queries
protected  void loadCollection(SessionImplementor session, Serializable id, Type type)
          Called by subclasses that load collections
protected  void loadCollectionBatch(SessionImplementor session, Serializable[] ids, Type type)
          Called by subclasses that batch initialize collections
protected  List loadEntity(SessionImplementor session, Serializable id, Type identifierType, Object optionalObject, Serializable optionalIdentifier)
          Called by subclasses that load entities
protected  List loadEntityBatch(SessionImplementor session, Serializable[] ids, Type idType, Object optionalObject, Serializable optionalID)
          Called by subclasses that batch load entities
protected  Object loadSingleRow(ResultSet resultSet, SessionImplementor session, QueryParameters queryParameters, boolean returnProxies)
           
protected  void postInstantiate()
          Calculate and cache select-clause suffixes.
protected  PreparedStatement prepareQueryStatement(String sql, QueryParameters queryParameters, boolean scroll, SessionImplementor session)
          Obtain a PreparedStatement with all parameters pre-bound.
protected  boolean upgradeLocks()
          Does this query return objects that might be already cached by the session, whose lock mode may need upgrading
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NO_SUFFIX

protected static final String[] NO_SUFFIX
Constructor Detail

Loader

public Loader()
Method Detail

getSQLString

protected abstract String getSQLString()
The SQL query string to be called; implemented by all subclasses


getPersisters

protected abstract Loadable[] getPersisters()
An array of persisters of entity classes contained in each row of results; implemented by all subclasses


getSuffixes

protected abstract String[] getSuffixes()
The suffix identifies a particular column of results in the SQL ResultSet; implemented by all subclasses


getOwners

protected abstract 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")


getCollectionPersister

protected abstract CollectionPersister getCollectionPersister()
An (optional) persister for a collection to be initialized; only collection loaders return a non-null value


getCollectionOwner

protected int getCollectionOwner()
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.


getLockModes

protected abstract LockMode[] getLockModes(Map lockModes)
What lock mode does this load entities with?

Parameters:
lockModes - a collection of lock modes specified dynamically via the Query interface

applyLocks

protected String applyLocks(String sql,
                            Map lockModes,
                            Dialect dialect)
                     throws HibernateException
Append FOR UPDATE OF clause, if necessary. This empty superclass implementation merely returns its first argument.

Throws:
HibernateException

upgradeLocks

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


isSingleRowLoader

protected boolean isSingleRowLoader()
Return false is this loader is a batch entity loader


loadSingleRow

protected Object loadSingleRow(ResultSet resultSet,
                               SessionImplementor session,
                               QueryParameters queryParameters,
                               boolean returnProxies)
                        throws SQLException,
                               HibernateException
Throws:
SQLException
HibernateException

getResultList

protected List getResultList(List results)
                      throws QueryException
Throws:
QueryException

getResultColumnOrRow

protected Object getResultColumnOrRow(Object[] row,
                                      ResultSet rs,
                                      SessionImplementor session)
                               throws SQLException,
                                      HibernateException
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.

Throws:
SQLException
HibernateException

bindPositionalParameters

protected int bindPositionalParameters(PreparedStatement st,
                                       QueryParameters queryParameters,
                                       int start,
                                       SessionImplementor session)
                                throws SQLException,
                                       HibernateException
Bind positional parameter values to the PreparedStatement (these are parameters specified by a JDBC-style ?).

Throws:
SQLException
HibernateException

prepareQueryStatement

protected final PreparedStatement prepareQueryStatement(String sql,
                                                        QueryParameters queryParameters,
                                                        boolean scroll,
                                                        SessionImplementor session)
                                                 throws SQLException,
                                                        HibernateException
Obtain a PreparedStatement with all parameters pre-bound. Bind JDBC-style ? parameters, named parameters, and limit parameters.

Throws:
SQLException
HibernateException

getResultSet

protected final ResultSet getResultSet(PreparedStatement st,
                                       RowSelection selection,
                                       SessionImplementor session)
                                throws SQLException,
                                       HibernateException
Fetch a PreparedStatement, call setMaxRows and then execute it, advance to the first result and return an SQL ResultSet

Throws:
SQLException
HibernateException

bindNamedParameters

protected int bindNamedParameters(PreparedStatement st,
                                  Map namedParams,
                                  int start,
                                  SessionImplementor session)
                           throws SQLException,
                                  HibernateException
Bind named parameters to the PreparedStatement. This has an empty implementation on this superclass and should be implemented by subclasses (queries) which allow named parameters.

Throws:
SQLException
HibernateException

loadEntity

protected final List loadEntity(SessionImplementor session,
                                Serializable id,
                                Type identifierType,
                                Object optionalObject,
                                Serializable optionalIdentifier)
                         throws SQLException,
                                HibernateException
Called by subclasses that load entities

Throws:
SQLException
HibernateException

loadEntityBatch

protected final List loadEntityBatch(SessionImplementor session,
                                     Serializable[] ids,
                                     Type idType,
                                     Object optionalObject,
                                     Serializable optionalID)
                              throws SQLException,
                                     HibernateException
Called by subclasses that batch load entities

Throws:
SQLException
HibernateException

loadCollection

protected final void loadCollection(SessionImplementor session,
                                    Serializable id,
                                    Type type)
                             throws SQLException,
                                    HibernateException
Called by subclasses that load collections

Throws:
SQLException
HibernateException

loadCollectionBatch

protected final void loadCollectionBatch(SessionImplementor session,
                                         Serializable[] ids,
                                         Type type)
                                  throws SQLException,
                                         HibernateException
Called by subclasses that batch initialize collections

Throws:
SQLException
HibernateException

list

protected List list(SessionImplementor session,
                    QueryParameters queryParameters,
                    Set querySpaces,
                    Type[] resultTypes)
             throws SQLException,
                    HibernateException
Return the query results, using the query cache, called by subclasses that implement cacheable queries

Throws:
SQLException
HibernateException

doList

protected final List doList(SessionImplementor session,
                            QueryParameters queryParameters)
                     throws SQLException,
                            HibernateException
Actually execute a query, ignoring the query cache

Throws:
SQLException
HibernateException

postInstantiate

protected void postInstantiate()
Calculate and cache select-clause suffixes. Must be called by subclasses after instantiation.


generateSuffixes

protected static String[] generateSuffixes(int length)
Utility method that generate 0_, 1_ suffixes. Subclasses don't necessarily need to use this algorithm, but it is intended that they will in most cases.


generateAlias

protected static String generateAlias(String description,
                                      int unique)
Generate a nice alias for the given class name or collection role name and unique integer. Subclasses do not have to use aliases of this form.

Returns:
an alias of the form foo1_