Package org.exoplatform.services.jcr.impl.core.query

Examples of org.exoplatform.services.jcr.impl.core.query.NAryQueryNode


                    exceptions.add(new InvalidQueryException("Unsupported location for fn:upper-case()"));
                }
            } else if (REP_SIMILAR.equals(funName)) {
                if (node.jjtGetNumChildren() == 3) {
                    if (queryNode instanceof NAryQueryNode) {
                        NAryQueryNode parent = (NAryQueryNode) queryNode;
                        RelationQueryNode rel = factory.createRelationQueryNode(
                                parent, RelationQueryNode.OPERATION_SIMILAR);
                        parent.addOperand(rel);
                        // assign path
                        node.jjtGetChild(1).jjtAccept(this, rel);

                        // get path string
                        node.jjtGetChild(2).jjtAccept(this, rel);
                        // check if string is set
                        if (rel.getStringValue() == null) {
                            exceptions.add(new InvalidQueryException(
                                    "Second argument for rep:similar() must be of type string"));
                        }
                    } else {
                        exceptions.add(new InvalidQueryException(
                                "Unsupported location for rep:similar()"));
                    }
                } else {
                    exceptions.add(new InvalidQueryException(
                            "Wrong number of arguments for rep:similar()"));
                }
            } else if (REP_SPELLCHECK.equals(funName)
                    && queryNode.getType() != QueryNode.TYPE_PATH) {
                if (node.jjtGetNumChildren() == 2) {
                    if (queryNode instanceof NAryQueryNode) {
                        NAryQueryNode parent = (NAryQueryNode) queryNode;
                        RelationQueryNode rel = factory.createRelationQueryNode(
                                parent, RelationQueryNode.OPERATION_SPELLCHECK);
                        parent.addOperand(rel);

                        // get string to check
                        node.jjtGetChild(1).jjtAccept(this, rel);
                        // check if string is set
                        if (rel.getStringValue() == null) {
View Full Code Here


      return node.childrenAccept(this, constraintNode);
   }

   public Object visit(ASTPredicate node, Object data)
   {
      NAryQueryNode parent = (NAryQueryNode)data;

      int type = node.getOperationType();
      QueryNode predicateNode;

      try
      {
         final InternalQName[] tmp = new InternalQName[2];
         final ASTLiteral[] value = new ASTLiteral[1];
         node.childrenAccept(new DefaultParserVisitor()
         {
            public Object visit(ASTIdentifier node, Object data)
            {
               if (tmp[0] == null)
               {
                  tmp[0] = node.getName();
               }
               else if (tmp[1] == null)
               {
                  tmp[1] = node.getName();
               }
               return data;
            }

            public Object visit(ASTLiteral node, Object data)
            {
               value[0] = node;
               return data;
            }

            public Object visit(ASTLowerFunction node, Object data)
            {
               getIdentifier(node);
               return data;
            }

            public Object visit(ASTUpperFunction node, Object data)
            {
               getIdentifier(node);
               return data;
            }

            private void getIdentifier(SimpleNode node)
            {
               if (node.jjtGetNumChildren() > 0)
               {
                  Node n = node.jjtGetChild(0);
                  if (n instanceof ASTIdentifier)
                  {
                     ASTIdentifier identifier = (ASTIdentifier)n;
                     if (tmp[0] == null)
                     {
                        tmp[0] = identifier.getName();
                     }
                     else if (tmp[1] == null)
                     {
                        tmp[1] = identifier.getName();
                     }
                  }
               }
            }
         }, data);
         InternalQName identifier = tmp[0];

         if (identifier != null && identifier.equals(Constants.JCR_PATH))
         {
            if (tmp[1] != null)
            {
               // simply ignore, this is a join of a mixin node type
            }
            else
            {
               createPathQuery(value[0].getValue(), parent.getType());
            }
            // done
            return data;
         }

         if (type == QueryConstants.OPERATION_BETWEEN)
         {
            AndQueryNode between = factory.createAndQueryNode(parent);
            RelationQueryNode rel =
               createRelationQueryNode(between, identifier, QueryConstants.OPERATION_GE_GENERAL,
                  (ASTLiteral)node.children[1]);
            node.childrenAccept(this, rel);
            between.addOperand(rel);
            rel =
               createRelationQueryNode(between, identifier, QueryConstants.OPERATION_LE_GENERAL,
                  (ASTLiteral)node.children[2]);
            node.childrenAccept(this, rel);
            between.addOperand(rel);
            predicateNode = between;
         }
         else if (type == QueryConstants.OPERATION_GE_GENERAL || type == QueryConstants.OPERATION_GT_GENERAL
            || type == QueryConstants.OPERATION_LE_GENERAL || type == QueryConstants.OPERATION_LT_GENERAL
            || type == QueryConstants.OPERATION_NE_GENERAL || type == QueryConstants.OPERATION_EQ_GENERAL)
         {
            predicateNode = createRelationQueryNode(parent, identifier, type, value[0]);
            node.childrenAccept(this, predicateNode);
         }
         else if (type == QueryConstants.OPERATION_LIKE)
         {
            ASTLiteral pattern = value[0];
            if (node.getEscapeString() != null)
            {
               if (node.getEscapeString().length() == 1)
               {
                  // backslash is the escape character we use internally
                  pattern.setValue(translateEscaping(pattern.getValue(), node.getEscapeString().charAt(0), '\\'));
               }
               else
               {
                  throw new IllegalArgumentException("ESCAPE string value must have length 1: '"
                     + node.getEscapeString() + "'");
               }
            }
            else
            {
               // no escape character specified.
               // if the pattern contains any backslash characters we need
               // to escape them.
               pattern.setValue(pattern.getValue().replaceAll("\\\\", "\\\\\\\\"));
            }
            predicateNode = createRelationQueryNode(parent, identifier, type, pattern);
            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, identifier, QueryConstants.OPERATION_EQ_VALUE,
                     (ASTLiteral)node.children[i]);
               node.childrenAccept(this, rel);
               in.addOperand(rel);
            }
            predicateNode = in;
         }
         else if (type == QueryConstants.OPERATION_NULL || type == QueryConstants.OPERATION_NOT_NULL)
         {
            predicateNode = createRelationQueryNode(parent, identifier, type, null);
         }
         else if (type == QueryConstants.OPERATION_SIMILAR)
         {
            ASTLiteral literal;
            if (node.children.length == 1)
            {
               literal = (ASTLiteral)node.children[0];
            }
            else
            {
               literal = (ASTLiteral)node.children[1];
            }
            predicateNode = createRelationQueryNode(parent, identifier, type, literal);
         }
         else if (type == QueryConstants.OPERATION_SPELLCHECK)
         {
            predicateNode =
               createRelationQueryNode(parent, Constants.JCR_PRIMARYTYPE, type, (ASTLiteral)node.children[0]);
         }
         else
         {
            throw new IllegalArgumentException("Unknown operation type: " + type);
         }
      }
      catch (ArrayIndexOutOfBoundsException e)
      {
         throw new IllegalArgumentException("Too few arguments in predicate");
      }

      if (predicateNode != null)
      {
         parent.addOperand(predicateNode);
      }

      return data;
   }
View Full Code Here

      return data;
   }

   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;
   }
View Full Code Here

      return parent;
   }

   public Object visit(ASTAndExpression node, Object data)
   {
      NAryQueryNode parent = (NAryQueryNode)data;
      AndQueryNode andQuery = factory.createAndQueryNode(parent);
      // pass to operands
      node.childrenAccept(this, andQuery);

      if (andQuery.getNumOperands() > 0)
      {
         parent.addOperand(andQuery);
      }
      return parent;
   }
View Full Code Here

      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;
   }
View Full Code Here

      return data;
   }

   public Object visit(ASTContainsExpression node, Object data)
   {
      NAryQueryNode parent = (NAryQueryNode)data;

      QPath relPath = null;
      if (node.getPropertyName() != null)
      {
         relPath = new QPath(new QPathEntry[]{new QPathEntry(node.getPropertyName(), 0)});
      }
      TextsearchQueryNode tsNode = factory.createTextsearchQueryNode(parent, node.getQuery());
      tsNode.setRelativePath(relPath);
      tsNode.setReferencesProperty(true);
      parent.addOperand(tsNode);
      return parent;
   }
View Full Code Here

                                = factory.createRelationQueryNode(queryNode,
                                        RelationQueryNode.OPERATION_NULL);
                        applyRelativePath(isNull);
                        node.childrenAccept(this, isNull);
                        NotQueryNode notNode = (NotQueryNode) queryNode;
                        NAryQueryNode parent = (NAryQueryNode) notNode.getParent();
                        parent.removeOperand(notNode);
                        parent.addOperand(isNull);
                    } else {
                        // not null expression
                        RelationQueryNode notNull =
                                factory.createRelationQueryNode(queryNode,
                                        RelationQueryNode.OPERATION_NOT_NULL);
                        applyRelativePath(notNull);
                        node.childrenAccept(this, notNull);
                        ((NAryQueryNode) queryNode).addOperand(notNull);
                    }
                } else {
                    if (queryNode.getType() == QueryNode.TYPE_PATH) {
                        createLocationStep(node, (NAryQueryNode) queryNode);
                    } else if (queryNode.getType() == QueryNode.TYPE_TEXTSEARCH
                            || queryNode.getType() == QueryNode.TYPE_RELATION) {
                        node.childrenAccept(this, queryNode);
                    } else {
                        // step within a predicate
                        RelationQueryNode tmp = factory.createRelationQueryNode(
                                null, RelationQueryNode.OPERATION_NOT_NULL);
                        node.childrenAccept(this, tmp);
                        QPathEntry[] entr = tmp.getRelativePath().getEntries();
                        if (tmpRelPath == null)
                        {

                           tmpRelPath = new QPath(new QPathEntry[]{entr[entr.length - 1]});
                        }
                        else
                        {
                           tmpRelPath = QPath.makeChildPath(tmpRelPath, entr[entr.length - 1]);
                        }
                       
                    }
                }
                break;
            case JJTNAMETEST:
                if (queryNode.getType() == QueryNode.TYPE_LOCATION
                        || queryNode.getType() == QueryNode.TYPE_DEREF
                        || queryNode.getType() == QueryNode.TYPE_RELATION
                        || queryNode.getType() == QueryNode.TYPE_TEXTSEARCH
                        || queryNode.getType() == QueryNode.TYPE_PATH) {
                    createNodeTest(node, queryNode);
                } else if (queryNode.getType() == QueryNode.TYPE_ORDER) {
                    createOrderSpec(node, (OrderQueryNode) queryNode);
                } else {
                    // traverse
                    node.childrenAccept(this, queryNode);
                }
                break;
            case JJTELEMENTNAMEORWILDCARD:
                if (queryNode.getType() == QueryNode.TYPE_LOCATION) {
                    SimpleNode child = (SimpleNode) node.jjtGetChild(0);
                    if (child.getId() != JJTANYNAME) {
                        createNodeTest(child, queryNode);
                    }
                }
                break;
            case JJTTEXTTEST:
                if (queryNode.getType() == QueryNode.TYPE_LOCATION) {
                    LocationStepQueryNode loc = (LocationStepQueryNode) queryNode;
                    loc.setNameTest(JCR_XMLTEXT);
                }
                break;
            case JJTTYPENAME:
                if (queryNode.getType() == QueryNode.TYPE_LOCATION) {
                    LocationStepQueryNode loc = (LocationStepQueryNode) queryNode;
                    String ntName = ((SimpleNode) node.jjtGetChild(0)).getValue();
                    try {
                        InternalQName nt = resolver.parseJCRName(ntName).getInternalName();
                        NodeTypeQueryNode nodeType = factory.createNodeTypeQueryNode(loc, nt);
                        loc.addPredicate(nodeType);
                    } catch (NamespaceException e) {
                        exceptions.add(new InvalidQueryException("Not a valid name: " + ntName));
                    } catch (RepositoryException e) {
                        exceptions.add(new InvalidQueryException("Not a valid name: " + ntName));
                    }
                }
                break;
            case JJTOREXPR:
                NAryQueryNode parent = (NAryQueryNode) queryNode;
                QueryNode orQueryNode = factory.createOrQueryNode(parent);
                parent.addOperand(orQueryNode);
                // traverse
                node.childrenAccept(this, orQueryNode);
                break;
            case JJTANDEXPR:
                parent = (NAryQueryNode) queryNode;
                QueryNode andQueryNode = factory.createAndQueryNode(parent);
                parent.addOperand(andQueryNode);
                // traverse
                node.childrenAccept(this, andQueryNode);
                break;
            case JJTCOMPARISONEXPR:
                createExpression(node, (NAryQueryNode) queryNode);
View Full Code Here

      return parent;
   }

   public Object visit(ASTAndExpression node, Object data)
   {
      NAryQueryNode parent = (NAryQueryNode) data;
      AndQueryNode andQuery = factory.createAndQueryNode(parent);
      // pass to operands
      node.childrenAccept(this, andQuery);

      parent.addOperand(andQuery);
      return parent;
   }
View Full Code Here

      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);

      parent.addOperand(notQuery);
      return parent;
   }
View Full Code Here

      return data;
   }

   public Object visit(ASTContainsExpression node, Object data)
   {
      NAryQueryNode parent = (NAryQueryNode) data;
      QPath relPath = null;
      if (node.getPropertyName() != null)
      {
         relPath = new QPath(new QPathEntry[]
         {new QPathEntry(node.getPropertyName(), 0)});
      }
      TextsearchQueryNode tsNode = factory.createTextsearchQueryNode(parent, node.getQuery());
      tsNode.setRelativePath(relPath);
      tsNode.setReferencesProperty(true);
      parent.addOperand(tsNode);
      return parent;
   }
View Full Code Here

TOP

Related Classes of org.exoplatform.services.jcr.impl.core.query.NAryQueryNode

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.