jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From thom...@apache.org
Subject svn commit: r1378961 - in /jackrabbit/oak/trunk/oak-jcr/src: main/java/org/apache/jackrabbit/oak/jcr/query/qom/ test/java/org/apache/jackrabbit/oak/jcr/query/qom/
Date Thu, 30 Aug 2012 14:37:40 GMT
Author: thomasm
Date: Thu Aug 30 14:37:39 2012
New Revision: 1378961

URL: http://svn.apache.org/viewvc?rev=1378961&view=rev
Log:
OAK-28 Query implementation - JQOM toString(): quote names as toString() is used to create
the SQL-2 statement

Modified:
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/ChildNodeImpl.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/ChildNodeJoinConditionImpl.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/ColumnImpl.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/DescendantNodeImpl.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/DescendantNodeJoinConditionImpl.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/EquiJoinConditionImpl.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/FullTextSearchImpl.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/FullTextSearchScoreImpl.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/LengthImpl.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/NodeLocalNameImpl.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/NodeNameImpl.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/PropertyExistenceImpl.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/PropertyValueImpl.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/QOMNode.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/SameNodeImpl.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/SameNodeJoinConditionImpl.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/SelectorImpl.java
    jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/query/qom/QomTest.java

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/ChildNodeImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/ChildNodeImpl.java?rev=1378961&r1=1378960&r2=1378961&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/ChildNodeImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/ChildNodeImpl.java
Thu Aug 30 14:37:39 2012
@@ -45,7 +45,9 @@ public class ChildNodeImpl extends Const
 
     @Override
     public String toString() {
-        return "ISCHILDNODE(" + selectorName + ", " + quotePath(parentPath) + ')';
+        return "ISCHILDNODE(" +
+                quoteSelectorName(selectorName) + ", " +
+                quotePath(parentPath) + ')';
     }
 
     @Override

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/ChildNodeJoinConditionImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/ChildNodeJoinConditionImpl.java?rev=1378961&r1=1378960&r2=1378961&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/ChildNodeJoinConditionImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/ChildNodeJoinConditionImpl.java
Thu Aug 30 14:37:39 2012
@@ -45,9 +45,9 @@ public class ChildNodeJoinConditionImpl 
 
     @Override
     public String toString() {
-        String child = getChildSelectorName();
-        String parent = getParentSelectorName();
-        return "ISCHILDNODE(" + child + ", " + parent + ')';
+        return "ISCHILDNODE(" +
+                quoteSelectorName(childSelectorName) + ", " +
+                quoteSelectorName(parentSelectorName) + ")";
     }
 
 }
\ No newline at end of file

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/ColumnImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/ColumnImpl.java?rev=1378961&r1=1378960&r2=1378961&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/ColumnImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/ColumnImpl.java
Thu Aug 30 14:37:39 2012
@@ -51,10 +51,11 @@ public class ColumnImpl extends QOMNode 
     @Override
     public String toString() {
         if (propertyName != null) {
-            return getSelectorName() + '.' + getPropertyName()
-                    + " AS [" + columnName + "]";
+            return quoteSelectorName(selectorName) + '.' +
+                    quotePropertyName(propertyName) +
+                    " AS " + quoteColumnName(columnName);
         }
-        return getSelectorName() + ".*";
+        return quoteSelectorName(selectorName) + ".*";
     }
 
 }

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/DescendantNodeImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/DescendantNodeImpl.java?rev=1378961&r1=1378960&r2=1378961&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/DescendantNodeImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/DescendantNodeImpl.java
Thu Aug 30 14:37:39 2012
@@ -45,7 +45,9 @@ public class DescendantNodeImpl extends 
 
     @Override
     public String toString() {
-        return "ISDESCENDANTNODE(" + getSelectorName() + ", " + quotePath(ancestorPath) +
')';
+        return "ISDESCENDANTNODE(" +
+                quoteSelectorName(selectorName) + ", " +
+                quotePath(ancestorPath) + ')';
     }
 
     @Override

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/DescendantNodeJoinConditionImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/DescendantNodeJoinConditionImpl.java?rev=1378961&r1=1378960&r2=1378961&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/DescendantNodeJoinConditionImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/DescendantNodeJoinConditionImpl.java
Thu Aug 30 14:37:39 2012
@@ -47,9 +47,9 @@ public class DescendantNodeJoinCondition
 
     @Override
     public String toString() {
-        String descendant = getDescendantSelectorName();
-        String ancestor = getAncestorSelectorName();
-        return "ISDESCENDANTNODE(" + descendant + ", " + ancestor + ')';
+        return "ISDESCENDANTNODE(" +
+                quoteSelectorName(descendantSelectorName) + ", " +
+                quoteSelectorName(ancestorSelectorName) + ')';
     }
 
 }

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/EquiJoinConditionImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/EquiJoinConditionImpl.java?rev=1378961&r1=1378960&r2=1378961&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/EquiJoinConditionImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/EquiJoinConditionImpl.java
Thu Aug 30 14:37:39 2012
@@ -60,9 +60,10 @@ public class EquiJoinConditionImpl exten
 
     @Override
     public String toString() {
-        // TODO quote property names?
-        return getSelector1Name() + '.' + getProperty1Name()
-                + " = " + getSelector2Name() + '.' + getProperty2Name();
+        return quoteSelectorName(selector1Name) + '.' +
+                quotePropertyName(property1Name) + " = " +
+                quoteSelectorName(selector2Name) + '.' +
+                quotePropertyName(property2Name);
     }
 
 }

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/FullTextSearchImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/FullTextSearchImpl.java?rev=1378961&r1=1378960&r2=1378961&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/FullTextSearchImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/FullTextSearchImpl.java
Thu Aug 30 14:37:39 2012
@@ -53,13 +53,12 @@ public class FullTextSearchImpl extends 
 
     @Override
     public String toString() {
-        // TODO quote property names?
         StringBuilder builder = new StringBuilder();
         builder.append("CONTAINS(");
-        builder.append(getSelectorName());
+        builder.append(quoteSelectorName(selectorName));
         if (propertyName != null) {
             builder.append('.');
-            builder.append(propertyName);
+            builder.append(quotePropertyName(propertyName));
             builder.append(", ");
         } else {
             builder.append(".*, ");

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/FullTextSearchScoreImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/FullTextSearchScoreImpl.java?rev=1378961&r1=1378960&r2=1378961&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/FullTextSearchScoreImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/FullTextSearchScoreImpl.java
Thu Aug 30 14:37:39 2012
@@ -38,7 +38,7 @@ public class FullTextSearchScoreImpl ext
 
     @Override
     public String toString() {
-        return "SCORE(" + getSelectorName() + ')';
+        return "SCORE(" + quoteSelectorName(selectorName) + ')';
     }
 
 }

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/LengthImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/LengthImpl.java?rev=1378961&r1=1378960&r2=1378961&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/LengthImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/LengthImpl.java
Thu Aug 30 14:37:39 2012
@@ -38,7 +38,7 @@ public class LengthImpl extends DynamicO
 
     @Override
     public String toString() {
-        return "LENGTH(" + getPropertyValue() + ')';
+        return "LENGTH(" + propertyValue + ')';
     }
 
 }

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/NodeLocalNameImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/NodeLocalNameImpl.java?rev=1378961&r1=1378960&r2=1378961&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/NodeLocalNameImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/NodeLocalNameImpl.java
Thu Aug 30 14:37:39 2012
@@ -38,7 +38,7 @@ public class NodeLocalNameImpl extends D
 
     @Override
     public String toString() {
-        return "LOCALNAME(" + getSelectorName() + ')';
+        return "LOCALNAME(" + quoteSelectorName(selectorName) + ')';
     }
 
 }

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/NodeNameImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/NodeNameImpl.java?rev=1378961&r1=1378960&r2=1378961&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/NodeNameImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/NodeNameImpl.java
Thu Aug 30 14:37:39 2012
@@ -38,7 +38,7 @@ public class NodeNameImpl extends Dynami
 
     @Override
     public String toString() {
-        return "NAME(" + getSelectorName() + ')';
+        return "NAME(" + quoteSelectorName(selectorName) + ')';
     }
 
 }

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/PropertyExistenceImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/PropertyExistenceImpl.java?rev=1378961&r1=1378960&r2=1378961&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/PropertyExistenceImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/PropertyExistenceImpl.java
Thu Aug 30 14:37:39 2012
@@ -45,8 +45,9 @@ public class PropertyExistenceImpl exten
 
     @Override
     public String toString() {
-        // TODO quote property names?
-        return getSelectorName() + '.' + propertyName + " IS NOT NULL";
+        return quoteSelectorName(selectorName) + '.' +
+                quotePropertyName(propertyName) +
+                " IS NOT NULL";
     }
 
     @Override

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/PropertyValueImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/PropertyValueImpl.java?rev=1378961&r1=1378960&r2=1378961&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/PropertyValueImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/PropertyValueImpl.java
Thu Aug 30 14:37:39 2012
@@ -45,8 +45,8 @@ public class PropertyValueImpl extends D
 
     @Override
     public String toString() {
-        // TODO quote property names?
-        return getSelectorName() + '.' + propertyName;
+        return quoteSelectorName(selectorName) + '.' +
+                quotePropertyName(propertyName);
     }
 
 }

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/QOMNode.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/QOMNode.java?rev=1378961&r1=1378960&r2=1378961&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/QOMNode.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/QOMNode.java
Thu Aug 30 14:37:39 2012
@@ -32,7 +32,27 @@ abstract class QOMNode {
     }
 
     protected String quotePath(String path) {
-        return '[' + path + ']';
+        return quoteName(path);
+    }
+
+    protected String quoteSelectorName(String name) {
+        return quoteName(name);
+    }
+
+    protected String quotePropertyName(String name) {
+        return quoteName(name);
+    }
+
+    protected String quoteColumnName(String name) {
+        return quoteName(name);
+    }
+
+    protected String quoteNodeTypeName(String name) {
+        return quoteName(name);
+    }
+
+    private static String quoteName(String name) {
+        return '[' + name + ']';
     }
 
 }

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/SameNodeImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/SameNodeImpl.java?rev=1378961&r1=1378960&r2=1378961&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/SameNodeImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/SameNodeImpl.java
Thu Aug 30 14:37:39 2012
@@ -45,7 +45,8 @@ public class SameNodeImpl extends Constr
 
     @Override
     public String toString() {
-        return "ISSAMENODE(" + getSelectorName() + ", " + quotePath(path) + ')';
+        return "ISSAMENODE(" + quoteSelectorName(selectorName) +
+                ", " + quotePath(path) + ')';
     }
 
     @Override

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/SameNodeJoinConditionImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/SameNodeJoinConditionImpl.java?rev=1378961&r1=1378960&r2=1378961&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/SameNodeJoinConditionImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/SameNodeJoinConditionImpl.java
Thu Aug 30 14:37:39 2012
@@ -55,9 +55,9 @@ public class SameNodeJoinConditionImpl e
     public String toString() {
         StringBuilder builder = new StringBuilder();
         builder.append("ISSAMENODE(");
-        builder.append(getSelector1Name());
+        builder.append(quoteSelectorName(selector1Name));
         builder.append(", ");
-        builder.append(getSelector2Name());
+        builder.append(quoteSelectorName(selector2Name));
         if (selector2Path != null) {
             builder.append(", ");
             builder.append(quotePath(selector2Path));

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/SelectorImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/SelectorImpl.java?rev=1378961&r1=1378960&r2=1378961&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/SelectorImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/SelectorImpl.java
Thu Aug 30 14:37:39 2012
@@ -44,7 +44,8 @@ public class SelectorImpl extends Source
 
     @Override
     public String toString() {
-        return "[" + nodeTypeName + "] AS " + getSelectorName();
+        return quoteNodeTypeName(nodeTypeName) + " AS " +
+                quoteSelectorName(selectorName);
     }
 
 }

Modified: jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/query/qom/QomTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/query/qom/QomTest.java?rev=1378961&r1=1378960&r2=1378961&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/query/qom/QomTest.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/query/qom/QomTest.java
Thu Aug 30 14:37:39 2012
@@ -22,6 +22,7 @@ import javax.jcr.RepositoryException;
 import javax.jcr.Session;
 import javax.jcr.Value;
 import javax.jcr.ValueFactory;
+import javax.jcr.query.Query;
 import javax.jcr.query.QueryManager;
 import javax.jcr.query.qom.And;
 import javax.jcr.query.qom.BindVariableValue;
@@ -84,6 +85,7 @@ public class QomTest extends AbstractRep
         And and = f.and(c0, c1);
         assertEquals(and.getConstraint1(), c0);
         assertEquals(and.getConstraint2(), c1);
+        assertEquals("([x].[c0] IS NOT NULL) AND ([x].[c1] IS NOT NULL)", and.toString());
     }
 
     @Test
@@ -92,12 +94,14 @@ public class QomTest extends AbstractRep
         Ordering o = f.ascending(p);
         assertEquals(p, o.getOperand());
         assertEquals(QueryObjectModelConstants.JCR_ORDER_ASCENDING, o.getOrder());
+        assertEquals("[selectorName].[propertyName]", p.toString());
     }
 
     @Test
     public void bindVariable() throws RepositoryException {
         BindVariableValue b = f.bindVariable("bindVariableName");
         assertEquals("bindVariableName", b.getBindVariableName());
+        assertEquals("$bindVariableName", b.toString());
     }
 
     @Test
@@ -105,6 +109,7 @@ public class QomTest extends AbstractRep
         ChildNode cn = f.childNode("selectorName", "parentPath");
         assertEquals("selectorName", cn.getSelectorName());
         assertEquals("parentPath", cn.getParentPath());
+        assertEquals("ISCHILDNODE([selectorName], [parentPath])", cn.toString());
     }
 
     @Test
@@ -113,6 +118,8 @@ public class QomTest extends AbstractRep
                 "parentSelectorName");
         assertEquals("childSelectorName", c.getChildSelectorName());
         assertEquals("parentSelectorName", c.getParentSelectorName());
+        assertEquals("ISCHILDNODE([childSelectorName], [parentSelectorName])",
+                c.toString());
     }
 
     @Test
@@ -121,6 +128,7 @@ public class QomTest extends AbstractRep
         assertEquals("selectorName", c.getSelectorName());
         assertEquals("propertyName", c.getPropertyName());
         assertEquals("columnName", c.getColumnName());
+        assertEquals("[selectorName].[propertyName] AS [columnName]", c.toString());
     }
 
     @Test
@@ -131,6 +139,7 @@ public class QomTest extends AbstractRep
         assertEquals(p, c.getOperand1());
         assertEquals(QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO, c.getOperator());
         assertEquals(l, c.getOperand2());
+        assertEquals("[selectorName].[propertyName] = 1", c.toString());
     }
 
     @Test
@@ -138,6 +147,7 @@ public class QomTest extends AbstractRep
         DescendantNode d = f.descendantNode("selectorName", "path");
         assertEquals("selectorName", d.getSelectorName());
         assertEquals("path", d.getAncestorPath());
+        assertEquals("ISDESCENDANTNODE([selectorName], [path])", d.toString());
     }
 
     @Test
@@ -146,6 +156,8 @@ public class QomTest extends AbstractRep
                 "ancestorSelectorName");
         assertEquals("descendantSelectorName", d.getDescendantSelectorName());
         assertEquals("ancestorSelectorName", d.getAncestorSelectorName());
+        assertEquals("ISDESCENDANTNODE([descendantSelectorName], [ancestorSelectorName])",
+                d.toString());
     }
 
     @Test
@@ -154,6 +166,7 @@ public class QomTest extends AbstractRep
         Ordering o = f.descending(p);
         assertEquals(p, o.getOperand());
         assertEquals(QueryObjectModelConstants.JCR_ORDER_DESCENDING, o.getOrder());
+        assertEquals("[selectorName].[propertyName] DESC", o.toString());
     }
 
     @Test
@@ -164,6 +177,8 @@ public class QomTest extends AbstractRep
         assertEquals("property1Name", e.getProperty1Name());
         assertEquals("selector2Name", e.getSelector2Name());
         assertEquals("property2Name", e.getProperty2Name());
+        assertEquals("[selector1Name].[property1Name] = [selector2Name].[property2Name]",
+                e.toString());
     }
 
     @Test
@@ -173,12 +188,14 @@ public class QomTest extends AbstractRep
         assertEquals("selectorName", x.getSelectorName());
         assertEquals("propertyName", x.getPropertyName());
         assertEquals(l, x.getFullTextSearchExpression());
+        assertEquals("CONTAINS([selectorName].[propertyName], 1)", x.toString());
     }
 
     @Test
     public void fullTextSearchScore() throws RepositoryException {
         FullTextSearchScore x = f.fullTextSearchScore("selectorName");
         assertEquals("selectorName", x.getSelectorName());
+        assertEquals("SCORE([selectorName])", x.toString());
     }
 
     @Test
@@ -191,6 +208,7 @@ public class QomTest extends AbstractRep
         assertEquals(right, j.getRight());
         assertEquals(QueryObjectModelConstants.JCR_JOIN_TYPE_INNER, j.getJoinType());
         assertEquals(jc, j.getJoinCondition());
+        assertEquals("ISCHILDNODE([childSelectorName], [parentSelectorName])", jc.toString());
     }
 
     @Test
@@ -198,6 +216,7 @@ public class QomTest extends AbstractRep
         PropertyValue p = f.propertyValue("selectorName", "propertyName");
         Length l = f.length(p);
         assertEquals(p, l.getPropertyValue());
+        assertEquals("LENGTH([selectorName].[propertyName])", l.toString());
     }
 
     @Test
@@ -205,6 +224,9 @@ public class QomTest extends AbstractRep
         Value v = vf.createValue(1);
         Literal l = f.literal(v);
         assertEquals(v, l.getLiteralValue());
+        assertEquals("1", l.toString());
+        assertEquals("'Joe''s'", f.literal(vf.createValue("Joe's")).toString());
+        assertEquals("' - \" - '", f.literal(vf.createValue(" - \" - ")).toString());
     }
 
     @Test
@@ -213,18 +235,21 @@ public class QomTest extends AbstractRep
         Length length = f.length(p);
         LowerCase l = f.lowerCase(length);
         assertEquals(length, l.getOperand());
+        assertEquals("LOWER(LENGTH([selectorName].[propertyName]))", l.toString());
     }
 
     @Test
     public void nodeLocalName() throws RepositoryException {
         NodeLocalName n = f.nodeLocalName("selectorName");
         assertEquals("selectorName", n.getSelectorName());
+        assertEquals("LOCALNAME([selectorName])", n.toString());
     }
 
     @Test
     public void nodeName() throws RepositoryException {
         NodeName n = f.nodeName("selectorName");
         assertEquals("selectorName", n.getSelectorName());
+        assertEquals("NAME([selectorName])", n.toString());
     }
 
     @Test
@@ -232,6 +257,7 @@ public class QomTest extends AbstractRep
         Constraint c = f.propertyExistence("x", "c0");
         Not n = f.not(c);
         assertEquals(c, n.getConstraint());
+        assertEquals("[x].[c0] IS NOT NULL", c.toString());
     }
 
     @Test
@@ -241,6 +267,7 @@ public class QomTest extends AbstractRep
         Or or = f.or(c0, c1);
         assertEquals(or.getConstraint1(), c0);
         assertEquals(or.getConstraint2(), c1);
+        assertEquals("([x].[c0] IS NOT NULL) OR ([x].[c1] IS NOT NULL)", or.toString());
     }
 
     @Test
@@ -248,6 +275,7 @@ public class QomTest extends AbstractRep
         PropertyExistence pe = f.propertyExistence("selectorName", "propertyName");
         assertEquals("selectorName", pe.getSelectorName());
         assertEquals("propertyName", pe.getPropertyName());
+        assertEquals("[selectorName].[propertyName] IS NOT NULL", pe.toString());
     }
 
     @Test
@@ -255,6 +283,7 @@ public class QomTest extends AbstractRep
         PropertyValue pv = f.propertyValue("selectorName", "propertyName");
         assertEquals("selectorName", pv.getSelectorName());
         assertEquals("propertyName", pv.getPropertyName());
+        assertEquals("[selectorName].[propertyName]", pv.toString());
     }
 
     @Test
@@ -262,6 +291,7 @@ public class QomTest extends AbstractRep
         SameNode s = f.sameNode("selectorName", "path");
         assertEquals("selectorName", s.getSelectorName());
         assertEquals("path", s.getPath());
+        assertEquals("ISSAMENODE([selectorName], [path])", s.toString());
     }
 
     @Test
@@ -270,6 +300,8 @@ public class QomTest extends AbstractRep
         assertEquals("selector1Name", s.getSelector1Name());
         assertEquals("selector2Name", s.getSelector2Name());
         assertEquals("selector2Path", s.getSelector2Path());
+        assertEquals("ISSAMENODE([selector1Name], [selector2Name], [selector2Path])",
+                s.toString());
     }
 
     @Test
@@ -277,6 +309,7 @@ public class QomTest extends AbstractRep
         Selector s = f.selector("nodeTypeName", "selectorName");
         assertEquals("nodeTypeName", s.getNodeTypeName());
         assertEquals("selectorName", s.getSelectorName());
+        assertEquals("[nodeTypeName] AS [selectorName]", s.toString());
     }
 
     @Test
@@ -285,6 +318,7 @@ public class QomTest extends AbstractRep
         Length length = f.length(p);
         UpperCase u = f.upperCase(length);
         assertEquals(length, u.getOperand());
+        assertEquals("UPPER(LENGTH([selectorName].[propertyName]))", u.toString());
     }
 
     @Test
@@ -299,7 +333,7 @@ public class QomTest extends AbstractRep
         Ordering[] ords = new Ordering[]{o};
         Column[] cols = new Column[]{col};
         QueryObjectModel q = f.createQuery(s, c, ords, cols);
-        // assertEquals(Query.JCR_SQL2, q.getLanguage());
+        assertEquals(Query.JCR_JQOM, q.getLanguage());
         String[] bv = q.getBindVariableNames();
         assertEquals(1, bv.length);
         assertEquals("var", bv[0]);



Mime
View raw message