jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r770712 - in /jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/query: qom/JoinImpl.java qom/JoinType.java qom/QueryObjectModelFactoryImpl.java sql2/Parser.java
Date Fri, 01 May 2009 15:29:17 GMT
Author: jukka
Date: Fri May  1 15:29:17 2009
New Revision: 770712

URL: http://svn.apache.org/viewvc?rev=770712&view=rev
Log:
JCR-2095: Use an enumeration for QOM join types

Implement the o.a.j.spi.commons.query.qom.JoinType enumeration and use it in the generic query
engine.

Added:
    jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/query/qom/JoinType.java
Modified:
    jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/query/qom/JoinImpl.java
    jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/query/qom/QueryObjectModelFactoryImpl.java
    jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/query/sql2/Parser.java

Modified: jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/query/qom/JoinImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/query/qom/JoinImpl.java?rev=770712&r1=770711&r2=770712&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/query/qom/JoinImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/query/qom/JoinImpl.java
Fri May  1 15:29:17 2009
@@ -40,7 +40,7 @@
     /**
      * The join type.
      */
-    private final String joinType;
+    private final JoinType joinType;
 
     /**
      * The join condition.
@@ -50,7 +50,7 @@
     JoinImpl(NamePathResolver resolver,
              SourceImpl left,
              SourceImpl right,
-             String joinType,
+             JoinType joinType,
              JoinConditionImpl joinCondition) {
         super(resolver);
         this.left = left;
@@ -59,6 +59,10 @@
         this.joinCondition = joinCondition;
     }
 
+    public JoinType getJoinTypeInstance() {
+        return joinType;
+    }
+
     /**
      * Gets the left node-tuple source.
      *
@@ -86,7 +90,7 @@
      *         </ul>
      */
     public String getJoinType() {
-        return joinType;
+        return joinType.toString();
     }
 
     /**

Added: jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/query/qom/JoinType.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/query/qom/JoinType.java?rev=770712&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/query/qom/JoinType.java
(added)
+++ jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/query/qom/JoinType.java
Fri May  1 15:29:17 2009
@@ -0,0 +1,94 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.spi.commons.query.qom;
+
+import javax.jcr.RepositoryException;
+import javax.jcr.query.qom.Join;
+import javax.jcr.query.qom.JoinCondition;
+import javax.jcr.query.qom.QueryObjectModelConstants;
+import javax.jcr.query.qom.QueryObjectModelFactory;
+import javax.jcr.query.qom.Source;
+
+/**
+ * Enumeration of the JCR 2.0 join types.
+ *
+ * @since Apache Jackrabbit 2.0
+ */
+public enum JoinType {
+
+    INNER(QueryObjectModelConstants.JCR_JOIN_TYPE_INNER),
+
+    LEFT("{http://www.jcp.org/jcr/1.0}joinTypeLeftOuter"),
+    // LEFT(QueryObjectModelConstants.JCR_JOIN_TYPE_LEFT_OUTER),
+
+    RIGHT("{http://www.jcp.org/jcr/1.0}joinTypeRightOuter");
+    // RIGHT(QueryObjectModelConstants.JCR_JOIN_TYPE_RIGHT_OUTER);
+
+    /**
+     * JCR name of this join type.
+     */
+    private final String name;
+
+    private JoinType(String name) {
+        this.name = name;
+    }
+
+    /**
+     * Returns the join of the given sources.
+     *
+     * @param factory factory for creating the join
+     * @param left left join source
+     * @param right right join source
+     * @param condition join condition
+     * @return join
+     * @throws RepositoryException if the join can not be created
+     */
+    public Join join(
+            QueryObjectModelFactory factory,
+            Source left, Source right, JoinCondition condition)
+            throws RepositoryException {
+        return factory.join(left, right, name, condition);
+    }
+
+    /**
+     * Returns the JCR 2.0 name of this join type.
+     *
+     * @see QueryObjectModelConstants
+     * @return JCR name of this join type
+     */
+    public String toString() {
+        return name;
+    }
+
+    /**
+     * Returns the join type with the given JCR name.
+     *
+     * @param name JCR name of a join type
+     * @return join type with the given name
+     * @throws RepositoryException if the given name is unknown
+     */
+    public static JoinType getJoinTypeByName(String name)
+            throws RepositoryException {
+        for (JoinType type : JoinType.values()) {
+            if (type.name.equals(name)) {
+                return type;
+            }
+        }
+        throw new RepositoryException("Unknown join type 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=770712&r1=770711&r2=770712&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 15:29:17 2009
@@ -67,15 +67,9 @@
  */
 public abstract class QueryObjectModelFactoryImpl implements QueryObjectModelFactory {
 
-    private static final Set<String> VALID_JOIN_TYPES = new HashSet<String>();
-
     private static final Set<String> VALID_ORDERS = new HashSet<String>();
 
     static {
-        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);
-
         VALID_ORDERS.add(QueryObjectModelConstants.JCR_ORDER_ASCENDING);
         VALID_ORDERS.add(QueryObjectModelConstants.JCR_ORDER_DESCENDING);
     }
@@ -225,7 +219,7 @@
      *
      * @param left          the left node-tuple source; non-null
      * @param right         the right node-tuple source; non-null
-     * @param joinType      either <ul> <li>{@link QueryObjectModelConstants#JCR_JOIN_TYPE_INNER},</li>
+     * @param joinTypeName  either <ul> <li>{@link QueryObjectModelConstants#JCR_JOIN_TYPE_INNER},</li>
      *                      <li>{@link QueryObjectModelConstants#JCR_JOIN_TYPE_LEFT_OUTER},</li>
      *                      <li>{@link QueryObjectModelConstants#JCR_JOIN_TYPE_RIGHT_OUTER}</li>
      *                      </ul>
@@ -237,7 +231,7 @@
      */
     public Join join(Source left,
                      Source right,
-                     String joinType,
+                     String joinTypeName,
                      JoinCondition joinCondition)
             throws InvalidQueryException, RepositoryException {
         if (!(left instanceof SourceImpl) || !(right instanceof SourceImpl)) {
@@ -246,11 +240,12 @@
         if (!(joinCondition instanceof JoinConditionImpl)) {
             throw new RepositoryException("Unknwon JoinCondition implementation");
         }
-        if (!VALID_JOIN_TYPES.contains(joinType)) {
-            throw new RepositoryException("Invalid joinType");
-        }
-        return new JoinImpl(resolver, (SourceImpl) left, (SourceImpl) right,
-                joinType, (JoinConditionImpl) joinCondition);
+        return new JoinImpl(
+                resolver,
+                (SourceImpl) left,
+                (SourceImpl) right,
+                JoinType.getJoinTypeByName(joinTypeName),
+                (JoinConditionImpl) joinCondition);
     }
 
     /**

Modified: jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/query/sql2/Parser.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/query/sql2/Parser.java?rev=770712&r1=770711&r2=770712&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/query/sql2/Parser.java
(original)
+++ jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/query/sql2/Parser.java
Fri May  1 15:29:17 2009
@@ -35,12 +35,12 @@
 import javax.jcr.query.qom.PropertyExistence;
 import javax.jcr.query.qom.PropertyValue;
 import javax.jcr.query.qom.QueryObjectModel;
-import javax.jcr.query.qom.QueryObjectModelConstants;
 import javax.jcr.query.qom.QueryObjectModelFactory;
 import javax.jcr.query.qom.Selector;
 import javax.jcr.query.qom.Source;
 import javax.jcr.query.qom.StaticOperand;
 
+import org.apache.jackrabbit.spi.commons.query.qom.JoinType;
 import org.apache.jackrabbit.spi.commons.query.qom.Operator;
 
 /**
@@ -169,15 +169,15 @@
         selectors.add(selector);
         Source source = selector;
         while (true) {
-            String type;
+            JoinType type;
             if (readIf("RIGHT")) {
                 read("OUTER");
-                type = QueryObjectModelConstants.JCR_JOIN_TYPE_RIGHT_OUTER;
+                type = JoinType.RIGHT;
             } else if (readIf("LEFT")) {
                 read("OUTER");
-                type = QueryObjectModelConstants.JCR_JOIN_TYPE_LEFT_OUTER;
+                type = JoinType.LEFT;
             } else if (readIf("INNER")) {
-                type = QueryObjectModelConstants.JCR_JOIN_TYPE_INNER;
+                type = JoinType.INNER;
             } else {
                 break;
             }
@@ -186,7 +186,7 @@
             selectors.add(selector);
             read("ON");
             JoinCondition on = parseJoinCondition();
-            source = factory.join(source, selector, type, on);
+            source = type.join(factory, source, selector, on);
         }
         return source;
     }



Mime
View raw message