Package org.openrdf.query.parser.serql.ast

Examples of org.openrdf.query.parser.serql.ast.ASTProjectionElem


    // Iterate over all projection elements to retrieve the defined aliases
    Set<String> aliases = new HashSet<String>();
    List<Node> unaliasedNodes = new ArrayList<Node>();

    for (int i = 0; i < node.jjtGetNumChildren(); i++) {
      ASTProjectionElem projElem = (ASTProjectionElem)node.jjtGetChild(i);

      String alias = projElem.getAlias();
      if (alias == null && projElem.getValueExpr() instanceof ASTVar) {
        alias = ((ASTVar)projElem.getValueExpr()).getName();
      }

      if (alias != null) {
        boolean isUnique = aliases.add(alias);

        if (!isUnique) {
          throw new VisitorException("Duplicate projection element names: '" + alias + "'");
        }
      }
      else {
        unaliasedNodes.add(projElem);
      }
    }

    // Iterate over the unaliased nodes and generate aliases for them
    int aliasNo = 1;
    for (Node projElem : unaliasedNodes) {
      // Generate unique alias for projection element
      String alias;
      while (aliases.contains(alias = "_" + aliasNo++)) {
        // try again
      }

      aliases.add(alias);

      ASTString aliasNode = new ASTString(SyntaxTreeBuilderTreeConstants.JJTSTRING);
      aliasNode.setValue(alias);
      aliasNode.jjtSetParent(projElem);
      projElem.jjtAppendChild(aliasNode);
    }

    return data;
  }
View Full Code Here


    Set<String> bodyVars = VariableCollector.process(selectNode.jjtGetParent());

    if (selectNode.isWildcard()) {
      // Make wildcard projection explicit
      for (String varName : bodyVars) {
        ASTProjectionElem projElemNode = new ASTProjectionElem(
            SyntaxTreeBuilderTreeConstants.JJTPROJECTIONELEM);
        selectNode.jjtAppendChild(projElemNode);
        projElemNode.jjtSetParent(selectNode);

        ASTVar varNode = new ASTVar(SyntaxTreeBuilderTreeConstants.JJTVAR);
        varNode.setName(varName);
        projElemNode.jjtAppendChild(varNode);
        varNode.jjtSetParent(projElemNode);
      }

      selectNode.setWildcard(false);
    }
View Full Code Here

      throws VisitorException
    {
      Iterator<Node> iter = selectNode.jjtGetChildren().iterator();

      while (iter.hasNext()) {
        ASTProjectionElem pe = (ASTProjectionElem)iter.next();

        if (pe.getValueExpr() instanceof ASTNull) {
          logger.warn("Use of NULL values in SeRQL queries has been deprecated");
          iter.remove();
        }
      }
View Full Code Here

      // Collect all variables used in the body of the select query
      ProjectionVariableCollector visitor = new ProjectionVariableCollector();
      node.jjtGetParent().jjtAccept(visitor, null);

      for (String varName : visitor.getVariableNames()) {
        ASTProjectionElem projElemNode = new ASTProjectionElem(
            SyntaxTreeBuilderTreeConstants.JJTPROJECTIONELEM);
        node.jjtAppendChild(projElemNode);
        projElemNode.jjtSetParent(node);

        ASTVar varNode = new ASTVar(SyntaxTreeBuilderTreeConstants.JJTVAR);
        varNode.setName(varName);
        projElemNode.jjtAppendChild(varNode);
        varNode.jjtSetParent(projElemNode);
      }

      node.setWildcard(false);
    }
View Full Code Here

TOP

Related Classes of org.openrdf.query.parser.serql.ast.ASTProjectionElem

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.