Author: steve.ebersole(a)jboss.com
Date: 2009-04-22 16:00:03 -0400 (Wed, 22 Apr 2009)
New Revision: 16409
Modified:
core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/PersisterSpaceContext.java
core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/PersisterTableExpressionGenerator.java
core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/path/impl/AbstractPathResolutionStrategy.java
core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/path/impl/FromClausePathResolutionStrategy.java
core/branches/antlr3/src/main/java/org/hibernate/sql/ast/tree/Table.java
Log:
use HQLLexer (instead of HQLParser) to reference token types
Modified:
core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/PersisterSpaceContext.java
===================================================================
---
core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/PersisterSpaceContext.java 2009-04-22
19:39:06 UTC (rev 16408)
+++
core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/PersisterSpaceContext.java 2009-04-22
20:00:03 UTC (rev 16409)
@@ -26,11 +26,10 @@
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
-
package org.hibernate.sql.ast.phase.hql.resolve;
/**
- * todo : javadocs
+ * The contract for defining a scoping for references to persisters.
*
* @author Steve Ebersole
*/
Modified:
core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/PersisterTableExpressionGenerator.java
===================================================================
---
core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/PersisterTableExpressionGenerator.java 2009-04-22
19:39:06 UTC (rev 16408)
+++
core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/PersisterTableExpressionGenerator.java 2009-04-22
20:00:03 UTC (rev 16409)
@@ -29,15 +29,12 @@
package org.hibernate.sql.ast.phase.hql.resolve;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
import org.hibernate.persister.MappedTableMetadata;
import org.hibernate.persister.collection.QueryableCollection;
import org.hibernate.persister.entity.Queryable;
import org.hibernate.sql.ast.alias.TableAliasGenerator;
import org.hibernate.sql.ast.common.HibernateTree;
-import org.hibernate.sql.ast.phase.hql.parse.HQLParser;
+import org.hibernate.sql.ast.phase.hql.parse.HQLLexer;
import org.hibernate.sql.ast.tree.Table;
import org.hibernate.sql.ast.util.TreePrinter;
@@ -49,8 +46,15 @@
* @author Steve Ebersole
*/
public abstract class PersisterTableExpressionGenerator {
- private static final Logger log = LoggerFactory.getLogger(
PersisterTableExpressionGenerator.class );
-
+ /**
+ * Generate the table expression for the given entity persister.
+ *
+ * @param persister The entity persister.
+ * @param aliasRoot The alias root for SQL alias generation.
+ * @param tableSpace The table space to which any generated table references need to
belong.
+ *
+ * @return The generated table expression (could be simply the root table in a joined
table structure).
+ */
public static Table generateTableExpression(
Queryable persister,
TableAliasGenerator.TableAliasRoot aliasRoot,
@@ -68,17 +72,17 @@
final String joinTableAlias = aliasRoot.generate( ++suffix );
final Table table = generateTableReference( joinedTable.getName(), joinTableAlias,
tableSpace );
- final HibernateTree join = new HibernateTree( HQLParser.JOIN, "join" );
+ final HibernateTree join = new HibernateTree( HQLLexer.JOIN, "join" );
drivingTable.addChild( join );
if ( joinedTable.useInnerJoin() ) {
- join.addChild( new HibernateTree( HQLParser.INNER, "inner" ) );
+ join.addChild( new HibernateTree( HQLLexer.INNER, "inner" ) );
}
else {
- join.addChild( new HibernateTree( HQLParser.LEFT, "left outer" ) );
+ join.addChild( new HibernateTree( HQLLexer.LEFT, "left outer" ) );
}
join.addChild( table );
- final HibernateTree on = new HibernateTree( HQLParser.ON, "on" );
+ final HibernateTree on = new HibernateTree( HQLLexer.ON, "on" );
join.addChild( on );
final HibernateTree joinCondition = generateJoinCorrelation(
drivingTableAlias,
@@ -91,12 +95,21 @@
// todo : temporary...
System.out.println(
- new TreePrinter( HQLParser.class ).renderAsString( drivingTable, "Generated
table space" )
+ new TreePrinter( HQLLexer.class ).renderAsString( drivingTable, "Generated table
space" )
);
return drivingTable;
}
+ /**
+ * Generate the table expression for the given collection persister.
+ *
+ * @param collectionPersister The collection persister
+ * @param aliasRoot The alias root for SQL alias generation.
+ * @param tableSpace The table space to which any generated table references need to
belong.
+ *
+ * @return The generated table expression (could be simply the root table in a joined
table structure).
+ */
public static Table generateTableExpression(
QueryableCollection collectionPersister,
TableAliasGenerator.TableAliasRoot aliasRoot,
@@ -126,15 +139,15 @@
tableSpace.getEntityElementTableSpace()
);
- final HibernateTree join = new HibernateTree( HQLParser.JOIN );
+ final HibernateTree join = new HibernateTree( HQLLexer.JOIN );
associationTable.addChild( join );
- join.addChild( new HibernateTree( HQLParser.LEFT, "left outer" ) );
+ join.addChild( new HibernateTree( HQLLexer.LEFT, "left outer" ) );
join.addChild( drivingTable );
String[] entityFkColumnNames = collectionPersister.getElementColumnNames();
String[] entityPkColumnNames = elementPersister.getKeyColumnNames();
- final HibernateTree on = new HibernateTree( HQLParser.ON );
+ final HibernateTree on = new HibernateTree( HQLLexer.ON );
join.addChild( on );
final HibernateTree joinCondition = generateJoinCorrelation(
associationTable.getAliasText(),
@@ -149,10 +162,19 @@
}
private static Table generateTableReference(String tableName, String tableAlias,
Table.TableSpace tableSpace) {
- Table table = new Table( tableName, tableAlias, tableSpace );
- return table;
+ return new Table( tableName, tableAlias, tableSpace );
}
+ /**
+ * Creates a join correlation subtree (AST representing all the conditions on which the
join occurs).
+ *
+ * @param lhsAlias The alias for the left-hand side (LHS) of the join
+ * @param lhsColumns The LHS columns
+ * @param rhsAlias The alias for the right-hand side (RHS) of the join
+ * @param rhsColumns The RHS columns
+ *
+ * @return The join correlation AST.
+ */
public static HibernateTree generateJoinCorrelation(
String lhsAlias,
String[] lhsColumns,
@@ -162,7 +184,7 @@
if ( lhsColumns.length > 1 ) {
for ( int i = 1; i < lhsColumns.length; i++ ) {
HibernateTree previous = correlation;
- correlation = new HibernateTree( HQLParser.AND, "and" );
+ correlation = new HibernateTree( HQLLexer.AND, "and" );
correlation.addChild( previous );
correlation.addChild( generateJoinCorrelation( lhsAlias, lhsColumns[i], rhsAlias,
rhsColumns[i] ) );
}
@@ -170,16 +192,26 @@
return correlation;
}
+ /**
+ * Creates a join correlation subtree. The difference here is that we have just a
single column on each side.
+ *
+ * @param lhsAlias The alias for the left-hand side (LHS) of the join
+ * @param lhsColumn The LHS column
+ * @param rhsAlias The alias for the right-hand side (RHS) of the join
+ * @param rhsColumn The RHS column
+ *
+ * @return The join correlation AST.
+ */
public static HibernateTree generateJoinCorrelation(String lhsAlias, String lhsColumn,
String rhsAlias, String rhsColumn) {
- HibernateTree lhs = new HibernateTree( HQLParser.COLUMN );
- lhs.addChild( new HibernateTree( HQLParser.ALIAS_REF, lhsAlias ) );
- lhs.addChild( new HibernateTree( HQLParser.IDENTIFIER, lhsColumn ) );
+ HibernateTree lhs = new HibernateTree( HQLLexer.COLUMN );
+ lhs.addChild( new HibernateTree( HQLLexer.ALIAS_REF, lhsAlias ) );
+ lhs.addChild( new HibernateTree( HQLLexer.IDENTIFIER, lhsColumn ) );
- HibernateTree rhs = new HibernateTree( HQLParser.COLUMN );
- rhs.addChild( new HibernateTree( HQLParser.ALIAS_REF, rhsAlias ) );
- rhs.addChild( new HibernateTree( HQLParser.IDENTIFIER, rhsColumn ) );
+ HibernateTree rhs = new HibernateTree( HQLLexer.COLUMN );
+ rhs.addChild( new HibernateTree( HQLLexer.ALIAS_REF, rhsAlias ) );
+ rhs.addChild( new HibernateTree( HQLLexer.IDENTIFIER, rhsColumn ) );
- HibernateTree correlation = new HibernateTree( HQLParser.EQUALS, "=" );
+ HibernateTree correlation = new HibernateTree( HQLLexer.EQUALS, "=" );
correlation.addChild( lhs );
correlation.addChild( rhs );
Modified:
core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/path/impl/AbstractPathResolutionStrategy.java
===================================================================
---
core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/path/impl/AbstractPathResolutionStrategy.java 2009-04-22
19:39:06 UTC (rev 16408)
+++
core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/path/impl/AbstractPathResolutionStrategy.java 2009-04-22
20:00:03 UTC (rev 16409)
@@ -38,6 +38,7 @@
import org.hibernate.sql.ast.common.HibernateToken;
import org.hibernate.sql.ast.common.HibernateTree;
import org.hibernate.sql.ast.phase.hql.parse.HQLParser;
+import org.hibernate.sql.ast.phase.hql.parse.HQLLexer;
import org.hibernate.sql.ast.phase.hql.resolve.PersisterSpace;
import org.hibernate.sql.ast.phase.hql.resolve.PersisterTableExpressionGenerator;
import org.hibernate.sql.ast.phase.hql.resolve.ResolutionContext;
@@ -270,7 +271,7 @@
* @return The join type node.
*/
protected HibernateTree buildJoinTypeNode() {
- return createNode( HQLParser.INNER, "inner" );
+ return createNode( HQLLexer.INNER, "inner" );
}
/**
@@ -369,13 +370,13 @@
* @return The column list.
*/
protected final HibernateTree generatePropertyColumnList(PersisterSpace origin, String
propertyName) {
- HibernateTree columnList = new HibernateTree( HQLParser.COLUMN_LIST );
+ HibernateTree columnList = new HibernateTree( HQLLexer.COLUMN_LIST );
Table containingTable = origin.getTableSpace().getContainingTable( propertyName );
for ( String columnName : origin.getTableSpace().getPropertyColumnNames( propertyName )
) {
- final HibernateTree column = new HibernateTree( HQLParser.COLUMN );
+ final HibernateTree column = new HibernateTree( HQLLexer.COLUMN );
columnList.addChild( column );
- column.addChild( new HibernateTree( HQLParser.ALIAS_REF,
containingTable.getAliasText() ) );
- column.addChild( new HibernateTree( HQLParser.IDENTIFIER, columnName ) );
+ column.addChild( new HibernateTree( HQLLexer.ALIAS_REF, containingTable.getAliasText()
) );
+ column.addChild( new HibernateTree( HQLLexer.IDENTIFIER, columnName ) );
}
return columnList;
}
@@ -400,7 +401,7 @@
}
protected AbstractPathedPropertyReferenceSource(String originationPath) {
- super( new HibernateToken( HQLParser.IDENTIFIER, originationPath ) );
+ super( new HibernateToken( HQLLexer.IDENTIFIER, originationPath ) );
this.originationPath = originationPath;
}
@@ -414,11 +415,11 @@
// in general we need the collection element column list
QueryableCollection collectionPersister = resolveCollectionPersister( lhs,
collectionPropertyName );
- HibernateTree columnList = new HibernateTree( HQLParser.COLUMN_LIST );
+ HibernateTree columnList = new HibernateTree( HQLLexer.COLUMN_LIST );
for ( String columnName : collectionPersister.getElementColumnNames() ) {
- final HibernateTree column = new HibernateTree( HQLParser.COLUMN );
- column.addChild( new HibernateTree( HQLParser.ALIAS_REF,
joinedCollectionTable.getAliasText() ) );
- column.addChild( new HibernateTree( HQLParser.IDENTIFIER, columnName ) );
+ final HibernateTree column = new HibernateTree( HQLLexer.COLUMN );
+ column.addChild( new HibernateTree( HQLLexer.ALIAS_REF,
joinedCollectionTable.getAliasText() ) );
+ column.addChild( new HibernateTree( HQLLexer.IDENTIFIER, columnName ) );
}
return columnList;
}
@@ -476,7 +477,7 @@
Table.EntityTableSpace tableSpace = new Table.EntityTableSpace( entityPersister,
tableAliasRoot );
Table joinedTableExpression = tableSpace.getDrivingTable();
- HibernateTree join = new HibernateTree( HQLParser.JOIN );
+ HibernateTree join = new HibernateTree( HQLLexer.JOIN );
join.addChild( buildJoinTypeNode() );
join.addChild( joinedTableExpression );
@@ -501,7 +502,7 @@
);
}
- HibernateTree on = new HibernateTree( HQLParser.ON );
+ HibernateTree on = new HibernateTree( HQLLexer.ON );
join.addChild( on );
on.addChild( joinCondition );
@@ -521,7 +522,7 @@
tableSpace
);
- HibernateTree joinNode = new HibernateTree( HQLParser.JOIN );
+ HibernateTree joinNode = new HibernateTree( HQLLexer.JOIN );
joinNode.addChild( buildJoinTypeNode() );
joinNode.addChild( collectionTableExpression );
@@ -548,12 +549,12 @@
if ( extraJoinConditions != null ) {
HibernateTree mappedJoinCondition = joinCondition;
- joinCondition = new HibernateTree( HQLParser.AND );
+ joinCondition = new HibernateTree( HQLLexer.AND );
joinCondition.addChild( mappedJoinCondition );
joinCondition.addChild( extraJoinConditions );
}
- HibernateTree on = new HibernateTree( HQLParser.ON );
+ HibernateTree on = new HibernateTree( HQLLexer.ON );
joinNode.addChild( on );
on.addChild( joinCondition );
Modified:
core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/path/impl/FromClausePathResolutionStrategy.java
===================================================================
---
core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/path/impl/FromClausePathResolutionStrategy.java 2009-04-22
19:39:06 UTC (rev 16408)
+++
core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/path/impl/FromClausePathResolutionStrategy.java 2009-04-22
20:00:03 UTC (rev 16409)
@@ -31,7 +31,7 @@
import org.hibernate.QueryException;
import org.hibernate.sql.ast.common.HibernateTree;
import org.hibernate.sql.ast.common.JoinType;
-import org.hibernate.sql.ast.phase.hql.parse.HQLParser;
+import org.hibernate.sql.ast.phase.hql.parse.HQLLexer;
import org.hibernate.sql.ast.phase.hql.resolve.PersisterSpace;
import org.hibernate.sql.ast.phase.hql.resolve.ResolutionContext;
import org.hibernate.sql.ast.phase.hql.resolve.path.PathedPropertyReferenceSource;
@@ -107,13 +107,13 @@
protected HibernateTree buildJoinTypeNode() {
if ( joinType == JoinType.INNER ) {
- return new HibernateTree( HQLParser.INNER );
+ return new HibernateTree( HQLLexer.INNER );
}
else if ( joinType == JoinType.LEFT ) {
- return new HibernateTree( HQLParser.LEFT );
+ return new HibernateTree( HQLLexer.LEFT );
}
else if ( joinType == JoinType.RIGHT ) {
- return new HibernateTree( HQLParser.RIGHT );
+ return new HibernateTree( HQLLexer.RIGHT );
}
// if no match found, throw exception
throw new QueryException( "Unrecognized join type [" + joinType.toString() +
"]" );
Modified: core/branches/antlr3/src/main/java/org/hibernate/sql/ast/tree/Table.java
===================================================================
--- core/branches/antlr3/src/main/java/org/hibernate/sql/ast/tree/Table.java 2009-04-22
19:39:06 UTC (rev 16408)
+++ core/branches/antlr3/src/main/java/org/hibernate/sql/ast/tree/Table.java 2009-04-22
20:00:03 UTC (rev 16409)
@@ -37,7 +37,7 @@
import org.hibernate.sql.ast.common.HibernateTree;
import org.hibernate.sql.ast.common.HibernateToken;
import org.hibernate.sql.ast.util.DisplayableNode;
-import org.hibernate.sql.ast.phase.hql.parse.HQLParser;
+import org.hibernate.sql.ast.phase.hql.parse.HQLLexer;
import org.hibernate.sql.ast.phase.hql.resolve.PersisterSpace;
import org.hibernate.sql.ast.phase.hql.resolve.PersisterTableExpressionGenerator;
import org.hibernate.persister.entity.Queryable;
@@ -54,9 +54,9 @@
private final TableSpace tableSpace;
public Table(String tableName, String tableAlias, TableSpace tableSpace) {
- super( new HibernateToken( HQLParser.TABLE ) );
- addChild( new HibernateTree( HQLParser.IDENTIFIER, tableName ) );
- addChild( new HibernateTree( HQLParser.ALIAS_NAME, tableAlias ) );
+ super( new HibernateToken( HQLLexer.TABLE ) );
+ addChild( new HibernateTree( HQLLexer.IDENTIFIER, tableName ) );
+ addChild( new HibernateTree( HQLLexer.ALIAS_NAME, tableAlias ) );
this.tableSpace = tableSpace;
tableSpace.addTable( this );
}
@@ -232,11 +232,11 @@
}
public HibernateTree buildIdentifierColumnReferences() {
- HibernateTree columnList = new HibernateTree( HQLParser.COLUMN_LIST );
+ HibernateTree columnList = new HibernateTree( HQLLexer.COLUMN_LIST );
for ( String columnName : getEntityPersister().getIdentifierColumnNames() ) {
- HibernateTree columnNode = new HibernateTree( HQLParser.COLUMN );
- columnNode.addChild( new HibernateTree( HQLParser.ALIAS_REF,
getDrivingTable().getAliasText() ) );
- columnNode.addChild( new HibernateTree( HQLParser.IDENTIFIER, columnName ) );
+ HibernateTree columnNode = new HibernateTree( HQLLexer.COLUMN );
+ columnNode.addChild( new HibernateTree( HQLLexer.ALIAS_REF,
getDrivingTable().getAliasText() ) );
+ columnNode.addChild( new HibernateTree( HQLLexer.IDENTIFIER, columnName ) );
columnList.addChild( columnNode );
}
return columnList;