Top Description Inners Fields Constructors Methods
org.hibernate.hql.ast

public Class QueryTranslatorImpl

extends Object
implements FilterTranslator
Class Inheritance
All Implemented Interfaces
org.hibernate.hql.FilterTranslator, org.hibernate.hql.QueryTranslator
Imports
java.util.ArrayList, .HashMap, .Iterator, .List, .Map, .Set, antlr.ANTLRException, .RecognitionException, .TokenStreamException, antlr.collections.AST, org.slf4j.Logger, .LoggerFactory, org.hibernate.HibernateException, .MappingException, .QueryException, .ScrollableResults, org.hibernate.engine.QueryParameters, .RowSelection, .SessionFactoryImplementor, .SessionImplementor, org.hibernate.event.EventSource, org.hibernate.hql.FilterTranslator, .ParameterTranslations, .QueryExecutionRequestException, org.hibernate.hql.antlr.HqlSqlTokenTypes, .HqlTokenTypes, .SqlTokenTypes, org.hibernate.hql.ast.exec.BasicExecutor, .MultiTableDeleteExecutor, .MultiTableUpdateExecutor, .StatementExecutor, org.hibernate.hql.ast.tree.AggregatedSelectExpression, .FromElement, .InsertStatement, .QueryNode, .Statement, org.hibernate.hql.ast.util.ASTPrinter, .ASTUtil, .NodeTraverser, org.hibernate.loader.hql.QueryLoader, org.hibernate.persister.entity.Queryable, org.hibernate.type.Type, org.hibernate.util.IdentitySet, .ReflectHelper, .StringHelper

A QueryTranslator that uses an Antlr-based parser.
Author
Joshua Davis ([email protected])

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class

Field Summary

Modifier and TypeField and Description
private static final Logger
private List<E>
private boolean
private Map<K, V>
private SessionFactoryImplementor
private String
private static final Logger
private ParameterTranslations
private final String
private QueryLoader
private boolean
private String
private Statement
private StatementExecutor
private Map<K, V>

Constructor Summary

AccessConstructor and Description
public
QueryTranslatorImpl(String
The query-identifier (used in stats collection)
queryIdentifier
,
String
The hql query to translate
query
,
Map<K, V>
Currently enabled filters
enabledFilters
,
SessionFactoryImplementor
The session factory constructing this translator instance.
factory
)

Creates a new AST-based query translator.

Method Summary

Modifier and TypeMethod and Description
private HqlSqlWalker
analyze(HqlParser parser, String collectionRole)

private StatementExecutor
public List<E>
public void
compile(Map<K, V>
Defined query substitutions.
replacements
,
boolean
Does this represent a shallow (scalar or entity-id) select?
shallow
)

Implements org.hibernate.hql.QueryTranslator.compile.

Compile a "normal" query.
public void
compile(String
the role name of the collection used as the basis for the filter.
collectionRole
,
Map<K, V>
Defined query substitutions.
replacements
,
boolean
Does this represent a shallow (scalar or entity-id) select?
shallow
)

Implements org.hibernate.hql.FilterTranslator.compile.

Compile a filter.
public boolean
containsCollectionFetches()

Implements org.hibernate.hql.QueryTranslator.containsCollectionFetches.

Does the translated query contain collection fetches?
private synchronized void
doCompile(Map<K, V>
Defined query substitutions.
replacements
,
boolean
Does this represent a shallow (scalar or entity-id) select?
shallow
,
String
the role name of the collection used as the basis for the filter, NULL if this is not a filter.
collectionRole
)

Performs both filter and non-filter compiling.

private void
private void
public int
executeUpdate(QueryParameters
The query bind parameters.
queryParameters
,
SessionImplementor
The session owning this query.
session
)

Implements org.hibernate.hql.QueryTranslator.executeUpdate.

Perform a bulk update/delete operation given the underlying query definition.
private void
generate(AST sqlAst)

public List<E>
public String[][]
getColumnNames()

Implements org.hibernate.hql.QueryTranslator.getColumnNames.

Returns the column names in the generated SQL.
public Class<T>
public Map<K, V>
getEnabledFilters()

Implements org.hibernate.hql.QueryTranslator.getEnabledFilters.

Returns the filters enabled for this query translator.
public int[]
public ParameterTranslations
getParameterTranslations()

Implements org.hibernate.hql.QueryTranslator.getParameterTranslations.

Return information about any parameters encountered during translation.
public String
getQueryIdentifier()

Implements org.hibernate.hql.QueryTranslator.getQueryIdentifier.

Retrieve the query identifier for this translator.
public Set<E>
getQuerySpaces()

Implements org.hibernate.hql.QueryTranslator.getQuerySpaces.

Returns the set of query spaces (table names) that the query refers to.
public String
getQueryString()

Implements org.hibernate.hql.QueryTranslator.getQueryString.

Returns the HQL string processed by the translator.
public String[]
getReturnAliases()

Implements org.hibernate.hql.QueryTranslator.getReturnAliases.

Returns an array of HQL aliases
public Type[]

Returns:

an array of Types.
getReturnTypes
()

Implements org.hibernate.hql.QueryTranslator.getReturnTypes.

Types of the return values of an iterate() style query.
public Statement
public String
getSQLString()

Implements org.hibernate.hql.QueryTranslator.getSQLString.

The SQL query string to be called; implemented by all subclasses
private HqlSqlWalker
public boolean
public boolean
public Iterator<E>
iterate(QueryParameters
The query bind parameters.
queryParameters
,
EventSource
The session owning this query.
session
)

Implements org.hibernate.hql.QueryTranslator.iterate.

Return the query results as an iterator
public List<E>
list(SessionImplementor
The session owning this query.
session
,
QueryParameters
The query bind parameters.
queryParameters
)

Implements org.hibernate.hql.QueryTranslator.list.

Perform a list operation given the underlying query definition.
private HqlParser
parse(boolean filter)

public ScrollableResults
scroll(QueryParameters
The query bind parameters.
queryParameters
,
SessionImplementor
The session owning this query.
session
)

Implements org.hibernate.hql.QueryTranslator.scroll.

Return the query results, as an instance of ScrollableResults
pack-priv void
showHqlAst(AST hqlAst)

public void
validateScrollability()

Implements org.hibernate.hql.QueryTranslator.validateScrollability.

Validate the scrollability of the translated query.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

AST_LOGback to summary
private static final Logger AST_LOG
collectedParameterSpecificationsback to summary
private List<E> collectedParameterSpecifications
compiledback to summary
private boolean compiled
enabledFiltersback to summary
private Map<K, V> enabledFilters
factoryback to summary
private SessionFactoryImplementor factory
hqlback to summary
private String hql
logback to summary
private static final Logger log
paramTranslationsback to summary
private ParameterTranslations paramTranslations
queryIdentifierback to summary
private final String queryIdentifier
queryLoaderback to summary
private QueryLoader queryLoader
shallowQueryback to summary
private boolean shallowQuery
sqlback to summary
private String sql
sqlAstback to summary
private Statement sqlAst
statementExecutorback to summary
private StatementExecutor statementExecutor
tokenReplacementsback to summary
private Map<K, V> tokenReplacements

Constructor Detail

QueryTranslatorImplback to summary
public QueryTranslatorImpl(String queryIdentifier, String query, Map<K, V> enabledFilters, SessionFactoryImplementor factory)

Creates a new AST-based query translator.

Parameters
queryIdentifier:String

The query-identifier (used in stats collection)

query:String

The hql query to translate

enabledFilters:Map<K, V>

Currently enabled filters

factory:SessionFactoryImplementor

The session factory constructing this translator instance.

Method Detail

analyzeback to summary
private HqlSqlWalker analyze(HqlParser parser, String collectionRole) throws QueryException, RecognitionException
buildAppropriateStatementExecutorback to summary
private StatementExecutor buildAppropriateStatementExecutor(HqlSqlWalker walker)
collectSqlStringsback to summary
public List<E> collectSqlStrings()

Implements org.hibernate.hql.QueryTranslator.collectSqlStrings.

compileback to summary
public void compile(Map<K, V> replacements, boolean shallow) throws QueryException, MappingException

Implements org.hibernate.hql.QueryTranslator.compile.

Compile a "normal" query. This method may be called multiple times. Subsequent invocations are no-ops.

Parameters
replacements:Map<K, V>

Defined query substitutions.

shallow:boolean

Does this represent a shallow (scalar or entity-id) select?

Exceptions
QueryException:
There was a problem parsing the query string.
MappingException:
There was a problem querying defined mappings.
compileback to summary
public void compile(String collectionRole, Map<K, V> replacements, boolean shallow) throws QueryException, MappingException

Implements org.hibernate.hql.FilterTranslator.compile.

Compile a filter. This method may be called multiple times. Subsequent invocations are no-ops.

Parameters
collectionRole:String

the role name of the collection used as the basis for the filter.

replacements:Map<K, V>

Defined query substitutions.

shallow:boolean

Does this represent a shallow (scalar or entity-id) select?

Exceptions
QueryException:
There was a problem parsing the query string.
MappingException:
There was a problem querying defined mappings.
containsCollectionFetchesback to summary
public boolean containsCollectionFetches()

Implements org.hibernate.hql.QueryTranslator.containsCollectionFetches.

Doc from org.hibernate.hql.QueryTranslator.containsCollectionFetches.

Does the translated query contain collection fetches?

Returns:boolean

true if the query does contain collection fetched; false otherwise.

doCompileback to summary
private synchronized void doCompile(Map<K, V> replacements, boolean shallow, String collectionRole)

Performs both filter and non-filter compiling.

Parameters
replacements:Map<K, V>

Defined query substitutions.

shallow:boolean

Does this represent a shallow (scalar or entity-id) select?

collectionRole:String

the role name of the collection used as the basis for the filter, NULL if this is not a filter.

errorIfDMLback to summary
private void errorIfDML() throws HibernateException
errorIfSelectback to summary
private void errorIfSelect() throws HibernateException
executeUpdateback to summary
public int executeUpdate(QueryParameters queryParameters, SessionImplementor session) throws HibernateException

Implements org.hibernate.hql.QueryTranslator.executeUpdate.

Doc from org.hibernate.hql.QueryTranslator.executeUpdate.

Perform a bulk update/delete operation given the underlying query definition.

Parameters
queryParameters:QueryParameters

The query bind parameters.

session:SessionImplementor

The session owning this query.

Returns:int

The number of entities updated or deleted.

generateback to summary
private void generate(AST sqlAst) throws QueryException, RecognitionException
getCollectedParameterSpecificationsback to summary
public List<E> getCollectedParameterSpecifications()
getColumnNamesback to summary
public String[][] getColumnNames()

Implements org.hibernate.hql.QueryTranslator.getColumnNames.

Doc from org.hibernate.hql.QueryTranslator.getColumnNames.

Returns the column names in the generated SQL.

Returns:String[][]

the column names in the generated SQL.

getDynamicInstantiationResultTypeback to summary
public Class<T> getDynamicInstantiationResultType()

Implements org.hibernate.hql.QueryTranslator.getDynamicInstantiationResultType.

getEnabledFiltersback to summary
public Map<K, V> getEnabledFilters()

Implements org.hibernate.hql.QueryTranslator.getEnabledFilters.

Doc from org.hibernate.hql.QueryTranslator.getEnabledFilters.

Returns the filters enabled for this query translator.

Returns:Map<K, V>

Filters enabled for this query execution.

getNamedParameterLocsback to summary
public int[] getNamedParameterLocs(String name)
getParameterTranslationsback to summary
public ParameterTranslations getParameterTranslations()

Implements org.hibernate.hql.QueryTranslator.getParameterTranslations.

Doc from org.hibernate.hql.QueryTranslator.getParameterTranslations.

Return information about any parameters encountered during translation.

Returns:ParameterTranslations

The parameter information.

getQueryIdentifierback to summary
public String getQueryIdentifier()

Implements org.hibernate.hql.QueryTranslator.getQueryIdentifier.

Doc from org.hibernate.hql.QueryTranslator.getQueryIdentifier.

Retrieve the query identifier for this translator. The query identifier is used in states collection.

Returns:String

the identifier

getQuerySpacesback to summary
public Set<E> getQuerySpaces()

Implements org.hibernate.hql.QueryTranslator.getQuerySpaces.

Doc from org.hibernate.hql.QueryTranslator.getQuerySpaces.

Returns the set of query spaces (table names) that the query refers to.

Returns:Set<E>

A set of query spaces (table names).

getQueryStringback to summary
public String getQueryString()

Implements org.hibernate.hql.QueryTranslator.getQueryString.

Doc from org.hibernate.hql.QueryTranslator.getQueryString.

Returns the HQL string processed by the translator.

Returns:String

the HQL string processed by the translator.

getReturnAliasesback to summary
public String[] getReturnAliases()

Implements org.hibernate.hql.QueryTranslator.getReturnAliases.

Doc from org.hibernate.hql.QueryTranslator.getReturnAliases.

Returns an array of HQL aliases

getReturnTypesback to summary
public Type[] getReturnTypes()

Implements org.hibernate.hql.QueryTranslator.getReturnTypes.

Types of the return values of an iterate() style query.

Returns:Type[]

an array of Types.

getSqlASTback to summary
public Statement getSqlAST()
getSQLStringback to summary
public String getSQLString()

Implements org.hibernate.hql.QueryTranslator.getSQLString.

The SQL query string to be called; implemented by all subclasses

Returns:String

Doc from org.hibernate.hql.QueryTranslator.getSQLString.

the SQL string generated by the translator.

getWalkerback to summary
private HqlSqlWalker getWalker()
isManipulationStatementback to summary
public boolean isManipulationStatement()

Implements org.hibernate.hql.QueryTranslator.isManipulationStatement.

isShallowQueryback to summary
public boolean isShallowQuery()
iterateback to summary
public Iterator<E> iterate(QueryParameters queryParameters, EventSource session) throws HibernateException

Implements org.hibernate.hql.QueryTranslator.iterate.

Return the query results as an iterator

Parameters
queryParameters:QueryParameters

Doc from org.hibernate.hql.QueryTranslator.iterate.

The query bind parameters.

session:EventSource

Doc from org.hibernate.hql.QueryTranslator.iterate.

The session owning this query.

Returns:Iterator<E>

Doc from org.hibernate.hql.QueryTranslator.iterate.

An iterator over the query results.

listback to summary
public List<E> list(SessionImplementor session, QueryParameters queryParameters) throws HibernateException

Implements org.hibernate.hql.QueryTranslator.list.

Doc from org.hibernate.hql.QueryTranslator.list.

Perform a list operation given the underlying query definition.

Parameters
session:SessionImplementor

The session owning this query.

queryParameters:QueryParameters

The query bind parameters.

Returns:List<E>

The query list results.

parseback to summary
private HqlParser parse(boolean filter) throws TokenStreamException, RecognitionException
scrollback to summary
public ScrollableResults scroll(QueryParameters queryParameters, SessionImplementor session) throws HibernateException

Implements org.hibernate.hql.QueryTranslator.scroll.

Return the query results, as an instance of ScrollableResults

Parameters
queryParameters:QueryParameters

Doc from org.hibernate.hql.QueryTranslator.scroll.

The query bind parameters.

session:SessionImplementor

Doc from org.hibernate.hql.QueryTranslator.scroll.

The session owning this query.

Returns:ScrollableResults

Doc from org.hibernate.hql.QueryTranslator.scroll.

The ScrollableResults wrapper around the query results.

showHqlAstback to summary
pack-priv void showHqlAst(AST hqlAst)
validateScrollabilityback to summary
public void validateScrollability() throws HibernateException

Implements org.hibernate.hql.QueryTranslator.validateScrollability.

Doc from org.hibernate.hql.QueryTranslator.validateScrollability.

Validate the scrollability of the translated query.

org.hibernate.hql.ast back to summary

public Class QueryTranslatorImpl.JavaConstantConverter

extends Object
implements VisitationStrategy
Class Inheritance
  • java.lang.Object
  • org.hibernate.hql.ast.QueryTranslatorImpl.JavaConstantConverter
All Implemented Interfaces
org.hibernate.hql.ast.util.NodeTraverser.VisitationStrategy

Field Summary

Modifier and TypeField and Description
private AST

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
private void
handleDotStructure(AST dotStructureRoot)

public void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

dotRootback to summary
private AST dotRoot

Constructor Detail

JavaConstantConverterback to summary
public JavaConstantConverter()

Method Detail

handleDotStructureback to summary
private void handleDotStructure(AST dotStructureRoot)
visitback to summary
public void visit(AST node)

Implements org.hibernate.hql.ast.util.NodeTraverser.VisitationStrategy.visit.