Author: porcelli
Date: 2009-04-23 15:20:25 -0400 (Thu, 23 Apr 2009)
New Revision: 16432
Modified:
core/branches/antlr3/src/main/antlr3/org/hibernate/sql/ast/phase/hql/parse/HQLLexer.g
core/branches/antlr3/src/main/antlr3/org/hibernate/sql/ast/phase/hql/parse/HQLParser.g
core/branches/antlr3/src/main/antlr3/org/hibernate/sql/ast/phase/hql/resolve/GeneratedHQLResolver.g
core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/HQLResolver.java
core/branches/antlr3/src/test/antlr3/org/hibernate/sql/ast/phase/hql/parse/TestHQLTreeWalker.g
core/branches/antlr3/src/test/java/org/hibernate/sql/ast/phase/hql/resolve/TestHQLResolver.java
Log:
added the order_spec
Modified:
core/branches/antlr3/src/main/antlr3/org/hibernate/sql/ast/phase/hql/parse/HQLLexer.g
===================================================================
---
core/branches/antlr3/src/main/antlr3/org/hibernate/sql/ast/phase/hql/parse/HQLLexer.g 2009-04-23
17:38:50 UTC (rev 16431)
+++
core/branches/antlr3/src/main/antlr3/org/hibernate/sql/ast/phase/hql/parse/HQLLexer.g 2009-04-23
19:20:25 UTC (rev 16432)
@@ -59,7 +59,6 @@
AND;
ANY;
AS;
- ASC;
AVG;
BETWEEN;
BIT_LENGTH;
@@ -76,7 +75,6 @@
CURRENT_TIMESTAMP;
DAY;
DELETE;
- DESC;
DISTINCT;
ELEMENTS;
ELSE;
@@ -124,6 +122,7 @@
ON;
OR;
ORDER_BY;
+ ORDER_SPEC;
OUTER;
POSITION;
PROPERTIES;
Modified:
core/branches/antlr3/src/main/antlr3/org/hibernate/sql/ast/phase/hql/parse/HQLParser.g
===================================================================
---
core/branches/antlr3/src/main/antlr3/org/hibernate/sql/ast/phase/hql/parse/HQLParser.g 2009-04-23
17:38:50 UTC (rev 16431)
+++
core/branches/antlr3/src/main/antlr3/org/hibernate/sql/ast/phase/hql/parse/HQLParser.g 2009-04-23
19:20:25 UTC (rev 16432)
@@ -523,7 +523,7 @@
sortSpecification
@init{boolean generateOmmitedElement = true;}
: sortKey collationSpecification? (orderingSpecification {generateOmmitedElement =
false;})?
- -> {generateOmmitedElement}? ^(SORT_SPEC sortKey collationSpecification? ASC)
+ -> {generateOmmitedElement}? ^(SORT_SPEC sortKey collationSpecification?
ORDER_SPEC["asc"])
-> ^(SORT_SPEC sortKey collationSpecification? orderingSpecification?)
;
@@ -544,8 +544,8 @@
;
orderingSpecification
- : ascending_key
- | descending_key
+ : ascending_key -> ORDER_SPEC[$ascending_key.start, "asc"]
+ | descending_key -> ORDER_SPEC[$descending_key.start, "desc"]
;
logicalExpression
@@ -1438,13 +1438,11 @@
;
ascending_key
- : {(validateIdentifierKey("ascending") ||
validateIdentifierKey("asc"))}?=> id=IDENTIFIER
- -> ASC[$id]
+ : {(validateIdentifierKey("ascending") ||
validateIdentifierKey("asc"))}?=> IDENTIFIER
;
descending_key
- : {(validateIdentifierKey("descending") ||
validateIdentifierKey("desc"))}?=> id=IDENTIFIER
- -> DESC[$id]
+ : {(validateIdentifierKey("descending") ||
validateIdentifierKey("desc"))}?=> IDENTIFIER
;
collate_key
Modified:
core/branches/antlr3/src/main/antlr3/org/hibernate/sql/ast/phase/hql/resolve/GeneratedHQLResolver.g
===================================================================
---
core/branches/antlr3/src/main/antlr3/org/hibernate/sql/ast/phase/hql/resolve/GeneratedHQLResolver.g 2009-04-23
17:38:50 UTC (rev 16431)
+++
core/branches/antlr3/src/main/antlr3/org/hibernate/sql/ast/phase/hql/resolve/GeneratedHQLResolver.g 2009-04-23
19:20:25 UTC (rev 16432)
@@ -75,7 +75,7 @@
throw new UnsupportedOperationException( "must be overridden!" );
}
- protected void normalizeIntermediateIndexOperation( PathedPropertyReferenceSource
propertyReferenceSource, Tree collectionProperty,
+ protected PathedPropertyReferenceSource normalizeIntermediateIndexOperation(
PathedPropertyReferenceSource propertyReferenceSource, Tree collectionProperty,
Tree selector ) {
throw new UnsupportedOperationException( "must be overridden!" );
}
@@ -107,7 +107,7 @@
protected void popStrategy(){
throw new UnsupportedOperationException( "must be overridden!" );
- }
+ }
}
filterStatement[String collectionRole]
@@ -251,7 +251,7 @@
;
sortSpecification
- : ^(SORT_SPEC valueExpression COLLATE? (ASC|DESC))
+ : ^(SORT_SPEC valueExpression COLLATE? ORDER_SPEC)
;
searchCondition
@@ -586,7 +586,7 @@
: {(isPersisterReferenceAlias())}?=> IDENTIFIER { $propertyReferenceSource =
normalizeQualifiedRoot( $IDENTIFIER ); }
| {(isUnqualifiedPropertyReference())}?=> IDENTIFIER { $propertyReferenceSource =
normalizeUnqualifiedRoot( $IDENTIFIER ); }
| intermediatePathedPropertyReference { $propertyReferenceSource =
$intermediatePathedPropertyReference.propertyReferenceSource; }
- | intermediateIndexOperation { $propertyReferenceSource = null; }
+ | intermediateIndexOperation { $propertyReferenceSource =
$intermediateIndexOperation.propertyReferenceSource; }
;
intermediatePathedPropertyReference returns [PathedPropertyReferenceSource
propertyReferenceSource]
@@ -594,9 +594,9 @@
{ $propertyReferenceSource = normalizePropertyPathIntermediary(
$pathedPropertyReferenceSource.propertyReferenceSource, $IDENTIFIER ); }
;
-intermediateIndexOperation
+intermediateIndexOperation returns [PathedPropertyReferenceSource
propertyReferenceSource]
: ^( LEFT_SQUARE indexOperationSource indexSelector )
- { normalizeIntermediateIndexOperation( $indexOperationSource.propertyReferenceSource,
$indexOperationSource.collectionProperty, $indexSelector.tree ); }
+ { $propertyReferenceSource = normalizeIntermediateIndexOperation(
$indexOperationSource.propertyReferenceSource, $indexOperationSource.collectionProperty,
$indexSelector.tree ); }
;
terminalIndexOperation
Modified:
core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/HQLResolver.java
===================================================================
---
core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/HQLResolver.java 2009-04-23
17:38:50 UTC (rev 16431)
+++
core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/HQLResolver.java 2009-04-23
19:20:25 UTC (rev 16432)
@@ -1,16 +1,23 @@
/*
- * Copyright (c) 2009, Red Hat Middleware LLC or third-party contributors as
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2009, Red Hat Middleware LLC or third-party
+ * contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Middleware LLC.
*
- * This copyrighted material is made available to anyone wishing to use, modify,
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
- * Lesser General Public License, as published by the Free Software Foundation.
+ * Lesser General Public License, as published by the Free Software
+ * Foundation.
*
* This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
- * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+ * License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
@@ -25,6 +32,7 @@
import org.antlr.runtime.tree.CommonTree;
import org.antlr.runtime.tree.Tree;
import org.antlr.runtime.tree.TreeNodeStream;
+
import org.hibernate.engine.SessionFactoryImplementor;
import org.hibernate.persister.entity.Queryable;
import org.hibernate.sql.ast.alias.DefaultTableAliasGenerator;
@@ -41,6 +49,7 @@
import org.hibernate.sql.ast.tree.Table;
import org.hibernate.sql.ast.tree.Table.EntityTableSpace;
import org.hibernate.sql.ast.util.TreePrinter;
+
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -57,25 +66,26 @@
private boolean isProcessingFunction = false;
- public HQLResolver( TreeNodeStream input,
- SessionFactoryImplementor sessionFactory ) {
+ public HQLResolver(TreeNodeStream input,
+ SessionFactoryImplementor sessionFactory) {
this( input, new RecognizerSharedState(), sessionFactory );
}
- public HQLResolver( TreeNodeStream input, RecognizerSharedState state,
- SessionFactoryImplementor sessionFactory ) {
+ public HQLResolver(TreeNodeStream input, RecognizerSharedState state,
+ SessionFactoryImplementor sessionFactory) {
super( input, state );
this.sessionFactory = sessionFactory;
this.persisterSpaceContext = new RootPersisterSpaceContext();
this.defaultTableAliasGenerator = new DefaultTableAliasGenerator(
- sessionFactory.getDialect() );
+ sessionFactory.getDialect()
+ );
this.printer = new TreePrinter( HQLParser.class );
this.pathResolutionStrategyStack = new PathResolutionStrategyStack();
this.pathResolutionStrategyStack
.push( new BasicPathResolutionStrategySupport( this ) );
}
- protected void registerPersisterSpace( Tree entityName, Tree alias ) {
+ protected void registerPersisterSpace(Tree entityName, Tree alias) {
String entityPersisterName = sessionFactory
.getImportedClassName( entityName.getText() );
Queryable entityPersister = ( Queryable ) sessionFactory
@@ -84,7 +94,8 @@
TableAliasGenerator.TableAliasRoot tableAliasRoot = getTableAliasGenerator()
.generateSqlAliasRoot( entityPersister, alias.getText() );
EntityTableSpace tableSpace = new Table.EntityTableSpace(
- entityPersister, tableAliasRoot );
+ entityPersister, tableAliasRoot
+ );
registerPersisterSpace( tableSpace.getPersisterSpace() );
}
@@ -116,21 +127,24 @@
return pathResolutionStrategyStack.getCurrent();
}
- public void registerAssociationFetch( PersisterSpace persisterSpace ) {
+ public void registerAssociationFetch(PersisterSpace persisterSpace) {
throw new UnsupportedOperationException( "must be implemented!" );
}
- public void registerPropertyFetch( PersisterSpace persisterSpace ) {
+ public void registerPropertyFetch(PersisterSpace persisterSpace) {
throw new UnsupportedOperationException( "must be implemented!" );
}
- protected void pushFromStrategy( JoinType joinType,
- Tree assosiationFetchTree, Tree propertyFetchTree, Tree alias ) {
+ protected void pushFromStrategy(JoinType joinType,
+ Tree assosiationFetchTree, Tree propertyFetchTree, Tree alias) {
boolean assosiationFetch = assosiationFetchTree != null ? true : false;
boolean propertyFetch = propertyFetchTree != null ? true : false;
- pathResolutionStrategyStack.push( new FromClausePathResolutionStrategy(
- this, joinType, assosiationFetch, propertyFetch, alias
- .getText() ) );
+ pathResolutionStrategyStack.push(
+ new FromClausePathResolutionStrategy(
+ this, joinType, assosiationFetch, propertyFetch, alias
+ .getText()
+ )
+ );
}
protected void pushSelectStrategy() {
@@ -142,7 +156,7 @@
pathResolutionStrategyStack.pop();
}
- private void registerPersisterSpace( PersisterSpace persisterSpace ) {
+ private void registerPersisterSpace(PersisterSpace persisterSpace) {
persisterSpaceContext.registerPersisterSpace( persisterSpace );
}
@@ -150,7 +164,7 @@
return locateOwningPersisterAlias( ( Tree ) input.LT( 1 ) ) != null;
}
- protected String locateOwningPersisterAlias( Tree property ) {
+ protected String locateOwningPersisterAlias(Tree property) {
PersisterSpace persisterReference = getCurrentPersisterSpaceContext()
.locatePersisterSpaceExposingProperty( property.getText() );
return persisterReference == null ? null : persisterReference
@@ -159,84 +173,116 @@
protected boolean isPersisterReferenceAlias() {
Tree alias = ( Tree ) input.LT( 1 );
- log.trace( "Checking [" + textOrNull( alias )
- + "] as persister-ref alias" );
+ log.trace(
+ "Checking [" + textOrNull( alias )
+ + "] as persister-ref alias"
+ );
return getCurrentPersisterSpaceContext().isContainedAlias(
- alias.getText() );
+ alias.getText()
+ );
}
protected PathedPropertyReferenceSource normalizeUnqualifiedPropertyReference(
- Tree property ) {
+ Tree property) {
return getCurrentPathResolutionStrategy().handleRoot(
getCurrentPersisterSpaceContext()
.locatePersisterSpaceExposingProperty(
- property.getText() ) );
+ property.getText()
+ )
+ );
}
protected PathedPropertyReferenceSource normalizeUnqualifiedRoot(
- Tree propertyName ) {
- log.debug( "normalizing path expression root as unqualified property ["
- + textOrNull( propertyName ) + "]" );
+ Tree propertyName) {
+ log.debug(
+ "normalizing path expression root as unqualified property ["
+ + textOrNull( propertyName ) + "]"
+ );
PathedPropertyReferenceSource root = getCurrentPathResolutionStrategy()
.handleRoot(
getCurrentPersisterSpaceContext()
.locatePersisterSpaceExposingProperty(
- propertyName.getText() ) );
+ propertyName.getText()
+ )
+ );
return root.handleIntermediatePathPart( propertyName.getText() );
}
- protected PathedPropertyReferenceSource normalizeQualifiedRoot( Tree alias ) {
- log.debug( "normalizing path expression root as alias ["
- + alias.getText() + "]" );
+ protected PathedPropertyReferenceSource normalizeQualifiedRoot(Tree alias) {
+ log.debug(
+ "normalizing path expression root as alias ["
+ + alias.getText() + "]"
+ );
return getCurrentPathResolutionStrategy().handleRoot(
getCurrentPersisterSpaceContext().locatePersisterSpaceByAlias(
- alias.getText() ) );
+ alias.getText()
+ )
+ );
}
protected Tree normalizePropertyPathTerminus(
- PathedPropertyReferenceSource source, Tree propertyNameNode ) {
- log.trace( "normalizing terminal path expression ["
- + textOrNull( propertyNameNode ) + "]" );
+ PathedPropertyReferenceSource source, Tree propertyNameNode) {
+ log.trace(
+ "normalizing terminal path expression ["
+ + textOrNull( propertyNameNode ) + "]"
+ );
return getCurrentPathResolutionStrategy().handleTerminalPathPart(
- source, propertyNameNode.getText() );
+ source, propertyNameNode.getText()
+ );
}
protected PathedPropertyReferenceSource normalizePropertyPathIntermediary(
- PathedPropertyReferenceSource source, Tree propertyName ) {
- log.trace( "normalizing intermediate path expression ["
- + textOrNull( propertyName ) + "]" );
+ PathedPropertyReferenceSource source, Tree propertyName) {
+ log.trace(
+ "normalizing intermediate path expression ["
+ + textOrNull( propertyName ) + "]"
+ );
return getCurrentPathResolutionStrategy().handleIntermediatePathPart(
( PathedPropertyReferenceSource ) source,
- propertyName.getText() );
+ propertyName.getText()
+ );
}
protected PathedPropertyReferenceSource normalizeUnqualifiedPropertyReferenceSource(
- Tree propertyName ) {
+ Tree propertyName) {
return getCurrentPathResolutionStrategy().handleRoot(
getCurrentPersisterSpaceContext()
.locatePersisterSpaceExposingProperty(
- propertyName.getText() ) );
+ propertyName.getText()
+ )
+ );
}
- protected void normalizeIntermediateIndexOperation(
- PathedPropertyReferenceSource propertyReferenceSource,
- Tree collectionProperty, Tree selector ) {
- throw new UnsupportedOperationException(
- "must be implemented!: normalizeIntermediateIndexOperation" );
+ protected PathedPropertyReferenceSource normalizeIntermediateIndexOperation(
+ PathedPropertyReferenceSource collectionSource,
+ Tree collectionProperty, Tree selector) {
+ log.trace(
+ "normalizing intermediate index access ["
+ + textOrNull( collectionProperty ) + "]"
+ );
+ return getCurrentPathResolutionStrategy()
+ .handleIntermediateIndexAccess(
+ collectionSource,
+ collectionProperty.getText(),
+ new HibernateTree( ( CommonTree ) selector )
+ );
}
protected void normalizeTerminalIndexOperation(
PathedPropertyReferenceSource propertyReferenceSource,
- Tree collectionProperty, Tree selector ) {
- log.trace( "normalizing terminal index access ["
- + textOrNull( collectionProperty ) + "]" );
+ Tree collectionProperty, Tree selector) {
+ log.trace(
+ "normalizing terminal index access ["
+ + textOrNull( collectionProperty ) + "]"
+ );
PathedPropertyReferenceSource collectionSource = propertyReferenceSource;
getCurrentPathResolutionStrategy().handleTerminalIndexAccess(
collectionSource, collectionProperty.getText(),
- new HibernateTree( ( CommonTree ) selector ) );
+ new HibernateTree( ( CommonTree ) selector )
+ );
}
- private String textOrNull( Tree tree ) {
+ private String textOrNull(Tree tree) {
return tree == null ? null : tree.getText();
}
Modified:
core/branches/antlr3/src/test/antlr3/org/hibernate/sql/ast/phase/hql/parse/TestHQLTreeWalker.g
===================================================================
---
core/branches/antlr3/src/test/antlr3/org/hibernate/sql/ast/phase/hql/parse/TestHQLTreeWalker.g 2009-04-23
17:38:50 UTC (rev 16431)
+++
core/branches/antlr3/src/test/antlr3/org/hibernate/sql/ast/phase/hql/parse/TestHQLTreeWalker.g 2009-04-23
19:20:25 UTC (rev 16432)
@@ -177,7 +177,7 @@
;
sortSpecification
- : ^(SORT_SPEC valueExpression COLLATE? (ASC|DESC))
+ : ^(SORT_SPEC valueExpression COLLATE? ORDER_SPEC)
;
searchCondition
Modified:
core/branches/antlr3/src/test/java/org/hibernate/sql/ast/phase/hql/resolve/TestHQLResolver.java
===================================================================
---
core/branches/antlr3/src/test/java/org/hibernate/sql/ast/phase/hql/resolve/TestHQLResolver.java 2009-04-23
17:38:50 UTC (rev 16431)
+++
core/branches/antlr3/src/test/java/org/hibernate/sql/ast/phase/hql/resolve/TestHQLResolver.java 2009-04-23
19:20:25 UTC (rev 16432)
@@ -39,12 +39,12 @@
super.tearDown();
}
- public void testBasicStructure() throws Throwable {
+ public void testBasicStructure() throws RecognitionException {
Tree queryTree = normalize( "from Animal" );
}
public void testBasicSelectStructure() throws Throwable {
- Tree queryTree = normalize( "from Zoo z where mammals['dog'] = ?" );
+ Tree queryTree = normalize( "from Zoo z where z.mammals['dog'].id =
?" );
}
public Tree normalize( String hql ) throws RecognitionException {