Package com.impossibl.postgres.jdbc.SQLTextTree

Examples of com.impossibl.postgres.jdbc.SQLTextTree.CompositeNode


    if (nodes.size() == 0) {
      return Collections.emptyList();
    }

    CompositeNode current = new CompositeNode(startPos);

    List<Node> comps = new ArrayList<>();

    Iterator<Node> nodeIter = nodes.iterator();
    while (nodeIter.hasNext()) {

      Node node = nodeIter.next();

      if (node instanceof PieceNode && matchList.contains(((PieceNode) node).getText().toUpperCase())) {

        current.trim();

        if (current.getNodeCount() > 0) {

          comps.add(current);
          current = new CompositeNode(node.getEndPos());

        }

        if (includeMatches) {
          comps.add(node);
        }

      }
      else {

        current.add(node);
      }

    }

    current.trim();

    if (current.getNodeCount() > 0) {
      comps.add(current);
    }

    return comps;
  }
View Full Code Here


    return groupNode;
  }

  static CompositeNode sequence(String identName, Object... args) {

    CompositeNode seqNode = new CompositeNode(-1);

    seqNode.add(ident(identName));
    sequence(seqNode, asList(args));

    return seqNode;
  }
View Full Code Here

    return seqNode;
  }

  static CompositeNode sequence(Object... args) {

    CompositeNode seqNode = new CompositeNode(-1);

    sequence(seqNode, asList(args));

    return seqNode;
  }
View Full Code Here

  }

  static Node concat(Node a, Node b) {

    if (a instanceof CompositeNode) {
      CompositeNode ac = (CompositeNode) a;
      if (b instanceof CompositeNode)
        ac.nodes.addAll(((CompositeNode) b).nodes);
      else
        ac.nodes.add(b);
      return a;
    }
    else if (b instanceof CompositeNode) {
      ((CompositeNode) b).nodes.add(0, a);
      return b;
    }
    else {
      CompositeNode c = new CompositeNode(-1);
      c.add(a);
      c.add(b);
      return c;
    }
  }
View Full Code Here

              break;
            }
          case ';':
            if (parents.size() == 2) {
              paramId = 1;
              CompositeNode comp = parents.pop();
              comp.setEndPos(ndx);
              parents.peek().add(comp);
              parents.push(new StatementNode(ndx));
            }
            else {
              parents.peek().add(new GrammarPiece(";", ndx));
            }
            break;
          default:
            if (Character.isWhitespace(c)) {
              WhitespacePiece whitespacePiece = new WhitespacePiece(sql.substring(ndx, ndx + 1), ndx);
              if (parents.peek().getLastNode() instanceof WhitespacePiece) {
                ((WhitespacePiece) parents.peek().getLastNode()).coalesce(whitespacePiece);
              }
              else {
                parents.peek().add(whitespacePiece);
              }
            }
            else if (Character.isDigit(c) || (c == '+' && Character.isDigit(lookAhead(sql, ndx)))) {
              ndx = consumeNumeric(sql, ndx, parents.peek());
              continue;
            }
            else if (Character.isJavaIdentifierStart(c)) {
              ndx = consumeUnquotedIdentifier(sql, ndx, parents.peek());
              continue;
            }
            else {
              GrammarPiece grammarPiece = new GrammarPiece(sql.substring(ndx, ndx + 1), ndx);
              if (parents.peek().getLastNode() instanceof GrammarPiece) {
                ((GrammarPiece) parents.peek().getLastNode()).coalesce(grammarPiece);
              }
              else {
                parents.peek().add(grammarPiece);
              }
            }
        }

        ++ndx;
      }

      // Auto close last statement
      if (parents.peek() instanceof StatementNode) {

        StatementNode stmt = (StatementNode) parents.peek();

        stmt.trim();

        if (stmt.getNodeCount() > 0) {
          CompositeNode tmp = parents.pop();
          tmp.setEndPos(ndx);
          parents.peek().add(tmp);
        }
      }

      if (parents.peek() instanceof StatementNode == false && parents.peek() instanceof MultiStatementNode == false) {
View Full Code Here

TOP

Related Classes of com.impossibl.postgres.jdbc.SQLTextTree.CompositeNode

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.