jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mreut...@apache.org
Subject svn commit: r158774 - in incubator/jackrabbit/trunk: applications/test/ src/grammar/sql/ src/java/org/apache/jackrabbit/core/search/ src/java/org/apache/jackrabbit/core/search/lucene/ src/test/org/apache/jackrabbit/test/api/query/
Date Wed, 23 Mar 2005 14:28:33 GMT
Author: mreutegg
Date: Wed Mar 23 06:28:28 2005
New Revision: 158774

URL: http://svn.apache.org/viewcvs?view=rev&rev=158774
Log:
- Implement SQL primary to mixin type joins properly.
- Added test cases for SQL 'join'.
- Implemented QueryNode tree dump for diagnostic purpose.

Added:
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/QueryTreeDump.java
  (with props)
    incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/SQLJoinTest.java
  (with props)
Modified:
    incubator/jackrabbit/trunk/applications/test/repositoryStubImpl.properties
    incubator/jackrabbit/trunk/src/grammar/sql/JCRSQL.jjt
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/QueryNode.java
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/lucene/LuceneQueryBuilder.java
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/lucene/QueryImpl.java
    incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/AbstractQueryTest.java
    incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/TestAll.java

Modified: incubator/jackrabbit/trunk/applications/test/repositoryStubImpl.properties
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/applications/test/repositoryStubImpl.properties?view=diff&r1=158773&r2=158774
==============================================================================
--- incubator/jackrabbit/trunk/applications/test/repositoryStubImpl.properties (original)
+++ incubator/jackrabbit/trunk/applications/test/repositoryStubImpl.properties Wed Mar 23
06:28:28 2005
@@ -214,6 +214,9 @@
 # Test class: RepositoryLoginTest
 javax.jcr.tck.RepositoryLoginTest.testroot=/testdata
 
+# Test class: ReferenceableRootNodesTest
+javax.jcr.tck.ReferenceableRootNodesTest.testroot=/testdata
+
 # ------------------------------------------------------------------------------
 # observation configuration
 # ------------------------------------------------------------------------------

Modified: incubator/jackrabbit/trunk/src/grammar/sql/JCRSQL.jjt
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/grammar/sql/JCRSQL.jjt?view=diff&r1=158773&r2=158774
==============================================================================
--- incubator/jackrabbit/trunk/src/grammar/sql/JCRSQL.jjt (original)
+++ incubator/jackrabbit/trunk/src/grammar/sql/JCRSQL.jjt Wed Mar 23 06:28:28 2005
@@ -303,11 +303,11 @@
 {
   (
     (
-      identifier = Identifier() { jjtThis.setIdentifier(identifier); }
+      identifier = Identifier() { jjtThis.setIdentifier(identifier); } ( <PERIOD> identifier
= Identifier() { jjtThis.setIdentifier(identifier); } )?
       (
         (
           operationType = ComparisonOperation() { jjtThis.setOperationType(operationType);
}
-          (Literal() | identifier = Identifier() { jjtThis.setIdentifier(identifier); } )
+          (Literal() | (identifier = Identifier() { jjtThis.setIdentifier(identifier); }
( <PERIOD> identifier = Identifier() { jjtThis.setIdentifier(identifier); } )? ) )
         )
       |
         ((<NOT> { jjtThis.setNegate(true); })?

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/QueryNode.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/QueryNode.java?view=diff&r1=158773&r2=158774
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/QueryNode.java (original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/QueryNode.java Wed
Mar 23 06:28:28 2005
@@ -87,6 +87,16 @@
     }
 
     /**
+     * Dumps this QueryNode and its child nodes to a String.
+     * @return the query tree as a String.
+     */
+    public String dump() {
+        StringBuffer tmp = new StringBuffer();
+        QueryTreeDump.dump(this, tmp);
+        return tmp.toString();
+    }
+
+    /**
      * Accepts a {@link QueryNodeVisitor} and calls the apropriate <code>visit</code>
      * method on the visitor depending on the concrete implementation of
      * this <code>QueryNode</code>.

Added: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/QueryTreeDump.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/QueryTreeDump.java?view=auto&rev=158774
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/QueryTreeDump.java
(added)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/QueryTreeDump.java
Wed Mar 23 06:28:28 2005
@@ -0,0 +1,267 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ *                     as applicable.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.core.search;
+
+import org.apache.jackrabbit.core.QName;
+
+import java.util.Arrays;
+
+/**
+ * Utility class to dump a {@link QueryNode} tree to a StringBuffer.
+ */
+public class QueryTreeDump implements QueryNodeVisitor {
+
+    /** Current indentation level */
+    private int indent;
+
+    /** Padding array filled with spaces */
+    private static final char[] PADDING = new char[255];
+
+    static {
+        Arrays.fill(PADDING, ' ');
+    }
+
+    /**
+     * Dumps the node tree to buffer.
+     * @param node the root node.
+     * @param buffer where to dump the tree.
+     */
+    private QueryTreeDump(QueryNode node, StringBuffer buffer) {
+        node.accept(this, buffer);
+    }
+
+    /**
+     * Dumps a query node tree to the string <code>buffer</code>.
+     * @param node the root node of a query tree.
+     * @param buffer a string buffer where to dump the tree structure.
+     */
+    public static void dump(QueryNode node, StringBuffer buffer) {
+        new QueryTreeDump(node, buffer);
+    }
+
+    public Object visit(QueryRootNode node, Object data) {
+        StringBuffer buffer = (StringBuffer) data;
+        buffer.append("+ Root node");
+        buffer.append("\n");
+        // select properties
+        QName[] select = node.getSelectProperties();
+        buffer.append("+ Select properties: ");
+        if (select.length == 0) {
+            buffer.append("*");
+        } else {
+            String comma = "";
+            for (int i = 0; i < select.length; i++) {
+                buffer.append(comma);
+                buffer.append(select[i].toString());
+                comma = ", ";
+            }
+        }
+        buffer.append("\n");
+        // path
+        traverse(new QueryNode[]{node.getLocationNode()}, buffer);
+        // order by
+        OrderQueryNode order = node.getOrderNode();
+        if (order != null) {
+            traverse(new QueryNode[]{order}, buffer);
+        }
+        return buffer;
+    }
+
+    public Object visit(OrQueryNode node, Object data) {
+        StringBuffer buffer = (StringBuffer) data;
+        buffer.append(PADDING, 0, indent);
+        buffer.append("+ OrQueryNode");
+        buffer.append("\n");
+        traverse(node.getOperands(), buffer);
+        return buffer;
+    }
+
+    public Object visit(AndQueryNode node, Object data) {
+        StringBuffer buffer = (StringBuffer) data;
+        buffer.append(PADDING, 0, indent);
+        buffer.append("+ AndQueryNode");
+        buffer.append("\n");
+        traverse(node.getOperands(), buffer);
+        return buffer;
+    }
+
+    public Object visit(NotQueryNode node, Object data) {
+        StringBuffer buffer = (StringBuffer) data;
+        buffer.append(PADDING, 0, indent);
+        buffer.append("+ NotQueryNode");
+        buffer.append("\n");
+        traverse(node.getOperands(), buffer);
+        return buffer;
+    }
+
+    public Object visit(ExactQueryNode node, Object data) {
+        StringBuffer buffer = (StringBuffer) data;
+        buffer.append(PADDING, 0, indent);
+        buffer.append("+ ExactQueryNode: ");
+        buffer.append(" Prop=").append(node.getPropertyName());
+        buffer.append(" Value=").append(node.getValue());
+        buffer.append("\n");
+        return buffer;
+    }
+
+    public Object visit(NodeTypeQueryNode node, Object data) {
+        StringBuffer buffer = (StringBuffer) data;
+        buffer.append(PADDING, 0, indent);
+        buffer.append("+ NodeTypeQueryNode: ");
+        buffer.append(" Prop=").append(node.getPropertyName());
+        buffer.append(" Value=").append(node.getValue());
+        buffer.append("\n");
+        return buffer;
+    }
+
+    public Object visit(TextsearchQueryNode node, Object data) {
+        StringBuffer buffer = (StringBuffer) data;
+        buffer.append(PADDING, 0, indent);
+        buffer.append("+ TextsearchQueryNode: ");
+        buffer.append(" Query=").append(node.getQuery());
+        buffer.append("\n");
+        return buffer;
+    }
+
+    public Object visit(PathQueryNode node, Object data) {
+        StringBuffer buffer = (StringBuffer) data;
+        buffer.append(PADDING, 0, indent);
+        buffer.append("+ PathQueryNode");
+        buffer.append("\n");
+        traverse(node.getOperands(), buffer);
+        return buffer;
+    }
+
+    public Object visit(LocationStepQueryNode node, Object data) {
+        StringBuffer buffer = (StringBuffer) data;
+        buffer.append(PADDING, 0, indent);
+        buffer.append("+ LocationStepQueryNode: ");
+        buffer.append(" NodeTest=");
+        if (node.getNameTest() == null) {
+            buffer.append("*");
+        } else {
+            buffer.append(node.getNameTest());
+        }
+        buffer.append(" Descendants=").append(node.getIncludeDescendants());
+        buffer.append(" Index=");
+        if (node.getIndex() == LocationStepQueryNode.NONE) {
+            buffer.append("NONE");
+        } else if (node.getIndex() == LocationStepQueryNode.LAST) {
+            buffer.append("last()");
+        } else {
+            buffer.append(node.getIndex());
+        }
+        buffer.append("\n");
+        traverse(node.getOperands(), buffer);
+        return buffer;
+    }
+
+    public Object visit(RelationQueryNode node, Object data) {
+        StringBuffer buffer = (StringBuffer) data;
+        buffer.append(PADDING, 0, indent);
+        buffer.append("+ RelationQueryNode: Op: ");
+        if (node.getOperation() == QueryConstants.OPERATION_BETWEEN) {
+            buffer.append("BETWEEN");
+        } else if (node.getOperation() == QueryConstants.OPERATION_EQ_GENERAL) {
+            buffer.append("= ");
+        } else if (node.getOperation() == QueryConstants.OPERATION_EQ_VALUE) {
+            buffer.append("eq");
+        } else if (node.getOperation() == QueryConstants.OPERATION_GE_VALUE) {
+            buffer.append("ge");
+        } else if (node.getOperation() == QueryConstants.OPERATION_GT_VALUE) {
+            buffer.append("gt");
+        } else if (node.getOperation() == QueryConstants.OPERATION_IN) {
+            buffer.append("IN");
+        } else if (node.getOperation() == QueryConstants.OPERATION_LE_VALUE) {
+            buffer.append("le");
+        } else if (node.getOperation() == QueryConstants.OPERATION_LIKE) {
+            buffer.append("LIKE");
+        } else if (node.getOperation() == QueryConstants.OPERATION_LT_VALUE) {
+            buffer.append("lt");
+        } else if (node.getOperation() == QueryConstants.OPERATION_NE_GENERAL) {
+            buffer.append("<>");
+        } else if (node.getOperation() == QueryConstants.OPERATION_NE_VALUE) {
+            buffer.append("ne");
+        } else if (node.getOperation() == QueryConstants.OPERATION_NOT_NULL) {
+            buffer.append("NOT NULL");
+        } else if (node.getOperation() == QueryConstants.OPERATION_NULL) {
+            buffer.append("IS NULL");
+        }
+        if (node.getValueType() == QueryConstants.TYPE_DATE) {
+            buffer.append(" Type=DATE Value=").append(node.getDateValue());
+        } else if (node.getValueType() == QueryConstants.TYPE_DOUBLE) {
+            buffer.append(" Type=DOUBLE Value=").append(node.getDoubleValue());
+        } else if (node.getValueType() == QueryConstants.TYPE_LONG) {
+            buffer.append(" Type=LONG Value=").append(node.getLongValue());
+        } else if (node.getValueType() == QueryConstants.TYPE_POSITION) {
+            buffer.append(" Type=POS Value=").append(node.getPositionValue());
+        } else if (node.getValueType() == QueryConstants.TYPE_STRING) {
+            buffer.append(" Type=STRING Value=").append(node.getStringValue());
+        } else if (node.getValueType() == QueryConstants.TYPE_TIMESTAMP) {
+            buffer.append(" Type=TIMESTAMP Value=").append(node.getDateValue());
+        }
+        buffer.append("\n");
+        return buffer;
+    }
+
+    public Object visit(OrderQueryNode node, Object data) {
+        StringBuffer buffer = (StringBuffer) data;
+        buffer.append(PADDING, 0, indent);
+        buffer.append("+ OrderQueryNode");
+        buffer.append("\n");
+        OrderQueryNode.OrderSpec[] specs = node.getOrderSpecs();
+        for (int i = 0; i < specs.length; i++) {
+            buffer.append(PADDING, 0, indent);
+            buffer.append("  ").append(specs[i].getProperty());
+            buffer.append(" asc=").append(specs[i].isAscending());
+            buffer.append("\n");
+        }
+        return buffer;
+    }
+
+    public Object visit(DerefQueryNode node, Object data) {
+        StringBuffer buffer = (StringBuffer) data;
+        buffer.append(PADDING, 0, indent);
+        buffer.append("+ DerefQueryNode: ");
+        buffer.append(" NodeTest=");
+        if (node.getNameTest() == null) {
+            buffer.append("*");
+        } else {
+            buffer.append(node.getNameTest());
+        }
+        buffer.append(" Descendants=").append(node.getIncludeDescendants());
+        buffer.append(" Index=");
+        if (node.getIndex() == LocationStepQueryNode.NONE) {
+            buffer.append("NONE");
+        } else if (node.getIndex() == LocationStepQueryNode.LAST) {
+            buffer.append("last()");
+        } else {
+            buffer.append(node.getIndex());
+        }
+        buffer.append("\n");
+        traverse(node.getOperands(), buffer);
+        return buffer;
+    }
+
+    private void traverse(QueryNode[] node, StringBuffer buffer) {
+        indent += 2;
+        for (int i = 0; i < node.length; i++) {
+            node[i].accept(this, buffer);
+        }
+        indent -= 2;
+    }
+}

Propchange: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/QueryTreeDump.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/lucene/LuceneQueryBuilder.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/lucene/LuceneQueryBuilder.java?view=diff&r1=158773&r2=158774
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/lucene/LuceneQueryBuilder.java
(original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/lucene/LuceneQueryBuilder.java
Wed Mar 23 06:28:28 2005
@@ -83,6 +83,11 @@
     private static QName primaryType = org.apache.jackrabbit.core.Constants.JCR_PRIMARYTYPE;
 
     /**
+     * QName for jcr:mixinTypes
+     */
+    private static QName mixinTypes = org.apache.jackrabbit.core.Constants.JCR_MIXINTYPES;
+
+    /**
      * Root node of the abstract query tree
      */
     private QueryRootNode root;
@@ -256,10 +261,14 @@
         String field = "";
         List values = new ArrayList();
         try {
-            field = Constants.JCR_PRIMARYTYPE.toJCRName(nsMappings);
             values.add(node.getValue().toJCRName(nsMappings));
             NodeTypeManager ntMgr = session.getWorkspace().getNodeTypeManager();
             NodeType base = ntMgr.getNodeType(node.getValue().toJCRName(session.getNamespaceResolver()));
+            if (base.isMixin()) {
+                field = mixinTypes.toJCRName(nsMappings);
+            } else {
+                field = primaryType.toJCRName(nsMappings);
+            }
             NodeTypeIterator allTypes = ntMgr.getAllNodeTypes();
             while (allTypes.hasNext()) {
                 NodeType nt = allTypes.nextNodeType();

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/lucene/QueryImpl.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/lucene/QueryImpl.java?view=diff&r1=158773&r2=158774
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/lucene/QueryImpl.java
(original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/lucene/QueryImpl.java
Wed Mar 23 06:28:28 2005
@@ -114,6 +114,9 @@
      * @throws RepositoryException if an error occurs
      */
     public QueryResult execute() throws RepositoryException {
+        if (log.isDebugEnabled()) {
+            log.debug("Executing query: \n" + root.dump());
+        }
         // build lucene query
         Query query = LuceneQueryBuilder.createQuery(root, session,
                 index.getItemStateProvider(), index.getNamespaceMappings(),

Modified: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/AbstractQueryTest.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/AbstractQueryTest.java?view=diff&r1=158773&r2=158774
==============================================================================
--- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/AbstractQueryTest.java
(original)
+++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/AbstractQueryTest.java
Wed Mar 23 06:28:28 2005
@@ -249,6 +249,19 @@
     }
 
     /**
+     * Executes the <code>sql</code> query and checks the results against
+     * the specified <code>nodes</code>.
+     * @param session the session to use for the query.
+     * @param sql the sql query.
+     * @param nodes the expected result nodes.
+     */
+    protected void executeSqlQuery(Session session, String sql, Node[] nodes)
+            throws RepositoryException {
+        QueryResult res = session.getWorkspace().getQueryManager().createQuery(sql, Query.SQL).execute();
+        checkResult(res, nodes);
+    }
+
+    /**
      * Checks if the result set contains exactly the <code>nodes</code>.
      * @param result the query result.
      * @param nodes the expected nodes in the result set.

Added: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/SQLJoinTest.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/SQLJoinTest.java?view=auto&rev=158774
==============================================================================
--- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/SQLJoinTest.java
(added)
+++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/SQLJoinTest.java
Wed Mar 23 06:28:28 2005
@@ -0,0 +1,135 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ *                     as applicable.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.test.api.query;
+
+import org.apache.jackrabbit.test.NotExecutableException;
+
+import javax.jcr.RepositoryException;
+import javax.jcr.Node;
+
+/**
+ * Tests SQL statements with a join of a node type with a mixin type.
+ *
+ * @tck.config testroot path to node that allows child nodes of type:
+ *   <code>nodetype</code>
+ * @tck.config nodetype name of a node type that allows assignment of mixin
+ *   referenceable.
+ * @tck.config nodename1 name of a child node of type: <code>nodetype</code>.
+ * @tck.config nodename2 name of a child node of type: <code>nodetype</code>.
+ *
+ * @test
+ * @sources SQLJoinTest.java
+ * @executeClass org.apache.jackrabbit.test.api.query.SQLJoinTest
+ * @keywords sql
+ */
+public class SQLJoinTest extends AbstractQueryTest {
+
+    /**
+     * Test a SQL query with a primary and mixin nodetype join.
+     */
+    public void testJoin() throws RepositoryException {
+        Node n1 = testRootNode.addNode(nodeName1, testNodeType);
+        n1.addMixin(mixReferenceable);
+        testRootNode.addNode(nodeName2, testNodeType);
+        testRootNode.save();
+
+        StringBuffer query = new StringBuffer("SELECT * FROM ");
+        query.append(testNodeType).append(", ").append(mixReferenceable);
+        query.append(" WHERE ");
+        query.append(testNodeType).append(".").append(jcrPath);
+        query.append(" = ");
+        query.append(mixReferenceable).append(".").append(jcrPath);
+        query.append(" AND ").append(jcrPath).append(" LIKE ");
+        query.append("'").append(testRoot).append("/%'");
+
+        executeSqlQuery(superuser, query.toString(), new Node[]{n1});
+    }
+
+    /**
+     * Test a SQL query with a nt:base primary type and mixin nodetype join.
+     */
+    public void testJoinNtBase() throws RepositoryException {
+        Node n1 = testRootNode.addNode(nodeName1, testNodeType);
+        n1.addMixin(mixReferenceable);
+        testRootNode.addNode(nodeName2, testNodeType);
+        testRootNode.save();
+
+        StringBuffer query = new StringBuffer("SELECT * FROM ");
+        query.append(ntBase).append(", ").append(mixReferenceable);
+        query.append(" WHERE ");
+        query.append(testNodeType).append(".").append(jcrPath);
+        query.append(" = ");
+        query.append(mixReferenceable).append(".").append(jcrPath);
+        query.append(" AND ").append(jcrPath).append(" LIKE ");
+        query.append("'").append(testRoot).append("/%'");
+
+        executeSqlQuery(superuser, query.toString(), new Node[]{n1});
+    }
+
+    /**
+     * Test a SQL query with a primary type and mixin nodetype join.
+     */
+    public void testJoinFilterPrimaryType() throws RepositoryException {
+        Node n1 = testRootNode.addNode(nodeName1, testNodeType);
+        n1.addMixin(mixReferenceable);
+        Node n2 = testRootNode.addNode(nodeName2, ntBase);
+        n2.addMixin(mixReferenceable);
+        testRootNode.save();
+
+        StringBuffer query = new StringBuffer("SELECT * FROM ");
+        query.append(testNodeType).append(", ").append(ntBase);
+        query.append(" WHERE ");
+        query.append(testNodeType).append(".").append(jcrPath);
+        query.append(" = ");
+        query.append(mixReferenceable).append(".").append(jcrPath);
+        query.append(" AND ").append(jcrPath).append(" LIKE ");
+        query.append("'").append(testRoot).append("/%'");
+
+        executeSqlQuery(superuser, query.toString(), new Node[]{n1});
+    }
+
+    /**
+     * Test a SQL query with a primary and mixin nodetype join on child nodes
+     * with same name siblings.
+     * @tck.config testroot path to node that allows child nodes with same name.
+     * @tck.config nodename1 node name of the same name siblings.
+     * @throws NotExecutableException if <code>testroot</code> does not allow
+     *  same name siblings.
+     */
+    public void testJoinSNS() throws RepositoryException, NotExecutableException {
+        Node n1 = testRootNode.addNode(nodeName1, testNodeType);
+        n1.addMixin(mixReferenceable);
+        if (!n1.getDefinition().allowSameNameSibs()) {
+            throw new NotExecutableException("Node at " + testRoot + " does not allow same
name siblings with name " + nodeName1);
+        }
+        testRootNode.addNode(nodeName1, testNodeType);
+        Node n2 = testRootNode.addNode(nodeName2, testNodeType);
+        n2.addMixin(mixReferenceable);
+        testRootNode.save();
+
+        StringBuffer query = new StringBuffer("SELECT * FROM ");
+        query.append(testNodeType).append(", ").append(mixReferenceable);
+        query.append(" WHERE ");
+        query.append(testNodeType).append(".").append(jcrPath);
+        query.append(" = ");
+        query.append(mixReferenceable).append(".").append(jcrPath);
+        query.append(" AND ").append(jcrPath).append(" LIKE ");
+        query.append("'").append(testRoot).append("/%'");
+
+        executeSqlQuery(superuser, query.toString(), new Node[]{n1, n2});
+    }
+}

Propchange: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/SQLJoinTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/TestAll.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/TestAll.java?view=diff&r1=158773&r2=158774
==============================================================================
--- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/TestAll.java
(original)
+++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/TestAll.java
Wed Mar 23 06:28:28 2005
@@ -40,6 +40,7 @@
         suite.addTestSuite(SaveTest.class);
         suite.addTestSuite(SQLOrderByTest.class);
         suite.addTestSuite(SQLQueryLevel2Test.class);
+        suite.addTestSuite(SQLJoinTest.class);
         suite.addTestSuite(XPathPosIndexTest.class);
         suite.addTestSuite(XPathDocOrderTest.class);
         suite.addTestSuite(XPathOrderByTest.class);



Mime
View raw message