jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mreut...@apache.org
Subject svn commit: r504476 - in /jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query: sql/JCRSQLQueryBuilder.java sql/QueryFormat.java xpath/QueryFormat.java
Date Wed, 07 Feb 2007 09:38:12 GMT
Author: mreutegg
Date: Wed Feb  7 01:38:11 2007
New Revision: 504476

URL: http://svn.apache.org/viewvc?view=rev&rev=504476
Log:
Minor query format fixes
- XPath: element test not used for node type query node
- SQL: format may produce invalid statement
- JCRSQL parser: create node type query node as direct child of location step node

Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/sql/JCRSQLQueryBuilder.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/sql/QueryFormat.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/xpath/QueryFormat.java

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/sql/JCRSQLQueryBuilder.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/sql/JCRSQLQueryBuilder.java?view=diff&rev=504476&r1=504475&r2=504476
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/sql/JCRSQLQueryBuilder.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/sql/JCRSQLQueryBuilder.java
Wed Feb  7 01:38:11 2007
@@ -96,6 +96,11 @@
     private final AndQueryNode constraintNode = new AndQueryNode(null);
 
     /**
+     * The QName of the node type in the from clause.
+     */
+    private QName nodeTypeName;
+
+    /**
      * List of PathQueryNode constraints that need to be merged
      */
     private final List pathConstraints = new ArrayList();
@@ -238,6 +243,14 @@
             steps[steps.length - 1].addPredicate(constraintNode);
         }
 
+        if (nodeTypeName != null) {
+            // add node type constraint
+            LocationStepQueryNode[] steps = pathNode.getPathSteps();
+            NodeTypeQueryNode nodeType
+                    = new NodeTypeQueryNode(steps[steps.length - 1], nodeTypeName);
+            steps[steps.length - 1].addPredicate(nodeType);
+        }
+
         return root;
     }
 
@@ -261,9 +274,7 @@
             public Object visit(ASTIdentifier node, Object data) {
                 if (!node.getName().equals(QName.NT_BASE)) {
                     // node is either primary or mixin node type
-                    NodeTypeQueryNode nodeType
-                            = new NodeTypeQueryNode(constraintNode, node.getName());
-                    constraintNode.addOperand(nodeType);
+                    nodeTypeName = node.getName();
                 }
                 return data;
             }

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/sql/QueryFormat.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/sql/QueryFormat.java?view=diff&rev=504476&r1=504475&r2=504476
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/sql/QueryFormat.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/sql/QueryFormat.java
Wed Feb  7 01:38:11 2007
@@ -132,14 +132,19 @@
             StringBuffer tmp = new StringBuffer();
             LocationStepQueryNode[] steps = node.getLocationNode().getPathSteps();
             QueryNode[] predicates = steps[steps.length - 1].getPredicates();
-            String and = "";
+            // are there any relevant predicates?
             for (int i = 0; i < predicates.length; i++) {
-                if (i == 0) {
+                if (predicates[i].getType() != QueryNode.TYPE_NODETYPE) {
                     tmp.append(" WHERE ");
                 }
-                tmp.append(and);
+            }
+            String and = "";
+            for (int i = 0; i < predicates.length; i++) {
+                if (predicates[i].getType() != QueryNode.TYPE_NODETYPE) {
+                    tmp.append(and);
+                    and = " AND ";
+                }
                 predicates[i].accept(this, tmp);
-                and = " AND ";
             }
 
             // node types have been collected by now
@@ -163,6 +168,10 @@
             if (steps.length == 2
                     && steps[1].getIncludeDescendants()
                     && steps[1].getNameTest() == null) {
+                // then this query selects all paths
+            } else if (steps.length == 1
+                    && steps[0].getIncludeDescendants()
+                    && steps[0].getNameTest() == null) {
                 // then this query selects all paths
             } else {
                 if (predicates.length > 0) {

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/xpath/QueryFormat.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/xpath/QueryFormat.java?view=diff&rev=504476&r1=504475&r2=504476
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/xpath/QueryFormat.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/xpath/QueryFormat.java
Wed Feb  7 01:38:11 2007
@@ -32,6 +32,7 @@
 import org.apache.jackrabbit.core.query.RelationQueryNode;
 import org.apache.jackrabbit.core.query.TextsearchQueryNode;
 import org.apache.jackrabbit.core.query.PropertyFunctionQueryNode;
+import org.apache.jackrabbit.core.query.DefaultQueryNodeVisitor;
 import org.apache.jackrabbit.name.NamespaceResolver;
 import org.apache.jackrabbit.name.NoPrefixDeclaredException;
 import org.apache.jackrabbit.name.QName;
@@ -198,17 +199,8 @@
     }
 
     public Object visit(NodeTypeQueryNode node, Object data) {
-        StringBuffer sb = (StringBuffer) data;
-        try {
-            sb.append("@");
-            NameFormat.format(QName.JCR_PRIMARYTYPE, resolver, sb);
-            sb.append("='");
-            NameFormat.format(node.getValue(), resolver, sb);
-            sb.append("'");
-        } catch (NoPrefixDeclaredException e) {
-            exceptions.add(e);
-        }
-        return sb;
+        // handled in location step visit
+        return data;
     }
 
     public Object visit(TextsearchQueryNode node, Object data) {
@@ -267,6 +259,18 @@
         if (node.getIncludeDescendants()) {
             sb.append('/');
         }
+        final QName[] nodeType = new QName[1];
+        node.acceptOperands(new DefaultQueryNodeVisitor() {
+            public Object visit(NodeTypeQueryNode node, Object data) {
+                nodeType[0] = node.getValue();
+                return data;
+            }
+        }, null);
+
+        if (nodeType[0] != null) {
+            sb.append("element(");
+        }
+
         if (node.getNameTest() == null) {
             sb.append("*");
         } else {
@@ -280,11 +284,26 @@
                 exceptions.add(e);
             }
         }
+
+        if (nodeType[0] != null) {
+            sb.append(", ");
+            try {
+                NameFormat.format(ISO9075.encode(nodeType[0]), resolver, sb);
+            } catch (NoPrefixDeclaredException e) {
+                exceptions.add(e);
+            }
+            sb.append(")");
+        }
+
         if (node.getIndex() != LocationStepQueryNode.NONE) {
             sb.append('[').append(node.getIndex()).append(']');
         }
         QueryNode[] predicates = node.getPredicates();
         for (int i = 0; i < predicates.length; i++) {
+            // ignore node type query nodes
+            if (predicates[i].getType() == QueryNode.TYPE_NODETYPE) {
+                continue;
+            }
             sb.append('[');
             predicates[i].accept(this, sb);
             sb.append(']');



Mime
View raw message