/** * Creates a new <code>JCRSQLQueryBuilder</code>. * * @param statement the root node of the SQL syntax tree. * @param resolver a namespace resolver to use for names in the * <code>statement</code>. * @param factory the query node factory. */ private JCRSQLQueryBuilder(ASTQuery statement, NameResolver resolver, QueryNodeFactory factory) { this.stmt = statement; this.resolver = resolver; this.factory = factory; this.constraintNode = factory.createAndQueryNode(null); }
public Object visit(ASTOrderByClause node, Object data) { QueryRootNode root = (QueryRootNode) data; OrderQueryNode order = factory.createOrderQueryNode(root); root.setOrderNode(order); node.childrenAccept(this, order); return root; }
/** * Creates a new <code>RelationQueryNode</code> without a type nor value * assigned. * * @param parent the parent node for this query node. * @param operation the operation. * @param factory the query node factory. */ protected RelationQueryNode(QueryNode parent, int operation, QueryNodeFactory factory) { super(parent); this.operation = operation; this.factory = factory; this.relPath = factory.createPathQueryNode(this); }
= factory.createRelationQueryNode(queryNode, RelationQueryNode.OPERATION_NULL); applyRelativePath(isNull); factory.createRelationQueryNode(queryNode, RelationQueryNode.OPERATION_NOT_NULL); applyRelativePath(notNull); RelationQueryNode tmp = factory.createRelationQueryNode( null, RelationQueryNode.OPERATION_NOT_NULL); node.childrenAccept(this, tmp); try { Name nt = resolver.getQName(ntName); NodeTypeQueryNode nodeType = factory.createNodeTypeQueryNode(loc, nt); loc.addPredicate(nodeType); } catch (NameException e) { case JJTOREXPR: NAryQueryNode parent = (NAryQueryNode) queryNode; QueryNode orQueryNode = factory.createOrQueryNode(parent); parent.addOperand(orQueryNode); case JJTANDEXPR: parent = (NAryQueryNode) queryNode; QueryNode andQueryNode = factory.createAndQueryNode(parent); parent.addOperand(andQueryNode); break;
public Object visit(ASTQuery node, Object data) { root = factory.createQueryRootNode(); root.setLocationNode(factory.createPathQueryNode(root)); pathNode.setAbsolute(true); if (pathConstraints.size() == 0) { LocationStepQueryNode step = factory.createLocationStepQueryNode(pathNode); step.setNameTest(null); step.setIncludeDescendants(true); LocationStepQueryNode[] steps = path.getPathSteps(); for (int i = 0; i < steps.length; i++) { LocationStepQueryNode step = factory.createLocationStepQueryNode(pathNode); step.setNameTest(steps[i].getNameTest()); step.setIncludeDescendants(steps[i].getIncludeDescendants()); = factory.createNodeTypeQueryNode(steps[steps.length - 1], nodeTypeName); steps[steps.length - 1].addPredicate(nodeType);
QueryNode not = factory.createNotQueryNode(queryNode); ((NAryQueryNode) queryNode).addOperand(not); SimpleNode literal = (SimpleNode) node.jjtGetChild(2).jjtGetChild(0); if (literal.getId() == JJTSTRINGLITERAL) { TextsearchQueryNode contains = factory.createTextsearchQueryNode( queryNode, unescapeQuotes(literal.getValue())); RelationQueryNode like = factory.createRelationQueryNode( queryNode, RelationQueryNode.OPERATION_LIKE); ((NAryQueryNode) queryNode).addOperand(like); if (queryNode.getType() == QueryNode.TYPE_RELATION) { RelationQueryNode relNode = (RelationQueryNode) queryNode; relNode.addOperand(factory.createPropertyFunctionQueryNode( relNode, PropertyFunctionQueryNode.LOWER_CASE)); if (queryNode.getType() == QueryNode.TYPE_RELATION) { RelationQueryNode relNode = (RelationQueryNode) queryNode; relNode.addOperand(factory.createPropertyFunctionQueryNode( relNode, PropertyFunctionQueryNode.UPPER_CASE)); if (queryNode instanceof NAryQueryNode) { NAryQueryNode parent = (NAryQueryNode) queryNode; RelationQueryNode rel = factory.createRelationQueryNode( parent, RelationQueryNode.OPERATION_SIMILAR); parent.addOperand(rel); if (queryNode instanceof NAryQueryNode) {
factory.createPathQueryNode(null).getValidJcrSystemNodeTypeNames()); pathNode.setAbsolute(true); pathNode.addPathStep(factory.createLocationStepQueryNode(pathNode)); pathConstraints.add(pathNode); return; if (i == 0) { pathNode.addPathStep(factory.createLocationStepQueryNode(pathNode)); } else { pathNode.addPathStep(factory.createLocationStepQueryNode(pathNode)); LocationStepQueryNode step = factory.createLocationStepQueryNode(pathNode); step.setNameTest(qName); step.setIncludeDescendants(descendant);
AndQueryNode between = factory.createAndQueryNode(parent); RelationQueryNode rel = createRelationQueryNode(between, identifier, QueryConstants.OPERATION_GE_GENERAL, (ASTLiteral) node.children[1]); node.childrenAccept(this, predicateNode); } else if (type == QueryConstants.OPERATION_IN) { OrQueryNode in = factory.createOrQueryNode(parent); for (int i = 1; i < node.children.length; i++) { RelationQueryNode rel = createRelationQueryNode(in,
public Object visit(ASTUpperFunction node, Object data) { RelationQueryNode parent = (RelationQueryNode) data; if (parent.getValueType() != QueryConstants.TYPE_STRING) { String msg = "UPPER() function is only supported for String literal"; throw new IllegalArgumentException(msg); } parent.addOperand(factory.createPropertyFunctionQueryNode(parent, PropertyFunctionQueryNode.UPPER_CASE)); return parent; }
/** * Adds a path element to the existing relative path. To add a path element * which matches all node names use {@link #STAR_NAME_TEST}. * * @param element the path element to append. */ public void addPathElement(Path.Element element) { LocationStepQueryNode step = factory.createLocationStepQueryNode(relPath); if (element.getName().equals(STAR_NAME_TEST)) { step.setNameTest(null); } else { step.setNameTest(element.getName()); } relPath.addPathStep(step); }
public Object visit(ASTOrExpression node, Object data) { NAryQueryNode parent = (NAryQueryNode) data; OrQueryNode orQuery = factory.createOrQueryNode(parent); // pass to operands node.childrenAccept(this, orQuery); if (orQuery.getNumOperands() > 0) { parent.addOperand(orQuery); } return parent; }
public Object visit(ASTNotExpression node, Object data) { NAryQueryNode parent = (NAryQueryNode) data; NotQueryNode notQuery = factory.createNotQueryNode(parent); // pass to operand node.childrenAccept(this, notQuery); if (notQuery.getNumOperands() > 0) { parent.addOperand(notQuery); } return parent; }
private DerefQueryNode createDerefQueryNode(SimpleNode node, boolean descendant, QueryNode pathNode) throws NamespaceException { DerefQueryNode derefNode = factory.createDerefQueryNode(pathNode, null, false);
this.resolver = resolver; this.factory = factory; this.root = factory.createQueryRootNode(); try {
= factory.createRelationQueryNode(queryNode, RelationQueryNode.OPERATION_NULL); applyRelativePath(isNull); factory.createRelationQueryNode(queryNode, RelationQueryNode.OPERATION_NOT_NULL); applyRelativePath(notNull); RelationQueryNode tmp = factory.createRelationQueryNode( null, RelationQueryNode.OPERATION_NOT_NULL); node.childrenAccept(this, tmp); try { Name nt = resolver.getQName(ntName); NodeTypeQueryNode nodeType = factory.createNodeTypeQueryNode(loc, nt); loc.addPredicate(nodeType); } catch (NameException e) { case JJTOREXPR: NAryQueryNode parent = (NAryQueryNode) queryNode; QueryNode orQueryNode = factory.createOrQueryNode(parent); parent.addOperand(orQueryNode); case JJTANDEXPR: parent = (NAryQueryNode) queryNode; QueryNode andQueryNode = factory.createAndQueryNode(parent); parent.addOperand(andQueryNode); break;
public Object visit(ASTQuery node, Object data) { root = factory.createQueryRootNode(); root.setLocationNode(factory.createPathQueryNode(root)); pathNode.setAbsolute(true); if (pathConstraints.size() == 0) { LocationStepQueryNode step = factory.createLocationStepQueryNode(pathNode); step.setNameTest(null); step.setIncludeDescendants(true); LocationStepQueryNode[] steps = path.getPathSteps(); for (int i = 0; i < steps.length; i++) { LocationStepQueryNode step = factory.createLocationStepQueryNode(pathNode); step.setNameTest(steps[i].getNameTest()); step.setIncludeDescendants(steps[i].getIncludeDescendants()); = factory.createNodeTypeQueryNode(steps[steps.length - 1], nodeTypeName); steps[steps.length - 1].addPredicate(nodeType);
QueryNode not = factory.createNotQueryNode(queryNode); ((NAryQueryNode) queryNode).addOperand(not); SimpleNode literal = (SimpleNode) node.jjtGetChild(2).jjtGetChild(0); if (literal.getId() == JJTSTRINGLITERAL) { TextsearchQueryNode contains = factory.createTextsearchQueryNode( queryNode, unescapeQuotes(literal.getValue())); RelationQueryNode like = factory.createRelationQueryNode( queryNode, RelationQueryNode.OPERATION_LIKE); ((NAryQueryNode) queryNode).addOperand(like); if (queryNode.getType() == QueryNode.TYPE_RELATION) { RelationQueryNode relNode = (RelationQueryNode) queryNode; relNode.addOperand(factory.createPropertyFunctionQueryNode( relNode, PropertyFunctionQueryNode.LOWER_CASE)); if (queryNode.getType() == QueryNode.TYPE_RELATION) { RelationQueryNode relNode = (RelationQueryNode) queryNode; relNode.addOperand(factory.createPropertyFunctionQueryNode( relNode, PropertyFunctionQueryNode.UPPER_CASE)); if (queryNode instanceof NAryQueryNode) { NAryQueryNode parent = (NAryQueryNode) queryNode; RelationQueryNode rel = factory.createRelationQueryNode( parent, RelationQueryNode.OPERATION_SIMILAR); parent.addOperand(rel); if (queryNode instanceof NAryQueryNode) {
factory.createPathQueryNode(null).getValidJcrSystemNodeTypeNames()); pathNode.setAbsolute(true); pathNode.addPathStep(factory.createLocationStepQueryNode(pathNode)); pathConstraints.add(pathNode); return; if (i == 0) { pathNode.addPathStep(factory.createLocationStepQueryNode(pathNode)); } else { pathNode.addPathStep(factory.createLocationStepQueryNode(pathNode)); LocationStepQueryNode step = factory.createLocationStepQueryNode(pathNode); step.setNameTest(qName); step.setIncludeDescendants(descendant);
AndQueryNode between = factory.createAndQueryNode(parent); RelationQueryNode rel = createRelationQueryNode(between, identifier, QueryConstants.OPERATION_GE_GENERAL, (ASTLiteral) node.children[1]); node.childrenAccept(this, predicateNode); } else if (type == QueryConstants.OPERATION_IN) { OrQueryNode in = factory.createOrQueryNode(parent); for (int i = 1; i < node.children.length; i++) { RelationQueryNode rel = createRelationQueryNode(in,
public Object visit(ASTLowerFunction node, Object data) { RelationQueryNode parent = (RelationQueryNode) data; if (parent.getValueType() != QueryConstants.TYPE_STRING) { String msg = "LOWER() function is only supported for String literal"; throw new IllegalArgumentException(msg); } parent.addOperand(factory.createPropertyFunctionQueryNode(parent, PropertyFunctionQueryNode.LOWER_CASE)); return parent; }