HHH-8741 - More checkstyle cleanups
This commit is contained in:
parent
3a2c9f83e6
commit
66d3902ec2
|
@ -47,7 +47,7 @@ import org.jboss.logging.Logger;
|
|||
* @author Gavin King
|
||||
*/
|
||||
public final class CollectionEntry implements Serializable {
|
||||
private static final Logger LOG = CoreLogging.logger( CollectionEntry.class );
|
||||
private static final Logger LOG = CoreLogging.logger( CollectionEntry.class );
|
||||
|
||||
//ATTRIBUTES MAINTAINED BETWEEN FLUSH CYCLES
|
||||
|
||||
|
|
|
@ -31,10 +31,9 @@ import org.hibernate.engine.spi.SessionFactoryImplementor;
|
|||
import org.hibernate.hql.spi.FilterTranslator;
|
||||
import org.hibernate.hql.spi.QueryTranslator;
|
||||
import org.hibernate.hql.spi.QueryTranslatorFactory;
|
||||
import org.hibernate.internal.CoreLogging;
|
||||
import org.hibernate.internal.CoreMessageLogger;
|
||||
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
/**
|
||||
* Generates translators which uses the Antlr-based parser to perform
|
||||
* the translation.
|
||||
|
@ -42,34 +41,28 @@ import org.jboss.logging.Logger;
|
|||
* @author Gavin King
|
||||
*/
|
||||
public class ASTQueryTranslatorFactory implements QueryTranslatorFactory {
|
||||
|
||||
private static final CoreMessageLogger LOG = Logger.getMessageLogger(CoreMessageLogger.class,
|
||||
ASTQueryTranslatorFactory.class.getName());
|
||||
private static final CoreMessageLogger LOG = CoreLogging.messageLogger( ASTQueryTranslatorFactory.class );
|
||||
|
||||
public ASTQueryTranslatorFactory() {
|
||||
LOG.usingAstQueryTranslatorFactory();
|
||||
LOG.usingAstQueryTranslatorFactory();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.hibernate.hql.spi.QueryTranslatorFactory#createQueryTranslator
|
||||
*/
|
||||
@Override
|
||||
public QueryTranslator createQueryTranslator(
|
||||
String queryIdentifier,
|
||||
String queryString,
|
||||
Map filters,
|
||||
SessionFactoryImplementor factory,
|
||||
EntityGraphQueryHint entityGraphQueryHint) {
|
||||
String queryString,
|
||||
Map filters,
|
||||
SessionFactoryImplementor factory,
|
||||
EntityGraphQueryHint entityGraphQueryHint) {
|
||||
return new QueryTranslatorImpl( queryIdentifier, queryString, filters, factory, entityGraphQueryHint );
|
||||
}
|
||||
|
||||
/**
|
||||
* @see QueryTranslatorFactory#createFilterTranslator
|
||||
*/
|
||||
@Override
|
||||
public FilterTranslator createFilterTranslator(
|
||||
String queryIdentifier,
|
||||
String queryString,
|
||||
Map filters,
|
||||
SessionFactoryImplementor factory) {
|
||||
String queryString,
|
||||
Map filters,
|
||||
SessionFactoryImplementor factory) {
|
||||
return new QueryTranslatorImpl( queryIdentifier, queryString, filters, factory );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,12 +35,11 @@ import antlr.Token;
|
|||
* in order to keep the grammar source file clean.
|
||||
*/
|
||||
class HqlLexer extends HqlBaseLexer {
|
||||
|
||||
private boolean possibleID;
|
||||
|
||||
public HqlLexer(Reader in) {
|
||||
super(in);
|
||||
}
|
||||
public HqlLexer(Reader in) {
|
||||
super( in );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTokenObjectClass(String cl) {
|
||||
|
@ -54,7 +53,7 @@ class HqlLexer extends HqlBaseLexer {
|
|||
|
||||
@Override
|
||||
protected Token makeToken(int i) {
|
||||
HqlToken token = ( HqlToken ) super.makeToken( i );
|
||||
HqlToken token = (HqlToken) super.makeToken( i );
|
||||
token.setPossibleID( possibleID );
|
||||
possibleID = false;
|
||||
return token;
|
||||
|
@ -63,12 +62,12 @@ class HqlLexer extends HqlBaseLexer {
|
|||
@Override
|
||||
public void panic() {
|
||||
//overriden to avoid System.exit
|
||||
panic("CharScanner: panic");
|
||||
panic( "CharScanner: panic" );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void panic(String s) {
|
||||
//overriden to avoid System.exit
|
||||
throw new QueryException(s);
|
||||
throw new QueryException( s );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -91,32 +91,40 @@ public final class HqlParser extends HqlBaseParser {
|
|||
|
||||
@Override
|
||||
public void traceIn(String ruleName) {
|
||||
if ( !LOG.isTraceEnabled() ) return;
|
||||
if ( inputState.guessing > 0 ) return;
|
||||
if ( !LOG.isTraceEnabled() ) {
|
||||
return;
|
||||
}
|
||||
if ( inputState.guessing > 0 ) {
|
||||
return;
|
||||
}
|
||||
String prefix = StringHelper.repeat( '-', ( traceDepth++ * 2 ) ) + "-> ";
|
||||
LOG.trace( prefix + ruleName );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void traceOut(String ruleName) {
|
||||
if ( !LOG.isTraceEnabled() ) return;
|
||||
if ( inputState.guessing > 0 ) return;
|
||||
if ( !LOG.isTraceEnabled() ) {
|
||||
return;
|
||||
}
|
||||
if ( inputState.guessing > 0 ) {
|
||||
return;
|
||||
}
|
||||
String prefix = "<-" + StringHelper.repeat( '-', ( --traceDepth * 2 ) ) + " ";
|
||||
LOG.trace( prefix + ruleName );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reportError(RecognitionException e) {
|
||||
public void reportError(RecognitionException e) {
|
||||
parseErrorHandler.reportError( e ); // Use the delegate.
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reportError(String s) {
|
||||
public void reportError(String s) {
|
||||
parseErrorHandler.reportError( s ); // Use the delegate.
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reportWarning(String s) {
|
||||
public void reportWarning(String s) {
|
||||
parseErrorHandler.reportWarning( s );
|
||||
}
|
||||
|
||||
|
@ -128,26 +136,31 @@ public final class HqlParser extends HqlBaseParser {
|
|||
* Overrides the base behavior to retry keywords as identifiers.
|
||||
*
|
||||
* @param token The token.
|
||||
* @param ex The recognition exception.
|
||||
* @param ex The recognition exception.
|
||||
*
|
||||
* @return AST - The new AST.
|
||||
*
|
||||
* @throws antlr.RecognitionException if the substitution was not possible.
|
||||
* @throws antlr.TokenStreamException if the substitution was not possible.
|
||||
*/
|
||||
@Override
|
||||
public AST handleIdentifierError(Token token, RecognitionException ex) throws RecognitionException, TokenStreamException {
|
||||
public AST handleIdentifierError(Token token, RecognitionException ex)
|
||||
throws RecognitionException, TokenStreamException {
|
||||
// If the token can tell us if it could be an identifier...
|
||||
if ( token instanceof HqlToken ) {
|
||||
HqlToken hqlToken = ( HqlToken ) token;
|
||||
HqlToken hqlToken = (HqlToken) token;
|
||||
// ... and the token could be an identifer and the error is
|
||||
// a mismatched token error ...
|
||||
if ( hqlToken.isPossibleID() && ( ex instanceof MismatchedTokenException ) ) {
|
||||
MismatchedTokenException mte = ( MismatchedTokenException ) ex;
|
||||
MismatchedTokenException mte = (MismatchedTokenException) ex;
|
||||
// ... and the expected token type was an identifier, then:
|
||||
if ( mte.expecting == HqlTokenTypes.IDENT ) {
|
||||
// Use the token as an identifier.
|
||||
reportWarning( "Keyword '"
|
||||
+ token.getText()
|
||||
+ "' is being interpreted as an identifier due to: " + mte.getMessage() );
|
||||
reportWarning(
|
||||
"Keyword '"
|
||||
+ token.getText()
|
||||
+ "' is being interpreted as an identifier due to: " + mte.getMessage()
|
||||
);
|
||||
// Add the token to the AST.
|
||||
ASTPair currentAST = new ASTPair();
|
||||
token.setType( HqlTokenTypes.WEIRD_IDENT );
|
||||
|
@ -167,93 +180,126 @@ public final class HqlParser extends HqlBaseParser {
|
|||
* </pre>
|
||||
*
|
||||
* @param x The sub tree to transform, the parent is assumed to be NOT.
|
||||
*
|
||||
* @return AST - The equivalent sub-tree.
|
||||
*/
|
||||
@Override
|
||||
public AST negateNode(AST x) {
|
||||
public AST negateNode(AST x) {
|
||||
//TODO: switch statements are always evil! We already had bugs because
|
||||
// of forgotten token types. Use polymorphism for this!
|
||||
switch ( x.getType() ) {
|
||||
case OR:
|
||||
x.setType(AND);
|
||||
x.setText("{and}");
|
||||
x.setFirstChild(negateNode( x.getFirstChild() ));
|
||||
x.getFirstChild().setNextSibling(negateNode( x.getFirstChild().getNextSibling() ));
|
||||
return x;
|
||||
case AND:
|
||||
x.setType(OR);
|
||||
x.setText("{or}");
|
||||
x.setFirstChild(negateNode( x.getFirstChild() ));
|
||||
x.getFirstChild().setNextSibling(negateNode( x.getFirstChild().getNextSibling() ));
|
||||
case OR: {
|
||||
x.setType( AND );
|
||||
x.setText( "{and}" );
|
||||
x.setFirstChild( negateNode( x.getFirstChild() ) );
|
||||
x.getFirstChild().setNextSibling( negateNode( x.getFirstChild().getNextSibling() ) );
|
||||
return x;
|
||||
case EQ:
|
||||
}
|
||||
case AND: {
|
||||
x.setType( OR );
|
||||
x.setText( "{or}" );
|
||||
x.setFirstChild( negateNode( x.getFirstChild() ) );
|
||||
x.getFirstChild().setNextSibling( negateNode( x.getFirstChild().getNextSibling() ) );
|
||||
return x;
|
||||
}
|
||||
case EQ: {
|
||||
// (NOT (EQ a b) ) => (NE a b)
|
||||
x.setType( NE );
|
||||
x.setText( "{not}" + x.getText() );
|
||||
return x; // (NOT (EQ a b) ) => (NE a b)
|
||||
case NE:
|
||||
return x;
|
||||
}
|
||||
case NE: {
|
||||
// (NOT (NE a b) ) => (EQ a b)
|
||||
x.setType( EQ );
|
||||
x.setText( "{not}" + x.getText() );
|
||||
return x; // (NOT (NE a b) ) => (EQ a b)
|
||||
case GT:
|
||||
return x;
|
||||
}
|
||||
case GT: {
|
||||
// (NOT (GT a b) ) => (LE a b)
|
||||
x.setType( LE );
|
||||
x.setText( "{not}" + x.getText() );
|
||||
return x; // (NOT (GT a b) ) => (LE a b)
|
||||
case LT:
|
||||
return x;
|
||||
}
|
||||
case LT: {
|
||||
// (NOT (LT a b) ) => (GE a b)
|
||||
x.setType( GE );
|
||||
x.setText( "{not}" + x.getText() );
|
||||
return x; // (NOT (LT a b) ) => (GE a b)
|
||||
case GE:
|
||||
return x;
|
||||
}
|
||||
case GE: {
|
||||
// (NOT (GE a b) ) => (LT a b)
|
||||
x.setType( LT );
|
||||
x.setText( "{not}" + x.getText() );
|
||||
return x; // (NOT (GE a b) ) => (LT a b)
|
||||
case LE:
|
||||
return x;
|
||||
}
|
||||
case LE: {
|
||||
// (NOT (LE a b) ) => (GT a b)
|
||||
x.setType( GT );
|
||||
x.setText( "{not}" + x.getText() );
|
||||
return x; // (NOT (LE a b) ) => (GT a b)
|
||||
case LIKE:
|
||||
return x;
|
||||
}
|
||||
case LIKE: {
|
||||
// (NOT (LIKE a b) ) => (NOT_LIKE a b)
|
||||
x.setType( NOT_LIKE );
|
||||
x.setText( "{not}" + x.getText() );
|
||||
return x; // (NOT (LIKE a b) ) => (NOT_LIKE a b)
|
||||
case NOT_LIKE:
|
||||
return x;
|
||||
}
|
||||
case NOT_LIKE: {
|
||||
// (NOT (NOT_LIKE a b) ) => (LIKE a b)
|
||||
x.setType( LIKE );
|
||||
x.setText( "{not}" + x.getText() );
|
||||
return x; // (NOT (NOT_LIKE a b) ) => (LIKE a b)
|
||||
case IN:
|
||||
return x;
|
||||
}
|
||||
case IN: {
|
||||
x.setType( NOT_IN );
|
||||
x.setText( "{not}" + x.getText() );
|
||||
return x;
|
||||
case NOT_IN:
|
||||
}
|
||||
case NOT_IN: {
|
||||
x.setType( IN );
|
||||
x.setText( "{not}" + x.getText() );
|
||||
return x;
|
||||
case IS_NULL:
|
||||
}
|
||||
case IS_NULL: {
|
||||
// (NOT (IS_NULL a b) ) => (IS_NOT_NULL a b)
|
||||
x.setType( IS_NOT_NULL );
|
||||
x.setText( "{not}" + x.getText() );
|
||||
return x; // (NOT (IS_NULL a b) ) => (IS_NOT_NULL a b)
|
||||
case IS_NOT_NULL:
|
||||
return x;
|
||||
}
|
||||
case IS_NOT_NULL: {
|
||||
// (NOT (IS_NOT_NULL a b) ) => (IS_NULL a b)
|
||||
x.setType( IS_NULL );
|
||||
x.setText( "{not}" + x.getText() );
|
||||
return x; // (NOT (IS_NOT_NULL a b) ) => (IS_NULL a b)
|
||||
case BETWEEN:
|
||||
return x;
|
||||
}
|
||||
case BETWEEN: {
|
||||
// (NOT (BETWEEN a b) ) => (NOT_BETWEEN a b)
|
||||
x.setType( NOT_BETWEEN );
|
||||
x.setText( "{not}" + x.getText() );
|
||||
return x; // (NOT (BETWEEN a b) ) => (NOT_BETWEEN a b)
|
||||
case NOT_BETWEEN:
|
||||
return x;
|
||||
}
|
||||
case NOT_BETWEEN: {
|
||||
// (NOT (NOT_BETWEEN a b) ) => (BETWEEN a b)
|
||||
x.setType( BETWEEN );
|
||||
x.setText( "{not}" + x.getText() );
|
||||
return x; // (NOT (NOT_BETWEEN a b) ) => (BETWEEN a b)
|
||||
return x;
|
||||
}
|
||||
/* This can never happen because this rule will always eliminate the child NOT.
|
||||
case NOT:
|
||||
return x.getFirstChild(); // (NOT (NOT x) ) => (x)
|
||||
case NOT: {
|
||||
// (NOT (NOT x) ) => (x)
|
||||
return x.getFirstChild();
|
||||
}
|
||||
*/
|
||||
default:
|
||||
AST not = super.negateNode( x ); // Just add a 'not' parent.
|
||||
if ( not != x ) {
|
||||
// relink the next sibling to the new 'not' parent
|
||||
not.setNextSibling(x.getNextSibling());
|
||||
x.setNextSibling(null);
|
||||
}
|
||||
return not;
|
||||
default: {
|
||||
// Just add a 'not' parent.
|
||||
AST not = super.negateNode( x );
|
||||
if ( not != x ) {
|
||||
// relink the next sibling to the new 'not' parent
|
||||
not.setNextSibling( x.getNextSibling() );
|
||||
x.setNextSibling( null );
|
||||
}
|
||||
return not;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -261,12 +307,13 @@ public final class HqlParser extends HqlBaseParser {
|
|||
* Post process equality expressions, clean up the subtree.
|
||||
*
|
||||
* @param x The equality expression.
|
||||
*
|
||||
* @return AST - The clean sub-tree.
|
||||
*/
|
||||
@Override
|
||||
public AST processEqualityExpression(AST x) {
|
||||
public AST processEqualityExpression(AST x) {
|
||||
if ( x == null ) {
|
||||
LOG.processEqualityExpression();
|
||||
LOG.processEqualityExpression();
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -337,7 +384,7 @@ public final class HqlParser extends HqlBaseParser {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void weakKeywords() throws TokenStreamException {
|
||||
public void weakKeywords() throws TokenStreamException {
|
||||
|
||||
int t = LA( 1 );
|
||||
switch ( t ) {
|
||||
|
@ -354,16 +401,16 @@ public final class HqlParser extends HqlBaseParser {
|
|||
break;
|
||||
default:
|
||||
// Case 2: The current token is after FROM and before '.'.
|
||||
if ( LA( 0 ) == FROM && t != IDENT && LA( 2 ) == DOT ) {
|
||||
HqlToken hqlToken = (HqlToken) LT( 1 );
|
||||
if ( hqlToken.isPossibleID() ) {
|
||||
hqlToken.setType( IDENT );
|
||||
if ( LOG.isDebugEnabled() ) {
|
||||
LOG.debugf( "weakKeywords() : new LT(1) token - %s", LT( 1 ) );
|
||||
if ( LA( 0 ) == FROM && t != IDENT && LA( 2 ) == DOT ) {
|
||||
HqlToken hqlToken = (HqlToken) LT( 1 );
|
||||
if ( hqlToken.isPossibleID() ) {
|
||||
hqlToken.setType( IDENT );
|
||||
if ( LOG.isDebugEnabled() ) {
|
||||
LOG.debugf( "weakKeywords() : new LT(1) token - %s", LT( 1 ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -385,7 +432,7 @@ public final class HqlParser extends HqlBaseParser {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void processMemberOf(Token n, AST p, ASTPair currentAST) {
|
||||
public void processMemberOf(Token n, AST p, ASTPair currentAST) {
|
||||
// convert MEMBER OF to the equivalent IN ELEMENTS structure...
|
||||
AST inNode = n == null ? astFactory.create( IN, "in" ) : astFactory.create( NOT_IN, "not in" );
|
||||
astFactory.makeASTRoot( currentAST, inNode );
|
||||
|
@ -397,7 +444,7 @@ public final class HqlParser extends HqlBaseParser {
|
|||
elementsNode.addChild( p );
|
||||
}
|
||||
|
||||
private Map<String,Set<String>> treatMap;
|
||||
private Map<String, Set<String>> treatMap;
|
||||
|
||||
@Override
|
||||
protected void registerTreat(AST pathToTreat, AST treatAs) {
|
||||
|
@ -434,6 +481,6 @@ public final class HqlParser extends HqlBaseParser {
|
|||
|
||||
static public void panic() {
|
||||
//overriden to avoid System.exit
|
||||
throw new QueryException("Parser: panic");
|
||||
throw new QueryException( "Parser: panic" );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -117,7 +117,7 @@ import antlr.collections.AST;
|
|||
* @see SqlASTFactory
|
||||
*/
|
||||
public class HqlSqlWalker extends HqlSqlBaseWalker implements ErrorReporter, ParameterBinder.NamedParameterSource {
|
||||
private static final CoreMessageLogger LOG = CoreLogging.messageLogger( HqlSqlWalker.class );
|
||||
private static final CoreMessageLogger LOG = CoreLogging.messageLogger( HqlSqlWalker.class );
|
||||
|
||||
private final QueryTranslatorImpl queryTranslatorImpl;
|
||||
private final HqlParser hqlParser;
|
||||
|
@ -135,7 +135,7 @@ public class HqlSqlWalker extends HqlSqlBaseWalker implements ErrorReporter, Par
|
|||
/**
|
||||
* Maps each top-level result variable to its SelectExpression;
|
||||
* (excludes result variables defined in subqueries)
|
||||
**/
|
||||
*/
|
||||
private Map<String, SelectExpression> selectExpressionsByResultVariable = new HashMap<String, SelectExpression>();
|
||||
|
||||
private Set<Serializable> querySpaces = new HashSet<Serializable>();
|
||||
|
@ -185,8 +185,12 @@ public class HqlSqlWalker extends HqlSqlBaseWalker implements ErrorReporter, Par
|
|||
|
||||
@Override
|
||||
public void traceIn(String ruleName, AST tree) {
|
||||
if ( !LOG.isTraceEnabled() ) return;
|
||||
if ( inputState.guessing > 0 ) return;
|
||||
if ( !LOG.isTraceEnabled() ) {
|
||||
return;
|
||||
}
|
||||
if ( inputState.guessing > 0 ) {
|
||||
return;
|
||||
}
|
||||
String prefix = StringHelper.repeat( '-', ( traceDepth++ * 2 ) ) + "-> ";
|
||||
String traceText = ruleName + " (" + buildTraceNodeName( tree ) + ")";
|
||||
LOG.trace( prefix + traceText );
|
||||
|
@ -200,14 +204,18 @@ public class HqlSqlWalker extends HqlSqlBaseWalker implements ErrorReporter, Par
|
|||
|
||||
@Override
|
||||
public void traceOut(String ruleName, AST tree) {
|
||||
if ( !LOG.isTraceEnabled() ) return;
|
||||
if ( inputState.guessing > 0 ) return;
|
||||
if ( !LOG.isTraceEnabled() ) {
|
||||
return;
|
||||
}
|
||||
if ( inputState.guessing > 0 ) {
|
||||
return;
|
||||
}
|
||||
String prefix = "<-" + StringHelper.repeat( '-', ( --traceDepth * 2 ) ) + " ";
|
||||
LOG.trace( prefix + ruleName );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void prepareFromClauseInputTree(AST fromClauseInput) {
|
||||
protected void prepareFromClauseInputTree(AST fromClauseInput) {
|
||||
if ( !isSubQuery() ) {
|
||||
// // inject param specifications to account for dynamic filter param values
|
||||
// if ( ! getEnabledFilters().isEmpty() ) {
|
||||
|
@ -235,7 +243,7 @@ public class HqlSqlWalker extends HqlSqlBaseWalker implements ErrorReporter, Par
|
|||
// }
|
||||
|
||||
if ( isFilter() ) {
|
||||
// Handle collection-filter compilation.
|
||||
// Handle collection-filter compilation.
|
||||
// IMPORTANT NOTE: This is modifying the INPUT (HQL) tree, not the output tree!
|
||||
QueryableCollection persister = sessionFactoryHelper.getCollectionPersister( collectionFilterRole );
|
||||
Type collectionElementType = persister.getElementType();
|
||||
|
@ -245,16 +253,17 @@ public class HqlSqlWalker extends HqlSqlBaseWalker implements ErrorReporter, Par
|
|||
|
||||
String collectionElementEntityName = persister.getElementPersister().getEntityName();
|
||||
ASTFactory inputAstFactory = hqlParser.getASTFactory();
|
||||
AST fromElement = ASTUtil.create( inputAstFactory, HqlTokenTypes.FILTER_ENTITY, collectionElementEntityName );
|
||||
AST fromElement = inputAstFactory.create( HqlTokenTypes.FILTER_ENTITY, collectionElementEntityName );
|
||||
ASTUtil.createSibling( inputAstFactory, HqlTokenTypes.ALIAS, "this", fromElement );
|
||||
fromClauseInput.addChild( fromElement );
|
||||
// Show the modified AST.
|
||||
LOG.debug("prepareFromClauseInputTree() : Filter - Added 'this' as a from element...");
|
||||
LOG.debug( "prepareFromClauseInputTree() : Filter - Added 'this' as a from element..." );
|
||||
queryTranslatorImpl.showHqlAst( hqlParser.getAST() );
|
||||
|
||||
// Create a parameter specification for the collection filter...
|
||||
Type collectionFilterKeyType = sessionFactoryHelper.requireQueryableCollection( collectionFilterRole ).getKeyType();
|
||||
ParameterNode collectionFilterKeyParameter = ( ParameterNode ) astFactory.create( PARAM, "?" );
|
||||
Type collectionFilterKeyType = sessionFactoryHelper.requireQueryableCollection( collectionFilterRole )
|
||||
.getKeyType();
|
||||
ParameterNode collectionFilterKeyParameter = (ParameterNode) astFactory.create( PARAM, "?" );
|
||||
CollectionFilterKeyParameterSpecification collectionFilterKeyParameterSpec = new CollectionFilterKeyParameterSpecification(
|
||||
collectionFilterRole, collectionFilterKeyType, positionalParameterCount++
|
||||
);
|
||||
|
@ -293,17 +302,17 @@ public class HqlSqlWalker extends HqlSqlBaseWalker implements ErrorReporter, Par
|
|||
}
|
||||
|
||||
@Override
|
||||
public void reportError(RecognitionException e) {
|
||||
public void reportError(RecognitionException e) {
|
||||
parseErrorHandler.reportError( e ); // Use the delegate.
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reportError(String s) {
|
||||
public void reportError(String s) {
|
||||
parseErrorHandler.reportError( s ); // Use the delegate.
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reportWarning(String s) {
|
||||
public void reportWarning(String s) {
|
||||
parseErrorHandler.reportWarning( s );
|
||||
}
|
||||
|
||||
|
@ -318,14 +327,14 @@ public class HqlSqlWalker extends HqlSqlBaseWalker implements ErrorReporter, Par
|
|||
}
|
||||
|
||||
@Override
|
||||
protected AST createFromElement(String path, AST alias, AST propertyFetch) throws SemanticException {
|
||||
protected AST createFromElement(String path, AST alias, AST propertyFetch) throws SemanticException {
|
||||
FromElement fromElement = currentFromClause.addFromElement( path, alias );
|
||||
fromElement.setAllPropertyFetch(propertyFetch!=null);
|
||||
fromElement.setAllPropertyFetch( propertyFetch != null );
|
||||
return fromElement;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AST createFromFilterElement(AST filterEntity, AST alias) throws SemanticException {
|
||||
protected AST createFromFilterElement(AST filterEntity, AST alias) throws SemanticException {
|
||||
FromElement fromElement = currentFromClause.addFromElement( filterEntity.getText(), alias );
|
||||
FromClause fromClause = fromElement.getFromClause();
|
||||
QueryableCollection persister = sessionFactoryHelper.getCollectionPersister( collectionFilterRole );
|
||||
|
@ -338,26 +347,28 @@ public class HqlSqlWalker extends HqlSqlBaseWalker implements ErrorReporter, Par
|
|||
JoinSequence join = sessionFactoryHelper.createJoinSequence();
|
||||
join.setRoot( persister, fkTableAlias );
|
||||
if ( !persister.isOneToMany() ) {
|
||||
join.addJoin( ( AssociationType ) persister.getElementType(),
|
||||
join.addJoin(
|
||||
(AssociationType) persister.getElementType(),
|
||||
fromElement.getTableAlias(),
|
||||
JoinType.INNER_JOIN,
|
||||
persister.getElementColumnNames( fkTableAlias ) );
|
||||
persister.getElementColumnNames( fkTableAlias )
|
||||
);
|
||||
}
|
||||
join.addCondition( fkTableAlias, keyColumnNames, " = ?" );
|
||||
fromElement.setJoinSequence( join );
|
||||
fromElement.setFilter( true );
|
||||
LOG.debug("createFromFilterElement() : processed filter FROM element.");
|
||||
LOG.debug( "createFromFilterElement() : processed filter FROM element." );
|
||||
return fromElement;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void createFromJoinElement(
|
||||
AST path,
|
||||
AST alias,
|
||||
int joinType,
|
||||
AST fetchNode,
|
||||
AST propertyFetch,
|
||||
AST with) throws SemanticException {
|
||||
protected void createFromJoinElement(
|
||||
AST path,
|
||||
AST alias,
|
||||
int joinType,
|
||||
AST fetchNode,
|
||||
AST propertyFetch,
|
||||
AST with) throws SemanticException {
|
||||
boolean fetch = fetchNode != null;
|
||||
if ( fetch && isSubQuery() ) {
|
||||
throw new QueryException( "fetch not allowed in subquery from-elements" );
|
||||
|
@ -366,9 +377,9 @@ public class HqlSqlWalker extends HqlSqlBaseWalker implements ErrorReporter, Par
|
|||
if ( path.getType() != SqlTokenTypes.DOT ) {
|
||||
throw new SemanticException( "Path expected for join!" );
|
||||
}
|
||||
DotNode dot = ( DotNode ) path;
|
||||
DotNode dot = (DotNode) path;
|
||||
JoinType hibernateJoinType = JoinProcessor.toHibernateJoinType( joinType );
|
||||
dot.setJoinType( hibernateJoinType ); // Tell the dot node about the join type.
|
||||
dot.setJoinType( hibernateJoinType ); // Tell the dot node about the join type.
|
||||
dot.setFetch( fetch );
|
||||
// Generate an explicit join for the root dot node. The implied joins will be collected and passed up
|
||||
// to the root dot node.
|
||||
|
@ -403,8 +414,8 @@ public class HqlSqlWalker extends HqlSqlBaseWalker implements ErrorReporter, Par
|
|||
}
|
||||
}
|
||||
|
||||
if ( LOG.isDebugEnabled() ) {
|
||||
LOG.debug("createFromJoinElement() : " + getASTPrinter().showAsString(fromElement, "-- join tree --") );
|
||||
if ( LOG.isDebugEnabled() ) {
|
||||
LOG.debug( "createFromJoinElement() : " + getASTPrinter().showAsString( fromElement, "-- join tree --" ) );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -412,8 +423,13 @@ public class HqlSqlWalker extends HqlSqlBaseWalker implements ErrorReporter, Par
|
|||
try {
|
||||
withClause( hqlWithNode );
|
||||
AST hqlSqlWithNode = returnAST;
|
||||
if ( LOG.isDebugEnabled() ) {
|
||||
LOG.debug( "handleWithFragment() : " + getASTPrinter().showAsString(hqlSqlWithNode, "-- with clause --") );
|
||||
if ( LOG.isDebugEnabled() ) {
|
||||
LOG.debug(
|
||||
"handleWithFragment() : " + getASTPrinter().showAsString(
|
||||
hqlSqlWithNode,
|
||||
"-- with clause --"
|
||||
)
|
||||
);
|
||||
}
|
||||
WithClauseVisitor visitor = new WithClauseVisitor( fromElement, queryTranslatorImpl );
|
||||
NodeTraverser traverser = new NodeTraverser( visitor );
|
||||
|
@ -439,13 +455,13 @@ public class HqlSqlWalker extends HqlSqlBaseWalker implements ErrorReporter, Par
|
|||
|
||||
fromElement.setWithClauseFragment( withClauseJoinAlias, "(" + sql.getSQL() + ")" );
|
||||
}
|
||||
catch( SemanticException e ) {
|
||||
catch (SemanticException e) {
|
||||
throw e;
|
||||
}
|
||||
catch( InvalidWithClauseException e ) {
|
||||
catch (InvalidWithClauseException e) {
|
||||
throw e;
|
||||
}
|
||||
catch ( Exception e) {
|
||||
catch (Exception e) {
|
||||
throw new SemanticException( e.getMessage() );
|
||||
}
|
||||
}
|
||||
|
@ -463,7 +479,7 @@ public class HqlSqlWalker extends HqlSqlBaseWalker implements ErrorReporter, Par
|
|||
}
|
||||
|
||||
public void visit(AST node) {
|
||||
// TODO : currently expects that the individual with expressions apply to the same sql table join.
|
||||
// TODO : currently expects that the individual with expressions apply to the same sql table join.
|
||||
// This may not be the case for joined-subclass where the property values
|
||||
// might be coming from different tables in the joined hierarchy. At some
|
||||
// point we should expand this to support that capability. However, that has
|
||||
|
@ -474,7 +490,7 @@ public class HqlSqlWalker extends HqlSqlBaseWalker implements ErrorReporter, Par
|
|||
// the join alias to which it applies and then pass that information
|
||||
// back to the FromElement so it can pass it along to the JoinSequence
|
||||
if ( node instanceof DotNode ) {
|
||||
DotNode dotNode = ( DotNode ) node;
|
||||
DotNode dotNode = (DotNode) node;
|
||||
FromElement fromElement = dotNode.getFromElement();
|
||||
if ( referencedFromElement != null ) {
|
||||
if ( fromElement != referencedFromElement ) {
|
||||
|
@ -484,9 +500,9 @@ public class HqlSqlWalker extends HqlSqlBaseWalker implements ErrorReporter, Par
|
|||
else {
|
||||
referencedFromElement = fromElement;
|
||||
joinAlias = extractAppliedAlias( dotNode );
|
||||
// TODO : temporary
|
||||
// TODO : temporary
|
||||
// needed because currently persister is the one that
|
||||
// creates and renders the join fragments for inheritance
|
||||
// creates and renders the join fragments for inheritance
|
||||
// hierarchies...
|
||||
if ( !joinAlias.equals( referencedFromElement.getTableAlias() ) ) {
|
||||
throw new InvalidWithClauseException(
|
||||
|
@ -497,10 +513,10 @@ public class HqlSqlWalker extends HqlSqlBaseWalker implements ErrorReporter, Par
|
|||
}
|
||||
}
|
||||
else if ( node instanceof ParameterNode ) {
|
||||
applyParameterSpecification( ( ( ParameterNode ) node ).getHqlParameterSpecification() );
|
||||
applyParameterSpecification( ( (ParameterNode) node ).getHqlParameterSpecification() );
|
||||
}
|
||||
else if ( node instanceof ParameterContainer ) {
|
||||
applyParameterSpecifications( ( ParameterContainer ) node );
|
||||
applyParameterSpecifications( (ParameterContainer) node );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -533,12 +549,12 @@ public class HqlSqlWalker extends HqlSqlBaseWalker implements ErrorReporter, Par
|
|||
/**
|
||||
* Sets the current 'FROM' context.
|
||||
*
|
||||
* @param fromNode The new 'FROM' context.
|
||||
* @param fromNode The new 'FROM' context.
|
||||
* @param inputFromNode The from node from the input AST.
|
||||
*/
|
||||
@Override
|
||||
protected void pushFromClause(AST fromNode, AST inputFromNode) {
|
||||
FromClause newFromClause = ( FromClause ) fromNode;
|
||||
protected void pushFromClause(AST fromNode, AST inputFromNode) {
|
||||
FromClause newFromClause = (FromClause) fromNode;
|
||||
newFromClause.setParentFromClause( currentFromClause );
|
||||
currentFromClause = newFromClause;
|
||||
}
|
||||
|
@ -551,15 +567,15 @@ public class HqlSqlWalker extends HqlSqlBaseWalker implements ErrorReporter, Par
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void lookupAlias(AST aliasRef)
|
||||
protected void lookupAlias(AST aliasRef)
|
||||
throws SemanticException {
|
||||
FromElement alias = currentFromClause.getFromElement( aliasRef.getText() );
|
||||
FromReferenceNode aliasRefNode = ( FromReferenceNode ) aliasRef;
|
||||
FromReferenceNode aliasRefNode = (FromReferenceNode) aliasRef;
|
||||
aliasRefNode.setFromElement( alias );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setImpliedJoinType(int joinType) {
|
||||
protected void setImpliedJoinType(int joinType) {
|
||||
impliedJoinType = JoinProcessor.toHibernateJoinType( joinType );
|
||||
}
|
||||
|
||||
|
@ -568,24 +584,28 @@ public class HqlSqlWalker extends HqlSqlBaseWalker implements ErrorReporter, Par
|
|||
}
|
||||
|
||||
@Override
|
||||
protected AST lookupProperty(AST dot, boolean root, boolean inSelect) throws SemanticException {
|
||||
DotNode dotNode = ( DotNode ) dot;
|
||||
protected AST lookupProperty(AST dot, boolean root, boolean inSelect) throws SemanticException {
|
||||
DotNode dotNode = (DotNode) dot;
|
||||
FromReferenceNode lhs = dotNode.getLhs();
|
||||
AST rhs = lhs.getNextSibling();
|
||||
switch ( rhs.getType() ) {
|
||||
case SqlTokenTypes.ELEMENTS:
|
||||
case SqlTokenTypes.INDICES:
|
||||
if (LOG.isDebugEnabled()) LOG.debugf("lookupProperty() %s => %s(%s)",
|
||||
dotNode.getPath(),
|
||||
rhs.getText(),
|
||||
lhs.getPath());
|
||||
CollectionFunction f = ( CollectionFunction ) rhs;
|
||||
if ( LOG.isDebugEnabled() ) {
|
||||
LOG.debugf(
|
||||
"lookupProperty() %s => %s(%s)",
|
||||
dotNode.getPath(),
|
||||
rhs.getText(),
|
||||
lhs.getPath()
|
||||
);
|
||||
}
|
||||
CollectionFunction f = (CollectionFunction) rhs;
|
||||
// Re-arrange the tree so that the collection function is the root and the lhs is the path.
|
||||
f.setFirstChild( lhs );
|
||||
lhs.setNextSibling( null );
|
||||
dotNode.setFirstChild( f );
|
||||
resolve( lhs ); // Don't forget to resolve the argument!
|
||||
f.resolve( inSelect ); // Resolve the collection function now.
|
||||
resolve( lhs ); // Don't forget to resolve the argument!
|
||||
f.resolve( inSelect ); // Resolve the collection function now.
|
||||
return f;
|
||||
default:
|
||||
// Resolve everything up to this dot, but don't resolve the placeholders yet.
|
||||
|
@ -595,7 +615,7 @@ public class HqlSqlWalker extends HqlSqlBaseWalker implements ErrorReporter, Par
|
|||
}
|
||||
|
||||
@Override
|
||||
protected boolean isNonQualifiedPropertyRef(AST ident) {
|
||||
protected boolean isNonQualifiedPropertyRef(AST ident) {
|
||||
final String identText = ident.getText();
|
||||
if ( currentFromClause.isFromElementAlias( identText ) ) {
|
||||
return false;
|
||||
|
@ -603,12 +623,12 @@ public class HqlSqlWalker extends HqlSqlBaseWalker implements ErrorReporter, Par
|
|||
|
||||
List fromElements = currentFromClause.getExplicitFromElements();
|
||||
if ( fromElements.size() == 1 ) {
|
||||
final FromElement fromElement = ( FromElement ) fromElements.get( 0 );
|
||||
final FromElement fromElement = (FromElement) fromElements.get( 0 );
|
||||
try {
|
||||
LOG.tracev( "Attempting to resolve property [{0}] as a non-qualified ref", identText );
|
||||
return fromElement.getPropertyMapping( identText ).toType( identText ) != null;
|
||||
}
|
||||
catch( QueryException e ) {
|
||||
catch (QueryException e) {
|
||||
// Should mean that no such property was found
|
||||
}
|
||||
}
|
||||
|
@ -618,7 +638,7 @@ public class HqlSqlWalker extends HqlSqlBaseWalker implements ErrorReporter, Par
|
|||
|
||||
@Override
|
||||
protected AST lookupNonQualifiedProperty(AST property) throws SemanticException {
|
||||
final FromElement fromElement = ( FromElement ) currentFromClause.getExplicitFromElements().get( 0 );
|
||||
final FromElement fromElement = (FromElement) currentFromClause.getExplicitFromElements().get( 0 );
|
||||
AST syntheticDotNode = generateSyntheticDotNodeForNonQualifiedPropertyRef( property, fromElement );
|
||||
return lookupProperty( syntheticDotNode, false, getCurrentClauseType() == HqlSqlTokenTypes.SELECT );
|
||||
}
|
||||
|
@ -626,9 +646,9 @@ public class HqlSqlWalker extends HqlSqlBaseWalker implements ErrorReporter, Par
|
|||
private AST generateSyntheticDotNodeForNonQualifiedPropertyRef(AST property, FromElement fromElement) {
|
||||
AST dot = getASTFactory().create( DOT, "{non-qualified-property-ref}" );
|
||||
// TODO : better way?!?
|
||||
( ( DotNode ) dot ).setPropertyPath( ( ( FromReferenceNode ) property ).getPath() );
|
||||
( (DotNode) dot ).setPropertyPath( ( (FromReferenceNode) property ).getPath() );
|
||||
|
||||
IdentNode syntheticAlias = ( IdentNode ) getASTFactory().create( IDENT, "{synthetic-alias}" );
|
||||
IdentNode syntheticAlias = (IdentNode) getASTFactory().create( IDENT, "{synthetic-alias}" );
|
||||
syntheticAlias.setFromElement( fromElement );
|
||||
syntheticAlias.setResolved();
|
||||
|
||||
|
@ -645,15 +665,16 @@ public class HqlSqlWalker extends HqlSqlBaseWalker implements ErrorReporter, Par
|
|||
}
|
||||
|
||||
try {
|
||||
QueryNode qn = ( QueryNode ) query;
|
||||
QueryNode qn = (QueryNode) query;
|
||||
|
||||
// Was there an explicit select expression?
|
||||
boolean explicitSelect = select != null && select.getNumberOfChildren() > 0;
|
||||
|
||||
|
||||
// Add in the EntityGraph attribute nodes.
|
||||
if (queryTranslatorImpl.getEntityGraphQueryHint() != null) {
|
||||
if ( queryTranslatorImpl.getEntityGraphQueryHint() != null ) {
|
||||
qn.getFromClause().getFromElements().addAll(
|
||||
queryTranslatorImpl.getEntityGraphQueryHint().toFromElements( qn.getFromClause(), this ) );
|
||||
queryTranslatorImpl.getEntityGraphQueryHint().toFromElements( qn.getFromClause(), this )
|
||||
);
|
||||
}
|
||||
|
||||
if ( !explicitSelect ) {
|
||||
|
@ -678,7 +699,7 @@ public class HqlSqlWalker extends HqlSqlBaseWalker implements ErrorReporter, Par
|
|||
// Attach any mapping-defined "ORDER BY" fragments
|
||||
Iterator itr = qn.getFromClause().getProjectionList().iterator();
|
||||
while ( itr.hasNext() ) {
|
||||
final FromElement fromElement = ( FromElement ) itr.next();
|
||||
final FromElement fromElement = (FromElement) itr.next();
|
||||
// if ( fromElement.isFetch() && fromElement.isCollectionJoin() ) {
|
||||
if ( fromElement.isFetch() && fromElement.getQueryableCollection() != null ) {
|
||||
// Does the collection referenced by this FromElement
|
||||
|
@ -706,7 +727,7 @@ public class HqlSqlWalker extends HqlSqlBaseWalker implements ErrorReporter, Par
|
|||
protected void postProcessDML(RestrictableStatement statement) throws SemanticException {
|
||||
statement.getFromClause().resolve();
|
||||
|
||||
FromElement fromElement = ( FromElement ) statement.getFromClause().getFromElements().get( 0 );
|
||||
FromElement fromElement = (FromElement) statement.getFromClause().getFromElements().get( 0 );
|
||||
Queryable persister = fromElement.getQueryable();
|
||||
// Make #@%$^#^&# sure no alias is applied to the table name
|
||||
fromElement.setText( persister.getTableName() );
|
||||
|
@ -721,32 +742,32 @@ public class HqlSqlWalker extends HqlSqlBaseWalker implements ErrorReporter, Par
|
|||
// fromElement.getTableAlias()
|
||||
// );
|
||||
// }
|
||||
if ( persister.getDiscriminatorType() != null || ! queryTranslatorImpl.getEnabledFilters().isEmpty() ) {
|
||||
if ( persister.getDiscriminatorType() != null || !queryTranslatorImpl.getEnabledFilters().isEmpty() ) {
|
||||
new SyntheticAndFactory( this ).addDiscriminatorWhereFragment(
|
||||
statement,
|
||||
persister,
|
||||
queryTranslatorImpl.getEnabledFilters(),
|
||||
fromElement.getTableAlias()
|
||||
statement,
|
||||
persister,
|
||||
queryTranslatorImpl.getEnabledFilters(),
|
||||
fromElement.getTableAlias()
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void postProcessUpdate(AST update) throws SemanticException {
|
||||
UpdateStatement updateStatement = ( UpdateStatement ) update;
|
||||
protected void postProcessUpdate(AST update) throws SemanticException {
|
||||
UpdateStatement updateStatement = (UpdateStatement) update;
|
||||
|
||||
postProcessDML( updateStatement );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void postProcessDelete(AST delete) throws SemanticException {
|
||||
postProcessDML( ( DeleteStatement ) delete );
|
||||
protected void postProcessDelete(AST delete) throws SemanticException {
|
||||
postProcessDML( (DeleteStatement) delete );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void postProcessInsert(AST insert) throws SemanticException, QueryException {
|
||||
InsertStatement insertStatement = ( InsertStatement ) insert;
|
||||
protected void postProcessInsert(AST insert) throws SemanticException, QueryException {
|
||||
InsertStatement insertStatement = (InsertStatement) insert;
|
||||
insertStatement.validate();
|
||||
|
||||
SelectClause selectClause = insertStatement.getSelectClause();
|
||||
|
@ -764,37 +785,39 @@ public class HqlSqlWalker extends HqlSqlBaseWalker implements ErrorReporter, Par
|
|||
}
|
||||
final BulkInsertionCapableIdentifierGenerator capableGenerator =
|
||||
BulkInsertionCapableIdentifierGenerator.class.cast( generator );
|
||||
if ( ! capableGenerator.supportsBulkInsertionIdentifierGeneration() ) {
|
||||
if ( !capableGenerator.supportsBulkInsertionIdentifierGeneration() ) {
|
||||
throw new QueryException(
|
||||
"Identifier generator reported it does not support implicit id handling as part of bulk insertions"
|
||||
);
|
||||
}
|
||||
|
||||
final String fragment = capableGenerator.determineBulkInsertionIdentifierGenerationSelectFragment(
|
||||
final String fragment = capableGenerator.determineBulkInsertionIdentifierGenerationSelectFragment(
|
||||
sessionFactoryHelper.getFactory().getDialect()
|
||||
);
|
||||
if ( fragment != null ) {
|
||||
// we got a fragment from the generator, so alter the sql tree...
|
||||
//
|
||||
// first, wrap the fragment as a node
|
||||
AST fragmentNode = getASTFactory().create( HqlSqlTokenTypes.SQL_TOKEN, fragment );
|
||||
// next, rearrange the SQL tree to add the fragment node as the first select expression
|
||||
AST originalFirstSelectExprNode = selectClause.getFirstChild();
|
||||
selectClause.setFirstChild( fragmentNode );
|
||||
fragmentNode.setNextSibling( originalFirstSelectExprNode );
|
||||
// finally, prepend the id column name(s) to the insert-spec
|
||||
insertStatement.getIntoClause().prependIdColumnSpec();
|
||||
// we got a fragment from the generator, so alter the sql tree...
|
||||
//
|
||||
// first, wrap the fragment as a node
|
||||
AST fragmentNode = getASTFactory().create( HqlSqlTokenTypes.SQL_TOKEN, fragment );
|
||||
// next, rearrange the SQL tree to add the fragment node as the first select expression
|
||||
AST originalFirstSelectExprNode = selectClause.getFirstChild();
|
||||
selectClause.setFirstChild( fragmentNode );
|
||||
fragmentNode.setNextSibling( originalFirstSelectExprNode );
|
||||
// finally, prepend the id column name(s) to the insert-spec
|
||||
insertStatement.getIntoClause().prependIdColumnSpec();
|
||||
}
|
||||
}
|
||||
|
||||
if ( sessionFactoryHelper.getFactory().getDialect().supportsParametersInInsertSelect() ) {
|
||||
AST child = selectClause.getFirstChild();
|
||||
int i = 0;
|
||||
while(child != null) {
|
||||
if(child instanceof ParameterNode) {
|
||||
while ( child != null ) {
|
||||
if ( child instanceof ParameterNode ) {
|
||||
// infer the parameter type from the type listed in the INSERT INTO clause
|
||||
((ParameterNode)child).setExpectedType(insertStatement.getIntoClause()
|
||||
.getInsertionTypes()[selectClause.getParameterPositions().get(i)]);
|
||||
( (ParameterNode) child ).setExpectedType(
|
||||
insertStatement.getIntoClause()
|
||||
.getInsertionTypes()[selectClause.getParameterPositions().get( i )]
|
||||
);
|
||||
i++;
|
||||
}
|
||||
child = child.getNextSibling();
|
||||
|
@ -822,22 +845,26 @@ public class HqlSqlWalker extends HqlSqlBaseWalker implements ErrorReporter, Par
|
|||
}
|
||||
versionValueNode = getASTFactory().create( HqlSqlTokenTypes.PARAM, "?" );
|
||||
ParameterSpecification paramSpec = new VersionTypeSeedParameterSpecification( versionType );
|
||||
( ( ParameterNode ) versionValueNode ).setHqlParameterSpecification( paramSpec );
|
||||
( (ParameterNode) versionValueNode ).setHqlParameterSpecification( paramSpec );
|
||||
parameters.add( 0, paramSpec );
|
||||
|
||||
if ( sessionFactoryHelper.getFactory().getDialect().requiresCastingOfParametersInSelectClause() ) {
|
||||
// we need to wrtap the param in a cast()
|
||||
MethodNode versionMethodNode = ( MethodNode ) getASTFactory().create( HqlSqlTokenTypes.METHOD_CALL, "(" );
|
||||
MethodNode versionMethodNode = (MethodNode) getASTFactory().create(
|
||||
HqlSqlTokenTypes.METHOD_CALL,
|
||||
"("
|
||||
);
|
||||
AST methodIdentNode = getASTFactory().create( HqlSqlTokenTypes.IDENT, "cast" );
|
||||
versionMethodNode.addChild( methodIdentNode );
|
||||
versionMethodNode.initializeMethodNode(methodIdentNode, true );
|
||||
versionMethodNode.initializeMethodNode( methodIdentNode, true );
|
||||
AST castExprListNode = getASTFactory().create( HqlSqlTokenTypes.EXPR_LIST, "exprList" );
|
||||
methodIdentNode.setNextSibling( castExprListNode );
|
||||
castExprListNode.addChild( versionValueNode );
|
||||
versionValueNode.setNextSibling(
|
||||
getASTFactory().create(
|
||||
HqlSqlTokenTypes.IDENT,
|
||||
sessionFactoryHelper.getFactory().getDialect().getTypeName( sqlTypes[0] ) )
|
||||
sessionFactoryHelper.getFactory().getDialect().getTypeName( sqlTypes[0] )
|
||||
)
|
||||
);
|
||||
processFunction( versionMethodNode, true );
|
||||
versionValueNode = versionMethodNode;
|
||||
|
@ -849,12 +876,14 @@ public class HqlSqlWalker extends HqlSqlBaseWalker implements ErrorReporter, Par
|
|||
Object seedValue = versionType.seed( null );
|
||||
versionValueNode = getASTFactory().create( HqlSqlTokenTypes.SQL_TOKEN, seedValue.toString() );
|
||||
}
|
||||
catch( Throwable t ) {
|
||||
catch (Throwable t) {
|
||||
throw new QueryException( "could not determine seed value for version on bulk insert [" + versionType + "]" );
|
||||
}
|
||||
}
|
||||
else if ( isDatabaseGeneratedTimestamp( versionType ) ) {
|
||||
String functionName = sessionFactoryHelper.getFactory().getDialect().getCurrentTimestampSQLFunctionName();
|
||||
String functionName = sessionFactoryHelper.getFactory()
|
||||
.getDialect()
|
||||
.getCurrentTimestampSQLFunctionName();
|
||||
versionValueNode = getASTFactory().create( HqlSqlTokenTypes.SQL_TOKEN, functionName );
|
||||
}
|
||||
else {
|
||||
|
@ -884,13 +913,13 @@ public class HqlSqlWalker extends HqlSqlBaseWalker implements ErrorReporter, Par
|
|||
|
||||
private boolean isIntegral(Type type) {
|
||||
return Long.class.isAssignableFrom( type.getReturnedClass() )
|
||||
|| Integer.class.isAssignableFrom( type.getReturnedClass() )
|
||||
|| long.class.isAssignableFrom( type.getReturnedClass() )
|
||||
|| int.class.isAssignableFrom( type.getReturnedClass() );
|
||||
|| Integer.class.isAssignableFrom( type.getReturnedClass() )
|
||||
|| long.class.isAssignableFrom( type.getReturnedClass() )
|
||||
|| int.class.isAssignableFrom( type.getReturnedClass() );
|
||||
}
|
||||
|
||||
private void useSelectClause(AST select) throws SemanticException {
|
||||
selectClause = ( SelectClause ) select;
|
||||
selectClause = (SelectClause) select;
|
||||
selectClause.initializeExplicitSelectClause( currentFromClause );
|
||||
}
|
||||
|
||||
|
@ -899,38 +928,38 @@ public class HqlSqlWalker extends HqlSqlBaseWalker implements ErrorReporter, Par
|
|||
AST sibling = qn.getFromClause();
|
||||
qn.setFirstChild( select );
|
||||
select.setNextSibling( sibling );
|
||||
selectClause = ( SelectClause ) select;
|
||||
selectClause = (SelectClause) select;
|
||||
selectClause.initializeDerivedSelectClause( currentFromClause );
|
||||
LOG.debug( "Derived SELECT clause created." );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void resolve(AST node) throws SemanticException {
|
||||
protected void resolve(AST node) throws SemanticException {
|
||||
if ( node != null ) {
|
||||
// This is called when it's time to fully resolve a path expression.
|
||||
ResolvableNode r = ( ResolvableNode ) node;
|
||||
ResolvableNode r = (ResolvableNode) node;
|
||||
if ( isInFunctionCall() ) {
|
||||
r.resolveInFunctionCall( false, true );
|
||||
}
|
||||
else {
|
||||
r.resolve( false, true ); // Generate implicit joins, only if necessary.
|
||||
r.resolve( false, true ); // Generate implicit joins, only if necessary.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void resolveSelectExpression(AST node) throws SemanticException {
|
||||
protected void resolveSelectExpression(AST node) throws SemanticException {
|
||||
// This is called when it's time to fully resolve a path expression.
|
||||
int type = node.getType();
|
||||
switch ( type ) {
|
||||
case DOT: {
|
||||
DotNode dot = ( DotNode ) node;
|
||||
DotNode dot = (DotNode) node;
|
||||
dot.resolveSelectExpression();
|
||||
break;
|
||||
}
|
||||
case ALIAS_REF: {
|
||||
// Notify the FROM element that it is being referenced by the select.
|
||||
FromReferenceNode aliasRefNode = ( FromReferenceNode ) node;
|
||||
FromReferenceNode aliasRefNode = (FromReferenceNode) node;
|
||||
//aliasRefNode.resolve( false, false, aliasRefNode.getText() ); //TODO: is it kosher to do it here?
|
||||
aliasRefNode.resolve( false, false ); //TODO: is it kosher to do it here?
|
||||
FromElement fromElement = aliasRefNode.getFromElement();
|
||||
|
@ -946,20 +975,22 @@ public class HqlSqlWalker extends HqlSqlBaseWalker implements ErrorReporter, Par
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void beforeSelectClause() throws SemanticException {
|
||||
protected void beforeSelectClause() throws SemanticException {
|
||||
// Turn off includeSubclasses on all FromElements.
|
||||
FromClause from = getCurrentFromClause();
|
||||
List fromElements = from.getFromElements();
|
||||
for ( Iterator iterator = fromElements.iterator(); iterator.hasNext(); ) {
|
||||
FromElement fromElement = ( FromElement ) iterator.next();
|
||||
FromElement fromElement = (FromElement) iterator.next();
|
||||
fromElement.setIncludeSubclasses( false );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AST generatePositionalParameter(AST inputNode) throws SemanticException {
|
||||
protected AST generatePositionalParameter(AST inputNode) throws SemanticException {
|
||||
if ( namedParameters.size() > 0 ) {
|
||||
throw new SemanticException( "cannot define positional parameter after any named parameters have been defined" );
|
||||
throw new SemanticException(
|
||||
"cannot define positional parameter after any named parameters have been defined"
|
||||
);
|
||||
}
|
||||
LOG.warnf(
|
||||
"[DEPRECATION] Encountered positional parameter near line %s, column %s. Positional parameter " +
|
||||
|
@ -967,10 +998,10 @@ public class HqlSqlWalker extends HqlSqlBaseWalker implements ErrorReporter, Par
|
|||
inputNode.getLine(),
|
||||
inputNode.getColumn()
|
||||
);
|
||||
ParameterNode parameter = ( ParameterNode ) astFactory.create( PARAM, "?" );
|
||||
ParameterNode parameter = (ParameterNode) astFactory.create( PARAM, "?" );
|
||||
PositionalParameterSpecification paramSpec = new PositionalParameterSpecification(
|
||||
inputNode.getLine(),
|
||||
inputNode.getColumn(),
|
||||
inputNode.getColumn(),
|
||||
positionalParameterCount++
|
||||
);
|
||||
parameter.setHqlParameterSpecification( paramSpec );
|
||||
|
@ -979,18 +1010,18 @@ public class HqlSqlWalker extends HqlSqlBaseWalker implements ErrorReporter, Par
|
|||
}
|
||||
|
||||
@Override
|
||||
protected AST generateNamedParameter(AST delimiterNode, AST nameNode) throws SemanticException {
|
||||
protected AST generateNamedParameter(AST delimiterNode, AST nameNode) throws SemanticException {
|
||||
String name = nameNode.getText();
|
||||
trackNamedParameterPositions( name );
|
||||
|
||||
// create the node initially with the param name so that it shows
|
||||
// appropriately in the "original text" attribute
|
||||
ParameterNode parameter = ( ParameterNode ) astFactory.create( NAMED_PARAM, name );
|
||||
ParameterNode parameter = (ParameterNode) astFactory.create( NAMED_PARAM, name );
|
||||
parameter.setText( "?" );
|
||||
|
||||
NamedParameterSpecification paramSpec = new NamedParameterSpecification(
|
||||
delimiterNode.getLine(),
|
||||
delimiterNode.getColumn(),
|
||||
delimiterNode.getColumn(),
|
||||
name
|
||||
);
|
||||
parameter.setHqlParameterSpecification( paramSpec );
|
||||
|
@ -1011,64 +1042,67 @@ public class HqlSqlWalker extends HqlSqlBaseWalker implements ErrorReporter, Par
|
|||
namedParameters.put( name, list );
|
||||
}
|
||||
else {
|
||||
( ( ArrayList ) o ).add( loc );
|
||||
( (ArrayList) o ).add( loc );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void processConstant(AST constant) throws SemanticException {
|
||||
literalProcessor.processConstant( constant, true ); // Use the delegate, resolve identifiers as FROM element aliases.
|
||||
protected void processConstant(AST constant) throws SemanticException {
|
||||
literalProcessor.processConstant(
|
||||
constant,
|
||||
true
|
||||
); // Use the delegate, resolve identifiers as FROM element aliases.
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void processBoolean(AST constant) throws SemanticException {
|
||||
protected void processBoolean(AST constant) throws SemanticException {
|
||||
literalProcessor.processBoolean( constant ); // Use the delegate.
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void processNumericLiteral(AST literal) {
|
||||
protected void processNumericLiteral(AST literal) {
|
||||
literalProcessor.processNumeric( literal );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void processIndex(AST indexOp) throws SemanticException {
|
||||
IndexNode indexNode = ( IndexNode ) indexOp;
|
||||
protected void processIndex(AST indexOp) throws SemanticException {
|
||||
IndexNode indexNode = (IndexNode) indexOp;
|
||||
indexNode.resolve( true, true );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void processFunction(AST functionCall, boolean inSelect) throws SemanticException {
|
||||
MethodNode methodNode = ( MethodNode ) functionCall;
|
||||
protected void processFunction(AST functionCall, boolean inSelect) throws SemanticException {
|
||||
MethodNode methodNode = (MethodNode) functionCall;
|
||||
methodNode.resolve( inSelect );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void processAggregation(AST node, boolean inSelect) throws SemanticException {
|
||||
AggregateNode aggregateNode = ( AggregateNode ) node;
|
||||
protected void processAggregation(AST node, boolean inSelect) throws SemanticException {
|
||||
AggregateNode aggregateNode = (AggregateNode) node;
|
||||
aggregateNode.resolve();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void processConstructor(AST constructor) throws SemanticException {
|
||||
ConstructorNode constructorNode = ( ConstructorNode ) constructor;
|
||||
protected void processConstructor(AST constructor) throws SemanticException {
|
||||
ConstructorNode constructorNode = (ConstructorNode) constructor;
|
||||
constructorNode.prepare();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setAlias(AST selectExpr, AST ident) {
|
||||
((SelectExpression) selectExpr).setAlias(ident.getText());
|
||||
@Override
|
||||
protected void setAlias(AST selectExpr, AST ident) {
|
||||
( (SelectExpression) selectExpr ).setAlias( ident.getText() );
|
||||
// only put the alias (i.e., result variable) in selectExpressionsByResultVariable
|
||||
// if is not defined in a subquery.
|
||||
if ( ! isSubQuery() ) {
|
||||
selectExpressionsByResultVariable.put( ident.getText(), ( SelectExpression ) selectExpr );
|
||||
if ( !isSubQuery() ) {
|
||||
selectExpressionsByResultVariable.put( ident.getText(), (SelectExpression) selectExpr );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isOrderExpressionResultVariableRef(AST orderExpressionNode) throws SemanticException {
|
||||
protected boolean isOrderExpressionResultVariableRef(AST orderExpressionNode) throws SemanticException {
|
||||
// ORDER BY is not supported in a subquery
|
||||
// TODO: should an exception be thrown if an ORDER BY is in a subquery?
|
||||
if ( ! isSubQuery() &&
|
||||
if ( !isSubQuery() &&
|
||||
orderExpressionNode.getType() == IDENT &&
|
||||
selectExpressionsByResultVariable.containsKey( orderExpressionNode.getText() ) ) {
|
||||
return true;
|
||||
|
@ -1077,13 +1111,13 @@ public class HqlSqlWalker extends HqlSqlBaseWalker implements ErrorReporter, Par
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void handleResultVariableRef(AST resultVariableRef) throws SemanticException {
|
||||
protected void handleResultVariableRef(AST resultVariableRef) throws SemanticException {
|
||||
if ( isSubQuery() ) {
|
||||
throw new SemanticException(
|
||||
"References to result variables in subqueries are not supported."
|
||||
);
|
||||
}
|
||||
( ( ResultVariableRefNode ) resultVariableRef ).setSelectExpression(
|
||||
( (ResultVariableRefNode) resultVariableRef ).setSelectExpression(
|
||||
selectExpressionsByResultVariable.get( resultVariableRef.getText() )
|
||||
);
|
||||
}
|
||||
|
@ -1094,10 +1128,13 @@ public class HqlSqlWalker extends HqlSqlBaseWalker implements ErrorReporter, Par
|
|||
public int[] getNamedParameterLocations(String name) throws QueryException {
|
||||
Object o = namedParameters.get( name );
|
||||
if ( o == null ) {
|
||||
throw new QueryException( QueryTranslator.ERROR_NAMED_PARAMETER_DOES_NOT_APPEAR + name, queryTranslatorImpl.getQueryString() );
|
||||
throw new QueryException(
|
||||
QueryTranslator.ERROR_NAMED_PARAMETER_DOES_NOT_APPEAR + name,
|
||||
queryTranslatorImpl.getQueryString()
|
||||
);
|
||||
}
|
||||
if ( o instanceof Integer ) {
|
||||
return new int[]{ (Integer) o };
|
||||
return new int[] {(Integer) o};
|
||||
}
|
||||
else {
|
||||
return ArrayHelper.toIntArray( (ArrayList) o );
|
||||
|
@ -1154,7 +1191,7 @@ public class HqlSqlWalker extends HqlSqlBaseWalker implements ErrorReporter, Par
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void evaluateAssignment(AST eq) throws SemanticException {
|
||||
protected void evaluateAssignment(AST eq) throws SemanticException {
|
||||
prepareLogicOperator( eq );
|
||||
Queryable persister = getCurrentFromClause().getFromElement().getQueryable();
|
||||
evaluateAssignment( eq, persister, -1 );
|
||||
|
@ -1179,10 +1216,10 @@ public class HqlSqlWalker extends HqlSqlBaseWalker implements ErrorReporter, Par
|
|||
}
|
||||
|
||||
@Override
|
||||
protected AST createIntoClause(String path, AST propertySpec) throws SemanticException {
|
||||
Queryable persister = ( Queryable ) getSessionFactoryHelper().requireClassPersister( path );
|
||||
protected AST createIntoClause(String path, AST propertySpec) throws SemanticException {
|
||||
Queryable persister = (Queryable) getSessionFactoryHelper().requireClassPersister( path );
|
||||
|
||||
IntoClause intoClause = ( IntoClause ) getASTFactory().create( INTO, persister.getEntityName() );
|
||||
IntoClause intoClause = (IntoClause) getASTFactory().create( INTO, persister.getEntityName() );
|
||||
intoClause.setFirstChild( propertySpec );
|
||||
intoClause.initialize( persister );
|
||||
|
||||
|
@ -1192,8 +1229,8 @@ public class HqlSqlWalker extends HqlSqlBaseWalker implements ErrorReporter, Par
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void prepareVersioned(AST updateNode, AST versioned) throws SemanticException {
|
||||
UpdateStatement updateStatement = ( UpdateStatement ) updateNode;
|
||||
protected void prepareVersioned(AST updateNode, AST versioned) throws SemanticException {
|
||||
UpdateStatement updateStatement = (UpdateStatement) updateNode;
|
||||
FromClause fromClause = updateStatement.getFromClause();
|
||||
if ( versioned != null ) {
|
||||
// Make sure that the persister is versioned
|
||||
|
@ -1216,7 +1253,7 @@ public class HqlSqlWalker extends HqlSqlBaseWalker implements ErrorReporter, Par
|
|||
if ( isTimestampBasedVersion( versionType ) ) {
|
||||
versionIncrementNode = getASTFactory().create( HqlSqlTokenTypes.PARAM, "?" );
|
||||
ParameterSpecification paramSpec = new VersionTypeSeedParameterSpecification( versionType );
|
||||
( ( ParameterNode ) versionIncrementNode ).setHqlParameterSpecification( paramSpec );
|
||||
( (ParameterNode) versionIncrementNode ).setHqlParameterSpecification( paramSpec );
|
||||
parameters.add( 0, paramSpec );
|
||||
}
|
||||
else {
|
||||
|
@ -1245,7 +1282,7 @@ public class HqlSqlWalker extends HqlSqlBaseWalker implements ErrorReporter, Par
|
|||
}
|
||||
|
||||
private AST generateVersionPropertyNode(Queryable persister) throws SemanticException {
|
||||
String versionPropertyName = persister.getPropertyNames()[ persister.getVersionProperty() ];
|
||||
String versionPropertyName = persister.getPropertyNames()[persister.getVersionProperty()];
|
||||
AST versionPropertyRef = getASTFactory().create( HqlSqlTokenTypes.IDENT, versionPropertyName );
|
||||
AST versionPropertyNode = lookupNonQualifiedProperty( versionPropertyRef );
|
||||
resolve( versionPropertyNode );
|
||||
|
@ -1253,28 +1290,28 @@ public class HqlSqlWalker extends HqlSqlBaseWalker implements ErrorReporter, Par
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void prepareLogicOperator(AST operator) throws SemanticException {
|
||||
( ( OperatorNode ) operator ).initialize();
|
||||
protected void prepareLogicOperator(AST operator) throws SemanticException {
|
||||
( (OperatorNode) operator ).initialize();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void prepareArithmeticOperator(AST operator) throws SemanticException {
|
||||
( ( OperatorNode ) operator ).initialize();
|
||||
protected void prepareArithmeticOperator(AST operator) throws SemanticException {
|
||||
( (OperatorNode) operator ).initialize();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void validateMapPropertyExpression(AST node) throws SemanticException {
|
||||
protected void validateMapPropertyExpression(AST node) throws SemanticException {
|
||||
try {
|
||||
FromReferenceNode fromReferenceNode = (FromReferenceNode) node;
|
||||
QueryableCollection collectionPersister = fromReferenceNode.getFromElement().getQueryableCollection();
|
||||
if ( ! Map.class.isAssignableFrom( collectionPersister.getCollectionType().getReturnedClass() ) ) {
|
||||
if ( !Map.class.isAssignableFrom( collectionPersister.getCollectionType().getReturnedClass() ) ) {
|
||||
throw new SemanticException( "node did not reference a map" );
|
||||
}
|
||||
}
|
||||
catch ( SemanticException se ) {
|
||||
catch (SemanticException se) {
|
||||
throw se;
|
||||
}
|
||||
catch ( Throwable t ) {
|
||||
catch (Throwable t) {
|
||||
throw new SemanticException( "node did not reference a map" );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -541,8 +541,8 @@ public class QueryTranslatorImpl implements FilterTranslator {
|
|||
// TODO : this is a bit dodgy, come up with a better way to check this (plus see above comment)
|
||||
String [] idColNames = owner.getQueryable().getIdentifierColumnNames();
|
||||
String expectedPrimaryOrderSeq = StringHelper.join(
|
||||
", ",
|
||||
StringHelper.qualify( owner.getTableAlias(), idColNames )
|
||||
", ",
|
||||
StringHelper.qualify( owner.getTableAlias(), idColNames )
|
||||
);
|
||||
if ( !primaryOrdering.getText().startsWith( expectedPrimaryOrderSeq ) ) {
|
||||
throw new HibernateException( "cannot scroll results with collection fetches which are not ordered primarily by the root entity's PK" );
|
||||
|
@ -606,9 +606,11 @@ public class QueryTranslatorImpl implements FilterTranslator {
|
|||
public void visit(AST node) {
|
||||
if ( dotRoot != null ) {
|
||||
// we are already processing a dot-structure
|
||||
if (ASTUtil.isSubtreeChild(dotRoot, node)) return;
|
||||
// we are now at a new tree level
|
||||
dotRoot = null;
|
||||
if ( ASTUtil.isSubtreeChild(dotRoot, node) ) {
|
||||
return;
|
||||
}
|
||||
// we are now at a new tree level
|
||||
dotRoot = null;
|
||||
}
|
||||
|
||||
if ( node.getType() == HqlTokenTypes.DOT ) {
|
||||
|
|
|
@ -58,7 +58,7 @@ import antlr.collections.AST;
|
|||
* @author Steve Ebersole
|
||||
*/
|
||||
public class SqlGenerator extends SqlGeneratorBase implements ErrorReporter {
|
||||
private static final CoreMessageLogger LOG = CoreLogging.messageLogger( SqlGenerator.class );
|
||||
private static final CoreMessageLogger LOG = CoreLogging.messageLogger( SqlGenerator.class );
|
||||
|
||||
public static boolean REGRESSION_STYLE_CROSS_JOINS;
|
||||
|
||||
|
@ -84,8 +84,12 @@ public class SqlGenerator extends SqlGeneratorBase implements ErrorReporter {
|
|||
|
||||
@Override
|
||||
public void traceIn(String ruleName, AST tree) {
|
||||
if ( !LOG.isTraceEnabled() ) return;
|
||||
if ( inputState.guessing > 0 ) return;
|
||||
if ( !LOG.isTraceEnabled() ) {
|
||||
return;
|
||||
}
|
||||
if ( inputState.guessing > 0 ) {
|
||||
return;
|
||||
}
|
||||
String prefix = StringHelper.repeat( '-', ( traceDepth++ * 2 ) ) + "-> ";
|
||||
String traceText = ruleName + " (" + buildTraceNodeName( tree ) + ")";
|
||||
LOG.trace( prefix + traceText );
|
||||
|
@ -99,8 +103,12 @@ public class SqlGenerator extends SqlGeneratorBase implements ErrorReporter {
|
|||
|
||||
@Override
|
||||
public void traceOut(String ruleName, AST tree) {
|
||||
if ( !LOG.isTraceEnabled() ) return;
|
||||
if ( inputState.guessing > 0 ) return;
|
||||
if ( !LOG.isTraceEnabled() ) {
|
||||
return;
|
||||
}
|
||||
if ( inputState.guessing > 0 ) {
|
||||
return;
|
||||
}
|
||||
String prefix = "<-" + StringHelper.repeat( '-', ( --traceDepth * 2 ) ) + " ";
|
||||
LOG.trace( prefix + ruleName );
|
||||
}
|
||||
|
@ -110,25 +118,25 @@ public class SqlGenerator extends SqlGeneratorBase implements ErrorReporter {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void out(String s) {
|
||||
protected void out(String s) {
|
||||
writer.clause( s );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void out(AST n) {
|
||||
protected void out(AST n) {
|
||||
if ( n instanceof Node ) {
|
||||
out( ( ( Node ) n ).getRenderText( sessionFactory ) );
|
||||
out( ( (Node) n ).getRenderText( sessionFactory ) );
|
||||
}
|
||||
else {
|
||||
super.out( n );
|
||||
}
|
||||
|
||||
if ( n instanceof ParameterNode ) {
|
||||
collectedParameters.add( ( ( ParameterNode ) n ).getHqlParameterSpecification() );
|
||||
collectedParameters.add( ( (ParameterNode) n ).getHqlParameterSpecification() );
|
||||
}
|
||||
else if ( n instanceof ParameterContainer ) {
|
||||
if ( ( ( ParameterContainer ) n ).hasEmbeddedParameters() ) {
|
||||
ParameterSpecification[] specifications = ( ( ParameterContainer ) n ).getEmbeddedParameters();
|
||||
if ( ( (ParameterContainer) n ).hasEmbeddedParameters() ) {
|
||||
ParameterSpecification[] specifications = ( (ParameterContainer) n ).getEmbeddedParameters();
|
||||
if ( specifications != null ) {
|
||||
collectedParameters.addAll( Arrays.asList( specifications ) );
|
||||
}
|
||||
|
@ -137,22 +145,22 @@ public class SqlGenerator extends SqlGeneratorBase implements ErrorReporter {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void commaBetweenParameters(String comma) {
|
||||
protected void commaBetweenParameters(String comma) {
|
||||
writer.commaBetweenParameters( comma );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reportError(RecognitionException e) {
|
||||
parseErrorHandler.reportError( e ); // Use the delegate.
|
||||
public void reportError(RecognitionException e) {
|
||||
parseErrorHandler.reportError( e );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reportError(String s) {
|
||||
parseErrorHandler.reportError( s ); // Use the delegate.
|
||||
public void reportError(String s) {
|
||||
parseErrorHandler.reportError( s );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reportWarning(String s) {
|
||||
public void reportWarning(String s) {
|
||||
parseErrorHandler.reportWarning( s );
|
||||
}
|
||||
|
||||
|
@ -171,7 +179,7 @@ public class SqlGenerator extends SqlGeneratorBase implements ErrorReporter {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void optionalSpace() {
|
||||
protected void optionalSpace() {
|
||||
int c = getLastChar();
|
||||
switch ( c ) {
|
||||
case -1:
|
||||
|
@ -188,10 +196,10 @@ public class SqlGenerator extends SqlGeneratorBase implements ErrorReporter {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void beginFunctionTemplate(AST node, AST nameNode) {
|
||||
protected void beginFunctionTemplate(AST node, AST nameNode) {
|
||||
// NOTE for AGGREGATE both nodes are the same; for METHOD the first is the METHOD, the second is the
|
||||
// METHOD_NAME
|
||||
FunctionNode functionNode = ( FunctionNode ) node;
|
||||
FunctionNode functionNode = (FunctionNode) node;
|
||||
SQLFunction sqlFunction = functionNode.getSQLFunction();
|
||||
if ( sqlFunction == null ) {
|
||||
// if SQLFunction is null we just write the function out as it appears in the hql statement
|
||||
|
@ -205,8 +213,8 @@ public class SqlGenerator extends SqlGeneratorBase implements ErrorReporter {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void endFunctionTemplate(AST node) {
|
||||
FunctionNode functionNode = ( FunctionNode ) node;
|
||||
protected void endFunctionTemplate(AST node) {
|
||||
FunctionNode functionNode = (FunctionNode) node;
|
||||
SQLFunction sqlFunction = functionNode.getSQLFunction();
|
||||
if ( sqlFunction == null ) {
|
||||
super.endFunctionTemplate( node );
|
||||
|
@ -214,7 +222,7 @@ public class SqlGenerator extends SqlGeneratorBase implements ErrorReporter {
|
|||
else {
|
||||
final Type functionType = functionNode.getFirstArgumentType();
|
||||
// this function has a registered SQLFunction -> redirect output and catch the arguments
|
||||
FunctionArguments functionArguments = ( FunctionArguments ) writer;
|
||||
FunctionArguments functionArguments = (FunctionArguments) writer;
|
||||
writer = outputStack.removeFirst();
|
||||
out( sqlFunction.render( functionType, functionArguments.getArgs(), sessionFactory ) );
|
||||
}
|
||||
|
@ -244,7 +252,7 @@ public class SqlGenerator extends SqlGeneratorBase implements ErrorReporter {
|
|||
*/
|
||||
class FunctionArguments implements SqlWriter {
|
||||
private int argInd;
|
||||
private final List<String> args = new ArrayList<String>(3);
|
||||
private final List<String> args = new ArrayList<String>( 3 );
|
||||
|
||||
@Override
|
||||
public void clause(String clause) {
|
||||
|
@ -281,20 +289,20 @@ public class SqlGenerator extends SqlGeneratorBase implements ErrorReporter {
|
|||
}
|
||||
}
|
||||
|
||||
public static void panic() {
|
||||
public static void panic() {
|
||||
throw new QueryException( "TreeWalker: panic" );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void fromFragmentSeparator(AST a) {
|
||||
protected void fromFragmentSeparator(AST a) {
|
||||
// check two "adjecent" nodes at the top of the from-clause tree
|
||||
AST next = a.getNextSibling();
|
||||
if ( next == null || !hasText( a ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
FromElement left = ( FromElement ) a;
|
||||
FromElement right = ( FromElement ) next;
|
||||
FromElement left = (FromElement) a;
|
||||
FromElement right = (FromElement) next;
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
// HACK ALERT !!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
|
@ -306,7 +314,7 @@ public class SqlGenerator extends SqlGeneratorBase implements ErrorReporter {
|
|||
// Essentially, look-ahead to the next FromElement that actually
|
||||
// writes something to the SQL
|
||||
while ( right != null && !hasText( right ) ) {
|
||||
right = ( FromElement ) right.getNextSibling();
|
||||
right = (FromElement) right.getNextSibling();
|
||||
}
|
||||
if ( right == null ) {
|
||||
return;
|
||||
|
@ -318,7 +326,7 @@ public class SqlGenerator extends SqlGeneratorBase implements ErrorReporter {
|
|||
}
|
||||
|
||||
if ( right.getRealOrigin() == left ||
|
||||
( right.getRealOrigin() != null && right.getRealOrigin() == left.getRealOrigin() ) ) {
|
||||
( right.getRealOrigin() != null && right.getRealOrigin() == left.getRealOrigin() ) ) {
|
||||
// right represents a joins originating from left; or
|
||||
// both right and left reprersent joins originating from the same FromElement
|
||||
if ( right.getJoinSequence() != null && right.getJoinSequence().isThetaStyle() ) {
|
||||
|
@ -344,14 +352,14 @@ public class SqlGenerator extends SqlGeneratorBase implements ErrorReporter {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void nestedFromFragment(AST d, AST parent) {
|
||||
protected void nestedFromFragment(AST d, AST parent) {
|
||||
// check a set of parent/child nodes in the from-clause tree
|
||||
// to determine if a comma is required between them
|
||||
if ( d != null && hasText( d ) ) {
|
||||
if ( parent != null && hasText( parent ) ) {
|
||||
// again, both should be FromElements
|
||||
FromElement left = ( FromElement ) parent;
|
||||
FromElement right = ( FromElement ) d;
|
||||
FromElement left = (FromElement) parent;
|
||||
FromElement right = (FromElement) d;
|
||||
if ( right.getRealOrigin() == left ) {
|
||||
// right represents a joins originating from left...
|
||||
if ( right.getJoinSequence() != null && right.getJoinSequence().isThetaStyle() ) {
|
||||
|
@ -373,7 +381,10 @@ public class SqlGenerator extends SqlGeneratorBase implements ErrorReporter {
|
|||
|
||||
@Override
|
||||
protected String renderOrderByElement(String expression, String order, String nulls) {
|
||||
final NullPrecedence nullPrecedence = NullPrecedence.parse( nulls, sessionFactory.getSettings().getDefaultNullPrecedence() );
|
||||
final NullPrecedence nullPrecedence = NullPrecedence.parse( nulls,
|
||||
sessionFactory.getSettings()
|
||||
.getDefaultNullPrecedence()
|
||||
);
|
||||
return sessionFactory.getDialect().renderOrderByElement( expression, null, order, nullPrecedence );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -40,11 +40,9 @@ public class MultiTableDeleteExecutor implements StatementExecutor {
|
|||
private final MultiTableBulkIdStrategy.DeleteHandler deleteHandler;
|
||||
|
||||
public MultiTableDeleteExecutor(HqlSqlWalker walker) {
|
||||
MultiTableBulkIdStrategy strategy = walker.getSessionFactoryHelper()
|
||||
.getFactory()
|
||||
.getSettings()
|
||||
final MultiTableBulkIdStrategy strategy = walker.getSessionFactoryHelper().getFactory().getSettings()
|
||||
.getMultiTableBulkIdStrategy();
|
||||
this.deleteHandler = strategy.buildDeleteHandler( walker.getSessionFactoryHelper().getFactory(), walker );
|
||||
this.deleteHandler = strategy.buildDeleteHandler( walker.getSessionFactoryHelper().getFactory(), walker );
|
||||
}
|
||||
|
||||
public String[] getSqlStatements() {
|
||||
|
|
|
@ -40,12 +40,8 @@ import antlr.collections.AST;
|
|||
* @author Steve Ebersole
|
||||
*/
|
||||
public abstract class AbstractNullnessCheckNode extends UnaryLogicOperatorNode {
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void initialize() {
|
||||
public void initialize() {
|
||||
// TODO : this really needs to be delayed unitl after we definitively know the operand node type;
|
||||
// where this is currently a problem is parameters for which where we cannot unequivocally
|
||||
// resolve an expected type
|
||||
|
|
|
@ -37,13 +37,12 @@ import antlr.collections.AST;
|
|||
* @author Steve Ebersole
|
||||
*/
|
||||
public abstract class AbstractRestrictableStatement extends AbstractStatement implements RestrictableStatement {
|
||||
|
||||
private FromClause fromClause;
|
||||
private AST whereClause;
|
||||
|
||||
protected abstract int getWhereClauseParentTokenType();
|
||||
|
||||
protected abstract CoreMessageLogger getLog();
|
||||
protected abstract CoreMessageLogger getLog();
|
||||
|
||||
/**
|
||||
* @see org.hibernate.hql.internal.ast.tree.RestrictableStatement#getFromClause
|
||||
|
|
|
@ -49,7 +49,6 @@ import antlr.collections.AST;
|
|||
* @author Steve Ebersole
|
||||
*/
|
||||
public class AssignmentSpecification {
|
||||
|
||||
private final Set tableNames;
|
||||
private final ParameterSpecification[] hqlParameters;
|
||||
private final AST eq;
|
||||
|
@ -100,12 +99,12 @@ public class AssignmentSpecification {
|
|||
}
|
||||
else {
|
||||
List parameterList = ASTUtil.collectChildren(
|
||||
rhs,
|
||||
new ASTUtil.IncludePredicate() {
|
||||
public boolean include(AST node) {
|
||||
return isParam( node );
|
||||
}
|
||||
}
|
||||
rhs,
|
||||
new ASTUtil.IncludePredicate() {
|
||||
public boolean include(AST node) {
|
||||
return isParam( node );
|
||||
}
|
||||
}
|
||||
);
|
||||
hqlParameters = new ParameterSpecification[ parameterList.size() ];
|
||||
Iterator itr = parameterList.iterator();
|
||||
|
|
|
@ -37,9 +37,10 @@ import antlr.SemanticException;
|
|||
*/
|
||||
public class BinaryArithmeticOperatorNode extends AbstractSelectExpression implements BinaryOperatorNode, DisplayableNode {
|
||||
|
||||
@Override
|
||||
public void initialize() throws SemanticException {
|
||||
Node lhs = getLeftHandOperand();
|
||||
Node rhs = getRightHandOperand();
|
||||
final Node lhs = getLeftHandOperand();
|
||||
final Node rhs = getRightHandOperand();
|
||||
if ( lhs == null ) {
|
||||
throw new SemanticException( "left-hand operand of a binary operator was null" );
|
||||
}
|
||||
|
@ -47,8 +48,8 @@ public class BinaryArithmeticOperatorNode extends AbstractSelectExpression imple
|
|||
throw new SemanticException( "right-hand operand of a binary operator was null" );
|
||||
}
|
||||
|
||||
Type lhType = ( lhs instanceof SqlNode ) ? ( ( SqlNode ) lhs ).getDataType() : null;
|
||||
Type rhType = ( rhs instanceof SqlNode ) ? ( ( SqlNode ) rhs ).getDataType() : null;
|
||||
final Type lhType = ( lhs instanceof SqlNode ) ? ( ( SqlNode ) lhs ).getDataType() : null;
|
||||
final Type rhType = ( rhs instanceof SqlNode ) ? ( ( SqlNode ) rhs ).getDataType() : null;
|
||||
|
||||
if ( ExpectedTypeAwareNode.class.isAssignableFrom( lhs.getClass() ) && rhType != null ) {
|
||||
Type expectedType = null;
|
||||
|
@ -92,6 +93,7 @@ public class BinaryArithmeticOperatorNode extends AbstractSelectExpression imple
|
|||
* the types of the operands. Sometimes we don't know both types,
|
||||
* if, for example, one is a parameter.
|
||||
*/
|
||||
@Override
|
||||
public Type getDataType() {
|
||||
if ( super.getDataType() == null ) {
|
||||
super.setDataType( resolveDataType() );
|
||||
|
@ -152,11 +154,9 @@ public class BinaryArithmeticOperatorNode extends AbstractSelectExpression imple
|
|||
}
|
||||
|
||||
private boolean isDateTimeType(Type type) {
|
||||
if ( type == null ) {
|
||||
return false;
|
||||
}
|
||||
return java.util.Date.class.isAssignableFrom( type.getReturnedClass() ) ||
|
||||
java.util.Calendar.class.isAssignableFrom( type.getReturnedClass() );
|
||||
return type != null
|
||||
&& ( java.util.Date.class.isAssignableFrom( type.getReturnedClass() )
|
||||
|| java.util.Calendar.class.isAssignableFrom( type.getReturnedClass() ) );
|
||||
}
|
||||
|
||||
private Type resolveDateTimeArithmeticResultType(Type lhType, Type rhType) {
|
||||
|
@ -197,6 +197,7 @@ public class BinaryArithmeticOperatorNode extends AbstractSelectExpression imple
|
|||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setScalarColumnText(int i) throws SemanticException {
|
||||
ColumnHelper.generateSingleScalarColumn( this, i );
|
||||
}
|
||||
|
@ -206,6 +207,7 @@ public class BinaryArithmeticOperatorNode extends AbstractSelectExpression imple
|
|||
*
|
||||
* @return The left-hand operand
|
||||
*/
|
||||
@Override
|
||||
public Node getLeftHandOperand() {
|
||||
return ( Node ) getFirstChild();
|
||||
}
|
||||
|
@ -215,10 +217,12 @@ public class BinaryArithmeticOperatorNode extends AbstractSelectExpression imple
|
|||
*
|
||||
* @return The right-hand operand
|
||||
*/
|
||||
@Override
|
||||
public Node getRightHandOperand() {
|
||||
return ( Node ) getFirstChild().getNextSibling();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDisplayText() {
|
||||
return "{dataType=" + getDataType() + "}";
|
||||
}
|
||||
|
|
|
@ -48,6 +48,7 @@ public class BinaryLogicOperatorNode extends HqlSqlWalkerNode implements BinaryO
|
|||
* Performs the operator node initialization by seeking out any parameter
|
||||
* nodes and setting their expected type, if possible.
|
||||
*/
|
||||
@Override
|
||||
public void initialize() throws SemanticException {
|
||||
Node lhs = getLeftHandOperand();
|
||||
if ( lhs == null ) {
|
||||
|
@ -139,19 +140,26 @@ public class BinaryLogicOperatorNode extends HqlSqlWalkerNode implements BinaryO
|
|||
? null
|
||||
: ( ( ParameterNode ) getRightHandOperand() ).getHqlParameterSpecification();
|
||||
|
||||
translate( valueElements, comparisonType, comparisonText,
|
||||
lhsElementTexts, rhsElementTexts,
|
||||
lhsEmbeddedCompositeParameterSpecification,
|
||||
rhsEmbeddedCompositeParameterSpecification, this );
|
||||
translate(
|
||||
valueElements,
|
||||
comparisonType,
|
||||
comparisonText,
|
||||
lhsElementTexts,
|
||||
rhsElementTexts,
|
||||
lhsEmbeddedCompositeParameterSpecification,
|
||||
rhsEmbeddedCompositeParameterSpecification,
|
||||
this
|
||||
);
|
||||
}
|
||||
|
||||
protected void translate( int valueElements, int comparisonType,
|
||||
String comparisonText, String[] lhsElementTexts,
|
||||
String[] rhsElementTexts,
|
||||
ParameterSpecification lhsEmbeddedCompositeParameterSpecification,
|
||||
ParameterSpecification rhsEmbeddedCompositeParameterSpecification,
|
||||
AST container ) {
|
||||
for ( int i = valueElements - 1; i > 0; i-- ) {
|
||||
protected void translate(
|
||||
int valueElements, int comparisonType,
|
||||
String comparisonText, String[] lhsElementTexts,
|
||||
String[] rhsElementTexts,
|
||||
ParameterSpecification lhsEmbeddedCompositeParameterSpecification,
|
||||
ParameterSpecification rhsEmbeddedCompositeParameterSpecification,
|
||||
AST container) {
|
||||
for ( int i = valueElements - 1; i > 0; i-- ) {
|
||||
if ( i == 1 ) {
|
||||
AST op1 = getASTFactory().create( comparisonType, comparisonText );
|
||||
AST lhs1 = getASTFactory().create( HqlSqlTokenTypes.SQL_TOKEN, lhsElementTexts[0] );
|
||||
|
@ -168,7 +176,7 @@ public class BinaryLogicOperatorNode extends HqlSqlWalkerNode implements BinaryO
|
|||
|
||||
// "pass along" our initial embedded parameter node(s) to the first generated
|
||||
// sql fragment so that it can be handled later for parameter binding...
|
||||
SqlFragment fragment = ( SqlFragment ) lhs1;
|
||||
SqlFragment fragment = (SqlFragment) lhs1;
|
||||
if ( lhsEmbeddedCompositeParameterSpecification != null ) {
|
||||
fragment.addEmbeddedParameter( lhsEmbeddedCompositeParameterSpecification );
|
||||
}
|
||||
|
@ -188,7 +196,7 @@ public class BinaryLogicOperatorNode extends HqlSqlWalkerNode implements BinaryO
|
|||
container = newContainer;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected static String[] extractMutationTexts(Node operand, int count) {
|
||||
if ( operand instanceof ParameterNode ) {
|
||||
|
|
|
@ -81,14 +81,13 @@ public class ComponentJoin extends FromElement {
|
|||
return componentType;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Type getDataType() {
|
||||
public Type getDataType() {
|
||||
return getComponentType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIdentityColumn() {
|
||||
public String getIdentityColumn() {
|
||||
// used to "resolve" the IdentNode when our alias is encountered *by itself* in the query; so
|
||||
// here we use the component
|
||||
// NOTE : ^^ is true *except for* when encountered by itself in the SELECT clause. That gets
|
||||
|
@ -103,7 +102,7 @@ public class ComponentJoin extends FromElement {
|
|||
}
|
||||
|
||||
@Override
|
||||
public String getDisplayText() {
|
||||
public String getDisplayText() {
|
||||
return "ComponentJoin{path=" + getComponentPath() + ", type=" + componentType.getReturnedClass() + "}";
|
||||
}
|
||||
|
||||
|
@ -115,37 +114,28 @@ public class ComponentJoin extends FromElement {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Type getDataType() {
|
||||
public Type getDataType() {
|
||||
return getComponentType();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public QueryableCollection getQueryableCollection() {
|
||||
public QueryableCollection getQueryableCollection() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public PropertyMapping getPropertyMapping(String propertyName) {
|
||||
public PropertyMapping getPropertyMapping(String propertyName) {
|
||||
return propertyMapping;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Type getPropertyType(String propertyName, String propertyPath) {
|
||||
public Type getPropertyType(String propertyName, String propertyPath) {
|
||||
int index = getComponentType().getPropertyIndex( propertyName );
|
||||
return getComponentType().getSubtypes()[index];
|
||||
}
|
||||
|
||||
@Override
|
||||
public String renderScalarIdentifierSelect(int i) {
|
||||
public String renderScalarIdentifierSelect(int i) {
|
||||
String[] cols = getBasePropertyMapping().toColumns( getTableAlias(), getComponentProperty() );
|
||||
StringBuilder buf = new StringBuilder();
|
||||
// For property references generate <tablealias>.<columnname> as <projectionalias>
|
||||
|
@ -165,10 +155,12 @@ public class ComponentJoin extends FromElement {
|
|||
}
|
||||
|
||||
private final class ComponentPropertyMapping implements PropertyMapping {
|
||||
@Override
|
||||
public Type getType() {
|
||||
return getComponentType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Type toType(String propertyName) throws QueryException {
|
||||
return getBasePropertyMapping().toType( getPropertyPath( propertyName ) );
|
||||
}
|
||||
|
@ -177,10 +169,12 @@ public class ComponentJoin extends FromElement {
|
|||
return getComponentPath() + '.' + propertyName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] toColumns(String alias, String propertyName) throws QueryException {
|
||||
return getBasePropertyMapping().toColumns( alias, getPropertyPath( propertyName ) );
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] toColumns(String propertyName) throws QueryException, UnsupportedOperationException {
|
||||
return getBasePropertyMapping().toColumns( getPropertyPath( propertyName ) );
|
||||
}
|
||||
|
|
|
@ -54,6 +54,7 @@ public class ConstructorNode extends SelectExpressionList implements AggregatedS
|
|||
private boolean isMap;
|
||||
private boolean isList;
|
||||
|
||||
@Override
|
||||
public ResultTransformer getResultTransformer() {
|
||||
if ( constructor != null ) {
|
||||
return new AliasToBeanConstructorResultTransformer( constructor );
|
||||
|
@ -69,6 +70,7 @@ public class ConstructorNode extends SelectExpressionList implements AggregatedS
|
|||
|
||||
private String[] aggregatedAliases;
|
||||
|
||||
@Override
|
||||
public String[] getAggregatedAliases() {
|
||||
if ( aggregatedAliases == null ) {
|
||||
aggregatedAliases = buildAggregatedAliases();
|
||||
|
@ -78,14 +80,15 @@ public class ConstructorNode extends SelectExpressionList implements AggregatedS
|
|||
|
||||
private String[] buildAggregatedAliases() {
|
||||
SelectExpression[] selectExpressions = collectSelectExpressions();
|
||||
String[] aliases = new String[selectExpressions.length] ;
|
||||
for ( int i=0; i<selectExpressions.length; i++ ) {
|
||||
String[] aliases = new String[selectExpressions.length];
|
||||
for ( int i = 0; i < selectExpressions.length; i++ ) {
|
||||
String alias = selectExpressions[i].getAlias();
|
||||
aliases[i] = alias==null ? Integer.toString(i) : alias;
|
||||
aliases[i] = alias == null ? Integer.toString( i ) : alias;
|
||||
}
|
||||
return aliases;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setScalarColumn(int i) throws SemanticException {
|
||||
SelectExpression[] selectExpressions = collectSelectExpressions();
|
||||
// Invoke setScalarColumnText on each constructor argument.
|
||||
|
@ -95,10 +98,12 @@ public class ConstructorNode extends SelectExpressionList implements AggregatedS
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getScalarColumnIndex() {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setScalarColumnText(int i) throws SemanticException {
|
||||
SelectExpression[] selectExpressions = collectSelectExpressions();
|
||||
// Invoke setScalarColumnText on each constructor argument.
|
||||
|
@ -109,7 +114,7 @@ public class ConstructorNode extends SelectExpressionList implements AggregatedS
|
|||
}
|
||||
|
||||
@Override
|
||||
protected AST getFirstSelectExpression() {
|
||||
protected AST getFirstSelectExpression() {
|
||||
// Collect the select expressions, skip the first child because it is the class name.
|
||||
return getFirstChild().getNextSibling();
|
||||
}
|
||||
|
@ -123,8 +128,8 @@ public class ConstructorNode extends SelectExpressionList implements AggregatedS
|
|||
* @deprecated (tell clover to ignore this method)
|
||||
*/
|
||||
@Deprecated
|
||||
@Override
|
||||
public Type getDataType() {
|
||||
@Override
|
||||
public Type getDataType() {
|
||||
/*
|
||||
// Return the type of the object created by the constructor.
|
||||
AST firstChild = getFirstChild();
|
||||
|
@ -140,7 +145,7 @@ public class ConstructorNode extends SelectExpressionList implements AggregatedS
|
|||
|
||||
public void prepare() throws SemanticException {
|
||||
constructorArgumentTypes = resolveConstructorArgumentTypes();
|
||||
String path = ( ( PathNode ) getFirstChild() ).getPath();
|
||||
String path = ( (PathNode) getFirstChild() ).getPath();
|
||||
if ( "map".equals( path.toLowerCase() ) ) {
|
||||
isMap = true;
|
||||
resultType = Map.class;
|
||||
|
@ -159,7 +164,7 @@ public class ConstructorNode extends SelectExpressionList implements AggregatedS
|
|||
SelectExpression[] argumentExpressions = collectSelectExpressions();
|
||||
if ( argumentExpressions == null ) {
|
||||
// return an empty Type array
|
||||
return new Type[]{};
|
||||
return new Type[] {};
|
||||
}
|
||||
|
||||
Type[] types = new Type[argumentExpressions.length];
|
||||
|
@ -179,10 +184,10 @@ public class ConstructorNode extends SelectExpressionList implements AggregatedS
|
|||
Class holderClass = ReflectHelper.classForName( className );
|
||||
return ReflectHelper.getConstructor( holderClass, constructorArgumentTypes );
|
||||
}
|
||||
catch ( ClassNotFoundException e ) {
|
||||
catch (ClassNotFoundException e) {
|
||||
throw new DetailedSemanticException( "Unable to locate class [" + className + "]", e );
|
||||
}
|
||||
catch ( PropertyNotFoundException e ) {
|
||||
catch (PropertyNotFoundException e) {
|
||||
// this is the exception returned by ReflectHelper.getConstructor() if it cannot
|
||||
// locate an appropriate constructor
|
||||
throw new DetailedSemanticException( formatMissingContructorExceptionMessage( className ), e );
|
||||
|
@ -195,11 +200,13 @@ public class ConstructorNode extends SelectExpressionList implements AggregatedS
|
|||
for ( int j = 0; j < constructorArgumentTypes.length; j++ ) {
|
||||
params[j] = constructorArgumentTypes[j] instanceof PrimitiveType
|
||||
? ( (PrimitiveType) constructorArgumentTypes[j] ).getPrimitiveClass().getName()
|
||||
: constructorArgumentTypes[j].getReturnedClass().getName();
|
||||
: constructorArgumentTypes[j].getReturnedClass().getName();
|
||||
}
|
||||
String formattedList = params.length == 0 ? "no arguments constructor" : StringHelper.join( ", ", params );
|
||||
return String.format( "Unable to locate appropriate constructor on class [%s]. Expected arguments are: %s",
|
||||
className, formattedList );
|
||||
return String.format(
|
||||
"Unable to locate appropriate constructor on class [%s]. Expected arguments are: %s",
|
||||
className, formattedList
|
||||
);
|
||||
}
|
||||
|
||||
public Constructor getConstructor() {
|
||||
|
@ -210,32 +217,39 @@ public class ConstructorNode extends SelectExpressionList implements AggregatedS
|
|||
return Arrays.asList( constructorArgumentTypes );
|
||||
}
|
||||
|
||||
@Override
|
||||
public List getAggregatedSelectionTypeList() {
|
||||
return getConstructorArgumentTypeList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public FromElement getFromElement() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isConstructor() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isReturnableEntity() throws SemanticException {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isScalar() {
|
||||
// Constructors are always considered scalar results.
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAlias(String alias) {
|
||||
throw new UnsupportedOperationException("constructor may not be aliased");
|
||||
throw new UnsupportedOperationException( "constructor may not be aliased" );
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAlias() {
|
||||
throw new UnsupportedOperationException("constructor may not be aliased");
|
||||
throw new UnsupportedOperationException( "constructor may not be aliased" );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
|
||||
* Copyright (c) 2008, 2013, Red Hat Inc. 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.
|
||||
* distributed under license by Red Hat Inc.
|
||||
*
|
||||
* 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
|
||||
|
@ -20,46 +20,39 @@
|
|||
* Free Software Foundation, Inc.
|
||||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*
|
||||
*/
|
||||
package org.hibernate.hql.internal.ast.tree;
|
||||
|
||||
import org.hibernate.hql.internal.antlr.HqlSqlTokenTypes;
|
||||
import org.hibernate.hql.internal.antlr.SqlTokenTypes;
|
||||
import org.hibernate.internal.CoreLogging;
|
||||
import org.hibernate.internal.CoreMessageLogger;
|
||||
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
/**
|
||||
* Defines a top-level AST node representing an HQL delete statement.
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class DeleteStatement extends AbstractRestrictableStatement {
|
||||
private static final CoreMessageLogger LOG = CoreLogging.messageLogger( DeleteStatement.class );
|
||||
|
||||
private static final CoreMessageLogger LOG = Logger.getMessageLogger(CoreMessageLogger.class, DeleteStatement.class.getName());
|
||||
|
||||
/**
|
||||
* @see org.hibernate.hql.internal.ast.tree.Statement#getStatementType()
|
||||
*/
|
||||
@Override
|
||||
public int getStatementType() {
|
||||
return HqlSqlTokenTypes.DELETE;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.hibernate.hql.internal.ast.tree.Statement#needsExecutor()
|
||||
*/
|
||||
@Override
|
||||
public boolean needsExecutor() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getWhereClauseParentTokenType() {
|
||||
protected int getWhereClauseParentTokenType() {
|
||||
return SqlTokenTypes.FROM;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected CoreMessageLogger getLog() {
|
||||
return LOG;
|
||||
@Override
|
||||
protected CoreMessageLogger getLog() {
|
||||
return LOG;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
|
||||
* Copyright (c) 2008, 2013, Red Hat Inc. 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.
|
||||
* distributed under license by Red Hat Inc.
|
||||
*
|
||||
* 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
|
||||
|
@ -20,7 +20,6 @@
|
|||
* Free Software Foundation, Inc.
|
||||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*
|
||||
*/
|
||||
package org.hibernate.hql.internal.ast.tree;
|
||||
|
||||
|
@ -61,9 +60,13 @@ public class DotNode extends FromReferenceNode implements DisplayableNode, Selec
|
|||
///////////////////////////////////////////////////////////////////////////
|
||||
public static boolean useThetaStyleImplicitJoins;
|
||||
public static boolean REGRESSION_STYLE_JOIN_SUPPRESSION;
|
||||
|
||||
public static interface IllegalCollectionDereferenceExceptionBuilder {
|
||||
public QueryException buildIllegalCollectionDereferenceException(String collectionPropertyName, FromReferenceNode lhs);
|
||||
public QueryException buildIllegalCollectionDereferenceException(
|
||||
String collectionPropertyName,
|
||||
FromReferenceNode lhs);
|
||||
}
|
||||
|
||||
public static final IllegalCollectionDereferenceExceptionBuilder DEF_ILLEGAL_COLL_DEREF_EXCP_BUILDER = new IllegalCollectionDereferenceExceptionBuilder() {
|
||||
public QueryException buildIllegalCollectionDereferenceException(String propertyName, FromReferenceNode lhs) {
|
||||
String lhsPath = ASTUtil.getPathText( lhs );
|
||||
|
@ -122,6 +125,7 @@ public class DotNode extends FromReferenceNode implements DisplayableNode, Selec
|
|||
* Sets the join type for this '.' node structure.
|
||||
*
|
||||
* @param joinType The type of join to use.
|
||||
*
|
||||
* @see JoinFragment
|
||||
*/
|
||||
public void setJoinType(JoinType joinType) {
|
||||
|
@ -138,7 +142,7 @@ public class DotNode extends FromReferenceNode implements DisplayableNode, Selec
|
|||
}
|
||||
|
||||
@Override
|
||||
public String getDisplayText() {
|
||||
public String getDisplayText() {
|
||||
StringBuilder buf = new StringBuilder();
|
||||
FromElement fromElement = getFromElement();
|
||||
buf.append( "{propertyName=" ).append( propertyName );
|
||||
|
@ -163,9 +167,9 @@ public class DotNode extends FromReferenceNode implements DisplayableNode, Selec
|
|||
* @throws SemanticException
|
||||
*/
|
||||
@Override
|
||||
public void resolveFirstChild() throws SemanticException {
|
||||
FromReferenceNode lhs = ( FromReferenceNode ) getFirstChild();
|
||||
SqlNode property = ( SqlNode ) lhs.getNextSibling();
|
||||
public void resolveFirstChild() throws SemanticException {
|
||||
FromReferenceNode lhs = (FromReferenceNode) getFirstChild();
|
||||
SqlNode property = (SqlNode) lhs.getNextSibling();
|
||||
|
||||
// Set the attributes of the property reference expression.
|
||||
String propName = property.getText();
|
||||
|
@ -177,23 +181,23 @@ public class DotNode extends FromReferenceNode implements DisplayableNode, Selec
|
|||
// Resolve the LHS fully, generate implicit joins. Pass in the property name so that the resolver can
|
||||
// discover foreign key (id) properties.
|
||||
lhs.resolve( true, true, null, this );
|
||||
setFromElement( lhs.getFromElement() ); // The 'from element' that the property is in.
|
||||
setFromElement( lhs.getFromElement() ); // The 'from element' that the property is in.
|
||||
|
||||
checkSubclassOrSuperclassPropertyReference( lhs, propName );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resolveInFunctionCall(boolean generateJoin, boolean implicitJoin) throws SemanticException {
|
||||
public void resolveInFunctionCall(boolean generateJoin, boolean implicitJoin) throws SemanticException {
|
||||
if ( isResolved() ) {
|
||||
return;
|
||||
}
|
||||
Type propertyType = prepareLhs(); // Prepare the left hand side and get the data type.
|
||||
if ( propertyType!=null && propertyType.isCollectionType() ) {
|
||||
resolveIndex(null);
|
||||
Type propertyType = prepareLhs(); // Prepare the left hand side and get the data type.
|
||||
if ( propertyType != null && propertyType.isCollectionType() ) {
|
||||
resolveIndex( null );
|
||||
}
|
||||
else {
|
||||
resolveFirstChild();
|
||||
super.resolve(generateJoin, implicitJoin);
|
||||
super.resolve( generateJoin, implicitJoin );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -202,12 +206,12 @@ public class DotNode extends FromReferenceNode implements DisplayableNode, Selec
|
|||
if ( isResolved() ) {
|
||||
return;
|
||||
}
|
||||
Type propertyType = prepareLhs(); // Prepare the left hand side and get the data type.
|
||||
dereferenceCollection( ( CollectionType ) propertyType, true, true, null, parent );
|
||||
Type propertyType = prepareLhs(); // Prepare the left hand side and get the data type.
|
||||
dereferenceCollection( (CollectionType) propertyType, true, true, null, parent );
|
||||
}
|
||||
|
||||
public void resolve(boolean generateJoin, boolean implicitJoin, String classAlias, AST parent)
|
||||
throws SemanticException {
|
||||
throws SemanticException {
|
||||
// If this dot has already been resolved, stop now.
|
||||
if ( isResolved() ) {
|
||||
return;
|
||||
|
@ -234,17 +238,17 @@ public class DotNode extends FromReferenceNode implements DisplayableNode, Selec
|
|||
else if ( propertyType.isEntityType() ) {
|
||||
// The property is another class..
|
||||
checkLhsIsNotCollection();
|
||||
dereferenceEntity( ( EntityType ) propertyType, implicitJoin, classAlias, generateJoin, parent );
|
||||
dereferenceEntity( (EntityType) propertyType, implicitJoin, classAlias, generateJoin, parent );
|
||||
initText();
|
||||
}
|
||||
else if ( propertyType.isCollectionType() ) {
|
||||
// The property is a collection...
|
||||
checkLhsIsNotCollection();
|
||||
dereferenceCollection( ( CollectionType ) propertyType, implicitJoin, false, classAlias, parent );
|
||||
dereferenceCollection( (CollectionType) propertyType, implicitJoin, false, classAlias, parent );
|
||||
}
|
||||
else {
|
||||
// Otherwise, this is a primitive type.
|
||||
if ( ! CollectionProperties.isAnyCollectionProperty( propertyName ) ) {
|
||||
if ( !CollectionProperties.isAnyCollectionProperty( propertyName ) ) {
|
||||
checkLhsIsNotCollection();
|
||||
}
|
||||
dereferenceType = DereferenceType.PRIMITIVE;
|
||||
|
@ -268,17 +272,24 @@ public class DotNode extends FromReferenceNode implements DisplayableNode, Selec
|
|||
return getDataType();
|
||||
}
|
||||
|
||||
private void dereferenceCollection(CollectionType collectionType, boolean implicitJoin, boolean indexed, String classAlias, AST parent)
|
||||
throws SemanticException {
|
||||
private void dereferenceCollection(
|
||||
CollectionType collectionType,
|
||||
boolean implicitJoin,
|
||||
boolean indexed,
|
||||
String classAlias,
|
||||
AST parent)
|
||||
throws SemanticException {
|
||||
|
||||
dereferenceType = DereferenceType.COLLECTION;
|
||||
String role = collectionType.getRole();
|
||||
|
||||
//foo.bars.size (also handles deprecated stuff like foo.bars.maxelement for backwardness)
|
||||
boolean isSizeProperty = getNextSibling()!=null &&
|
||||
CollectionProperties.isAnyCollectionProperty( getNextSibling().getText() );
|
||||
boolean isSizeProperty = getNextSibling() != null &&
|
||||
CollectionProperties.isAnyCollectionProperty( getNextSibling().getText() );
|
||||
|
||||
if ( isSizeProperty ) indexed = true; //yuck!
|
||||
if ( isSizeProperty ) {
|
||||
indexed = true; //yuck!
|
||||
}
|
||||
|
||||
QueryableCollection queryableCollection = getSessionFactoryHelper().requireQueryableCollection( role );
|
||||
String propName = getPath();
|
||||
|
@ -305,7 +316,7 @@ public class DotNode extends FromReferenceNode implements DisplayableNode, Selec
|
|||
useAlias = true;
|
||||
}
|
||||
}
|
||||
if ( ! useAlias ) {
|
||||
if ( !useAlias ) {
|
||||
final String lhsTableName = lhsFromElement.getQueryable().getTableName();
|
||||
columns = getFromElement().toColumns( lhsTableName, propertyPath, false, true );
|
||||
}
|
||||
|
@ -315,23 +326,23 @@ public class DotNode extends FromReferenceNode implements DisplayableNode, Selec
|
|||
// We do not look for an existing join on the same path, because
|
||||
// it makes sense to join twice on the same collection role
|
||||
FromElementFactory factory = new FromElementFactory(
|
||||
currentFromClause,
|
||||
getLhs().getFromElement(),
|
||||
propName,
|
||||
currentFromClause,
|
||||
getLhs().getFromElement(),
|
||||
propName,
|
||||
classAlias,
|
||||
getColumns(),
|
||||
implicitJoin
|
||||
getColumns(),
|
||||
implicitJoin
|
||||
);
|
||||
FromElement elem = factory.createCollection( queryableCollection, role, joinType, fetch, indexed );
|
||||
|
||||
LOG.debugf( "dereferenceCollection() : Created new FROM element for %s : %s", propName, elem );
|
||||
|
||||
setImpliedJoin( elem );
|
||||
setFromElement( elem ); // This 'dot' expression now refers to the resulting from element.
|
||||
setFromElement( elem ); // This 'dot' expression now refers to the resulting from element.
|
||||
|
||||
if ( isSizeProperty ) {
|
||||
elem.setText("");
|
||||
elem.setUseWhereFragment(false);
|
||||
elem.setText( "" );
|
||||
elem.setUseWhereFragment( false );
|
||||
}
|
||||
|
||||
if ( !implicitJoin ) {
|
||||
|
@ -340,10 +351,15 @@ public class DotNode extends FromReferenceNode implements DisplayableNode, Selec
|
|||
getWalker().addQuerySpaces( entityPersister.getQuerySpaces() );
|
||||
}
|
||||
}
|
||||
getWalker().addQuerySpaces( queryableCollection.getCollectionSpaces() ); // Always add the collection's query spaces.
|
||||
getWalker().addQuerySpaces( queryableCollection.getCollectionSpaces() ); // Always add the collection's query spaces.
|
||||
}
|
||||
|
||||
private void dereferenceEntity(EntityType entityType, boolean implicitJoin, String classAlias, boolean generateJoin, AST parent) throws SemanticException {
|
||||
private void dereferenceEntity(
|
||||
EntityType entityType,
|
||||
boolean implicitJoin,
|
||||
String classAlias,
|
||||
boolean generateJoin,
|
||||
AST parent) throws SemanticException {
|
||||
checkForCorrelatedSubquery( "dereferenceEntity" );
|
||||
// three general cases we check here as to whether to render a physical SQL join:
|
||||
// 1) is our parent a DotNode as well? If so, our property reference is
|
||||
|
@ -373,11 +389,11 @@ public class DotNode extends FromReferenceNode implements DisplayableNode, Selec
|
|||
// our parent is another dot node, meaning we are being further dereferenced.
|
||||
// thus we need to generate a join unless the parent refers to the associated
|
||||
// entity's PK (because 'our' table would know the FK).
|
||||
parentAsDotNode = ( DotNode ) parent;
|
||||
parentAsDotNode = (DotNode) parent;
|
||||
property = parentAsDotNode.propertyName;
|
||||
joinIsNeeded = generateJoin && !isReferenceToPrimaryKey( parentAsDotNode.propertyName, entityType );
|
||||
}
|
||||
else if ( ! getWalker().isSelectStatement() ) {
|
||||
else if ( !getWalker().isSelectStatement() ) {
|
||||
// in non-select queries, the only time we should need to join is if we are in a subquery from clause
|
||||
joinIsNeeded = getWalker().getCurrentStatementType() == SqlTokenTypes.SELECT && getWalker().isInFrom();
|
||||
}
|
||||
|
@ -403,15 +419,15 @@ public class DotNode extends FromReferenceNode implements DisplayableNode, Selec
|
|||
}
|
||||
|
||||
private void dereferenceEntityJoin(String classAlias, EntityType propertyType, boolean impliedJoin, AST parent)
|
||||
throws SemanticException {
|
||||
throws SemanticException {
|
||||
dereferenceType = DereferenceType.ENTITY;
|
||||
if ( LOG.isDebugEnabled() ) {
|
||||
if ( LOG.isDebugEnabled() ) {
|
||||
LOG.debugf(
|
||||
"dereferenceEntityJoin() : generating join for %s in %s (%s) parent = %s",
|
||||
propertyName,
|
||||
getFromElement().getClassName(),
|
||||
classAlias == null ? "<no alias>" : classAlias,
|
||||
ASTUtil.getDebugString(parent)
|
||||
ASTUtil.getDebugString( parent )
|
||||
);
|
||||
}
|
||||
// Create a new FROM node for the referenced class.
|
||||
|
@ -461,27 +477,27 @@ public class DotNode extends FromReferenceNode implements DisplayableNode, Selec
|
|||
// always (?) ok to reuse.
|
||||
boolean useFoundFromElement = found && ( elem.isImplied() || areSame( classAlias, elem.getClassAlias() ) );
|
||||
|
||||
if ( ! useFoundFromElement ) {
|
||||
if ( !useFoundFromElement ) {
|
||||
// If this is an implied join in a from element, then use the impled join type which is part of the
|
||||
// tree parser's state (set by the gramamar actions).
|
||||
JoinSequence joinSequence = getSessionFactoryHelper()
|
||||
.createJoinSequence( impliedJoin, propertyType, tableAlias, joinType, joinColumns );
|
||||
.createJoinSequence( impliedJoin, propertyType, tableAlias, joinType, joinColumns );
|
||||
|
||||
// If the lhs of the join is a "component join", we need to go back to the
|
||||
// first non-component-join as the origin to properly link aliases and
|
||||
// join columns
|
||||
FromElement lhsFromElement = getLhs().getFromElement();
|
||||
while ( lhsFromElement != null && ComponentJoin.class.isInstance( lhsFromElement ) ) {
|
||||
while ( lhsFromElement != null && ComponentJoin.class.isInstance( lhsFromElement ) ) {
|
||||
lhsFromElement = lhsFromElement.getOrigin();
|
||||
}
|
||||
if ( lhsFromElement == null ) {
|
||||
throw new QueryException( "Unable to locate appropriate lhs" );
|
||||
}
|
||||
|
||||
|
||||
String role = lhsFromElement.getClassName() + "." + propertyName;
|
||||
|
||||
FromElementFactory factory = new FromElementFactory(
|
||||
currentFromClause,
|
||||
currentFromClause,
|
||||
lhsFromElement,
|
||||
joinPath,
|
||||
classAlias,
|
||||
|
@ -505,7 +521,7 @@ public class DotNode extends FromReferenceNode implements DisplayableNode, Selec
|
|||
}
|
||||
setImpliedJoin( elem );
|
||||
getWalker().addQuerySpaces( elem.getEntityPersister().getQuerySpaces() );
|
||||
setFromElement( elem ); // This 'dot' expression now refers to the resulting from element.
|
||||
setFromElement( elem ); // This 'dot' expression now refers to the resulting from element.
|
||||
}
|
||||
|
||||
private boolean areSame(String alias1, String alias2) {
|
||||
|
@ -516,7 +532,7 @@ public class DotNode extends FromReferenceNode implements DisplayableNode, Selec
|
|||
private void setImpliedJoin(FromElement elem) {
|
||||
this.impliedJoin = elem;
|
||||
if ( getFirstChild().getType() == SqlTokenTypes.DOT ) {
|
||||
DotNode dotLhs = ( DotNode ) getFirstChild();
|
||||
DotNode dotLhs = (DotNode) getFirstChild();
|
||||
if ( dotLhs.getImpliedJoin() != null ) {
|
||||
this.impliedJoin = dotLhs.getImpliedJoin();
|
||||
}
|
||||
|
@ -524,7 +540,7 @@ public class DotNode extends FromReferenceNode implements DisplayableNode, Selec
|
|||
}
|
||||
|
||||
@Override
|
||||
public FromElement getImpliedJoin() {
|
||||
public FromElement getImpliedJoin() {
|
||||
return impliedJoin;
|
||||
}
|
||||
|
||||
|
@ -541,8 +557,9 @@ public class DotNode extends FromReferenceNode implements DisplayableNode, Selec
|
|||
*
|
||||
* @param propertyName The name of the property to check.
|
||||
* @param owningType The type represeting the entity "owning" the property
|
||||
*
|
||||
* @return True if propertyName references the entity's (owningType->associatedEntity)
|
||||
* primary key; false otherwise.
|
||||
* primary key; false otherwise.
|
||||
*/
|
||||
private boolean isReferenceToPrimaryKey(String propertyName, EntityType owningType) {
|
||||
EntityPersister persister = getSessionFactoryHelper()
|
||||
|
@ -552,13 +569,15 @@ public class DotNode extends FromReferenceNode implements DisplayableNode, Selec
|
|||
// only the identifier property field name can be a reference to the associated entity's PK...
|
||||
return propertyName.equals( persister.getIdentifierPropertyName() ) && owningType.isReferenceToPrimaryKey();
|
||||
}
|
||||
// here, we have two possibilities:
|
||||
// 1) the property-name matches the explicitly identifier property name
|
||||
// 2) the property-name matches the implicit 'id' property name
|
||||
// the referenced node text is the special 'id'
|
||||
if (EntityPersister.ENTITY_ID.equals(propertyName)) return owningType.isReferenceToPrimaryKey();
|
||||
String keyPropertyName = getSessionFactoryHelper().getIdentifierOrUniqueKeyPropertyName(owningType);
|
||||
return keyPropertyName != null && keyPropertyName.equals(propertyName) && owningType.isReferenceToPrimaryKey();
|
||||
// here, we have two possibilities:
|
||||
// 1) the property-name matches the explicitly identifier property name
|
||||
// 2) the property-name matches the implicit 'id' property name
|
||||
// the referenced node text is the special 'id'
|
||||
if ( EntityPersister.ENTITY_ID.equals( propertyName ) ) {
|
||||
return owningType.isReferenceToPrimaryKey();
|
||||
}
|
||||
String keyPropertyName = getSessionFactoryHelper().getIdentifierOrUniqueKeyPropertyName( owningType );
|
||||
return keyPropertyName != null && keyPropertyName.equals( propertyName ) && owningType.isReferenceToPrimaryKey();
|
||||
}
|
||||
|
||||
private void checkForCorrelatedSubquery(String methodName) {
|
||||
|
@ -569,7 +588,7 @@ public class DotNode extends FromReferenceNode implements DisplayableNode, Selec
|
|||
|
||||
private boolean isCorrelatedSubselect() {
|
||||
return getWalker().isSubQuery() &&
|
||||
getFromElement().getFromClause() != getWalker().getCurrentFromClause();
|
||||
getFromElement().getFromClause() != getWalker().getCurrentFromClause();
|
||||
}
|
||||
|
||||
private void checkLhsIsNotCollection() throws SemanticException {
|
||||
|
@ -577,6 +596,7 @@ public class DotNode extends FromReferenceNode implements DisplayableNode, Selec
|
|||
throw ILLEGAL_COLL_DEREF_EXCP_BUILDER.buildIllegalCollectionDereferenceException( propertyName, getLhs() );
|
||||
}
|
||||
}
|
||||
|
||||
private void dereferenceComponent(AST parent) {
|
||||
dereferenceType = DereferenceType.COMPONENT;
|
||||
setPropertyNameAndPath( parent );
|
||||
|
@ -586,9 +606,11 @@ public class DotNode extends FromReferenceNode implements DisplayableNode, Selec
|
|||
// special shortcut for id properties, skip the join!
|
||||
// this must only occur at the _end_ of a path expression
|
||||
if ( LOG.isDebugEnabled() ) {
|
||||
LOG.debugf( "dereferenceShortcut() : property %s in %s does not require a join.",
|
||||
LOG.debugf(
|
||||
"dereferenceShortcut() : property %s in %s does not require a join.",
|
||||
propertyName,
|
||||
getFromElement().getClassName() );
|
||||
getFromElement().getClassName()
|
||||
);
|
||||
}
|
||||
|
||||
initText();
|
||||
|
@ -603,7 +625,7 @@ public class DotNode extends FromReferenceNode implements DisplayableNode, Selec
|
|||
|
||||
private void setPropertyNameAndPath(AST parent) {
|
||||
if ( isDotNode( parent ) ) {
|
||||
DotNode dotNode = ( DotNode ) parent;
|
||||
DotNode dotNode = (DotNode) parent;
|
||||
AST lhs = dotNode.getFirstChild();
|
||||
AST rhs = lhs.getNextSibling();
|
||||
propertyName = rhs.getText();
|
||||
|
@ -617,10 +639,12 @@ public class DotNode extends FromReferenceNode implements DisplayableNode, Selec
|
|||
}
|
||||
|
||||
@Override
|
||||
public Type getDataType() {
|
||||
public Type getDataType() {
|
||||
if ( super.getDataType() == null ) {
|
||||
FromElement fromElement = getLhs().getFromElement();
|
||||
if ( fromElement == null ) return null;
|
||||
if ( fromElement == null ) {
|
||||
return null;
|
||||
}
|
||||
// If the lhs is a collection, use CollectionPropertyMapping
|
||||
Type propertyType = fromElement.getPropertyType( propertyName, propertyPath );
|
||||
LOG.debugf( "getDataType() : %s -> %s", propertyPath, propertyType );
|
||||
|
@ -638,7 +662,7 @@ public class DotNode extends FromReferenceNode implements DisplayableNode, Selec
|
|||
}
|
||||
|
||||
public FromReferenceNode getLhs() {
|
||||
FromReferenceNode lhs = ( ( FromReferenceNode ) getFirstChild() );
|
||||
FromReferenceNode lhs = ( (FromReferenceNode) getFirstChild() );
|
||||
if ( lhs == null ) {
|
||||
throw new IllegalStateException( "DOT node with no left-hand-side!" );
|
||||
}
|
||||
|
@ -651,14 +675,14 @@ public class DotNode extends FromReferenceNode implements DisplayableNode, Selec
|
|||
* @return the full path of the node.
|
||||
*/
|
||||
@Override
|
||||
public String getPath() {
|
||||
public String getPath() {
|
||||
if ( path == null ) {
|
||||
FromReferenceNode lhs = getLhs();
|
||||
if ( lhs == null ) {
|
||||
path = getText();
|
||||
}
|
||||
else {
|
||||
SqlNode rhs = ( SqlNode ) lhs.getNextSibling();
|
||||
SqlNode rhs = (SqlNode) lhs.getNextSibling();
|
||||
path = lhs.getPath() + "." + rhs.getOriginalText();
|
||||
}
|
||||
}
|
||||
|
@ -681,16 +705,16 @@ public class DotNode extends FromReferenceNode implements DisplayableNode, Selec
|
|||
*/
|
||||
public void resolveSelectExpression() throws SemanticException {
|
||||
if ( getWalker().isShallowQuery() || getWalker().getCurrentFromClause().isSubQuery() ) {
|
||||
resolve(false, true);
|
||||
resolve( false, true );
|
||||
}
|
||||
else {
|
||||
resolve(true, false);
|
||||
resolve( true, false );
|
||||
Type type = getDataType();
|
||||
if ( type.isEntityType() ) {
|
||||
FromElement fromElement = getFromElement();
|
||||
fromElement.setIncludeSubclasses( true ); // Tell the destination fromElement to 'includeSubclasses'.
|
||||
if ( useThetaStyleImplicitJoins ) {
|
||||
fromElement.getJoinSequence().setUseThetaStyle( true ); // Use theta style (for regression)
|
||||
fromElement.getJoinSequence().setUseThetaStyle( true ); // Use theta style (for regression)
|
||||
// Move the node up, after the origin node.
|
||||
FromElement origin = fromElement.getOrigin();
|
||||
if ( origin != null ) {
|
||||
|
@ -703,7 +727,7 @@ public class DotNode extends FromReferenceNode implements DisplayableNode, Selec
|
|||
FromReferenceNode lhs = getLhs();
|
||||
while ( lhs != null ) {
|
||||
checkSubclassOrSuperclassPropertyReference( lhs, lhs.getNextSibling().getText() );
|
||||
lhs = ( FromReferenceNode ) lhs.getFirstChild();
|
||||
lhs = (FromReferenceNode) lhs.getFirstChild();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue