org.hibernate.hql.classic
Class QueryTranslatorImpl

java.lang.Object
  extended by org.hibernate.loader.Loader
      extended by org.hibernate.loader.BasicLoader
          extended by org.hibernate.hql.classic.QueryTranslatorImpl
All Implemented Interfaces:
FilterTranslator, QueryTranslator

public class QueryTranslatorImpl
extends BasicLoader
implements FilterTranslator

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


Field Summary
 
Fields inherited from class org.hibernate.loader.BasicLoader
NO_SUFFIX
 
Fields inherited from interface org.hibernate.hql.QueryTranslator
ERROR_CANNOT_DETERMINE_TYPE, ERROR_CANNOT_FETCH_WITH_ITERATE, ERROR_CANNOT_FORMAT_LITERAL, ERROR_NAMED_PARAMETER_DOES_NOT_APPEAR
 
Constructor Summary
QueryTranslatorImpl(String queryString, Map enabledFilters, SessionFactoryImplementor factory)
          Construct a query translator; this form used internally.
QueryTranslatorImpl(String queryIdentifier, String queryString, Map enabledFilters, SessionFactoryImplementor factory)
          Construct a query translator
 
Method Summary
protected  String applyLocks(String sql, LockOptions lockOptions, Dialect dialect)
          Append FOR UPDATE OF clause, if necessary.
 List collectSqlStrings()
           
 void compile(Map replacements, boolean scalar)
          Compile a "normal" query.
 void compile(String collectionRole, Map replacements, boolean scalar)
          Compile a filter.
 boolean containsCollectionFetches()
          Does the translated query contain collection fetches?
 int executeUpdate(QueryParameters queryParameters, SessionImplementor session)
          Perform a bulk update/delete operation given the underlying query definition.
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
 String getAliasName(String alias)
           
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.
 CollectionPersister[] getCollectionPersisters()
          Overrides method from Loader
protected  String[] getCollectionSuffixes()
           
 String[][] getColumnNames()
          Returns the column names in the generated SQL.
 Map getEnabledFilters()
          Returns the filters enabled for this query translator.
protected  Loadable[] getEntityPersisters()
          Persisters for the return values of a find() style query.
 Class getHolderClass()
           
protected  LockMode[] getLockModes(LockOptions lockOptions)
          What lock options does this load entities with?
 int[] getNamedParameterLocs(String name)
           
protected  EntityType[] getOwnerAssociationTypes()
          An array of the owner types corresponding to the Loader.getOwners() returns.
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").
 ParameterTranslations getParameterTranslations()
          Return information about any parameters encountered during translation.
 String getQueryIdentifier()
          Identifies the query for statistics reporting, if null, no statistics will be reported
 Set getQuerySpaces()
          Returns the set of query spaces (table names) that the query refers to.
 String getQueryString()
          Returns the HQL string processed by the translator.
protected  Object getResultColumnOrRow(Object[] row, ResultTransformer transformer, ResultSet rs, SessionImplementor session)
          Get the actual object that is returned in the user-visible result list.
protected  List getResultList(List results, ResultTransformer resultTransformer)
           
 String[] getReturnAliases()
          Returns an array of HQL aliases
 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()
           
protected  boolean isCompiled()
           
 boolean isManipulationStatement()
           
protected  boolean isSubselectLoadingEnabled()
           
 Iterator iterate(QueryParameters queryParameters, EventSource session)
          Return the query results as an iterator
 List list(SessionImplementor session, QueryParameters queryParameters)
          Perform a list operation given the underlying query definition.
protected  ResultTransformer resolveResultTransformer(ResultTransformer resultTransformer)
          Determine the actual ResultTransformer that will be used to transform query results.
 ScrollableResults scroll(QueryParameters queryParameters, SessionImplementor session)
          Perform a scroll operation given the underlying query definition.
 String toString()
           
protected  boolean upgradeLocks()
          Does this query return objects that might be already cached by the session, whose lock mode may need upgrading
 void validateScrollability()
          Validate the scrollability of the translated query.
 
Methods inherited from class org.hibernate.loader.BasicLoader
generateSuffixes, generateSuffixes, getCollectionAliases, getEntityAliases, postInstantiate
 
Methods inherited from class org.hibernate.loader.Loader
applyPostLoadLocks, areResultSetRowsTransformedImmediately, autoDiscoverTypes, bindNamedParameters, bindParameterValues, bindPositionalParameters, checkScrollability, doList, getEntityEagerPropertyFetches, getFactory, getResultSet, hasSubselectLoadableCollections, isSingleRowLoader, list, loadCollection, loadCollectionBatch, loadCollectionSubselect, loadEntity, loadEntity, loadEntityBatch, loadSequentialRowsForward, loadSequentialRowsReverse, loadSingleRow, needsFetchingScroll, prepareQueryStatement, preprocessSQL, scroll
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

QueryTranslatorImpl

public QueryTranslatorImpl(String queryIdentifier,
                           String queryString,
                           Map enabledFilters,
                           SessionFactoryImplementor factory)
Construct a query translator

Parameters:
queryIdentifier - A unique identifier for the query of which this translation is part; typically this is the original, user-supplied query string.
queryString - The "preprocessed" query string; at the very least already processed by QuerySplitter.
enabledFilters - Any enabled filters.
factory - The session factory.

QueryTranslatorImpl

public QueryTranslatorImpl(String queryString,
                           Map enabledFilters,
                           SessionFactoryImplementor factory)
Construct a query translator; this form used internally.

Parameters:
queryString - The query string to process.
enabledFilters - Any enabled filters.
factory - The session factory.
Method Detail

compile

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

Specified by:
compile in interface QueryTranslator
Parameters:
replacements - Defined query substitutions.
scalar - Does this represent a shallow (scalar or entity-id) select?
Throws:
QueryException - There was a problem parsing the query string.
MappingException - There was a problem querying defined mappings.

compile

public void compile(String collectionRole,
                    Map replacements,
                    boolean scalar)
             throws QueryException,
                    MappingException
Compile a filter. This method may be called multiple times. Subsequent invocations are no-ops.

Specified by:
compile in interface FilterTranslator
Parameters:
collectionRole - the role name of the collection used as the basis for the filter.
replacements - Defined query substitutions.
scalar - Does this represent a shallow (scalar or entity-id) select?
Throws:
QueryException - There was a problem parsing the query string.
MappingException - There was a problem querying defined mappings.

getSQLString

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

Specified by:
getSQLString in interface QueryTranslator
Specified by:
getSQLString in class Loader
Returns:
The sql command this loader should use to get its ResultSet.

collectSqlStrings

public List collectSqlStrings()
Specified by:
collectSqlStrings in interface QueryTranslator

getQueryString

public String getQueryString()
Description copied from interface: QueryTranslator
Returns the HQL string processed by the translator.

Specified by:
getQueryString in interface QueryTranslator
Returns:
the HQL string processed by the translator.

getEntityPersisters

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

Specified by:
getEntityPersisters in class Loader
Returns:
an array of EntityPersisters.

getReturnTypes

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

Specified by:
getReturnTypes in interface QueryTranslator
Returns:
an array of Types.

getReturnAliases

public String[] getReturnAliases()
Description copied from interface: QueryTranslator
Returns an array of HQL aliases

Specified by:
getReturnAliases in interface QueryTranslator

getColumnNames

public String[][] getColumnNames()
Description copied from interface: QueryTranslator
Returns the column names in the generated SQL.

Specified by:
getColumnNames in interface QueryTranslator
Returns:
the column names in the generated SQL.

getAliasName

public String getAliasName(String alias)

getNamedParameterLocs

public int[] getNamedParameterLocs(String name)
                            throws QueryException
Overrides:
getNamedParameterLocs in class Loader
Throws:
QueryException

getQuerySpaces

public final Set getQuerySpaces()
Description copied from interface: QueryTranslator
Returns the set of query spaces (table names) that the query refers to.

Specified by:
getQuerySpaces in interface QueryTranslator
Returns:
A set of query spaces (table names).

getCollectionPersisters

public CollectionPersister[] getCollectionPersisters()
Overrides method from Loader

Overrides:
getCollectionPersisters in class Loader

getCollectionSuffixes

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

getSuffixes

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

getAliases

protected 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

list

public List list(SessionImplementor session,
                 QueryParameters queryParameters)
          throws HibernateException
Description copied from interface: QueryTranslator
Perform a list operation given the underlying query definition.

Specified by:
list in interface QueryTranslator
Parameters:
session - The session owning this query.
queryParameters - The query bind parameters.
Returns:
The query list results.
Throws:
HibernateException

iterate

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

Specified by:
iterate in interface QueryTranslator
Parameters:
queryParameters - The query bind parameters.
session - The session owning this query.
Returns:
An iterator over the query results.
Throws:
HibernateException

executeUpdate

public int executeUpdate(QueryParameters queryParameters,
                         SessionImplementor session)
                  throws HibernateException
Description copied from interface: QueryTranslator
Perform a bulk update/delete operation given the underlying query definition.

Specified by:
executeUpdate in interface QueryTranslator
Parameters:
queryParameters - The query bind parameters.
session - The session owning this query.
Returns:
The number of entities updated or deleted.
Throws:
HibernateException

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 class Loader
Parameters:
resultTransformer - the specified result transformer
Returns:
the actual result transformer

getResultColumnOrRow

protected Object getResultColumnOrRow(Object[] row,
                                      ResultTransformer transformer,
                                      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,
                             ResultTransformer resultTransformer)
                      throws QueryException
Overrides:
getResultList in class Loader
Throws:
QueryException

getLockModes

protected LockMode[] getLockModes(LockOptions lockOptions)
Description copied from class: Loader
What lock options does this load entities with?

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

applyLocks

protected String applyLocks(String sql,
                            LockOptions lockOptions,
                            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

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 class Loader

isCompiled

protected boolean isCompiled()

toString

public String toString()
Overrides:
toString 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"). The indexes contained here are relative to the result of Loader.getEntityPersisters().

Overrides:
getOwners in class Loader
Returns:
The owner indicators (see discussion above).

getOwnerAssociationTypes

protected EntityType[] getOwnerAssociationTypes()
Description copied from class: Loader
An array of the owner types corresponding to the Loader.getOwners() returns. Indices indicating no owner would be null here.

Overrides:
getOwnerAssociationTypes in class Loader
Returns:
The types for the owners.

getHolderClass

public Class getHolderClass()

getEnabledFilters

public Map getEnabledFilters()
Description copied from interface: QueryTranslator
Returns the filters enabled for this query translator.

Specified by:
getEnabledFilters in interface QueryTranslator
Returns:
Filters enabled for this query execution.

scroll

public ScrollableResults scroll(QueryParameters queryParameters,
                                SessionImplementor session)
                         throws HibernateException
Description copied from interface: QueryTranslator
Perform a scroll operation given the underlying query definition.

Specified by:
scroll in interface QueryTranslator
Parameters:
queryParameters - The query bind parameters.
session - The session owning this query.
Returns:
The ScrollableResults wrapper around the query results.
Throws:
HibernateException

getQueryIdentifier

public String getQueryIdentifier()
Description copied from class: Loader
Identifies the query for statistics reporting, if null, no statistics will be reported

Specified by:
getQueryIdentifier in interface QueryTranslator
Overrides:
getQueryIdentifier in class Loader
Returns:
the identifier

isSubselectLoadingEnabled

protected boolean isSubselectLoadingEnabled()
Overrides:
isSubselectLoadingEnabled in class Loader

validateScrollability

public void validateScrollability()
                           throws HibernateException
Description copied from interface: QueryTranslator
Validate the scrollability of the translated query.

Specified by:
validateScrollability in interface QueryTranslator
Throws:
HibernateException

containsCollectionFetches

public boolean containsCollectionFetches()
Description copied from interface: QueryTranslator
Does the translated query contain collection fetches?

Specified by:
containsCollectionFetches in interface QueryTranslator
Returns:
true if the query does contain collection fetched; false otherwise.

isManipulationStatement

public boolean isManipulationStatement()
Specified by:
isManipulationStatement in interface QueryTranslator

getParameterTranslations

public ParameterTranslations getParameterTranslations()
Description copied from interface: QueryTranslator
Return information about any parameters encountered during translation.

Specified by:
getParameterTranslations in interface QueryTranslator
Returns:
The parameter information.


Copyright © 2001-2010 Red Hat, Inc. All Rights Reserved.