1 package org.hibernate.hql.ast.tree; 3 4 import org.hibernate.hql.antlr.HqlSqlTokenTypes; 5 import org.hibernate.hql.ast.util.ASTUtil; 6 7 import antlr.collections.AST; 8 9 import org.apache.commons.logging.Log; 10 11 16 public abstract class AbstractRestrictableStatement extends AbstractStatement implements RestrictableStatement { 17 18 private FromClause fromClause; 19 private AST whereClause; 20 21 protected abstract int getWhereClauseParentTokenType(); 22 protected abstract Log getLog(); 23 24 27 public final FromClause getFromClause() { 28 if ( fromClause == null ) { 29 fromClause = ( FromClause ) ASTUtil.findTypeInChildren( this, HqlSqlTokenTypes.FROM ); 30 } 31 return fromClause; 32 } 33 34 37 public final boolean hasWhereClause() { 38 AST whereClause = locateWhereClause(); 39 return whereClause != null && whereClause.getNumberOfChildren() > 0; 40 } 41 42 45 public final AST getWhereClause() { 46 if ( whereClause == null ) { 47 whereClause = locateWhereClause(); 48 if ( whereClause == null ) { 50 getLog().debug( "getWhereClause() : Creating a new WHERE clause..." ); 51 whereClause = ASTUtil.create( getWalker().getASTFactory(), HqlSqlTokenTypes.WHERE, "WHERE" ); 52 AST parent = ASTUtil.findTypeInChildren( this, getWhereClauseParentTokenType() ); 54 whereClause.setNextSibling( parent.getNextSibling() ); 55 parent.setNextSibling( whereClause ); 56 } 57 } 58 return whereClause; 59 } 60 61 protected AST locateWhereClause() { 62 return ASTUtil.findTypeInChildren( this, HqlSqlTokenTypes.WHERE ); 63 } 64 } 65 | Popular Tags |