Package org.hibernate.hql.classic
Class QueryTranslatorImpl
java.lang.Object
org.hibernate.loader.Loader
org.hibernate.loader.BasicLoader
org.hibernate.hql.classic.QueryTranslatorImpl
- All Implemented Interfaces:
FilterTranslator,QueryTranslator
An instance of QueryTranslator translates a Hibernate
query string to SQL.
-
Field Summary
Fields inherited from class org.hibernate.loader.BasicLoader
NO_SUFFIXFields 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
ConstructorsConstructorDescriptionQueryTranslatorImpl(String queryIdentifier, String queryString, Map enabledFilters, SessionFactoryImplementor factory) Construct a query translatorQueryTranslatorImpl(String queryString, Map enabledFilters, SessionFactoryImplementor factory) Construct a query translator; this form used internally. -
Method Summary
Modifier and TypeMethodDescriptionprotected StringapplyLocks(String sql, LockOptions lockOptions, Dialect dialect) Append FOR UPDATE OF clause, if necessary.voidCompile a filter.voidCompile a "normal" query.booleanDoes the translated query contain collection fetches?intexecuteUpdate(QueryParameters queryParameters, SessionImplementor session) Perform a bulk update/delete operation given the underlying query definition.protected String[]Get the SQL table aliases of entities whose associations are subselect-loadable, returning null if this loader does not support subselect loadinggetAliasName(String alias) protected int[]Get the index of the entity that owns the collection, or -1 if there is no owner in the query results (ie.Overrides method from Loaderprotected String[]String[][]Returns the column names in the generated SQL.Returns the filters enabled for this query translator.protected Loadable[]Persisters for the return values of a find() style query.protected LockMode[]getLockModes(LockOptions lockOptions) What lock options does this load entities with?int[]getNamedParameterLocs(String name) protected EntityType[]An array of the owner types corresponding to theLoader.getOwners()returns.protected int[]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").Return information about any parameters encountered during translation.Identifies the query for statistics reporting, if null, no statistics will be reportedfinal SetReturns the set of query spaces (table names) that the query refers to.Returns the HQL string processed by the translator.protected ObjectgetResultColumnOrRow(Object[] row, ResultTransformer transformer, ResultSet rs, SessionImplementor session) Get the actual object that is returned in the user-visible result list.protected ListgetResultList(List results, ResultTransformer resultTransformer) String[]Returns an array of HQL aliasesType[]Types of the return values of an iterate() style query.The SQL query string to be called; implemented by all subclassesprotected String[]protected booleanbooleanprotected booleaniterate(QueryParameters queryParameters, EventSource session) Return the query results as an iteratorlist(SessionImplementor session, QueryParameters queryParameters) Perform a list operation given the underlying query definition.protected ResultTransformerresolveResultTransformer(ResultTransformer resultTransformer) Determine the actual ResultTransformer that will be used to transform query results.scroll(QueryParameters queryParameters, SessionImplementor session) Perform a scroll operation given the underlying query definition.toString()protected booleanDoes this query return objects that might be already cached by the session, whose lock mode may need upgradingvoidValidate the scrollability of the translated query.Methods inherited from class org.hibernate.loader.BasicLoader
generateSuffixes, generateSuffixes, getCollectionAliases, getEntityAliases, postInstantiateMethods inherited from class org.hibernate.loader.Loader
applyPostLoadLocks, areResultSetRowsTransformedImmediately, autoDiscoverTypes, bindNamedParameters, bindParameterValues, bindPositionalParameters, checkScrollability, doList, extractKeysFromResultSet, getCompositeKeyManyToOneTargetIndices, getEntityEagerPropertyFetches, getFactory, getResultSet, hasSubselectLoadableCollections, isSingleRowLoader, list, loadCollection, loadCollectionBatch, loadCollectionSubselect, loadEntity, loadEntity, loadEntityBatch, loadSequentialRowsForward, loadSequentialRowsReverse, loadSingleRow, needsFetchingScroll, prepareQueryStatement, preprocessSQL, scroll
-
Constructor Details
-
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 byQuerySplitter.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 Details
-
compile
Compile a "normal" query. This method may be called multiple times. Subsequent invocations are no-ops.- Specified by:
compilein interfaceQueryTranslator- 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:
compilein interfaceFilterTranslator- 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
Description copied from class:LoaderThe SQL query string to be called; implemented by all subclasses- Specified by:
getSQLStringin interfaceQueryTranslator- Specified by:
getSQLStringin classLoader- Returns:
- The sql command this loader should use to get its
ResultSet.
-
collectSqlStrings
- Specified by:
collectSqlStringsin interfaceQueryTranslator
-
getQueryString
Description copied from interface:QueryTranslatorReturns the HQL string processed by the translator.- Specified by:
getQueryStringin interfaceQueryTranslator- Returns:
- the HQL string processed by the translator.
-
getEntityPersisters
Persisters for the return values of a find() style query.- Specified by:
getEntityPersistersin classLoader- Returns:
- an array of EntityPersisters.
-
getReturnTypes
Types of the return values of an iterate() style query.- Specified by:
getReturnTypesin interfaceQueryTranslator- Returns:
- an array of Types.
-
getReturnAliases
Description copied from interface:QueryTranslatorReturns an array of HQL aliases- Specified by:
getReturnAliasesin interfaceQueryTranslator
-
getColumnNames
Description copied from interface:QueryTranslatorReturns the column names in the generated SQL.- Specified by:
getColumnNamesin interfaceQueryTranslator- Returns:
- the column names in the generated SQL.
-
getAliasName
-
getNamedParameterLocs
- Overrides:
getNamedParameterLocsin classLoader- Throws:
QueryException
-
getQuerySpaces
Description copied from interface:QueryTranslatorReturns the set of query spaces (table names) that the query refers to.- Specified by:
getQuerySpacesin interfaceQueryTranslator- Returns:
- A set of query spaces (table names).
-
getCollectionPersisters
Overrides method from Loader- Overrides:
getCollectionPersistersin classLoader
-
getCollectionSuffixes
- Specified by:
getCollectionSuffixesin classBasicLoader
-
getSuffixes
- Specified by:
getSuffixesin classBasicLoader
-
getAliases
Description copied from class:LoaderGet the SQL table aliases of entities whose associations are subselect-loadable, returning null if this loader does not support subselect loading- Overrides:
getAliasesin classLoader
-
list
public List list(SessionImplementor session, QueryParameters queryParameters) throws HibernateException Description copied from interface:QueryTranslatorPerform a list operation given the underlying query definition.- Specified by:
listin interfaceQueryTranslator- 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:
iteratein interfaceQueryTranslator- 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:QueryTranslatorPerform a bulk update/delete operation given the underlying query definition.- Specified by:
executeUpdatein interfaceQueryTranslator- Parameters:
queryParameters- The query bind parameters.session- The session owning this query.- Returns:
- The number of entities updated or deleted.
- Throws:
HibernateException
-
resolveResultTransformer
Description copied from class:LoaderDetermine the actual ResultTransformer that will be used to transform query results.- Overrides:
resolveResultTransformerin classLoader- 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:LoaderGet 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:
getResultColumnOrRowin classLoader- Throws:
SQLExceptionHibernateException
-
getResultList
protected List getResultList(List results, ResultTransformer resultTransformer) throws QueryException - Overrides:
getResultListin classLoader- Throws:
QueryException
-
getLockModes
Description copied from class:LoaderWhat lock options does this load entities with?- Specified by:
getLockModesin classLoader- 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:LoaderAppend FOR UPDATE OF clause, if necessary. This empty superclass implementation merely returns its first argument.- Overrides:
applyLocksin classLoader- Throws:
QueryException
-
upgradeLocks
protected boolean upgradeLocks()Description copied from class:LoaderDoes this query return objects that might be already cached by the session, whose lock mode may need upgrading- Overrides:
upgradeLocksin classLoader
-
getCollectionOwners
protected int[] getCollectionOwners()Description copied from class:LoaderGet 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:
getCollectionOwnersin classLoader
-
isCompiled
protected boolean isCompiled() -
toString
-
getOwners
protected int[] getOwners()Description copied from class:LoaderAn 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 ofLoader.getEntityPersisters(). -
getOwnerAssociationTypes
Description copied from class:LoaderAn array of the owner types corresponding to theLoader.getOwners()returns. Indices indicating no owner would be null here.- Overrides:
getOwnerAssociationTypesin classLoader- Returns:
- The types for the owners.
-
getHolderClass
-
getEnabledFilters
Description copied from interface:QueryTranslatorReturns the filters enabled for this query translator.- Specified by:
getEnabledFiltersin interfaceQueryTranslator- Returns:
- Filters enabled for this query execution.
-
scroll
public ScrollableResults scroll(QueryParameters queryParameters, SessionImplementor session) throws HibernateException Description copied from interface:QueryTranslatorPerform a scroll operation given the underlying query definition.- Specified by:
scrollin interfaceQueryTranslator- Parameters:
queryParameters- The query bind parameters.session- The session owning this query.- Returns:
- The ScrollableResults wrapper around the query results.
- Throws:
HibernateException
-
getQueryIdentifier
Description copied from class:LoaderIdentifies the query for statistics reporting, if null, no statistics will be reported- Specified by:
getQueryIdentifierin interfaceQueryTranslator- Overrides:
getQueryIdentifierin classLoader- Returns:
- the identifier
-
isSubselectLoadingEnabled
protected boolean isSubselectLoadingEnabled()- Overrides:
isSubselectLoadingEnabledin classLoader
-
validateScrollability
Description copied from interface:QueryTranslatorValidate the scrollability of the translated query.- Specified by:
validateScrollabilityin interfaceQueryTranslator- Throws:
HibernateException
-
containsCollectionFetches
public boolean containsCollectionFetches()Description copied from interface:QueryTranslatorDoes the translated query contain collection fetches?- Specified by:
containsCollectionFetchesin interfaceQueryTranslator- Returns:
- true if the query does contain collection fetched; false otherwise.
-
isManipulationStatement
public boolean isManipulationStatement()- Specified by:
isManipulationStatementin interfaceQueryTranslator
-
getDynamicInstantiationResultType
- Specified by:
getDynamicInstantiationResultTypein interfaceQueryTranslator
-
getParameterTranslations
Description copied from interface:QueryTranslatorReturn information about any parameters encountered during translation.- Specified by:
getParameterTranslationsin interfaceQueryTranslator- Returns:
- The parameter information.
-