jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From thom...@apache.org
Subject svn commit: r1383432 - 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 Tue, 11 Sep 2012 14:35:25 GMT
Author: thomasm
Date: Tue Sep 11 14:35:25 2012
New Revision: 1383432

URL: http://svn.apache.org/viewvc?rev=1383432&view=rev
Log:
OAK-28 Query implementation: improved JQOM compatibility

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/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/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/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/QueryObjectModelFactoryImpl.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/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=1383432&r1=1383431&r2=1383432&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
Tue Sep 11 14:35:25 2012
@@ -45,9 +45,13 @@ public class ChildNodeImpl extends Const
 
     @Override
     public String toString() {
-        return "ISCHILDNODE(" +
-                quoteSelectorName(selectorName) + ", " +
-                quotePath(parentPath) + ')';
+        StringBuilder buff = new StringBuilder();
+        buff.append("ISCHILDNODE(");
+        if (selectorName != null) {
+            buff.append(quoteSelectorName(selectorName)).append(", ");
+        }
+        buff.append(quotePath(parentPath)).append(')');
+        return buff.toString();
     }
 
     @Override

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=1383432&r1=1383431&r2=1383432&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
Tue Sep 11 14:35:25 2012
@@ -50,12 +50,20 @@ public class ColumnImpl extends QOMNode 
 
     @Override
     public String toString() {
+        StringBuilder buff = new StringBuilder();
+        if (selectorName != null) {
+            buff.append(quoteSelectorName(selectorName));
+            buff.append('.');
+        }
         if (propertyName != null) {
-            return quoteSelectorName(selectorName) + '.' +
-                    quotePropertyName(propertyName) +
-                    " AS " + quoteColumnName(columnName);
+            buff.append(quotePropertyName(propertyName));
+        } else {
+            buff.append('*');
+        }
+        if (columnName != null) {
+            buff.append(" AS ").append(quoteColumnName(columnName));
         }
-        return quoteSelectorName(selectorName) + ".*";
+        return buff.toString();
     }
 
 }

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=1383432&r1=1383431&r2=1383432&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
Tue Sep 11 14:35:25 2012
@@ -45,9 +45,13 @@ public class DescendantNodeImpl extends 
 
     @Override
     public String toString() {
-        return "ISDESCENDANTNODE(" +
-                quoteSelectorName(selectorName) + ", " +
-                quotePath(ancestorPath) + ')';
+        StringBuilder buff = new StringBuilder();
+        buff.append("ISDESCENDANTNODE(");
+        if (selectorName != null) {
+            buff.append(quoteSelectorName(selectorName)).append(", ");
+        }
+        buff.append(quotePath(ancestorPath)).append(')');
+        return buff.toString();
     }
 
     @Override

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=1383432&r1=1383431&r2=1383432&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
Tue Sep 11 14:35:25 2012
@@ -55,14 +55,16 @@ public class FullTextSearchImpl extends 
     public String toString() {
         StringBuilder builder = new StringBuilder();
         builder.append("CONTAINS(");
-        builder.append(quoteSelectorName(selectorName));
-        if (propertyName != null) {
+        if (selectorName != null) {
+            builder.append(quoteSelectorName(selectorName));
             builder.append('.');
+        }
+        if (propertyName != null) {
             builder.append(quotePropertyName(propertyName));
-            builder.append(", ");
         } else {
-            builder.append(".*, ");
+            builder.append('*');
         }
+        builder.append(", ");
         builder.append(getFullTextSearchExpression());
         builder.append(')');
         return builder.toString();

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=1383432&r1=1383431&r2=1383432&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
Tue Sep 11 14:35:25 2012
@@ -38,6 +38,9 @@ public class FullTextSearchScoreImpl ext
 
     @Override
     public String toString() {
+        if (selectorName == null) {
+            return "SCORE()";
+        }
         return "SCORE(" + quoteSelectorName(selectorName) + ')';
     }
 

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=1383432&r1=1383431&r2=1383432&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
Tue Sep 11 14:35:25 2012
@@ -38,6 +38,9 @@ public class NodeLocalNameImpl extends D
 
     @Override
     public String toString() {
+        if (selectorName == null) {
+            return "LOCALNAME()";
+        }
         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=1383432&r1=1383431&r2=1383432&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
Tue Sep 11 14:35:25 2012
@@ -38,6 +38,9 @@ public class NodeNameImpl extends Dynami
 
     @Override
     public String toString() {
+        if (selectorName == null) {
+            return "NAME()";
+        }
         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=1383432&r1=1383431&r2=1383432&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
Tue Sep 11 14:35:25 2012
@@ -45,9 +45,17 @@ public class PropertyExistenceImpl exten
 
     @Override
     public String toString() {
-        return quoteSelectorName(selectorName) + '.' +
-                quotePropertyName(propertyName) +
-                " IS NOT NULL";
+        StringBuilder buff = new StringBuilder();
+        if (selectorName != null) {
+            buff.append(quoteSelectorName(selectorName)).append('.');
+        }
+        if (propertyName != null) {
+            buff.append(quotePropertyName(propertyName));
+        } else {
+            buff.append("*");
+        }
+        buff.append(" IS NOT NULL");
+        return buff.toString();
     }
 
     @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=1383432&r1=1383431&r2=1383432&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
Tue Sep 11 14:35:25 2012
@@ -45,8 +45,16 @@ public class PropertyValueImpl extends D
 
     @Override
     public String toString() {
-        return quoteSelectorName(selectorName) + '.' +
-                quotePropertyName(propertyName);
+        StringBuilder buff = new StringBuilder();
+        if (selectorName != null) {
+            buff.append(quoteSelectorName(selectorName)).append('.');
+        }
+        if (propertyName != null) {
+            buff.append(quotePropertyName(propertyName));
+        } else {
+            buff.append("*");
+        }
+        return buff.toString();
     }
 
 }

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=1383432&r1=1383431&r2=1383432&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
Tue Sep 11 14:35:25 2012
@@ -22,7 +22,7 @@ package org.apache.jackrabbit.oak.jcr.qu
  * The base class for all QOM nodes.
  */
 abstract class QOMNode {
-
+    
     protected String protect(Object expression) {
         String str = expression.toString();
         if (str.indexOf(' ') >= 0) {

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/QueryObjectModelFactoryImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/QueryObjectModelFactoryImpl.java?rev=1383432&r1=1383431&r2=1383432&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/QueryObjectModelFactoryImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/QueryObjectModelFactoryImpl.java
Tue Sep 11 14:35:25 2012
@@ -13,6 +13,7 @@
  */
 package org.apache.jackrabbit.oak.jcr.query.qom;
 
+import javax.jcr.RepositoryException;
 import javax.jcr.Value;
 import javax.jcr.ValueFactory;
 import javax.jcr.query.qom.ChildNode;
@@ -82,20 +83,22 @@ public class QueryObjectModelFactoryImpl
     }
 
     @Override
-    public ChildNodeJoinCondition childNodeJoinCondition(String childSelectorName, String
parentSelectorName)
-            {
+    public ChildNodeJoinCondition childNodeJoinCondition(
+            String childSelectorName, String parentSelectorName) {
         return new ChildNodeJoinConditionImpl(childSelectorName, parentSelectorName);
     }
 
     @Override
-    public Column column(String selectorName, String propertyName, String columnName) {
-        return new ColumnImpl(selectorName, propertyName, columnName);
+    public Column column(String selectorName, 
+            String propertyName, String columnName) throws RepositoryException {
+        return new ColumnImpl(selectorName, getOakName(propertyName), columnName);
     }
 
     @Override
-    public Comparison comparison(DynamicOperand operand1, String operator, StaticOperand
operand2)
-            {
-        return new ComparisonImpl((DynamicOperandImpl) operand1, Operator.getOperatorByName(operator),
(StaticOperandImpl) operand2);
+    public Comparison comparison(DynamicOperand operand1, 
+            String operator, StaticOperand operand2) {
+        return new ComparisonImpl((DynamicOperandImpl) operand1, 
+                Operator.getOperatorByName(operator), (StaticOperandImpl) operand2);
     }
 
     @Override
@@ -104,9 +107,11 @@ public class QueryObjectModelFactoryImpl
     }
 
     @Override
-    public DescendantNodeJoinCondition descendantNodeJoinCondition(String descendantSelectorName,
+    public DescendantNodeJoinCondition descendantNodeJoinCondition(
+            String descendantSelectorName,
             String ancestorSelectorName) {
-        return new DescendantNodeJoinConditionImpl(descendantSelectorName, ancestorSelectorName);
+        return new DescendantNodeJoinConditionImpl(
+                descendantSelectorName, ancestorSelectorName);
     }
 
     @Override
@@ -115,15 +120,18 @@ public class QueryObjectModelFactoryImpl
     }
 
     @Override
-    public EquiJoinCondition equiJoinCondition(String selector1Name, String property1Name,
String selector2Name,
-            String property2Name) {
-        return new EquiJoinConditionImpl(selector1Name, property1Name, selector2Name, property2Name);
+    public EquiJoinCondition equiJoinCondition(
+            String selector1Name, String property1Name, 
+            String selector2Name, String property2Name) throws RepositoryException {
+        return new EquiJoinConditionImpl(selector1Name, getOakName(property1Name), 
+                selector2Name, getOakName(property2Name));
     }
 
     @Override
     public FullTextSearch fullTextSearch(String selectorName, String propertyName,
-            StaticOperand fullTextSearchExpression) {
-        return new FullTextSearchImpl(selectorName, propertyName, (StaticOperandImpl) fullTextSearchExpression);
+            StaticOperand fullTextSearchExpression) throws RepositoryException {
+        return new FullTextSearchImpl(selectorName, getOakName(propertyName), 
+                (StaticOperandImpl) fullTextSearchExpression);
     }
 
     @Override
@@ -133,7 +141,8 @@ public class QueryObjectModelFactoryImpl
 
     @Override
     public Join join(Source left, Source right, String joinType, JoinCondition joinCondition)
{
-        return new JoinImpl((SourceImpl) left, (SourceImpl) right, JoinType.getJoinTypeByName(joinType),
(JoinConditionImpl) joinCondition);
+        return new JoinImpl((SourceImpl) left, (SourceImpl) right, 
+                JoinType.getJoinTypeByName(joinType), (JoinConditionImpl) joinCondition);
     }
 
     @Override
@@ -172,13 +181,16 @@ public class QueryObjectModelFactoryImpl
     }
 
     @Override
-    public PropertyExistence propertyExistence(String selectorName, String propertyName)
{
-        return new PropertyExistenceImpl(selectorName, propertyName);
+    public PropertyExistence propertyExistence(String selectorName, 
+            String propertyName) throws RepositoryException {
+        return new PropertyExistenceImpl(selectorName, 
+                getOakName(propertyName));
     }
 
     @Override
-    public PropertyValue propertyValue(String selectorName, String propertyName) {
-        return new PropertyValueImpl(selectorName, propertyName);
+    public PropertyValue propertyValue(String selectorName, 
+            String propertyName) throws RepositoryException {
+        return new PropertyValueImpl(selectorName, getOakName(propertyName));
     }
 
     @Override
@@ -187,13 +199,15 @@ public class QueryObjectModelFactoryImpl
     }
 
     @Override
-    public SameNodeJoinCondition sameNodeJoinCondition(String selector1Name, String selector2Name,
String selector2Path) {
+    public SameNodeJoinCondition sameNodeJoinCondition(String selector1Name, 
+            String selector2Name, String selector2Path) {
         return new SameNodeJoinConditionImpl(selector1Name, selector2Name, selector2Path);
     }
 
     @Override
-    public Selector selector(String nodeTypeName, String selectorName) {
-        return new SelectorImpl(nodeTypeName, selectorName);
+    public Selector selector(String nodeTypeName, String selectorName) 
+            throws RepositoryException {
+        return new SelectorImpl(getOakName(nodeTypeName), selectorName);
     }
 
     @Override
@@ -202,10 +216,19 @@ public class QueryObjectModelFactoryImpl
     }
 
     @Override
-    public QueryObjectModel createQuery(Source source, Constraint constraint, Ordering[]
orderings, Column[] columns) {
-        QueryObjectModelImpl qom = new QueryObjectModelImpl(queryManager, valueFactory, source,
constraint, orderings, columns);
+    public QueryObjectModel createQuery(Source source, Constraint constraint, 
+            Ordering[] orderings, Column[] columns) {
+        QueryObjectModelImpl qom = new QueryObjectModelImpl(queryManager, 
+                valueFactory, source, constraint, orderings, columns);
         qom.bindVariables();
         return qom;
     }
+    
+    private String getOakName(String jcrName) throws RepositoryException {
+        if (jcrName == null) {
+            return null;
+        }
+        return queryManager.getSessionDelegate().getOakNameOrThrow(jcrName);
+    }
 
 }

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=1383432&r1=1383431&r2=1383432&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
Tue Sep 11 14:35:25 2012
@@ -45,8 +45,13 @@ public class SameNodeImpl extends Constr
 
     @Override
     public String toString() {
-        return "ISSAMENODE(" + quoteSelectorName(selectorName) +
-                ", " + quotePath(path) + ')';
+        StringBuilder buff = new StringBuilder();
+        buff.append("ISSAMENODE(");
+        if (selectorName != null) {
+            buff.append(quoteSelectorName(selectorName)).append(", ");
+        }
+        buff.append(quotePath(path)).append(')');
+        return buff.toString();
     }
 
     @Override

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=1383432&r1=1383431&r2=1383432&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
Tue Sep 11 14:35:25 2012
@@ -44,8 +44,12 @@ public class SelectorImpl extends Source
 
     @Override
     public String toString() {
-        return quoteNodeTypeName(nodeTypeName) + " AS " +
-                quoteSelectorName(selectorName);
+        StringBuilder buff = new StringBuilder();
+        buff.append(quoteNodeTypeName(nodeTypeName));
+        if (selectorName != null) {
+            buff.append(" AS ").append(quoteSelectorName(selectorName));
+        }
+        return buff.toString();
     }
 
 }

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=1383432&r1=1383431&r2=1383432&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
Tue Sep 11 14:35:25 2012
@@ -18,10 +18,12 @@
  */
 package org.apache.jackrabbit.oak.jcr.query.qom;
 
+import javax.jcr.PropertyType;
 import javax.jcr.RepositoryException;
 import javax.jcr.Session;
 import javax.jcr.Value;
 import javax.jcr.ValueFactory;
+import javax.jcr.nodetype.NodeType;
 import javax.jcr.query.Query;
 import javax.jcr.query.QueryManager;
 import javax.jcr.query.qom.And;
@@ -77,6 +79,33 @@ public class QomTest extends AbstractRep
         QueryManager qm = session.getWorkspace().getQueryManager();
         f = qm.getQOMFactory();
     }
+    
+    @Test
+    public void jcrNameConversion() throws RepositoryException {
+        assertEquals("[nt:base]", 
+                f.column(null, NodeType.NT_BASE, null).toString());
+        assertEquals("[s1].[nt:base] = [s2].[nt:base]", 
+                f.equiJoinCondition("s1", NodeType.NT_BASE, "s2", NodeType.NT_BASE).toString());
+        assertEquals("CONTAINS([nt:base], null)", 
+                f.fullTextSearch(null, NodeType.NT_BASE, null).toString());
+        assertEquals("CAST('nt:base' AS NAME)", 
+                f.literal(vf.createValue(NodeType.NT_BASE, PropertyType.NAME)).toString());
+        assertEquals("[nt:base] IS NOT NULL", 
+                f.propertyExistence(null, NodeType.NT_BASE).toString());
+        assertEquals("[nt:base]", 
+                f.propertyValue(null, NodeType.NT_BASE).toString());
+        assertEquals("[nt:base]", 
+                f.selector(NodeType.NT_BASE, null).toString());
+        
+        Source source1 = f.selector(NodeType.NT_BASE, "selector");
+        Column[] columns = new Column[] { f.column("selector", null, null) };
+        Constraint constraint2 = f.childNode("selector", "/");
+        QueryObjectModel qom = f.createQuery(source1, constraint2, null,
+                columns);
+        assertEquals("select [selector].* from " + 
+                "[nt:base] AS [selector] " + 
+                "where ISCHILDNODE([selector], [/])", qom.toString());
+    }
 
     @Test
     public void and() throws RepositoryException {
@@ -110,6 +139,8 @@ public class QomTest extends AbstractRep
         assertEquals("selectorName", cn.getSelectorName());
         assertEquals("parentPath", cn.getParentPath());
         assertEquals("ISCHILDNODE([selectorName], [parentPath])", cn.toString());
+        
+        assertEquals("ISCHILDNODE([p])", f.childNode(null, "p").toString());
     }
 
     @Test
@@ -129,6 +160,15 @@ public class QomTest extends AbstractRep
         assertEquals("propertyName", c.getPropertyName());
         assertEquals("columnName", c.getColumnName());
         assertEquals("[selectorName].[propertyName] AS [columnName]", c.toString());
+        
+        assertEquals("[p]", f.column(null, "p", null).toString());
+        assertEquals("[p] AS [c]", f.column(null, "p", "c").toString());
+        assertEquals("[s].[p]", f.column("s", "p", null).toString());
+        assertEquals("[s].[p] AS [c]", f.column("s", "p", "c").toString());
+        assertEquals("[s].* AS [c]", f.column("s", null, "c").toString());
+        assertEquals("* AS [c]", f.column(null, null, "c").toString());
+        assertEquals("*", f.column(null, null, null).toString());
+        assertEquals("[s].*", f.column("s", null, null).toString());
     }
 
     @Test
@@ -148,6 +188,9 @@ public class QomTest extends AbstractRep
         assertEquals("selectorName", d.getSelectorName());
         assertEquals("path", d.getAncestorPath());
         assertEquals("ISDESCENDANTNODE([selectorName], [path])", d.toString());
+        
+        assertEquals("ISDESCENDANTNODE([p])", 
+                f.descendantNode(null, "p").toString());
     }
 
     @Test
@@ -189,6 +232,11 @@ public class QomTest extends AbstractRep
         assertEquals("propertyName", x.getPropertyName());
         assertEquals(l, x.getFullTextSearchExpression());
         assertEquals("CONTAINS([selectorName].[propertyName], 1)", x.toString());
+        
+        assertEquals("CONTAINS([p], null)", f.fullTextSearch(null,  "p",  null).toString());
+        assertEquals("CONTAINS([s].[p], null)", f.fullTextSearch("s",  "p",  null).toString());
+        assertEquals("CONTAINS([s].*, null)", f.fullTextSearch("s",  null,  null).toString());
+        assertEquals("CONTAINS(*, null)", f.fullTextSearch(null,  null,  null).toString());
     }
 
     @Test
@@ -196,6 +244,9 @@ public class QomTest extends AbstractRep
         FullTextSearchScore x = f.fullTextSearchScore("selectorName");
         assertEquals("selectorName", x.getSelectorName());
         assertEquals("SCORE([selectorName])", x.toString());
+        
+        assertEquals("SCORE()", f.fullTextSearchScore(null).toString());
+
     }
 
     @Test
@@ -243,6 +294,7 @@ public class QomTest extends AbstractRep
         NodeLocalName n = f.nodeLocalName("selectorName");
         assertEquals("selectorName", n.getSelectorName());
         assertEquals("LOCALNAME([selectorName])", n.toString());
+        assertEquals("LOCALNAME()", f.nodeLocalName(null).toString());
     }
 
     @Test
@@ -250,6 +302,7 @@ public class QomTest extends AbstractRep
         NodeName n = f.nodeName("selectorName");
         assertEquals("selectorName", n.getSelectorName());
         assertEquals("NAME([selectorName])", n.toString());
+        assertEquals("NAME()", f.nodeName(null).toString());
     }
 
     @Test
@@ -258,6 +311,11 @@ public class QomTest extends AbstractRep
         Not n = f.not(c);
         assertEquals(c, n.getConstraint());
         assertEquals("[x].[c0] IS NOT NULL", c.toString());
+        
+        assertEquals("* IS NOT NULL", f.propertyExistence(null, null).toString());
+        assertEquals("[s].* IS NOT NULL", f.propertyExistence("s", null).toString());
+        assertEquals("[p] IS NOT NULL", f.propertyExistence(null, "p").toString());
+        assertEquals("[s].[p] IS NOT NULL", f.propertyExistence("s", "p").toString());
     }
 
     @Test
@@ -276,6 +334,15 @@ public class QomTest extends AbstractRep
         assertEquals("selectorName", pe.getSelectorName());
         assertEquals("propertyName", pe.getPropertyName());
         assertEquals("[selectorName].[propertyName] IS NOT NULL", pe.toString());
+        
+        assertEquals("* IS NOT NULL", 
+                f.propertyExistence(null, null).toString());
+        assertEquals("[s].* IS NOT NULL", 
+                f.propertyExistence("s", null).toString());
+        assertEquals("[p] IS NOT NULL", 
+                f.propertyExistence(null, "p").toString());
+        assertEquals("[s].[p] IS NOT NULL", 
+                f.propertyExistence("s", "p").toString());
     }
 
     @Test
@@ -284,6 +351,11 @@ public class QomTest extends AbstractRep
         assertEquals("selectorName", pv.getSelectorName());
         assertEquals("propertyName", pv.getPropertyName());
         assertEquals("[selectorName].[propertyName]", pv.toString());
+        
+        assertEquals("*", f.propertyValue(null, null).toString());
+        assertEquals("[s].*", f.propertyValue("s", null).toString());
+        assertEquals("[p]", f.propertyValue(null, "p").toString());
+        assertEquals("[s].[p]", f.propertyValue("s", "p").toString());
     }
 
     @Test
@@ -292,6 +364,10 @@ public class QomTest extends AbstractRep
         assertEquals("selectorName", s.getSelectorName());
         assertEquals("path", s.getPath());
         assertEquals("ISSAMENODE([selectorName], [path])", s.toString());
+        
+        assertEquals("ISSAMENODE([path])", f.sameNode(null, "path").toString());
+        assertEquals("ISSAMENODE([s], [path])", f.sameNode("s", "path").toString());
+
     }
 
     @Test
@@ -310,7 +386,8 @@ public class QomTest extends AbstractRep
         assertEquals("nodeTypeName", s.getNodeTypeName());
         assertEquals("selectorName", s.getSelectorName());
         assertEquals("[nodeTypeName] AS [selectorName]", s.toString());
-    }
+        assertEquals("[n]", f.selector("n",  null).toString());
+           }
 
     @Test
     public void upperCase() throws RepositoryException {



Mime
View raw message