Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

org.hibernate.hql.ast
Class QueryTranslatorImpl  view QueryTranslatorImpl download QueryTranslatorImpl.java

java.lang.Object
  extended byorg.hibernate.hql.ast.QueryTranslatorImpl
All Implemented Interfaces:
org.hibernate.hql.FilterTranslator, org.hibernate.hql.QueryTranslator

public class QueryTranslatorImpl
extends java.lang.Object
implements org.hibernate.hql.FilterTranslator

A QueryTranslator that uses an AST based parser.
User: josh
Date: Dec 31, 2003
Time: 7:50:35 AM


Field Summary
private static org.apache.commons.logging.Log AST_LOG
           
private  boolean compiled
           
private  java.util.Map enabledFilters
           
private  org.hibernate.engine.SessionFactoryImplementor factory
           
private  java.lang.String hql
           
private static org.apache.commons.logging.Log log
           
private  org.hibernate.hql.ParameterTranslations paramTranslations
           
private  java.lang.String queryIdentifier
           
private  org.hibernate.loader.hql.QueryLoader queryLoader
           
private  boolean shallowQuery
           
private  java.lang.String sql
           
private  org.hibernate.hql.ast.tree.Statement sqlAst
           
private  org.hibernate.hql.ast.exec.StatementExecutor statementExecutor
           
private  java.util.Map tokenReplacements
           
 
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(java.lang.String queryIdentifier, java.lang.String query, java.util.Map enabledFilters, org.hibernate.engine.SessionFactoryImplementor factory)
          Creates a new AST-based query translator.
 
Method Summary
private  HqlSqlWalker analyze(HqlParser parser, java.lang.String collectionRole)
           
private  org.hibernate.hql.ast.exec.StatementExecutor buildAppropriateStatementExecutor(HqlSqlWalker walker)
           
 java.util.List collectSqlStrings()
           
 void compile(java.util.Map replacements, boolean shallow)
          Compile a "normal" query.
 void compile(java.lang.String collectionRole, java.util.Map replacements, boolean shallow)
          Compile a filter.
 boolean containsCollectionFetches()
          Does the translated query contain collection fetches?
private  void doCompile(java.util.Map replacements, boolean shallow, java.lang.String collectionRole)
          Performs both filter and non-filter compiling.
private  void errorIfDML()
           
private  void errorIfSelect()
           
 int executeUpdate(org.hibernate.engine.QueryParameters queryParameters, org.hibernate.engine.SessionImplementor session)
          Perform a bulk update/delete operation given the underlying query defintion.
private  void generate(antlr.collections.AST sqlAst)
           
 java.lang.String[][] getColumnNames()
          Returns the column names in the generated SQL.
 java.util.Map getEnabledFilters()
          Returns the filters enabled for this query translator.
 int[] getNamedParameterLocs(java.lang.String name)
           
 org.hibernate.hql.ParameterTranslations getParameterTranslations()
          Return information about any parameters encountered during translation.
 java.lang.String getQueryIdentifier()
          Retrieve the query identifier for this translator.
 java.util.Set getQuerySpaces()
          Returns the set of query spaces (table names) that the query referrs to.
 java.lang.String getQueryString()
          Returns the HQL string processed by the translator.
 java.lang.String[] getReturnAliases()
          Returns an array of HQL aliases
 org.hibernate.type.Type[] getReturnTypes()
          Types of the return values of an iterate() style query.
 org.hibernate.hql.ast.tree.Statement getSqlAST()
           
 java.lang.String getSQLString()
          The SQL query string to be called; implemented by all subclasses
private  HqlSqlWalker getWalker()
           
 boolean isManipulationStatement()
           
 boolean isShallowQuery()
           
 java.util.Iterator iterate(org.hibernate.engine.QueryParameters queryParameters, org.hibernate.event.EventSource session)
          Return the query results as an iterator
 java.util.List list(org.hibernate.engine.SessionImplementor session, org.hibernate.engine.QueryParameters queryParameters)
          Perform a list operation given the underlying query definition.
private  HqlParser parse(boolean filter)
           
 org.hibernate.ScrollableResults scroll(org.hibernate.engine.QueryParameters queryParameters, org.hibernate.engine.SessionImplementor session)
          Return the query results, as an instance of ScrollableResults
(package private)  void showHqlAst(antlr.collections.AST hqlAst)
           
 void validateScrollability()
          Validate the scrollability of the translated query.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

private static final org.apache.commons.logging.Log log

AST_LOG

private static final org.apache.commons.logging.Log AST_LOG

factory

private org.hibernate.engine.SessionFactoryImplementor factory

queryIdentifier

private final java.lang.String queryIdentifier

hql

private java.lang.String hql

shallowQuery

private boolean shallowQuery

tokenReplacements

private java.util.Map tokenReplacements

enabledFilters

private java.util.Map enabledFilters

compiled

private boolean compiled

queryLoader

private org.hibernate.loader.hql.QueryLoader queryLoader

statementExecutor

private org.hibernate.hql.ast.exec.StatementExecutor statementExecutor

sqlAst

private org.hibernate.hql.ast.tree.Statement sqlAst

sql

private java.lang.String sql

paramTranslations

private org.hibernate.hql.ParameterTranslations paramTranslations
Constructor Detail

QueryTranslatorImpl

public QueryTranslatorImpl(java.lang.String queryIdentifier,
                           java.lang.String query,
                           java.util.Map enabledFilters,
                           org.hibernate.engine.SessionFactoryImplementor factory)
Creates a new AST-based query translator.

Method Detail

compile

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

Specified by:
compile in interface org.hibernate.hql.QueryTranslator

compile

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

Specified by:
compile in interface org.hibernate.hql.FilterTranslator

doCompile

private void doCompile(java.util.Map replacements,
                       boolean shallow,
                       java.lang.String collectionRole)
Performs both filter and non-filter compiling.


generate

private void generate(antlr.collections.AST sqlAst)
               throws org.hibernate.QueryException,
                      antlr.RecognitionException

analyze

private HqlSqlWalker analyze(HqlParser parser,
                             java.lang.String collectionRole)
                      throws org.hibernate.QueryException,
                             antlr.RecognitionException

parse

private HqlParser parse(boolean filter)
                 throws antlr.TokenStreamException,
                        antlr.RecognitionException

showHqlAst

void showHqlAst(antlr.collections.AST hqlAst)

errorIfDML

private void errorIfDML()
                 throws org.hibernate.HibernateException

errorIfSelect

private void errorIfSelect()
                    throws org.hibernate.HibernateException

getQueryIdentifier

public java.lang.String getQueryIdentifier()
Description copied from interface: org.hibernate.hql.QueryTranslator
Retrieve the query identifier for this translator. The query identifier is used in stats collection.

Specified by:
getQueryIdentifier in interface org.hibernate.hql.QueryTranslator

getSqlAST

public org.hibernate.hql.ast.tree.Statement getSqlAST()

getWalker

private HqlSqlWalker getWalker()

getReturnTypes

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

Specified by:
getReturnTypes in interface org.hibernate.hql.QueryTranslator

getReturnAliases

public java.lang.String[] getReturnAliases()
Description copied from interface: org.hibernate.hql.QueryTranslator
Returns an array of HQL aliases

Specified by:
getReturnAliases in interface org.hibernate.hql.QueryTranslator

getColumnNames

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

Specified by:
getColumnNames in interface org.hibernate.hql.QueryTranslator

getQuerySpaces

public java.util.Set getQuerySpaces()
Description copied from interface: org.hibernate.hql.QueryTranslator
Returns the set of query spaces (table names) that the query referrs to.

Specified by:
getQuerySpaces in interface org.hibernate.hql.QueryTranslator

list

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

Specified by:
list in interface org.hibernate.hql.QueryTranslator

iterate

public java.util.Iterator iterate(org.hibernate.engine.QueryParameters queryParameters,
                                  org.hibernate.event.EventSource session)
                           throws org.hibernate.HibernateException
Return the query results as an iterator

Specified by:
iterate in interface org.hibernate.hql.QueryTranslator

scroll

public org.hibernate.ScrollableResults scroll(org.hibernate.engine.QueryParameters queryParameters,
                                              org.hibernate.engine.SessionImplementor session)
                                       throws org.hibernate.HibernateException
Return the query results, as an instance of ScrollableResults

Specified by:
scroll in interface org.hibernate.hql.QueryTranslator

executeUpdate

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

Specified by:
executeUpdate in interface org.hibernate.hql.QueryTranslator

getSQLString

public java.lang.String getSQLString()
The SQL query string to be called; implemented by all subclasses

Specified by:
getSQLString in interface org.hibernate.hql.QueryTranslator

collectSqlStrings

public java.util.List collectSqlStrings()
Specified by:
collectSqlStrings in interface org.hibernate.hql.QueryTranslator

isShallowQuery

public boolean isShallowQuery()

getQueryString

public java.lang.String getQueryString()
Description copied from interface: org.hibernate.hql.QueryTranslator
Returns the HQL string processed by the translator.

Specified by:
getQueryString in interface org.hibernate.hql.QueryTranslator

getEnabledFilters

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

Specified by:
getEnabledFilters in interface org.hibernate.hql.QueryTranslator

getNamedParameterLocs

public int[] getNamedParameterLocs(java.lang.String name)

containsCollectionFetches

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

Specified by:
containsCollectionFetches in interface org.hibernate.hql.QueryTranslator

isManipulationStatement

public boolean isManipulationStatement()
Specified by:
isManipulationStatement in interface org.hibernate.hql.QueryTranslator

validateScrollability

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

Specified by:
validateScrollability in interface org.hibernate.hql.QueryTranslator

buildAppropriateStatementExecutor

private org.hibernate.hql.ast.exec.StatementExecutor buildAppropriateStatementExecutor(HqlSqlWalker walker)

getParameterTranslations

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

Specified by:
getParameterTranslations in interface org.hibernate.hql.QueryTranslator