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

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


net.sf.hibernate.hql
Class QueryTranslator

java.lang.Object
  extended bynet.sf.hibernate.loader.Loader
      extended bynet.sf.hibernate.hql.QueryTranslator
Direct Known Subclasses:
FilterTranslator

public class QueryTranslator
extends Loader

An instance of QueryTranslator translates a Hibernate query string to SQL.


Field Summary
 
Fields inherited from class net.sf.hibernate.loader.Loader
NO_SUFFIX
 
Constructor Summary
QueryTranslator(String queryString)
          Construct a query translator
 
Method Summary
protected  void addFromAssociation(String elementName, String collectionRole)
          Used for collection filters
protected  String applyLocks(String sql, Map lockModes, Dialect dialect)
          Append FOR UPDATE OF clause, if necessary.
protected  int bindNamedParameters(PreparedStatement ps, Map namedParams, int start, SessionImplementor session)
          Bind named parameters to the PreparedStatement.
 void compile(SessionFactoryImplementor factory, Map replacements, boolean scalar)
          Compile a "normal" query.
static String[] concreteQueries(String query, SessionFactoryImplementor factory)
          Handle Hibernate "implicit" polymorphism, by translating the query string into several "concrete" queries against mapped classes.
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  CollectionPersister getCollectionPersister()
          Overrides method from Loader
protected  SessionFactoryImplementor getFactory()
           
protected  LockMode[] getLockModes(Map lockModes)
          What lock mode does this load entities with?
protected  int[] getNamedParameterLocs(String name)
           
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  Loadable[] getPersisters()
          Persisters for the return values of a find() style query.
 Set getQuerySpaces()
           
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)
           
 Type[] getReturnTypes()
          Types of the return values of an iterate() style query.
 String getSQLString()
          The SQL query string to be called; implemented by all subclasses
protected  String[] getSuffixes()
          The suffix identifies a particular column of results in the SQL ResultSet; implemented by all subclasses
protected  boolean isCompiled()
           
 Iterator iterate(QueryParameters queryParameters, SessionImplementor session)
          Return the query results as an iterator
 List list(SessionImplementor session, QueryParameters queryParameters)
           
 Object loadSingleRow(ResultSet resultSet, SessionImplementor session, QueryParameters queryParameters, boolean returnProxies)
           
 ScrollableResults scroll(QueryParameters queryParameters, SessionImplementor session)
          Return the query results, as an instance of ScrollableResults
protected  void setFactory(SessionFactoryImplementor factory)
           
 String toString()
           
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 net.sf.hibernate.loader.Loader
bindPositionalParameters, doList, generateAlias, generateSuffixes, getResultSet, isSingleRowLoader, list, loadCollection, loadCollectionBatch, loadEntity, loadEntityBatch, postInstantiate, prepareQueryStatement
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

QueryTranslator

public QueryTranslator(String queryString)
Construct a query translator

Method Detail

compile

public void compile(SessionFactoryImplementor factory,
                    Map replacements,
                    boolean scalar)
             throws QueryException,
                    MappingException
Compile a "normal" query. This method may be called multiple times. Subsequent invocations are no-ops.

Throws:
QueryException
MappingException

loadSingleRow

public Object loadSingleRow(ResultSet resultSet,
                            SessionImplementor session,
                            QueryParameters queryParameters,
                            boolean returnProxies)
                     throws SQLException,
                            HibernateException
Overrides:
loadSingleRow in class Loader
Throws:
SQLException
HibernateException

getPersisters

protected Loadable[] getPersisters()
Persisters for the return values of a find() style query.

Specified by:
getPersisters in class Loader
Returns:
an array of ClassPersisters.

getReturnTypes

public Type[] getReturnTypes()
Types of the return values of an iterate() style query.

Returns:
an array of Types.

getSQLString

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

Specified by:
getSQLString in class Loader

getNamedParameterLocs

protected int[] getNamedParameterLocs(String name)
                               throws QueryException
Throws:
QueryException

getQuerySpaces

public final Set getQuerySpaces()

getCollectionPersister

protected CollectionPersister getCollectionPersister()
Overrides method from Loader

Specified by:
getCollectionPersister in class Loader

getSuffixes

protected String[] getSuffixes()
Description copied from class: Loader
The suffix identifies a particular column of results in the SQL ResultSet; implemented by all subclasses

Specified by:
getSuffixes in class Loader

addFromAssociation

protected void addFromAssociation(String elementName,
                                  String collectionRole)
                           throws QueryException
Used for collection filters

Throws:
QueryException

bindNamedParameters

protected int bindNamedParameters(PreparedStatement ps,
                                  Map namedParams,
                                  int start,
                                  SessionImplementor session)
                           throws SQLException,
                                  HibernateException
Description copied from class: Loader
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.

Overrides:
bindNamedParameters in class Loader
Throws:
SQLException
HibernateException

list

public List list(SessionImplementor session,
                 QueryParameters queryParameters)
          throws HibernateException,
                 SQLException
Throws:
HibernateException
SQLException

iterate

public Iterator iterate(QueryParameters queryParameters,
                        SessionImplementor session)
                 throws HibernateException,
                        SQLException
Return the query results as an iterator

Throws:
HibernateException
SQLException

scroll

public ScrollableResults scroll(QueryParameters queryParameters,
                                SessionImplementor session)
                         throws HibernateException,
                                SQLException
Return the query results, as an instance of ScrollableResults

Throws:
HibernateException
SQLException

concreteQueries

public static String[] concreteQueries(String query,
                                       SessionFactoryImplementor factory)
Handle Hibernate "implicit" polymorphism, by translating the query string into several "concrete" queries against mapped classes.


getResultColumnOrRow

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

getResultList

protected List getResultList(List results)
                      throws QueryException
Overrides:
getResultList in class Loader
Throws:
QueryException

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

applyLocks

protected String applyLocks(String sql,
                            Map lockModes,
                            Dialect dialect)
                     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 class Loader
Throws:
QueryException

upgradeLocks

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

Overrides:
upgradeLocks in class Loader

getCollectionOwner

protected int getCollectionOwner()
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:
getCollectionOwner in class Loader

setFactory

protected void setFactory(SessionFactoryImplementor factory)

getFactory

protected SessionFactoryImplementor getFactory()

isCompiled

protected boolean isCompiled()

toString

public String toString()

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

Specified by:
getOwners in class Loader