Example #1
0
 private AST createSubquery(AST node) {
   AST ast = ASTUtil.createParent(astFactory, RANGE, "RANGE", node);
   ast = ASTUtil.createParent(astFactory, FROM, "from", ast);
   ast = ASTUtil.createParent(astFactory, SELECT_FROM, "SELECT_FROM", ast);
   ast = ASTUtil.createParent(astFactory, QUERY, "QUERY", ast);
   return ast;
 }
Example #2
0
 private AST processIsEmpty(AST node, boolean negated) {
   node.setNextSibling(null);
   // NOTE: Because we're using ASTUtil.createParent(), the tree must be created from the bottom
   // up.
   // IS EMPTY x => (EXISTS (QUERY (SELECT_FROM (FROM x) ) ) )
   AST ast = createSubquery(node);
   ast = ASTUtil.createParent(astFactory, EXISTS, "exists", ast);
   // Add NOT if it's negated.
   if (!negated) {
     ast = ASTUtil.createParent(astFactory, NOT, "not", ast);
   }
   return ast;
 }
 /**
  * Locate the select clause that is part of this select statement. Note, that this might return
  * null as derived select clauses (i.e., no select clause at the HQL-level) get generated much
  * later than when we get created; thus it depends upon lifecycle.
  *
  * @return Our select clause, or null.
  */
 public final SelectClause getSelectClause() {
   // Due to the complexity in initializing the SelectClause, do not generate one here.
   // If it is not found; simply return null...
   //
   // Also, do not cache since it gets generated well after we are created.
   return (SelectClause) ASTUtil.findTypeInChildren(this, SqlTokenTypes.SELECT_CLAUSE);
 }
Example #4
0
 public void processMemberOf(Token n, AST p, ASTPair currentAST) {
   AST inAst = n == null ? astFactory.create(IN, "in") : astFactory.create(NOT_IN, "not in");
   astFactory.makeASTRoot(currentAST, inAst);
   AST ast = createSubquery(p);
   ast = ASTUtil.createParent(astFactory, IN_LIST, "inList", ast);
   inAst.addChild(ast);
 }
  protected void prepareFromClauseInputTree(AST fromClauseInput) {
    // Handle fiter compilation.
    // IMPORTANT NOTE: This is modifying the INPUT (HQL) tree, not the output tree!
    if (isFilter() && !isSubQuery()) {
      QueryableCollection persister =
          sessionFactoryHelper.getCollectionPersister(filterCollectionRole);
      Type collectionElementType = persister.getElementType();
      if (!collectionElementType.isEntityType()) {
        throw new QueryException("collection of values in filter: this");
      }

      String collectionElementEntityName = persister.getElementPersister().getEntityName();
      ASTFactory inputAstFactory = hqlParser.getASTFactory();
      AST fromElement =
          ASTUtil.create(inputAstFactory, HqlTokenTypes.FILTER_ENTITY, collectionElementEntityName);
      ASTUtil.createSibling(inputAstFactory, HqlTokenTypes.ALIAS, "this", fromElement);
      fromClauseInput.addChild(fromElement);
      // Show the modified AST.
      if (log.isDebugEnabled()) {
        log.debug("prepareFromClauseInputTree() : Filter - Added 'this' as a from element...");
      }
      queryTranslatorImpl.showHqlAst(hqlParser.getAST());
    }
  }
  public final OrderByClause getOrderByClause() {
    if (orderByClause == null) {
      orderByClause = locateOrderByClause();

      // if there is no order by, make one
      if (orderByClause == null) {
        log.debug("getOrderByClause() : Creating a new ORDER BY clause");
        orderByClause =
            (OrderByClause)
                ASTUtil.create(getWalker().getASTFactory(), SqlTokenTypes.ORDER, "ORDER");

        // Find the WHERE; if there is no WHERE, find the FROM...
        AST prevSibling = ASTUtil.findTypeInChildren(this, SqlTokenTypes.WHERE);
        if (prevSibling == null) {
          prevSibling = ASTUtil.findTypeInChildren(this, SqlTokenTypes.FROM);
        }

        // Now, inject the newly built ORDER BY into the tree
        orderByClause.setNextSibling(prevSibling.getNextSibling());
        prevSibling.setNextSibling(orderByClause);
      }
    }
    return orderByClause;
  }
 private AST createFromElement(String text) {
   AST ast =
       ASTUtil.create(
           fromClause.getASTFactory(),
           implied
               ? IMPLIED_FROM
               : FROM_FRAGMENT, // This causes the factory to instantiate the desired class.
           text);
   // Reset the node type, because the rest of the system is expecting FROM_FRAGMENT, all we wanted
   // was
   // for the factory to create the right sub-class.  This might get reset again later on anyway to
   // make the
   // SQL generation simpler.
   ast.setType(FROM_FRAGMENT);
   return ast;
 }
  public void resolve(boolean inSelect) throws SemanticException {
    // Get the function name node.
    AST name = getFirstChild();
    initializeMethodNode(name, inSelect);
    AST exprList = name.getNextSibling();
    // If the expression list has exactly one expression, and the type of the expression is a
    // collection
    // then this might be a collection function, such as index(c) or size(c).
    if (ASTUtil.hasExactlyOneChild(exprList)) {
      if ("type".equals(methodName)) {
        typeDiscriminator(exprList.getFirstChild());
        return;
      }
      if (isCollectionPropertyMethod()) {
        collectionProperty(exprList.getFirstChild(), name);
        return;
      }
    }

    dialectFunction(exprList);
  }
 private OrderByClause locateOrderByClause() {
   return (OrderByClause) ASTUtil.findTypeInChildren(this, SqlTokenTypes.ORDER);
 }
Example #10
0
 public List getExplicitFromElements() {
   return ASTUtil.collectChildren(this, explicitFromPredicate);
 }
Example #11
0
 public List getCollectionFetches() {
   return ASTUtil.collectChildren(this, collectionFetchPredicate);
 }
Example #12
0
 /**
  * Returns the list of from elements that will be part of the result set.
  *
  * @return the list of from elements that will be part of the result set.
  */
 public List getProjectionList() {
   return ASTUtil.collectChildren(this, projectionListPredicate);
 }
Example #13
0
 /**
  * Returns the list of from elements in order.
  *
  * @return the list of from elements (instances of FromElement).
  */
 public List getFromElements() {
   return ASTUtil.collectChildren(this, fromElementPredicate);
 }
Example #14
0
 private AST createIsNullParent(AST node, boolean negated) {
   node.setNextSibling(null);
   int type = negated ? IS_NOT_NULL : IS_NULL;
   String text = negated ? "is not null" : "is null";
   return ASTUtil.createParent(astFactory, type, text, node);
 }