org.hibernate.hql.ast

Class QueryTranslatorImpl

Implemented Interfaces:
FilterTranslator, QueryTranslator

public class QueryTranslatorImpl
extends java.lang.Object
implements FilterTranslator

A QueryTranslator that uses an Antlr-based parser.
Author:
Joshua Davis (pgmjsd@sourceforge.net)

Nested Class Summary

static class
QueryTranslatorImpl.JavaConstantConverter

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 queryIdentifier, String query, Map enabledFilters, SessionFactoryImplementor factory)
Creates a new AST-based query translator.

Method Summary

List
collectSqlStrings()
void
compile(Map replacements, boolean shallow)
Compile a "normal" query.
void
compile(String collectionRole, Map replacements, boolean shallow)
Compile a filter.
boolean
containsCollectionFetches()
int
executeUpdate(QueryParameters queryParameters, SessionImplementor session)
String[][]
getColumnNames()
Map
getEnabledFilters()
int[]
getNamedParameterLocs(String name)
ParameterTranslations
getParameterTranslations()
String
getQueryIdentifier()
Set
getQuerySpaces()
String
getQueryString()
String[]
getReturnAliases()
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
Statement
getSqlAST()
boolean
isManipulationStatement()
boolean
isShallowQuery()
Iterator
iterate(QueryParameters queryParameters, EventSource session)
Return the query results as an iterator
List
list(SessionImplementor session, QueryParameters queryParameters)
ScrollableResults
scroll(QueryParameters queryParameters, SessionImplementor session)
Return the query results, as an instance of ScrollableResults
void
validateScrollability()

Constructor Details

QueryTranslatorImpl

public QueryTranslatorImpl(String queryIdentifier,
                           String query,
                           Map enabledFilters,
                           SessionFactoryImplementor factory)
Creates a new AST-based query translator.
Parameters:
queryIdentifier - The query-identifier (used in stats collection)
query - The hql query to translate
enabledFilters - Currently enabled filters
factory - The session factory constructing this translator instance.

Method Details

collectSqlStrings

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

compile

public void compile(Map replacements,
                    boolean shallow)
            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.
shallow - 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 shallow)
            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.
shallow - 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.

containsCollectionFetches

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

executeUpdate

public int executeUpdate(QueryParameters queryParameters,
                         SessionImplementor session)
            throws HibernateException
Specified by:
executeUpdate in interface QueryTranslator

getColumnNames

public String[][] getColumnNames()
Specified by:
getColumnNames in interface QueryTranslator

getEnabledFilters

public Map getEnabledFilters()
Specified by:
getEnabledFilters in interface QueryTranslator

getNamedParameterLocs

public int[] getNamedParameterLocs(String name)

getParameterTranslations

public ParameterTranslations getParameterTranslations()
Specified by:
getParameterTranslations in interface QueryTranslator

getQueryIdentifier

public String getQueryIdentifier()
Specified by:
getQueryIdentifier in interface QueryTranslator

getQuerySpaces

public Set getQuerySpaces()
Specified by:
getQuerySpaces in interface QueryTranslator

getQueryString

public String getQueryString()
Specified by:
getQueryString in interface QueryTranslator

getReturnAliases

public String[] getReturnAliases()
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()
The SQL query string to be called; implemented by all subclasses
Specified by:
getSQLString in interface QueryTranslator

getSqlAST

public Statement getSqlAST()

isManipulationStatement

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

isShallowQuery

public boolean isShallowQuery()

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
Specified by:
list in interface QueryTranslator

scroll

public ScrollableResults scroll(QueryParameters queryParameters,
                                SessionImplementor session)
            throws HibernateException
Return the query results, as an instance of ScrollableResults
Specified by:
scroll in interface QueryTranslator

validateScrollability

public void validateScrollability()
            throws HibernateException
Specified by:
validateScrollability in interface QueryTranslator