jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mreut...@apache.org
Subject svn commit: r643391 - in /jackrabbit/trunk/jackrabbit-core/src: main/java/org/apache/jackrabbit/core/query/lucene/ test/java/org/apache/jackrabbit/core/query/
Date Tue, 01 Apr 2008 13:35:31 GMT
Author: mreutegg
Date: Tue Apr  1 06:35:28 2008
New Revision: 643391

URL: http://svn.apache.org/viewvc?rev=643391&view=rev
Log:
JCR-1104: JSR 283 support
- query (work in progress)

Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/JQOM2LuceneQueryBuilder.java
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/AbstractQueryTest.java
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/UpperLowerCaseQueryTest.java

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/JQOM2LuceneQueryBuilder.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/JQOM2LuceneQueryBuilder.java?rev=643391&r1=643390&r2=643391&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/JQOM2LuceneQueryBuilder.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/JQOM2LuceneQueryBuilder.java
Tue Apr  1 06:35:28 2008
@@ -749,6 +749,18 @@
         } else if (operand instanceof CaseTermQuery) {
             CaseTermQuery ctq = (CaseTermQuery) operand;
             return transformTermQuery(new TermQuery(ctq.getTerm()), toUpperCase);
+        } else if (operand instanceof MatchAllQuery) {
+            return operand;
+        } else if (operand instanceof BooleanQuery) {
+            BooleanQuery original = (BooleanQuery) operand;
+            BooleanQuery transformed = new BooleanQuery();
+            BooleanClause[] clauses = original.getClauses();
+            for (int i = 0; i < clauses.length; i++) {
+                Query q = (Query) transformCase(clauses[i].getQuery(),
+                        data, toUpperCase);
+                transformed.add(q, clauses[i].getOccur());
+            }
+            return transformed;
         } else {
             throw new InvalidQueryException(
                     "lower/upper-case not supported on operand "

Modified: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/AbstractQueryTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/AbstractQueryTest.java?rev=643391&r1=643390&r2=643391&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/AbstractQueryTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/AbstractQueryTest.java
Tue Apr  1 06:35:28 2008
@@ -17,6 +17,7 @@
 package org.apache.jackrabbit.core.query;
 
 import org.apache.jackrabbit.test.AbstractJCRTest;
+import org.apache.jackrabbit.spi.commons.query.jsr283.qom.QueryObjectModelFactory;
 
 import javax.jcr.query.QueryResult;
 import javax.jcr.query.RowIterator;
@@ -39,13 +40,17 @@
 
     protected QueryManager qm;
 
+    protected QueryObjectModelFactory qomFactory;
+
     protected void setUp() throws Exception {
         super.setUp();
         qm = superuser.getWorkspace().getQueryManager();
+        qomFactory = ((QueryManagerImpl) qm).getQOMFactory();
     }
 
     protected void tearDown() throws Exception {
         qm = null;
+        qomFactory = null;
         super.tearDown();
     }
 

Modified: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/UpperLowerCaseQueryTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/UpperLowerCaseQueryTest.java?rev=643391&r1=643390&r2=643391&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/UpperLowerCaseQueryTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/UpperLowerCaseQueryTest.java
Tue Apr  1 06:35:28 2008
@@ -16,19 +16,40 @@
  */
 package org.apache.jackrabbit.core.query;
 
+import org.apache.jackrabbit.spi.commons.query.jsr283.qom.QueryObjectModelConstants;
+
 import javax.jcr.Node;
 import javax.jcr.NodeIterator;
 import javax.jcr.RepositoryException;
 import javax.jcr.query.InvalidQueryException;
+import javax.jcr.query.QueryResult;
 import java.util.HashSet;
 import java.util.Set;
 import java.util.Random;
+import java.util.Map;
+import java.util.HashMap;
 
 /**
  * <code>UpperLowerCaseQueryTest</code> tests the functions fn:lower-case() and
- * fn:upper-case() in XPath and LOWER() and UPPER() in SQL.
+ * fn:upper-case() in XPath, LOWER() and UPPER() in SQL and UpperCase and
+ * LowerCase in JQOM.
  */
-public class UpperLowerCaseQueryTest extends AbstractQueryTest {
+public class UpperLowerCaseQueryTest extends AbstractQueryTest implements QueryObjectModelConstants
{
+
+    /**
+     * Maps operator strings to QueryObjectModelConstants.
+     */
+    private static final Map OPERATORS = new HashMap();
+
+    static {
+        OPERATORS.put("=", new Integer(OPERATOR_EQUAL_TO));
+        OPERATORS.put(">", new Integer(OPERATOR_GREATER_THAN));
+        OPERATORS.put(">=", new Integer(OPERATOR_GREATER_THAN_OR_EQUAL_TO));
+        OPERATORS.put("<", new Integer(OPERATOR_LESS_THAN));
+        OPERATORS.put("<=", new Integer(OPERATOR_LESS_THAN_OR_EQUAL_TO));
+        OPERATORS.put("like", new Integer(OPERATOR_LIKE));
+        OPERATORS.put("!=", new Integer(OPERATOR_NOT_EQUAL_TO));
+    }
 
     public void testEqualsGeneralComparison() throws RepositoryException {
         check(new String[]{"foo", "Foo", "fOO", "FOO", "fooBar", "fo", "fooo"},
@@ -272,6 +293,21 @@
                 sqlOperation + " '" + queryTerm.toLowerCase() + "'";
         executeSQLQuery(sql, nodes);
 
+        QueryResult result = qomFactory.createQuery(
+                qomFactory.selector(testNodeType, "s"),
+                qomFactory.and(
+                        qomFactory.childNode("s", testRoot),
+                        qomFactory.comparison(
+                                qomFactory.lowerCase(
+                                        qomFactory.propertyValue("s", propertyName1)),
+                                getOperatorForString(operation),
+                                qomFactory.literal(
+                                        superuser.getValueFactory().createValue(
+                                                queryTerm.toLowerCase()))
+                        )
+                ), null, null).execute();
+        checkResult(result, nodes);
+
         // run queries with upper-case
         xpath = testPath;
         if (operation.equals("like")) {
@@ -287,9 +323,32 @@
                 testRoot + "/%' and UPPER(" + propertyName1 + ") " +
                 sqlOperation + " '" + queryTerm.toUpperCase() + "'";
         executeSQLQuery(sql, nodes);
+
+        result = qomFactory.createQuery(
+                qomFactory.selector(testNodeType, "s"),
+                qomFactory.and(
+                        qomFactory.childNode("s", testRoot),
+                        qomFactory.comparison(
+                                qomFactory.upperCase(
+                                        qomFactory.propertyValue("s", propertyName1)),
+                                getOperatorForString(operation),
+                                qomFactory.literal(
+                                        superuser.getValueFactory().createValue(
+                                                queryTerm.toUpperCase()))
+                        )
+                ), null, null).execute();
+        checkResult(result, nodes);
     }
 
     private char getRandomChar(String pool, Random random) {
         return pool.charAt(random.nextInt(pool.length()));
+    }
+
+    protected static int getOperatorForString(String operator) {
+        Integer i = (Integer) OPERATORS.get(operator);
+        if (i == null) {
+            throw new IllegalArgumentException("unknown operator: " + operator);
+        }
+        return i.intValue();
     }
 }



Mime
View raw message