org.hibernate.hql.classic

Class QueryTranslatorImpl

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, Map lockModes, 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 defintion.
String
getAliasName(String alias)
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 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(Map lockModes)
What lock mode 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()
Retrieve the query identifier for this translator.
Set
getQuerySpaces()
Returns the set of query spaces (table names) that the query referrs 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()
Returns the SQL string generated by the translator.
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.
ScrollableResults
scroll(QueryParameters queryParameters, SessionImplementor session)
Perform a scroll operation given the underlying query defintion.
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, getCollectionSuffixes, getEntityAliases, getSuffixes, postInstantiate

Methods inherited from class org.hibernate.loader.Loader

applyLocks, autoDiscoverTypes, bindNamedParameters, bindParameterValues, bindPositionalParameters, checkScrollability, doList, getAliases, getCollectionAliases, getCollectionOwners, getCollectionPersisters, getEntityAliases, getEntityEagerPropertyFetches, getEntityPersisters, getFactory, getLockModes, getNamedParameterLocs, getOwnerAssociationTypes, getOwners, getQueryIdentifier, getResultColumnOrRow, getResultList, getResultSet, getSQLString, hasSubselectLoadableCollections, isSingleRowLoader, isSubselectLoadingEnabled, list, loadCollection, loadCollectionBatch, loadCollectionSubselect, loadEntity, loadEntity, loadEntityBatch, loadSequentialRowsForward, loadSequentialRowsReverse, loadSingleRow, needsFetchingScroll, postInstantiate, prepareQueryStatement, preprocessSQL, scroll, toString, upgradeLocks

Constructor Details

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.

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.

Method Details

applyLocks

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

collectSqlStrings

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

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

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

containsCollectionFetches

public boolean containsCollectionFetches()
Does the translated query contain collection fetches?
Specified by:
containsCollectionFetches in interface QueryTranslator
Returns:
tru if the query does contain collection fetched; false otherwise.

executeUpdate

public int executeUpdate(QueryParameters queryParameters,
                         SessionImplementor session)
            throws HibernateException
Perform a bulk update/delete operation given the underlying query defintion.
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.

getAliasName

public String getAliasName(String alias)

getAliases

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
Overrides:
getAliases in interface Loader

getCollectionOwners

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. in the case of a collection initializer) or no collection.
Overrides:
getCollectionOwners in interface Loader

getCollectionPersisters

public CollectionPersister[] getCollectionPersisters()
Overrides method from Loader
Overrides:
getCollectionPersisters in interface Loader

getCollectionSuffixes

protected String[] getCollectionSuffixes()
Overrides:
getCollectionSuffixes in interface BasicLoader

getColumnNames

public String[][] getColumnNames()
Returns the column names in the generated SQL.
Specified by:
getColumnNames in interface QueryTranslator
Returns:
the column names in the generated SQL.

getEnabledFilters

public Map getEnabledFilters()
Returns the filters enabled for this query translator.
Specified by:
getEnabledFilters in interface QueryTranslator
Returns:
Filters enabled for this query execution.

getEntityPersisters

protected Loadable[] getEntityPersisters()
Persisters for the return values of a find() style query.
Overrides:
getEntityPersisters in interface Loader
Returns:
an array of EntityPersisters.

getHolderClass

public Class getHolderClass()

getLockModes

protected LockMode[] getLockModes(Map lockModes)
What lock mode does this load entities with?
Overrides:
getLockModes in interface Loader
Parameters:
lockModes - a collection of lock modes specified dynamically via the Query interface

getNamedParameterLocs

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

getOwnerAssociationTypes

protected EntityType[] getOwnerAssociationTypes()
An array of the owner types corresponding to the Loader.getOwners() returns. Indices indicating no owner would be null here.
Overrides:
getOwnerAssociationTypes in interface Loader
Returns:
The types for the owners.

getOwners

protected int[] getOwners()
Overrides:
getOwners in interface Loader
Returns:
The owner indicators (see discussion above).

getParameterTranslations

public ParameterTranslations getParameterTranslations()
Return information about any parameters encountered during translation.
Specified by:
getParameterTranslations in interface QueryTranslator
Returns:
The parameter information.

getQueryIdentifier

public String getQueryIdentifier()
Retrieve the query identifier for this translator. The query identifier is used in stats collection.
Specified by:
getQueryIdentifier in interface QueryTranslator
Overrides:
getQueryIdentifier in interface Loader
Returns:
the identifier

getQuerySpaces

public final Set getQuerySpaces()
Returns the set of query spaces (table names) that the query referrs to.
Specified by:
getQuerySpaces in interface QueryTranslator
Returns:
A set of query spaces (table names).

getQueryString

public String getQueryString()
Returns the HQL string processed by the translator.
Specified by:
getQueryString in interface QueryTranslator
Returns:
the HQL string processed by the translator.

getResultColumnOrRow

protected Object getResultColumnOrRow(Object[] row,
                                      ResultTransformer transformer,
                                      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.
Overrides:
getResultColumnOrRow in interface Loader

getResultList

protected List getResultList(List results,
                             ResultTransformer resultTransformer)
            throws QueryException
Overrides:
getResultList in interface Loader

getReturnAliases

public String[] getReturnAliases()
Returns an array of HQL aliases
Specified by:
getReturnAliases in interface QueryTranslator

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.

getSQLString

public String getSQLString()
Returns the SQL string generated by the translator.
Specified by:
getSQLString in interface QueryTranslator
Overrides:
getSQLString in interface Loader
Returns:
the SQL string generated by the translator.

getSuffixes

protected String[] getSuffixes()
Overrides:
getSuffixes in interface BasicLoader

isCompiled

protected boolean isCompiled()

isManipulationStatement

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

isSubselectLoadingEnabled

protected boolean isSubselectLoadingEnabled()
Overrides:
isSubselectLoadingEnabled in interface Loader

iterate

public Iterator iterate(QueryParameters queryParameters,
                        EventSource session)
            throws HibernateException
Return the query results as an iterator
Specified by:
iterate in interface QueryTranslator

list

public List list(SessionImplementor session,
                 QueryParameters queryParameters)
            throws HibernateException
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.

scroll

public ScrollableResults scroll(QueryParameters queryParameters,
                                SessionImplementor session)
            throws HibernateException
Perform a scroll operation given the underlying query defintion.
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.

toString

public String toString()
Overrides:
toString in interface Loader

upgradeLocks

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

validateScrollability

public void validateScrollability()
            throws HibernateException
Validate the scrollability of the translated query.
Specified by:
validateScrollability in interface QueryTranslator