Author: steve.ebersole(a)jboss.com
Date: 2009-04-15 21:16:21 -0400 (Wed, 15 Apr 2009)
New Revision: 16350
Added:
core/branches/antlr3/src/main/java/org/hibernate/sql/ast/util/ColumnMapper.java
Removed:
core/branches/antlr3/src/main/java/org/hibernate/hql/antlr/
core/branches/antlr3/src/main/java/org/hibernate/hql/ast/
core/branches/antlr3/src/main/java/org/hibernate/loader/hql/
core/branches/antlr3/src/main/java/org/hibernate/sql/ast/common/AbstractToken.java
core/branches/antlr3/src/main/java/org/hibernate/sql/ast/common/CommonHibernateLexer.java
core/branches/antlr3/src/main/java/org/hibernate/sql/ast/common/Node.java
core/branches/antlr3/src/main/java/org/hibernate/sql/ast/common/NodeFactory.java
core/branches/antlr3/src/main/java/org/hibernate/sql/ast/common/NumericLiteralToken.java
core/branches/antlr3/src/main/java/org/hibernate/sql/ast/common/TokenImpl.java
core/branches/antlr3/src/main/java/org/hibernate/sql/ast/ordering/OrderByFragmentRenderer.java
core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/
core/branches/antlr3/src/main/java/org/hibernate/sql/ast/util/PathHelper.java
Modified:
core/branches/antlr3/pom.xml
core/branches/antlr3/src/main/antlr3/org/hibernate/sql/ast/ordering/OrderByParser.g
core/branches/antlr3/src/main/java/org/hibernate/loader/criteria/CriteriaQueryTranslator.java
core/branches/antlr3/src/main/java/org/hibernate/sql/ast/common/JoinType.java
core/branches/antlr3/src/main/java/org/hibernate/sql/ast/ordering/OrderByFragmentParser.java
core/branches/antlr3/src/main/java/org/hibernate/sql/ast/ordering/OrderByFragmentTranslator.java
Log:
clean up toward a buildable project (still have few issues)
Modified: core/branches/antlr3/pom.xml
===================================================================
--- core/branches/antlr3/pom.xml 2009-04-16 00:41:18 UTC (rev 16349)
+++ core/branches/antlr3/pom.xml 2009-04-16 01:16:21 UTC (rev 16350)
@@ -182,7 +182,7 @@
<plugin>
<groupId>org.antlr</groupId>
<artifactId>antlr3-maven-plugin</artifactId>
- <version>3.1.3</version>
+ <version>3.1.3-steve</version>
<configuration>
</configuration>
<executions>
Modified:
core/branches/antlr3/src/main/antlr3/org/hibernate/sql/ast/ordering/OrderByParser.g
===================================================================
---
core/branches/antlr3/src/main/antlr3/org/hibernate/sql/ast/ordering/OrderByParser.g 2009-04-16
00:41:18 UTC (rev 16349)
+++
core/branches/antlr3/src/main/antlr3/org/hibernate/sql/ast/ordering/OrderByParser.g 2009-04-16
01:16:21 UTC (rev 16350)
@@ -64,122 +64,96 @@
}
@parser::members {
- private final TranslationContext context;
-
-// public OrderByParserParser(TokenStream input, TranslationContext context) {
-// super( input );
-// this.context = context;
-// }
-
/**
* Process the given node as a quote identifier. These need to be quoted in the
dialect-specific way.
*
* @param ident The quoted-identifier node.
*
* @return The processed node.
- *
- * @see org.hibernate.dialect.Dialect#quote
*/
protected CommonTree quotedIdentifier(CommonTree ident) {
- String quotedText = Template.TEMPLATE + "." + context.getDialect().quote(
'`' + ident.getText() + '`' );
- return createTreeNode( ident.getToken().getType(), quotedText );
+ // here we assume single-quote as the identifier quote character...
+ return createTreeNode( IDENTIFIER, Template.TEMPLATE + ".'" +
ident.getText() + "'" );
}
+
/**
* Process the given node as a quote string.
*
- * @param ident The quoted string. This is used from within function param
recognition, and represents a
+ * @param token The quoted string. This is used from within function param
recognition, and represents a
* SQL-quoted string.
*
* @return The processed node.
*/
- protected CommonTree quotedString(CommonTree ident) {
- String quotedText = context.getDialect().quote( ident.getText() );
- return createTreeNode( ident.getToken().getType(), quotedText );
+ protected CommonTree quotedString(Token token) {
+ return createTreeNode( STRING_LITERAL, "'" + token.getText() +
"'" );
}
/**
* A check to see if the text of the given node represents a known function name.
*
- * @param ast The node whose text we want to check.
+ * @param token The node whose text we want to check.
*
* @return True if the node's text is a known function name, false otherwise.
*
* @see org.hibernate.dialect.function.SQLFunctionRegistry
*/
- protected boolean isFunctionName(CommonToken token) {
- return context.getSqlFunctionRegistry().hasFunction( token.getText() );
+ protected boolean isFunctionName(Token token) {
+ return false;
}
/**
+ * Process the given node as a function name. Differs from {@link
#resolveFunction(org.antlr.runtime.tree.CommonTree)
+ * specifically in that here we are expecting just a function name without parens or
arguments.
+ *
+ * @param token The token representing the function name.
+ *
+ * @return The processed node.
+ */
+ protected CommonTree resolveFunction(Token token) {
+ return resolveFunction( new CommonTree( token ) );
+ }
+
+ /**
* Process the given node as a function.
*
- * @param The node representing the function invocation (including parameters as
subtree components).
+ * @param tree The node representing the function invocation (including parameters as
subtree components).
*
* @return The processed node.
*/
protected CommonTree resolveFunction(CommonTree tree) {
- // todo : handle sub functions?
- Tree parameters = tree.getChild(0);
- assert EXPR_LIST == parameters.getType();
+ Tree argumentList = tree.getChild( 0 );
+ assert argumentList == null || "{param list}".equals( argumentList.getText()
);
- final String functionName = tree.getText();
- final SQLFunction function = context.getSqlFunctionRegistry().findSQLFunction(
functionName );
- if ( function == null ) {
- String text = functionName;
- if ( parameters.getChildCount() > 0 ) {
- text+= '(';
- for ( int i = 0, x = parameters.getChildCount(); i < x; i++ ) {
- text+= parameters.getChild(i).getText();
- if ( i < x ) {
- text+= ", ";
- }
- }
- text+= ')';
- }
- return createTreeNode( IDENT, text );
- }
- else {
- ArrayList expressions = new ArrayList();
- for ( int i = 0, x = parameters.getChildCount(); i < x; i++ ) {
- expressions.add( parameters.getChild(i).getText() );
- }
- final String text = function.render( expressions, context.getSessionFactory() );
- return createTreeNode( IDENT, text );
- }
+ String text = tree.getText();
+ int count = argumentList == null ? 0 : argumentList.getChildCount();
+ if ( count > 0 ) {
+ text += '(';
+ for ( int i = 0; i < count; i++ ) {
+ Tree argument = argumentList.getChild( i );
+ text += argument.getText();
+ if ( i < count ) {
+ text += ", ";
+ }
+ }
+ text += ')';
+ }
+ return createTreeNode( IDENTIFIER, text );
}
+ protected CommonTree resolveIdent(Token token) {
+ return resolveIdent( new CommonTree( token ) );
+ }
+
/**
- * Process the given node as an IDENT. May represent either a column reference or a
property reference.
+ * Process the given node as an IDENTIFIER. May represent either a column reference
or a property reference.
*
* @param ident The node whose text represents either a column or property
reference.
*
* @return The processed node.
*/
protected CommonTree resolveIdent(CommonTree ident) {
- String text = ident.getText();
- String[] replacements;
- try {
- replacements = context.getColumnMapper().map( text );
- }
- catch( Throwable t ) {
- replacements = null;
- }
-
- if ( replacements == null || replacements.length == 0 ) {
- return createTreeNode( IDENT, Template.TEMPLATE + "." + text );
- }
- else if ( replacements.length == 1 ) {
- return createTreeNode( IDENT, Template.TEMPLATE + "." + replacements[0] );
- }
- else {
- final CommonTree root = createTreeNode( IDENT_LIST, "{ident list}" );
- for ( int i = 0; i < replacements.length; i++ ) {
- final String identText = Template.TEMPLATE + '.' + replacements[i];
- root.addChild( createTreeNode( IDENT, identText ) );
- }
- return root;
- }
+ return createTreeNode( IDENTIFIER, Template.TEMPLATE + "." +
ident.getText() );
}
private boolean validateIdentifierAsKeyword(String text) {
@@ -199,8 +173,8 @@
return token == null ? null : token.getText();
}
- private CommonTree createTreeNode(int type, String text) {
- return new CommonTree( CommonToken( type, text ) );
+ protected CommonTree createTreeNode(int type, String text) {
+ return new CommonTree( new CommonToken( type, text ) );
}
}
@@ -238,15 +212,15 @@
*/
expression
: hardQuoteExpression
- | ( IDENT ('.' IDENT)* OPEN_PAREN ) => functionCall
+ | ( IDENTIFIER ('.' IDENTIFIER)* OPEN_PAREN ) => functionCall
| simplePropertyPath
- | i=IDENT -> {isFunctionName($i)}? { resolveFunction( i ) }
- -> { resolveIdent( i ) }
+ | IDENTIFIER -> {isFunctionName($IDENTIFIER)}? { resolveFunction( $IDENTIFIER )
}
+ -> { resolveIdent( $IDENTIFIER ) }
;
hardQuoteExpression
@after { $tree = quotedIdentifier( $tree ); }
- : HARD_QUOTE IDENT HARD_QUOTE -> IDENT
+ : HARD_QUOTE IDENTIFIER HARD_QUOTE -> IDENTIFIER
;
/**
@@ -258,10 +232,10 @@
;
/**
- * A function-name is an IDENT followed by zero or more (DOT IDENT) sequences
+ * A function-name is an IDENTIFIER followed by zero or more (DOT IDENTIFIER) sequences
*/
functionName returns [String nameText]
- : i=IDENT { $nameText = $i.text; } ( '.' i=IDENT { $nameText += ( '.' +
$i.text ); } )+
+ : i=IDENTIFIER { $nameText = $i.text; } ( '.' i=IDENTIFIER { $nameText += (
'.' + $i.text ); } )+
;
/**
@@ -278,7 +252,7 @@
functionParameter :
expression
| numericLiteral
- | qs=QUOTED_STRING -> { quotedString( $qs ) }
+ | qs=STRING_LITERAL -> { quotedString( $qs ) }
;
numericLiteral
@@ -298,7 +272,7 @@
;
collateKeyword
- : {(validateIdentifierAsKeyword("collate"))}?=> id=IDENT
+ : {(validateIdentifierAsKeyword("collate"))}?=> id=IDENTIFIER
-> COLLATE[$id]
;
@@ -307,7 +281,7 @@
* The collation name wrt {@link #collationSpecification}. Namely, the character-set.
*/
collationName
- : IDENT
+ : IDENTIFIER
;
/**
@@ -320,69 +294,72 @@
;
/**
- * A simple-property-path is an IDENT followed by one or more (DOT IDENT) sequences
+ * A simple-property-path is an IDENTIFIER followed by one or more (DOT IDENTIFIER)
sequences
*/
simplePropertyPath
@after { $tree = resolveIdent($tree); }
- : p=simplePropertyPathText -> { createTreeNode(IDENT, $p.pathText) }
+ : p=simplePropertyPathText -> { createTreeNode(IDENTIFIER, $p.pathText) }
;
simplePropertyPathText returns [String pathText]
- : i=IDENT { $pathText = $i.text; } ( '.' i=IDENT { $pathText += ( '.' +
$i.text ); } )+
+ : i=IDENTIFIER { $pathText = $i.text; } ( '.' i=IDENTIFIER { $pathText += (
'.' + $i.text ); } )+
;
// Lexer rules
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-WS : (NEWLINE | SPACE | '\u000C') { $channel=HIDDEN; } ;
+WS
+ : (SPACE | EOL | '\u000C') { $channel=HIDDEN; }
+ ;
fragment
-NEWLINE :
- ( '\r' (options{greedy=true;}: '\n')? | '\n' )
-;
+EOL
+ : ( '\r' (options{greedy=true;}: '\n')? | '\n' )
+ ;
fragment
-SPACE :
- ' ' | '\t'
-;
+SPACE
+ : ' '
+ | '\t'
+ ;
-OPEN_PAREN : '(';
-CLOSE_PAREN : ')';
+OPEN_PAREN
+ : '('
+ ;
+CLOSE_PAREN
+ : ')'
+ ;
-COMMA : ',';
+COMMA
+ : ','
+ ;
-HARD_QUOTE : '`';
+HARD_QUOTE
+ : '`'
+ ;
-IDENT : ID ;
+INTEGER_LITERAL
+ : (
+ '0'
+ | '1'..'9' ('0'..'9')*
+ )
+ ;
-fragment
-ID : ID_START_FRAGMENT ( ID_FRAGMENT )* ;
+DECIMAL_LITERAL : ('0' | '1'..'9' '0'..'9'*)
INTEGER_TYPE_SUFFIX ;
-fragment
-ID_START_FRAGMENT
- : '_'
- | '$'
- | 'a'..'z'
- | '\u0080'..'\ufffe'
- ;
+HEX_LITERAL
+ : '0' ('x'|'X') HEX_DIGIT+ INTEGER_TYPE_SUFFIX?
+ ;
-fragment
-ID_FRAGMENT
- : ID_START_FRAGMENT
- | '0'..'9'
- ;
+OCTAL_LITERAL : '0' ('0'..'7')+ INTEGER_TYPE_SUFFIX? ;
-HEX_LITERAL : '0' ('x'|'X')
('0'..'9'|'a'..'f'|'A'..'F')+
INTEGRAL_TYPE_SUFFIX? ;
-OCTAL_LITERAL : '0' ('0'..'7')+ INTEGRAL_TYPE_SUFFIX? ;
+fragment
+HEX_DIGIT : ('0'..'9'|'a'..'f'|'A'..'F')
;
-DECIMAL_LITERAL : ('0' | '1'..'9' '0'..'9'*)
INTEGRAL_TYPE_SUFFIX? ;
-
fragment
-INTEGRAL_TYPE_SUFFIX
- : ('l'|'L')
- ;
+INTEGER_TYPE_SUFFIX : ('l'|'L') ;
FLOATING_POINT_LITERAL
: ('0'..'9')+ '.' ('0'..'9')* EXPONENT?
FLOAT_TYPE_SUFFIX?
@@ -397,14 +374,42 @@
fragment
FLOAT_TYPE_SUFFIX : ('f'|'F'|'d'|'D') ;
-QUOTED_STRING :
- ('\'' (options{greedy=true;}: ~('\'' | '\r' |
'\n') | '\'' '\'' | NEWLINE)* '\'' )+
-;
-/**
- * Recognize either double-quote (") or back-tick (`) as delimiting a quoted
identifier
- */
-QUOTED_IDENT :
- '"' (~('"' | '\r' | '\n') |
'"' '"')+ '"'
- | '`' (~('`' | '\r' | '\n') | '`'
'`')+ '`'
-;
+STRING_LITERAL
+ : '\'' ( ESCAPE_SEQUENCE | ~('\''|'\\') )
'\''
+ ;
+
+fragment
+ESCAPE_SEQUENCE
+ : '\\'
('b'|'t'|'n'|'f'|'r'|'\"'|'\''|'\\')
+ | UNICODE_ESCAPE
+ | OCTAL_ESCAPE
+ ;
+
+fragment
+OCTAL_ESCAPE
+ : '\\' ('0'..'3') ('0'..'7')
('0'..'7')
+ | '\\' ('0'..'7') ('0'..'7')
+ | '\\' ('0'..'7')
+ ;
+
+fragment
+UNICODE_ESCAPE
+ : '\\' 'u' HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT
+ ;
+
+IDENTIFIER
+ : IDENTIFIER_START_FRAGMENT (IDENTIFER_FRAGMENT)*
+ ;
+
+fragment
+IDENTIFIER_START_FRAGMENT
+ :
('a'..'z'|'A'..'Z'|'_'|'$'|'\u0080'..'\ufffe')
+ ;
+
+fragment
+IDENTIFER_FRAGMENT
+ : IDENTIFIER_START_FRAGMENT
+ | '0'..'9'
+ ;
+
Modified:
core/branches/antlr3/src/main/java/org/hibernate/loader/criteria/CriteriaQueryTranslator.java
===================================================================
---
core/branches/antlr3/src/main/java/org/hibernate/loader/criteria/CriteriaQueryTranslator.java 2009-04-16
00:41:18 UTC (rev 16349)
+++
core/branches/antlr3/src/main/java/org/hibernate/loader/criteria/CriteriaQueryTranslator.java 2009-04-16
01:16:21 UTC (rev 16350)
@@ -41,7 +41,6 @@
import org.hibernate.LockMode;
import org.hibernate.MappingException;
import org.hibernate.QueryException;
-import org.hibernate.hql.ast.util.SessionFactoryHelper;
import org.hibernate.criterion.CriteriaQuery;
import org.hibernate.criterion.Projection;
import org.hibernate.engine.QueryParameters;
@@ -509,7 +508,7 @@
// Detect discriminator values...
if ( value instanceof Class ) {
Class entityClass = ( Class ) value;
- Queryable q = SessionFactoryHelper.findQueryableUsingImports( sessionFactory,
entityClass.getName() );
+ Queryable q = findQueryableUsingImports( entityClass.getName() );
if ( q != null ) {
Type type = q.getDiscriminatorType();
String stringValue = q.getDiscriminatorSQLValue();
@@ -536,6 +535,26 @@
);
}
+
+ /**
+ * Given a (potentially unqualified) class name, locate its persister.
+ *
+ * @param className The (potentially unqualified) class name.
+ * @return The defined persister for this class, or null if none found.
+ */
+ private Queryable findQueryableUsingImports(String className) {
+ final String importedClassName = sessionFactory.getImportedClassName( className );
+ if ( importedClassName == null ) {
+ return null;
+ }
+ try {
+ return ( Queryable ) sessionFactory.getEntityPersister( importedClassName );
+ }
+ catch ( MappingException me ) {
+ return null;
+ }
+ }
+
private PropertyMapping getPropertyMapping(String entityName)
throws MappingException {
return ( PropertyMapping ) sessionFactory.getEntityPersister( entityName );
Deleted:
core/branches/antlr3/src/main/java/org/hibernate/sql/ast/common/AbstractToken.java
===================================================================
---
core/branches/antlr3/src/main/java/org/hibernate/sql/ast/common/AbstractToken.java 2009-04-16
00:41:18 UTC (rev 16349)
+++
core/branches/antlr3/src/main/java/org/hibernate/sql/ast/common/AbstractToken.java 2009-04-16
01:16:21 UTC (rev 16350)
@@ -1,77 +0,0 @@
-/*
- * Hibernate, Relational Persistence for Idiomatic Java
- *
- * Copyright (c) 2008, 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,
- * copy, or redistribute it subject to the terms and conditions of the GNU
- * 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
- * for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this distribution; if not, write to:
- * Free Software Foundation, Inc.
- * 51 Franklin Street, Fifth Floor
- * Boston, MA 02110-1301 USA
- */
-package org.hibernate.sql.ast.common;
-
-/**
- * TODO : javadoc
- *
- * @author Steve Ebersole
- */
-public abstract class AbstractToken extends antlr.CommonToken {
- private int previousTokenType;
-
- /**
- * Getter for property 'previousTokenType'.
- *
- * @return Value for property 'previousTokenType'.
- */
- public int getPreviousTokenType() {
- return previousTokenType;
- }
-
- /**
- * {@inheritDoc}
- */
- public void setType(int type) {
- this.previousTokenType = getType();
- super.setType( type );
- }
-
- /**
- * {@inheritDoc}
- */
- public String toDisplayString() {
- StringBuffer text = new StringBuffer( super.toString() );
- text.append( "['" )
- .append( getText() )
- .append( "', <" )
- .append( getType() )
- .append( "> previously: <" )
- .append( getPreviousTokenType() )
- .append( ">, line=" )
- .append( line )
- .append( ", col=" )
- .append( col );
- appendTextualInfo( text );
- text.append( "]" );
- return text.toString();
- }
-
- protected void appendTextualInfo(StringBuffer text) {
- }
-
- public String getLocation() {
- return getLine() + ":" + getColumn();
- }
-}
Deleted:
core/branches/antlr3/src/main/java/org/hibernate/sql/ast/common/CommonHibernateLexer.java
===================================================================
---
core/branches/antlr3/src/main/java/org/hibernate/sql/ast/common/CommonHibernateLexer.java 2009-04-16
00:41:18 UTC (rev 16349)
+++
core/branches/antlr3/src/main/java/org/hibernate/sql/ast/common/CommonHibernateLexer.java 2009-04-16
01:16:21 UTC (rev 16350)
@@ -1,70 +0,0 @@
-/*
- * Hibernate, Relational Persistence for Idiomatic Java
- *
- * Copyright (c) 2008, 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,
- * copy, or redistribute it subject to the terms and conditions of the GNU
- * 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
- * for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this distribution; if not, write to:
- * Free Software Foundation, Inc.
- * 51 Franklin Street, Fifth Floor
- * Boston, MA 02110-1301 USA
- */
-package org.hibernate.sql.ast.common;
-
-import java.io.InputStream;
-import java.io.Reader;
-
-/**
- * The common lexer for Hibernate stream parsers.
- *
- * @author Steve Ebersole
- */
-public class CommonHibernateLexer extends CommonHibernateLexerSupport {
- private boolean possibleIdentifier = false;
-
- public CommonHibernateLexer(InputStream in) {
- super( in );
- super.setTokenObjectClass( TokenImpl.class.getName() );
- }
-
- public CommonHibernateLexer(Reader in) {
- super( in );
- super.setTokenObjectClass( TokenImpl.class.getName() );
- }
-
- public void setTokenObjectClass(String s) {
- // no-op, we've already set ours in the constructor
- }
-
- protected void setPossibleIdentifier(boolean possibleIdentifier) {
- this.possibleIdentifier = possibleIdentifier;
- }
-
- protected antlr.Token makeToken(int i) {
- TokenImpl token = ( TokenImpl ) super.makeToken( i );
- token.setPossibleIdentifier( possibleIdentifier );
- possibleIdentifier = false;
- return token;
- }
-
- public void panic() {
- panic("CharScanner: panic");
- }
-
- public void panic(String s) {
- // todo : better exception type?
- throw new PanicException( s );
- }
-}
Modified: core/branches/antlr3/src/main/java/org/hibernate/sql/ast/common/JoinType.java
===================================================================
---
core/branches/antlr3/src/main/java/org/hibernate/sql/ast/common/JoinType.java 2009-04-16
00:41:18 UTC (rev 16349)
+++
core/branches/antlr3/src/main/java/org/hibernate/sql/ast/common/JoinType.java 2009-04-16
01:16:21 UTC (rev 16350)
@@ -3,8 +3,6 @@
import java.io.Serializable;
import java.util.HashMap;
-import org.hibernate.sql.ast.util.ASTUtil;
-
/**
* Represents a canonical join type.
* <p/>
@@ -62,25 +60,25 @@
return INSTANCES.get( name );
}
- public static JoinType resolve(Node node) {
- switch ( node.getType() ) {
- case Sql92TokenTypes.INNER :
- return JoinType.INNER;
- case Sql92TokenTypes.LEFT :
- return JoinType.LEFT;
- case Sql92TokenTypes.RIGHT :
- return JoinType.RIGHT;
- case Sql92TokenTypes.CROSS :
- return JoinType.CROSS;
- case Sql92TokenTypes.FULL :
- return JoinType.FULL;
- default :
- throw new IllegalArgumentException(
- "Cannot resolve join-type node [type=" +
- ASTUtil.getTokenTypeName( Sql92TokenTypes.class, node.getType() ) +
- ", text=" + node.getText() +
- "]"
- );
- }
- }
+// public static JoinType resolve(Node node) {
+// switch ( node.getType() ) {
+// case Sql92TokenTypes.INNER :
+// return JoinType.INNER;
+// case Sql92TokenTypes.LEFT :
+// return JoinType.LEFT;
+// case Sql92TokenTypes.RIGHT :
+// return JoinType.RIGHT;
+// case Sql92TokenTypes.CROSS :
+// return JoinType.CROSS;
+// case Sql92TokenTypes.FULL :
+// return JoinType.FULL;
+// default :
+// throw new IllegalArgumentException(
+// "Cannot resolve join-type node [type=" +
+// ASTUtil.getTokenTypeName( Sql92TokenTypes.class, node.getType() ) +
+// ", text=" + node.getText() +
+// "]"
+// );
+// }
+// }
}
Deleted: core/branches/antlr3/src/main/java/org/hibernate/sql/ast/common/Node.java
===================================================================
--- core/branches/antlr3/src/main/java/org/hibernate/sql/ast/common/Node.java 2009-04-16
00:41:18 UTC (rev 16349)
+++ core/branches/antlr3/src/main/java/org/hibernate/sql/ast/common/Node.java 2009-04-16
01:16:21 UTC (rev 16350)
@@ -1,104 +0,0 @@
-/*
- * Hibernate, Relational Persistence for Idiomatic Java
- *
- * Copyright (c) 2008, 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,
- * copy, or redistribute it subject to the terms and conditions of the GNU
- * 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
- * for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this distribution; if not, write to:
- * Free Software Foundation, Inc.
- * 51 Franklin Street, Fifth Floor
- * Boston, MA 02110-1301 USA
- */
-package org.hibernate.sql.ast.common;
-
-import antlr.Token;
-import antlr.collections.AST;
-
-/**
- * Basic AST node
- *
- * @author Joshua Davis
- * @author Steve Ebersole
- */
-public class Node extends antlr.CommonAST {
- private String filename;
- private int line;
- private int column;
-
- public Node() {
- super();
- }
-
- public Node(Token tok) {
- super( tok ); // NOTE: This will call initialize(tok)!
- }
-
- /**
- * Retrieve the textual representation of a node to be used in the resulting sql.
- * <p/>
- * This is intended for subclasses to override to allow certain nodes to provide their
own renderable representation
- * instead of the default {@link antlr.collections.AST#getText()}.
- *
- * @return The renderable text.
- */
- public String getRenderableText() {
- return getText();
- }
-
- public void initialize(Token token) {
- super.initialize( token );
- // Propagate line/column information from the lexer during
- // stream parsing.
- filename = token.getFilename();
- line = token.getLine();
- column = token.getColumn();
- }
-
- public void initialize(AST ast) {
- super.initialize( ast );
- if ( ast instanceof Node ) {
- // Propagate line/column information from the source AST during tree walking.
- transferTrackingInfo( ( Node ) ast );
- }
- }
-
- public void transferTrackingInfo(AST ast) {
- if ( ast instanceof Node ) {
- transferTrackingInfo( ( Node ) ast );
- }
- else {
- line = ast.getLine();
- column = ast.getColumn();
- }
- }
-
- public void transferTrackingInfo(Node node) {
- filename = node.filename;
- line = node.line;
- column = node.column;
- }
-
- public String getFilename() {
- return filename;
- }
-
- public int getLine() {
- return line;
- }
-
- public int getColumn() {
- return column;
- }
-}
Deleted: core/branches/antlr3/src/main/java/org/hibernate/sql/ast/common/NodeFactory.java
===================================================================
---
core/branches/antlr3/src/main/java/org/hibernate/sql/ast/common/NodeFactory.java 2009-04-16
00:41:18 UTC (rev 16349)
+++
core/branches/antlr3/src/main/java/org/hibernate/sql/ast/common/NodeFactory.java 2009-04-16
01:16:21 UTC (rev 16350)
@@ -1,52 +0,0 @@
-/*
- * Hibernate, Relational Persistence for Idiomatic Java
- *
- * Copyright (c) 2008, 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,
- * copy, or redistribute it subject to the terms and conditions of the GNU
- * 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
- * for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this distribution; if not, write to:
- * Free Software Foundation, Inc.
- * 51 Franklin Street, Fifth Floor
- * Boston, MA 02110-1301 USA
- */
-package org.hibernate.sql.ast.common;
-
-import antlr.ASTFactory;
-
-/**
- * An {@link ASTFactory} which includes line/column tracking information into its
generated
- * {@link antlr.collections.AST nodes}.
- *
- * @author Joshua Davis
- * @author Steve Ebersole
- */
-public class NodeFactory extends ASTFactory {
- /**
- * Determine the default {@link antlr.collections.AST node} class to use. Used from
within
- * {@link #getASTNodeType(int)} when no specific override is defined/needed for a
particular token type.
- *
- * @return The default {@link antlr.collections.AST node} class to use
- */
- protected Class determineDefaultNodeClass() {
- return Node.class;
- }
-
- /**
- * {@inheritDoc}
- */
- public Class getASTNodeType(int tokenType) {
- return determineDefaultNodeClass();
- }
-}
Deleted:
core/branches/antlr3/src/main/java/org/hibernate/sql/ast/common/NumericLiteralToken.java
===================================================================
---
core/branches/antlr3/src/main/java/org/hibernate/sql/ast/common/NumericLiteralToken.java 2009-04-16
00:41:18 UTC (rev 16349)
+++
core/branches/antlr3/src/main/java/org/hibernate/sql/ast/common/NumericLiteralToken.java 2009-04-16
01:16:21 UTC (rev 16350)
@@ -1,50 +0,0 @@
-/*
- * Hibernate, Relational Persistence for Idiomatic Java
- *
- * Copyright (c) 2008, 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,
- * copy, or redistribute it subject to the terms and conditions of the GNU
- * 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
- * for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this distribution; if not, write to:
- * Free Software Foundation, Inc.
- * 51 Franklin Street, Fifth Floor
- * Boston, MA 02110-1301 USA
- */
-package org.hibernate.sql.ast.common;
-
-/**
- * A custom token class for representing numeric literals. The reasoning is that there
are 2 classifications
- * by which we need to identify numeric literals:<ol>
- * <li>The SQL notions of <tt>exact</tt> and
<tt>approximate</tt></li>
- * <li>The java language types (i.e. <tt>int</tt>,
<tt>long</tt>, etc)</li>
- * </ol>
- * <p/>
- * Explicitly handling the intersection of these two classification sets is unwieldy
(EXACT_INTEGER_LITERAL, etc) so
- * we instead track one classification by the token-types, and the other is tracked by
state on the token. Since we
- * generally need to treat with the java types, we use this custom token to track whether
the literal is <tt>exact</tt>
- * or <tt>approximate</tt>.
- *
- * @author Steve Ebersole
- */
-public class NumericLiteralToken extends AbstractToken {
- private boolean isApproximate = false; // assume exact
-
- public boolean isApproximate() {
- return isApproximate;
- }
-
- public void setApproximate(boolean approximate) {
- isApproximate = approximate;
- }
-}
Deleted: core/branches/antlr3/src/main/java/org/hibernate/sql/ast/common/TokenImpl.java
===================================================================
---
core/branches/antlr3/src/main/java/org/hibernate/sql/ast/common/TokenImpl.java 2009-04-16
00:41:18 UTC (rev 16349)
+++
core/branches/antlr3/src/main/java/org/hibernate/sql/ast/common/TokenImpl.java 2009-04-16
01:16:21 UTC (rev 16350)
@@ -1,58 +0,0 @@
-/*
- * Hibernate, Relational Persistence for Idiomatic Java
- *
- * Copyright (c) 2008, 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,
- * copy, or redistribute it subject to the terms and conditions of the GNU
- * 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
- * for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this distribution; if not, write to:
- * Free Software Foundation, Inc.
- * 51 Franklin Street, Fifth Floor
- * Boston, MA 02110-1301 USA
- */
-package org.hibernate.sql.ast.common;
-
-/**
- * A custom token class for various Hibernate lexers; specifically we are adding the
- * {@link #isPossibleIdentifier() keyword-as-identifier} capability and tracking of any
changes in token types
- * via {@link #getPreviousTokenType()}.
- *
- * @author Steve Ebersole
- */
-public class TokenImpl extends AbstractToken {
- private boolean possibleIdentifier;
-
- /**
- * Getter for property 'possibleIdentifier'.
- *
- * @return Value for property 'possibleIdentifier'.
- */
- public boolean isPossibleIdentifier() {
- return possibleIdentifier;
- }
-
- /**
- * Setter for property 'possibleIdentifier'.
- *
- * @param possibleIdentifier Value to set for property 'possibleIdentifier'.
- */
- public void setPossibleIdentifier(boolean possibleIdentifier) {
- this.possibleIdentifier = possibleIdentifier;
- }
-
- protected void appendTextualInfo(StringBuffer text) {
- text.append( ",possibleIdentifier?=" ).append( possibleIdentifier );
- }
-
-}
Modified:
core/branches/antlr3/src/main/java/org/hibernate/sql/ast/ordering/OrderByFragmentParser.java
===================================================================
---
core/branches/antlr3/src/main/java/org/hibernate/sql/ast/ordering/OrderByFragmentParser.java 2009-04-16
00:41:18 UTC (rev 16349)
+++
core/branches/antlr3/src/main/java/org/hibernate/sql/ast/ordering/OrderByFragmentParser.java 2009-04-16
01:16:21 UTC (rev 16350)
@@ -26,24 +26,23 @@
import java.util.ArrayList;
-import antlr.TokenStream;
-import antlr.CommonAST;
-import antlr.TokenStreamException;
-import antlr.collections.AST;
-
import org.hibernate.sql.Template;
import org.hibernate.dialect.function.SQLFunction;
import org.hibernate.util.StringHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.antlr.runtime.TokenStream;
+import org.antlr.runtime.CommonToken;
+import org.antlr.runtime.tree.CommonTree;
+import org.antlr.runtime.tree.Tree;
/**
* Extension of the Antlr-generated parser for the purpose of adding our custom parsing
behavior.
*
* @author Steve Ebersole
*/
-public class OrderByFragmentParser extends GeneratedOrderByFragmentParser {
+public class OrderByFragmentParser extends OrderByParserParser {
private static final Logger log = LoggerFactory.getLogger( OrderByFragmentParser.class
);
private final TranslationContext context;
@@ -51,98 +50,80 @@
public OrderByFragmentParser(TokenStream lexer, TranslationContext context) {
super( lexer );
- super.setASTFactory( new Factory() );
this.context = context;
}
+//
+//
+// // handle trace logging
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+//
+// public void traceIn(String ruleName) throws TokenStreamException {
+// if ( inputState.guessing > 0 ) {
+// return;
+// }
+// String prefix = StringHelper.repeat( "-", (traceDepth++ * 2) ) +
"->";
+// trace( prefix + ruleName );
+// }
+//
+// public void traceOut(String ruleName) throws TokenStreamException {
+// if ( inputState.guessing > 0 ) {
+// return;
+// }
+// String prefix = "<-" + StringHelper.repeat( "-", (--traceDepth
* 2) );
+// trace( prefix + ruleName );
+// }
+//
+// private void trace(String msg) {
+// log.trace( msg );
+// }
+protected CommonTree quotedIdentifier(CommonTree ident) {
+ return createTreeNode( IDENTIFIER, Template.TEMPLATE + "." +
context.getDialect().quote( '`' + ident.getText() + '`' ) );
+}
- // handle trace logging
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-
- public void traceIn(String ruleName) throws TokenStreamException {
- if ( inputState.guessing > 0 ) {
- return;
- }
- String prefix = StringHelper.repeat( "-", (traceDepth++ * 2) ) +
"->";
- trace( prefix + ruleName );
+ protected CommonTree quotedString(CommonTree ident) {
+ return createTreeNode( IDENTIFIER, context.getDialect().quote( ident.getText() ) );
}
- public void traceOut(String ruleName) throws TokenStreamException {
- if ( inputState.guessing > 0 ) {
- return;
- }
- String prefix = "<-" + StringHelper.repeat( "-", (--traceDepth *
2) );
- trace( prefix + ruleName );
- }
+ protected boolean isFunctionName(CommonToken token) {
+ return context.getSqlFunctionRegistry().hasFunction( token.getText() );
+ }
- private void trace(String msg) {
- log.trace( msg );
- }
+ protected CommonTree resolveFunction(CommonTree tree) {
+ Tree argumentList = tree.getChild( 0 );
+ assert "{param list}".equals( argumentList.getText() );
-
- /**
- * {@inheritDoc}
- */
- protected AST quotedIdentifier(AST ident) {
- return getASTFactory().create(
- IDENT,
- Template.TEMPLATE + "." + context.getDialect().quote( '`' +
ident.getText() + '`' )
- );
- }
-
- /**
- * {@inheritDoc}
- */
- protected AST quotedString(AST ident) {
- return getASTFactory().create( IDENT, context.getDialect().quote( ident.getText() ) );
- }
-
- /**
- * {@inheritDoc}
- */
- protected boolean isFunctionName(AST ast) {
- return context.getSqlFunctionRegistry().hasFunction( ast.getText() );
- }
-
- /**
- * {@inheritDoc}
- */
- protected AST resolveFunction(AST ast) {
- AST child = ast.getFirstChild();
- assert "{param list}".equals( child.getText() );
- child = child.getFirstChild();
-
- final String functionName = ast.getText();
+ final String functionName = tree.getText();
final SQLFunction function = context.getSqlFunctionRegistry().findSQLFunction(
functionName );
+
if ( function == null ) {
+ // If the function is not registered with the session factory we just need to
render it as-is
+ // including its arguments...
String text = functionName;
- if ( child != null ) {
- text += '(';
- while ( child != null ) {
- text += child.getText();
- child = child.getNextSibling();
- if ( child != null ) {
- text += ", ";
- }
- }
- text += ')';
- }
- return getASTFactory().create( IDENT, text );
+ int count = argumentList.getChildCount();
+ if ( count > 0 ) {
+ text += '(';
+ for ( int i = 0; i < count; i++ ) {
+ Tree argument = argumentList.getChild( i );
+ text += argument.getText();
+ if ( i < count ) {
+ text += ", ";
+ }
+ }
+ text += ')';
+ }
+ return createTreeNode( IDENTIFIER, text );
}
else {
ArrayList expressions = new ArrayList();
- while ( child != null ) {
- expressions.add( child.getText() );
- child = child.getNextSibling();
- }
+ for ( int i = 0; i < argumentList.getChildCount(); i++ ) {
+ expressions.add( argumentList.getChild( i ).getText() );
+ }
final String text = function.render( expressions, context.getSessionFactory() );
- return getASTFactory().create( IDENT, text );
+ return createTreeNode( IDENTIFIER, text );
}
}
- /**
- * {@inheritDoc}
- */
- protected AST resolveIdent(AST ident) {
+ protected CommonTree resolveIdent(CommonTree ident) {
String text = ident.getText();
String[] replacements;
try {
@@ -153,62 +134,62 @@
}
if ( replacements == null || replacements.length == 0 ) {
- return getASTFactory().create( IDENT, Template.TEMPLATE + "." + text );
+ return createTreeNode( IDENTIFIER, Template.TEMPLATE + "." + text );
}
else if ( replacements.length == 1 ) {
- return getASTFactory().create( IDENT, Template.TEMPLATE + "." +
replacements[0] );
+ return createTreeNode( IDENTIFIER, Template.TEMPLATE + "." + replacements[0]
);
}
else {
- final AST root = getASTFactory().create( IDENT_LIST, "{ident list}" );
+ final CommonTree root = createTreeNode( IDENT_LIST, "{ident list}"
);
for ( int i = 0; i < replacements.length; i++ ) {
final String identText = Template.TEMPLATE + '.' + replacements[i];
- root.addChild( getASTFactory().create( IDENT, identText ) );
+ root.addChild( createTreeNode( IDENTIFIER, identText ) );
}
return root;
}
}
-
- /**
- * {@inheritDoc}
- */
- protected AST postProcessSortSpecification(AST sortSpec) {
- assert SORT_SPEC == sortSpec.getType();
- SortSpecification sortSpecification = ( SortSpecification ) sortSpec;
- AST sortKey = sortSpecification.getSortKey();
- if ( IDENT_LIST == sortKey.getFirstChild().getType() ) {
- AST identList = sortKey.getFirstChild();
- AST ident = identList.getFirstChild();
- AST holder = new CommonAST();
- do {
- holder.addChild(
- createSortSpecification(
- ident,
- sortSpecification.getCollation(),
- sortSpecification.getOrdering()
- )
- );
- ident = ident.getNextSibling();
- } while ( ident != null );
- sortSpec = holder.getFirstChild();
- }
- return sortSpec;
- }
-
- private SortSpecification createSortSpecification(
- AST ident,
- CollationSpecification collationSpecification,
- OrderingSpecification orderingSpecification) {
- AST sortSpecification = getASTFactory().create( SORT_SPEC, "{{sort
specification}}" );
- AST sortKey = getASTFactory().create( SORT_KEY, "{{sort key}}" );
- AST newIdent = getASTFactory().create( ident.getType(), ident.getText() );
- sortKey.setFirstChild( newIdent );
- sortSpecification.setFirstChild( sortKey );
- if ( collationSpecification != null ) {
- sortSpecification.addChild( collationSpecification );
- }
- if ( orderingSpecification != null ) {
- sortSpecification.addChild( orderingSpecification );
- }
- return ( SortSpecification ) sortSpecification;
- }
+//
+// /**
+// * {@inheritDoc}
+// */
+// protected AST postProcessSortSpecification(AST sortSpec) {
+// assert SORT_SPEC == sortSpec.getType();
+// SortSpecification sortSpecification = ( SortSpecification ) sortSpec;
+// AST sortKey = sortSpecification.getSortKey();
+// if ( IDENT_LIST == sortKey.getFirstChild().getType() ) {
+// AST identList = sortKey.getFirstChild();
+// AST ident = identList.getFirstChild();
+// AST holder = new CommonAST();
+// do {
+// holder.addChild(
+// createSortSpecification(
+// ident,
+// sortSpecification.getCollation(),
+// sortSpecification.getOrdering()
+// )
+// );
+// ident = ident.getNextSibling();
+// } while ( ident != null );
+// sortSpec = holder.getFirstChild();
+// }
+// return sortSpec;
+// }
+//
+// private SortSpecification createSortSpecification(
+// AST ident,
+// CollationSpecification collationSpecification,
+// OrderingSpecification orderingSpecification) {
+// AST sortSpecification = getASTFactory().create( SORT_SPEC, "{{sort
specification}}" );
+// AST sortKey = getASTFactory().create( SORT_KEY, "{{sort key}}" );
+// AST newIdent = getASTFactory().create( ident.getType(), ident.getText() );
+// sortKey.setFirstChild( newIdent );
+// sortSpecification.setFirstChild( sortKey );
+// if ( collationSpecification != null ) {
+// sortSpecification.addChild( collationSpecification );
+// }
+// if ( orderingSpecification != null ) {
+// sortSpecification.addChild( orderingSpecification );
+// }
+// return ( SortSpecification ) sortSpecification;
+// }
}
Deleted:
core/branches/antlr3/src/main/java/org/hibernate/sql/ast/ordering/OrderByFragmentRenderer.java
===================================================================
---
core/branches/antlr3/src/main/java/org/hibernate/sql/ast/ordering/OrderByFragmentRenderer.java 2009-04-16
00:41:18 UTC (rev 16349)
+++
core/branches/antlr3/src/main/java/org/hibernate/sql/ast/ordering/OrderByFragmentRenderer.java 2009-04-16
01:16:21 UTC (rev 16350)
@@ -1,88 +0,0 @@
-/*
- * Hibernate, Relational Persistence for Idiomatic Java
- *
- * Copyright (c) 2008, 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,
- * copy, or redistribute it subject to the terms and conditions of the GNU
- * 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
- * for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this distribution; if not, write to:
- * Free Software Foundation, Inc.
- * 51 Franklin Street, Fifth Floor
- * Boston, MA 02110-1301 USA
- *
- */
-package org.hibernate.sql.ast.ordering;
-
-import antlr.collections.AST;
-
-import org.hibernate.sql.ast.common.Node;
-import org.hibernate.sql.ast.util.ASTPrinter;
-import org.hibernate.util.StringHelper;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * TODO : javadoc
- *
- * @author Steve Ebersole
- */
-public class OrderByFragmentRenderer extends GeneratedOrderByFragmentRenderer {
- private static final Logger log = LoggerFactory.getLogger( OrderByFragmentRenderer.class
);
-
- /**
- * {@inheritDoc}
- */
- protected void out(AST ast) {
- out( ( ( Node ) ast ).getRenderableText() );
- }
-
- // handle trace logging
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-
- private final ASTPrinter printer = new ASTPrinter( OrderByTemplateTokenTypes.class );
- private int traceDepth = 0;
-
- /**
- * {@inheritDoc}
- */
- public final void traceIn(String ruleName, AST tree) {
- if ( inputState.guessing > 0 ) {
- return;
- }
- String prefix = StringHelper.repeat( '-', (traceDepth++ * 2) ) + "->
";
- String traceText = ruleName + " (" + buildTraceNodeName(tree) +
")";
- traceExecution( prefix + traceText );
- }
-
- protected String buildTraceNodeName(AST tree) {
- return tree == null
- ? "???"
- : tree.getText() + " [" + printer.getTokenTypeName( tree.getType() ) +
"]";
- }
-
- /**
- * {@inheritDoc}
- */
- public final void traceOut(String ruleName, AST tree) {
- if ( inputState.guessing > 0 ) {
- return;
- }
- String prefix = "<-" + StringHelper.repeat( '-', (--traceDepth *
2) ) + " ";
- traceExecution( prefix + ruleName );
- }
-
- protected void traceExecution(String msg) {
- log.trace( msg );
- }
-}
Modified:
core/branches/antlr3/src/main/java/org/hibernate/sql/ast/ordering/OrderByFragmentTranslator.java
===================================================================
---
core/branches/antlr3/src/main/java/org/hibernate/sql/ast/ordering/OrderByFragmentTranslator.java 2009-04-16
00:41:18 UTC (rev 16349)
+++
core/branches/antlr3/src/main/java/org/hibernate/sql/ast/ordering/OrderByFragmentTranslator.java 2009-04-16
01:16:21 UTC (rev 16350)
@@ -30,7 +30,11 @@
import org.slf4j.LoggerFactory;
import org.hibernate.HibernateException;
-import org.hibernate.hql.ast.util.ASTPrinter;
+import org.hibernate.sql.ast.util.ASTPrinter;
+import org.antlr.runtime.CharStream;
+import org.antlr.runtime.TokenStream;
+import org.antlr.runtime.ANTLRStringStream;
+import org.antlr.runtime.CommonTokenStream;
/**
* A translator which coordinates translation of an <tt>order-by</tt>
mapping.
@@ -54,8 +58,8 @@
* @return The translated fragment.
*/
public String render(String fragment) {
- GeneratedOrderByLexer lexer = new GeneratedOrderByLexer( new StringReader( fragment )
);
- OrderByFragmentParser parser = new OrderByFragmentParser( lexer, context );
+ OrderByParserLexer lexer = new OrderByParserLexer( new ANTLRStringStream( fragment )
);
+ OrderByFragmentParser parser = new OrderByFragmentParser( new CommonTokenStream( lexer
), context );
try {
parser.orderByFragment();
}
@@ -66,22 +70,23 @@
throw new HibernateException( "Unable to parse order-by fragment", t );
}
- if ( log.isTraceEnabled() ) {
- ASTPrinter printer = new ASTPrinter( OrderByTemplateTokenTypes.class );
- log.trace( printer.showAsString( parser.getAST(), "--- {order-by fragment}
---" ) );
- }
-
- OrderByFragmentRenderer renderer = new OrderByFragmentRenderer();
- try {
- renderer.orderByFragment( parser.getAST() );
- }
- catch ( HibernateException e ) {
- throw e;
- }
- catch ( Throwable t ) {
- throw new HibernateException( "Unable to render parsed order-by fragment", t
);
- }
-
- return renderer.getRenderedFragment();
+// if ( log.isTraceEnabled() ) {
+// ASTPrinter printer = new ASTPrinter( OrderByParserParser.class );
+// log.trace( printer.showAsString( parser..getAST(), "--- {order-by fragment}
---" ) );
+// }
+//
+// OrderByFragmentRenderer renderer = new OrderByFragmentRenderer();
+// try {
+// renderer.orderByFragment( parser.getAST() );
+// }
+// catch ( HibernateException e ) {
+// throw e;
+// }
+// catch ( Throwable t ) {
+// throw new HibernateException( "Unable to render parsed order-by fragment",
t );
+// }
+//
+// return renderer.getRenderedFragment();
+ return null;
}
}
Added: core/branches/antlr3/src/main/java/org/hibernate/sql/ast/util/ColumnMapper.java
===================================================================
--- core/branches/antlr3/src/main/java/org/hibernate/sql/ast/util/ColumnMapper.java
(rev 0)
+++
core/branches/antlr3/src/main/java/org/hibernate/sql/ast/util/ColumnMapper.java 2009-04-16
01:16:21 UTC (rev 16350)
@@ -0,0 +1,48 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2008, 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,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * 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
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ *
+ */
+package org.hibernate.sql.ast.util;
+
+import org.hibernate.HibernateException;
+
+/**
+ * Contract for mapping a (an assumed) property reference to its columns.
+ * <p/>
+ * todo : this should probably get moved into the general sql-rendering package.
+ *
+ * @author Steve Ebersole
+ */
+public interface ColumnMapper {
+ /**
+ * Resolve the property reference to its underlying columns.
+ *
+ * @param reference The property reference name.
+ *
+ * @return The underlying columns, or null if the property reference is unknown.
+ *
+ * @throws HibernateException Generally indicates that the property reference is unkown;
interpretation is the
+ * same as a null return.
+ */
+ public String[] map(String reference) throws HibernateException;
+}
Deleted: core/branches/antlr3/src/main/java/org/hibernate/sql/ast/util/PathHelper.java
===================================================================
---
core/branches/antlr3/src/main/java/org/hibernate/sql/ast/util/PathHelper.java 2009-04-16
00:41:18 UTC (rev 16349)
+++
core/branches/antlr3/src/main/java/org/hibernate/sql/ast/util/PathHelper.java 2009-04-16
01:16:21 UTC (rev 16350)
@@ -1,111 +0,0 @@
-/*
- * Hibernate, Relational Persistence for Idiomatic Java
- *
- * Copyright (c) 2008, 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,
- * copy, or redistribute it subject to the terms and conditions of the GNU
- * 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
- * for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this distribution; if not, write to:
- * Free Software Foundation, Inc.
- * 51 Franklin Street, Fifth Floor
- * Boston, MA 02110-1301 USA
- */
-package org.hibernate.sql.ast.util;
-
-import org.hibernate.util.StringHelper;
-import org.hibernate.sql.ast.common.Sql92TokenTypes;
-
-import antlr.ASTFactory;
-import antlr.collections.AST;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Provides utility methods for dealing with path expressions.
- * <p/>
- * Note that these utilities do not properly account for index operations.
- *
- * @author Joshua Davis
- * @author Steve Ebersole
- */
-public final class PathHelper implements Sql92TokenTypes {
- private static final Logger log = LoggerFactory.getLogger( PathHelper.class );
-
- /**
- * Direct instantiation of PathHelper disallowed.
- */
- private PathHelper() {
- }
-
- /**
- * Turns a path into an AST.
- *
- * @param path The path.
- * @param factory The AST factory to use.
- * @return An HQL AST representing the path.
- */
- public static AST parsePath(String path, ASTFactory factory) {
- String[] identifiers = StringHelper.split( ".", path );
- AST lhs = null;
- for ( int i = 0; i < identifiers.length; i++ ) {
- String identifier = identifiers[i];
- AST child = ASTUtil.create( factory, IDENT, identifier );
- if ( i == 0 ) {
- lhs = child;
- }
- else {
- lhs = ASTUtil.createBinarySubtree( factory, DOT, ".", lhs, child );
- }
- }
- if ( log.isDebugEnabled() ) {
- log.debug( "parsePath() : " + path + " -> " +
ASTUtil.getDebugString( lhs ) );
- }
- return lhs;
- }
-
- /**
- * Provides the inverse functionality of {@link #parsePath}. In other words, for any
path
- * 'p' not involving index operations, p == reconstitutePathString( parsePath(
p, someASTFactory ) ).
- *
- * @param pathAST The path AST structure.
- * @return The corresponding path string.
- */
- public static String rebuildPathExpression(AST pathAST) {
- final StringBuffer buffer = new StringBuffer();
- visitExpression( pathAST, buffer );
- return buffer.toString();
- }
-
- private static void visitExpression(AST expression, StringBuffer buffer) {
- if ( DOT == expression.getType() ) {
- visitDot( expression.getFirstChild(), expression.getFirstChild().getNextSibling(),
buffer );
- }
- else if ( IDENT == expression.getType() ) {
- visitIdent( expression, buffer );
- }
- }
-
- private static void visitDot(AST lhs, AST rhs, StringBuffer buffer) {
- visitExpression( lhs, buffer );
- buffer.append( '.' ).append( rhs.getText() );
- }
-
- private static void visitIdent(AST ident, StringBuffer buffer) {
- buffer.append( ident.getText() );
- }
-
- public static String getAlias(String path) {
- return StringHelper.root( path );
- }
-}