jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r389557 - in /jackrabbit/branches/1.0/jackrabbit/src: main/java/org/apache/jackrabbit/core/query/lucene/ main/java/org/apache/jackrabbit/core/query/xpath/ test/java/org/apache/jackrabbit/core/query/
Date Tue, 28 Mar 2006 17:59:49 GMT
Author: jukka
Date: Tue Mar 28 09:59:47 2006
New Revision: 389557

URL: http://svn.apache.org/viewcvs?rev=389557&view=rev
Log:
1.0: Merged revisions 384804: JCR-338 Query Builder and jcr:deref problem. Can't add predicate
after jcr:deref

Added:
    jackrabbit/branches/1.0/jackrabbit/src/test/java/org/apache/jackrabbit/core/query/DerefTest.java
      - copied unchanged from r384804, incubator/jackrabbit/trunk/jackrabbit/src/test/java/org/apache/jackrabbit/core/query/DerefTest.java
Modified:
    jackrabbit/branches/1.0/jackrabbit/src/main/java/org/apache/jackrabbit/core/query/lucene/DerefQuery.java
    jackrabbit/branches/1.0/jackrabbit/src/main/java/org/apache/jackrabbit/core/query/lucene/LuceneQueryBuilder.java
    jackrabbit/branches/1.0/jackrabbit/src/main/java/org/apache/jackrabbit/core/query/xpath/SimpleNode.java
    jackrabbit/branches/1.0/jackrabbit/src/main/java/org/apache/jackrabbit/core/query/xpath/XPathQueryBuilder.java
    jackrabbit/branches/1.0/jackrabbit/src/test/java/org/apache/jackrabbit/core/query/TestAll.java

Modified: jackrabbit/branches/1.0/jackrabbit/src/main/java/org/apache/jackrabbit/core/query/lucene/DerefQuery.java
URL: http://svn.apache.org/viewcvs/jackrabbit/branches/1.0/jackrabbit/src/main/java/org/apache/jackrabbit/core/query/lucene/DerefQuery.java?rev=389557&r1=389556&r2=389557&view=diff
==============================================================================
--- jackrabbit/branches/1.0/jackrabbit/src/main/java/org/apache/jackrabbit/core/query/lucene/DerefQuery.java
(original)
+++ jackrabbit/branches/1.0/jackrabbit/src/main/java/org/apache/jackrabbit/core/query/lucene/DerefQuery.java
Tue Mar 28 09:59:47 2006
@@ -274,9 +274,13 @@
                 }
 
                 // retrieve uuids of target nodes
+                String prefix = FieldNames.createNamedValue(refProperty, "");
                 for (int i = hits.nextSetBit(0); i >= 0; i = hits.nextSetBit(i + 1)) {
                     String[] values = reader.document(i).getValues(FieldNames.PROPERTIES);
-                    String prefix = FieldNames.createNamedValue(refProperty, "");
+                    if (values == null) {
+                        // no reference properties at all on this node
+                        continue;
+                    }
                     for (int v = 0; v < values.length; v++) {
                         if (values[v].startsWith(prefix)) {
                             uuids.add(values[v].substring(prefix.length()));

Modified: jackrabbit/branches/1.0/jackrabbit/src/main/java/org/apache/jackrabbit/core/query/lucene/LuceneQueryBuilder.java
URL: http://svn.apache.org/viewcvs/jackrabbit/branches/1.0/jackrabbit/src/main/java/org/apache/jackrabbit/core/query/lucene/LuceneQueryBuilder.java?rev=389557&r1=389556&r2=389557&view=diff
==============================================================================
--- jackrabbit/branches/1.0/jackrabbit/src/main/java/org/apache/jackrabbit/core/query/lucene/LuceneQueryBuilder.java
(original)
+++ jackrabbit/branches/1.0/jackrabbit/src/main/java/org/apache/jackrabbit/core/query/lucene/LuceneQueryBuilder.java
Tue Mar 28 09:59:47 2006
@@ -508,18 +508,37 @@
         if (context == null) {
             exceptions.add(new IllegalArgumentException("Unsupported query"));
         }
+
         try {
             String refProperty = node.getRefProperty().toJCRName(nsMappings);
             String nameTest = null;
             if (node.getNameTest() != null) {
                 nameTest = node.getNameTest().toJCRName(nsMappings);
             }
-            return new DerefQuery(context, refProperty, nameTest);
+
+            if (node.getIncludeDescendants()) {
+                Query refPropQuery = new MatchAllQuery(refProperty);
+                context = new DescendantSelfAxisQuery(context, refPropQuery, false);
+            }
+
+            context = new DerefQuery(context, refProperty, nameTest);
+
+            // attach predicates
+            Object[] predicates = node.acceptOperands(this, data);
+            if (predicates.length > 0) {
+                BooleanQuery andQuery = new BooleanQuery();
+                for (int i = 0; i < predicates.length; i++) {
+                    andQuery.add((Query) predicates[i], true, false);
+                }
+                andQuery.add(context, true, false);
+                context = andQuery;
+            }
+
         } catch (NoPrefixDeclaredException e) {
             // should never happen
             exceptions.add(e);
         }
-        // fallback in case of exception
+
         return context;
     }
 

Modified: jackrabbit/branches/1.0/jackrabbit/src/main/java/org/apache/jackrabbit/core/query/xpath/SimpleNode.java
URL: http://svn.apache.org/viewcvs/jackrabbit/branches/1.0/jackrabbit/src/main/java/org/apache/jackrabbit/core/query/xpath/SimpleNode.java?rev=389557&r1=389556&r2=389557&view=diff
==============================================================================
--- jackrabbit/branches/1.0/jackrabbit/src/main/java/org/apache/jackrabbit/core/query/xpath/SimpleNode.java
(original)
+++ jackrabbit/branches/1.0/jackrabbit/src/main/java/org/apache/jackrabbit/core/query/xpath/SimpleNode.java
Tue Mar 28 09:59:47 2006
@@ -85,7 +85,7 @@
     public Object childrenAccept(XPathVisitor visitor, Object data) {
         if (children != null) {
             for (int i = 0; i < children.length; ++i) {
-                children[i].jjtAccept(visitor, data);
+                data = children[i].jjtAccept(visitor, data);
             }
         }
         return data;

Modified: jackrabbit/branches/1.0/jackrabbit/src/main/java/org/apache/jackrabbit/core/query/xpath/XPathQueryBuilder.java
URL: http://svn.apache.org/viewcvs/jackrabbit/branches/1.0/jackrabbit/src/main/java/org/apache/jackrabbit/core/query/xpath/XPathQueryBuilder.java?rev=389557&r1=389556&r2=389557&view=diff
==============================================================================
--- jackrabbit/branches/1.0/jackrabbit/src/main/java/org/apache/jackrabbit/core/query/xpath/XPathQueryBuilder.java
(original)
+++ jackrabbit/branches/1.0/jackrabbit/src/main/java/org/apache/jackrabbit/core/query/xpath/XPathQueryBuilder.java
Tue Mar 28 09:59:47 2006
@@ -323,7 +323,7 @@
             case JJTSTEPEXPR:
                 if (isAttributeAxis(node)) {
                     if (queryNode.getType() == QueryNode.TYPE_RELATION
-                            || queryNode.getType() == QueryNode.TYPE_DEREF
+                            || (queryNode.getType() == QueryNode.TYPE_DEREF && ((DerefQueryNode)
queryNode).getRefProperty() == null)
                             || queryNode.getType() == QueryNode.TYPE_ORDER
                             || queryNode.getType() == QueryNode.TYPE_PATH
                             || queryNode.getType() == QueryNode.TYPE_TEXTSEARCH) {
@@ -349,7 +349,7 @@
                     }
                 } else {
                     if (queryNode.getType() == QueryNode.TYPE_PATH) {
-                        queryNode = createLocationStep(node, (NAryQueryNode) queryNode);
+                        createLocationStep(node, (NAryQueryNode) queryNode);
                     } else if (queryNode.getType() == QueryNode.TYPE_TEXTSEARCH) {
                         // ignore
                     } else {
@@ -456,6 +456,14 @@
                     specs[specs.length - 1].setAscending(false);
                 }
                 break;
+            case JJTPREDICATELIST:
+                if (queryNode.getType() == QueryNode.TYPE_PATH) {
+                    // switch to last location
+                    QueryNode[] operands = ((PathQueryNode) queryNode).getOperands();
+                    queryNode = operands[operands.length - 1];
+                }
+                node.childrenAccept(this, queryNode);
+                break;
             default:
                 // per default traverse
                 node.childrenAccept(this, queryNode);
@@ -475,16 +483,16 @@
      */
     private LocationStepQueryNode createLocationStep(SimpleNode node, NAryQueryNode parent)
{
         LocationStepQueryNode queryNode = null;
-        boolean descenant = false;
+        boolean descendant = false;
         Node p = node.jjtGetParent();
         for (int i = 0; i < p.jjtGetNumChildren(); i++) {
             SimpleNode c = (SimpleNode) p.jjtGetChild(i);
             if (c == node) {
-                queryNode = new LocationStepQueryNode(parent, null, descenant);
+                queryNode = new LocationStepQueryNode(parent, null, descendant);
                 parent.addOperand(queryNode);
                 break;
             }
-            descenant = (c.getId() == JJTSLASHSLASH
+            descendant = (c.getId() == JJTSLASHSLASH
                     || c.getId() == JJTROOTDESCENDANTS);
         }
 
@@ -780,6 +788,14 @@
             } else if (JCR_DEREF.toJCRName(resolver).equals(fName)) {
                 // check number of arguments
                 if (node.jjtGetNumChildren() == 3) {
+                    boolean descendant = false;
+                    if (queryNode.getType() == QueryNode.TYPE_LOCATION) {
+                        LocationStepQueryNode loc = (LocationStepQueryNode) queryNode;
+                        // remember if descendant axis
+                        descendant = loc.getIncludeDescendants();
+                        queryNode = loc.getParent();
+                        ((NAryQueryNode) queryNode).removeOperand(loc);
+                    }
                     if (queryNode.getType() == QueryNode.TYPE_PATH) {
                         PathQueryNode pathNode = (PathQueryNode) queryNode;
                         DerefQueryNode derefNode = new DerefQueryNode(pathNode, null, false);
@@ -810,6 +826,20 @@
                         } else {
                             exceptions.add(new InvalidQueryException("Wrong second argument
type for jcr:like"));
                         }
+
+                        // check if descendant
+                        if (!descendant) {
+                            Node p = node.jjtGetParent();
+                            for (int i = 0; i < p.jjtGetNumChildren(); i++) {
+                                SimpleNode c = (SimpleNode) p.jjtGetChild(i);
+                                if (c == node) {
+                                    break;
+                                }
+                                descendant = (c.getId() == JJTSLASHSLASH
+                                        || c.getId() == JJTROOTDESCENDANTS);
+                            }
+                        }
+                        derefNode.setIncludeDescendants(descendant);
                         pathNode.addPathStep(derefNode);
                     } else {
                         exceptions.add(new InvalidQueryException("Unsupported location for
jcr:deref()"));

Modified: jackrabbit/branches/1.0/jackrabbit/src/test/java/org/apache/jackrabbit/core/query/TestAll.java
URL: http://svn.apache.org/viewcvs/jackrabbit/branches/1.0/jackrabbit/src/test/java/org/apache/jackrabbit/core/query/TestAll.java?rev=389557&r1=389556&r2=389557&view=diff
==============================================================================
--- jackrabbit/branches/1.0/jackrabbit/src/test/java/org/apache/jackrabbit/core/query/TestAll.java
(original)
+++ jackrabbit/branches/1.0/jackrabbit/src/test/java/org/apache/jackrabbit/core/query/TestAll.java
Tue Mar 28 09:59:47 2006
@@ -42,6 +42,7 @@
         suite.addTestSuite(XPathAxisTest.class);
         suite.addTestSuite(SkipDeletedNodesTest.class);
         suite.addTestSuite(MixinTest.class);
+        suite.addTestSuite(DerefTest.class);
         suite.addTestSuite(VersionStoreQueryTest.class);
 
         // exclude long running tests per default



Mime
View raw message