jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r770682 - in /jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/query/qom: ComparisonImpl.java Operator.java QueryObjectModelFactoryImpl.java
Date Fri, 01 May 2009 13:49:53 GMT
Author: jukka
Date: Fri May  1 13:49:52 2009
New Revision: 770682

URL: http://svn.apache.org/viewvc?rev=770682&view=rev
Log:
JCR-2094: Use an enumeration for QOM operators

Use the Operator enumeration in spi-commons

Modified:
    jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/query/qom/ComparisonImpl.java
    jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/query/qom/Operator.java
    jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/query/qom/QueryObjectModelFactoryImpl.java

Modified: jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/query/qom/ComparisonImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/query/qom/ComparisonImpl.java?rev=770682&r1=770681&r2=770682&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/query/qom/ComparisonImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/query/qom/ComparisonImpl.java
Fri May  1 13:49:52 2009
@@ -36,7 +36,7 @@
     /**
      * The operator.
      */
-    private final String operator;
+    private final Operator operator;
 
     /**
      * The second operand.
@@ -45,7 +45,7 @@
 
     ComparisonImpl(NamePathResolver resolver,
                    DynamicOperandImpl operand1,
-                   String operator,
+                   Operator operator,
                    StaticOperandImpl operand2) {
         super(resolver);
         this.operand1 = operand1;
@@ -75,7 +75,7 @@
      *         </ul>
      */
     public String getOperator() {
-        return operator;
+        return operator.toString();
     }
 
     /**

Modified: jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/query/qom/Operator.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/query/qom/Operator.java?rev=770682&r1=770681&r2=770682&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/query/qom/Operator.java
(original)
+++ jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/query/qom/Operator.java
Fri May  1 13:49:52 2009
@@ -143,4 +143,21 @@
         };
     }
 
+    /**
+     * Returns the operator with the given JCR name.
+     *
+     * @param name JCR name of an a operator
+     * @return operator with the given name
+     * @throws RepositoryException if the given name is unknown
+     */
+    public static Operator getOperatorByName(String name)
+            throws RepositoryException {
+        for (Operator operator : Operator.values()) {
+            if (operator.name.equals(name)) {
+                return operator;
+            }
+        }
+        throw new RepositoryException("Unknown query name: " + name);
+    }
+
 }

Modified: jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/query/qom/QueryObjectModelFactoryImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/query/qom/QueryObjectModelFactoryImpl.java?rev=770682&r1=770681&r2=770682&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/query/qom/QueryObjectModelFactoryImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/query/qom/QueryObjectModelFactoryImpl.java
Fri May  1 13:49:52 2009
@@ -67,21 +67,11 @@
  */
 public abstract class QueryObjectModelFactoryImpl implements QueryObjectModelFactory {
 
-    private static final Set<String> VALID_OPERATORS = new HashSet<String>();
-
     private static final Set<String> VALID_JOIN_TYPES = new HashSet<String>();
 
     private static final Set<String> VALID_ORDERS = new HashSet<String>();
 
     static {
-        VALID_OPERATORS.add(QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO);
-        VALID_OPERATORS.add(QueryObjectModelConstants.JCR_OPERATOR_GREATER_THAN);
-        VALID_OPERATORS.add(QueryObjectModelConstants.JCR_OPERATOR_GREATER_THAN_OR_EQUAL_TO);
-        VALID_OPERATORS.add(QueryObjectModelConstants.JCR_OPERATOR_LESS_THAN);
-        VALID_OPERATORS.add(QueryObjectModelConstants.JCR_OPERATOR_LESS_THAN_OR_EQUAL_TO);
-        VALID_OPERATORS.add(QueryObjectModelConstants.JCR_OPERATOR_LIKE);
-        VALID_OPERATORS.add(QueryObjectModelConstants.JCR_OPERATOR_NOT_EQUAL_TO);
-
         VALID_JOIN_TYPES.add(QueryObjectModelConstants.JCR_JOIN_TYPE_INNER);
         VALID_JOIN_TYPES.add(QueryObjectModelConstants.JCR_JOIN_TYPE_LEFT_OUTER);
         VALID_JOIN_TYPES.add(QueryObjectModelConstants.JCR_JOIN_TYPE_RIGHT_OUTER);
@@ -442,40 +432,34 @@
     /**
      * Filters node-tuples based on the outcome of a binary operation.
      *
-     * @param operand1 the first operand; non-null
-     * @param operator the operator; either <ul> <li>{@link #JCR_OPERATOR_EQUAL_TO},</li>
+     * @param left the first operand; non-null
+     * @param operatorName the operator; either <ul> <li>{@link #JCR_OPERATOR_EQUAL_TO},</li>
      *                 <li>{@link #JCR_OPERATOR_NOT_EQUAL_TO},</li> <li>{@link
      *                 #JCR_OPERATOR_LESS_THAN},</li> <li>{@link #JCR_OPERATOR_LESS_THAN_OR_EQUAL_TO},</li>
      *                 <li>{@link #JCR_OPERATOR_GREATER_THAN},</li> <li>{@link
      *                 #JCR_OPERATOR_GREATER_THAN_OR_EQUAL_TO}, or</li> <li>{@link
      *                 #JCR_OPERATOR_LIKE}</li> </ul>
-     * @param operand2 the second operand; non-null
+     * @param right the second operand; non-null
      * @return the constraint; non-null
      * @throws javax.jcr.query.InvalidQueryException
      *                                       if the query is invalid
      * @throws javax.jcr.RepositoryException if the operation otherwise fails
      */
-    public Comparison comparison(DynamicOperand operand1,
-                                 String operator,
-                                 StaticOperand operand2)
+    public Comparison comparison(
+            DynamicOperand left, String operatorName, StaticOperand right)
             throws InvalidQueryException, RepositoryException {
-        if (operand1 == null || operand2 == null) {
-            // TODO: correct exception?
-            throw new RepositoryException("operands must not be null");
+        if (!(left instanceof DynamicOperandImpl)) {
+            throw new RepositoryException("Invalid left operand: " + left);
         }
-        if (!VALID_OPERATORS.contains(operator)) {
-            // TODO: correct exception?
-            throw new RepositoryException("invalid operator");
-        }
-        if (operand1 instanceof DynamicOperandImpl
-                && operand2 instanceof StaticOperandImpl) {
-            return new ComparisonImpl(resolver,
-                    (DynamicOperandImpl) operand1,
-                    operator,
-                    (StaticOperandImpl) operand2);
-        } else {
-            throw new RepositoryException("Unknown operand implementation");
+        if (!(right instanceof StaticOperandImpl)) {
+            throw new RepositoryException("Invalid right operand: " + right);
         }
+
+        return new ComparisonImpl(
+                resolver,
+                (DynamicOperandImpl) left,
+                Operator.getOperatorByName(operatorName),
+                (StaticOperandImpl) right);
     }
 
     /**



Mime
View raw message