cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From johnth...@apache.org
Subject svn commit: r1422186 - in /cayenne/main/trunk: docs/doc/src/main/resources/ framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/ framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/query/ framework/cayenne-jdk1.5-unp...
Date Sat, 15 Dec 2012 04:50:04 GMT
Author: johnthuss
Date: Sat Dec 15 04:50:00 2012
New Revision: 1422186

URL: http://svn.apache.org/viewvc?rev=1422186&view=rev
Log:
CAY-1294 Generify query

Adds type parameter to SelectQuery to indicate query result type,
along with a new 'select' method on ObjectContext.

Added:
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/query/Select.java
Modified:
    cayenne/main/trunk/docs/doc/src/main/resources/RELEASE-NOTES.txt
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/BaseContext.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/ObjectContext.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/query/SelectQuery.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/remote/IncrementalSelectQuery.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/MockObjectContext.java
    cayenne/main/trunk/framework/cayenne-wocompat-unpublished/src/main/java/org/apache/cayenne/wocompat/EOQuery.java

Modified: cayenne/main/trunk/docs/doc/src/main/resources/RELEASE-NOTES.txt
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/docs/doc/src/main/resources/RELEASE-NOTES.txt?rev=1422186&r1=1422185&r2=1422186&view=diff
==============================================================================
--- cayenne/main/trunk/docs/doc/src/main/resources/RELEASE-NOTES.txt (original)
+++ cayenne/main/trunk/docs/doc/src/main/resources/RELEASE-NOTES.txt Sat Dec 15 04:50:00 2012
@@ -39,6 +39,7 @@ CAY-1772 Real support for DbEntity catal
 CAY-1778 TransactionManager to simplify user-managed transactions 
 CAY-1779 Flatten object entities for many to many relationships on reverse engineering 
 CAY-1781 Add StatelessContextRequestHandler as an alternative to the Session-based one
+CAY-1294 Generify query
 
 Bug Fixes:
 

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/BaseContext.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/BaseContext.java?rev=1422186&r1=1422185&r2=1422186&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/BaseContext.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/BaseContext.java
Sat Dec 15 04:50:00 2012
@@ -41,6 +41,7 @@ import org.apache.cayenne.map.ObjEntity;
 import org.apache.cayenne.query.ObjectIdQuery;
 import org.apache.cayenne.query.Query;
 import org.apache.cayenne.query.RefreshQuery;
+import org.apache.cayenne.query.Select;
 import org.apache.cayenne.reflect.AttributeProperty;
 import org.apache.cayenne.reflect.ClassDescriptor;
 import org.apache.cayenne.reflect.PropertyDescriptor;
@@ -284,6 +285,11 @@ public abstract class BaseContext implem
     @SuppressWarnings("unchecked")
     public abstract List performQuery(Query query);
 
+    @SuppressWarnings("unchecked")
+    public <T> List<T> select(Select<T> query) {
+    	return performQuery(query);
+    }
+    
     public void prepareForAccess(Persistent object, String property, boolean lazyFaulting)
{
         if (object.getPersistenceState() == PersistenceState.HOLLOW) {
 

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/ObjectContext.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/ObjectContext.java?rev=1422186&r1=1422185&r2=1422186&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/ObjectContext.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/ObjectContext.java
Sat Dec 15 04:50:00 2012
@@ -26,6 +26,7 @@ import java.util.List;
 import org.apache.cayenne.graph.GraphManager;
 import org.apache.cayenne.map.EntityResolver;
 import org.apache.cayenne.query.Query;
+import org.apache.cayenne.query.Select;
 
 /**
  * A Cayenne object facade to a persistent store. Instances of ObjectContext are used in
@@ -165,6 +166,11 @@ public interface ObjectContext extends S
     List performQuery(Query query);
 
     /**
+     * Executes a selecting query, returning a list of persistent objects or data rows.
+     */
+    <T> List<T> select(Select<T> query);
+    
+    /**
      * Executes any kind of query providing the result in a form of QueryResponse.
      */
     QueryResponse performGenericQuery(Query query);

Added: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/query/Select.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/query/Select.java?rev=1422186&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/query/Select.java
(added)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/query/Select.java
Sat Dec 15 04:50:00 2012
@@ -0,0 +1,28 @@
+/*****************************************************************
+ *   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.cayenne.query;
+
+/**
+ * A common interface for grouping together different kinds of queries
+ * that return results. 
+ */
+public interface Select<T> extends Query {
+
+}

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/query/SelectQuery.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/query/SelectQuery.java?rev=1422186&r1=1422185&r2=1422186&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/query/SelectQuery.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/query/SelectQuery.java
Sat Dec 15 04:50:00 2012
@@ -39,8 +39,8 @@ import org.apache.cayenne.util.XMLSerial
  * Supports expression qualifier, multiple orderings and a number of other parameters that
  * serve as runtime hints to Cayenne on how to optimize the fetch and result processing.
  */
-public class SelectQuery extends QualifiedQuery implements ParameterizedQuery,
-        XMLSerializable {
+public class SelectQuery<T> extends QualifiedQuery implements ParameterizedQuery,
+        XMLSerializable, Select<T> {
 
     public static final String DISTINCT_PROPERTY = "cayenne.SelectQuery.distinct";
     public static final boolean DISTINCT_DEFAULT = false;
@@ -93,7 +93,7 @@ public class SelectQuery extends Qualifi
      *
      * @param rootClass the Class of objects fetched by this query.
      */
-    public SelectQuery(Class<?> rootClass) {
+    public SelectQuery(Class<T> rootClass) {
         this(rootClass, null);
     }
 
@@ -104,7 +104,18 @@ public class SelectQuery extends Qualifi
      * @param rootClass the Class of objects fetched by this query.
      * @param qualifier an Expression indicating which objects should be fetched.
      */
-    public SelectQuery(Class<?> rootClass, Expression qualifier) {
+    public static <T> SelectQuery<T> query(Class<T> rootClass, Expression
qualifier) {
+    	return new SelectQuery<T>(rootClass, qualifier);
+    }
+    
+    /**
+     * Creates a SelectQuery that selects objects of a given persistent class that match
+     * supplied qualifier.
+     *
+     * @param rootClass the Class of objects fetched by this query.
+     * @param qualifier an Expression indicating which objects should be fetched.
+     */
+    public SelectQuery(Class<T> rootClass, Expression qualifier) {
         this(rootClass, qualifier, null);
     }
 
@@ -117,7 +128,7 @@ public class SelectQuery extends Qualifi
      * @param orderings defines how to order the results, may be null.
      * @since 3.1
      */
-    public SelectQuery(Class<?> rootClass, Expression qualifier, List<Ordering>
orderings) {
+    public SelectQuery(Class<T> rootClass, Expression qualifier, List<Ordering>
orderings) {
         init(rootClass, qualifier);
         addOrderings(orderings);
     }
@@ -342,7 +353,7 @@ public class SelectQuery extends Qualifi
      * A shortcut for {@link #queryWithParameters(Map, boolean)}that prunes parts of
      * qualifier that have no parameter value set.
      */
-    public SelectQuery queryWithParameters(Map<String, ?> parameters) {
+    public SelectQuery<T> queryWithParameters(Map<String, ?> parameters) {
         return queryWithParameters(parameters, true);
     }
 
@@ -353,9 +364,9 @@ public class SelectQuery extends Qualifi
      * @see org.apache.cayenne.exp.Expression#expWithParameters(java.util.Map, boolean)
      *      parameter substitution.
      */
-    public SelectQuery queryWithParameters(Map<String, ?> parameters, boolean pruneMissing)
{
+    public SelectQuery<T> queryWithParameters(Map<String, ?> parameters, boolean
pruneMissing) {
         // create a query replica
-        SelectQuery query = new SelectQuery();
+        SelectQuery<T> query = new SelectQuery<T>();
         query.setDistinct(distinct);
 
         query.metaData.copyFromInfo(this.metaData);
@@ -379,7 +390,7 @@ public class SelectQuery extends Qualifi
      *
      * @since 1.1
      */
-    public Query createQuery(Map<String, ?> parameters) {
+    public SelectQuery<T> createQuery(Map<String, ?> parameters) {
         return queryWithParameters(parameters);
     }
 

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/remote/IncrementalSelectQuery.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/remote/IncrementalSelectQuery.java?rev=1422186&r1=1422185&r2=1422186&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/remote/IncrementalSelectQuery.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/remote/IncrementalSelectQuery.java
Sat Dec 15 04:50:00 2012
@@ -50,12 +50,12 @@ import org.apache.cayenne.util.XMLEncode
  * 
  * @since 3.0
  */
-class IncrementalSelectQuery extends SelectQuery {
+class IncrementalSelectQuery<T> extends SelectQuery<T> {
 
-    private SelectQuery query;
+    private SelectQuery<T> query;
     private String cacheKey;
 
-    IncrementalSelectQuery(SelectQuery delegate, String cacheKey) {
+    IncrementalSelectQuery(SelectQuery<T> delegate, String cacheKey) {
         this.query = delegate;
         this.cacheKey = cacheKey;
     }
@@ -181,7 +181,7 @@ class IncrementalSelectQuery extends Sel
     }
 
     @Override
-    public Query createQuery(Map parameters) {
+    public SelectQuery<T> createQuery(Map parameters) {
         return query.createQuery(parameters);
     }
 
@@ -266,12 +266,12 @@ class IncrementalSelectQuery extends Sel
     }
 
     @Override
-    public SelectQuery queryWithParameters(Map parameters, boolean pruneMissing) {
+    public SelectQuery<T> queryWithParameters(Map parameters, boolean pruneMissing)
{
         return query.queryWithParameters(parameters, pruneMissing);
     }
 
     @Override
-    public SelectQuery queryWithParameters(Map parameters) {
+    public SelectQuery<T> queryWithParameters(Map parameters) {
         return query.queryWithParameters(parameters);
     }
 

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/MockObjectContext.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/MockObjectContext.java?rev=1422186&r1=1422185&r2=1422186&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/MockObjectContext.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/MockObjectContext.java
Sat Dec 15 04:50:00 2012
@@ -25,6 +25,8 @@ import java.util.List;
 import org.apache.cayenne.graph.GraphManager;
 import org.apache.cayenne.map.EntityResolver;
 import org.apache.cayenne.query.Query;
+import org.apache.cayenne.query.Select;
+import org.apache.cayenne.query.SelectQuery;
 
 /**
  * A noop ObjectContext used for unit testing.
@@ -82,6 +84,10 @@ public class MockObjectContext implement
         return null;
     }
 
+    public <T> List<T> select(Select<T> query) {
+        return performQuery(query);
+    }
+    
     public int[] performNonSelectingQuery(Query query) {
         return null;
     }

Modified: cayenne/main/trunk/framework/cayenne-wocompat-unpublished/src/main/java/org/apache/cayenne/wocompat/EOQuery.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-wocompat-unpublished/src/main/java/org/apache/cayenne/wocompat/EOQuery.java?rev=1422186&r1=1422185&r2=1422186&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-wocompat-unpublished/src/main/java/org/apache/cayenne/wocompat/EOQuery.java
(original)
+++ cayenne/main/trunk/framework/cayenne-wocompat-unpublished/src/main/java/org/apache/cayenne/wocompat/EOQuery.java
Sat Dec 15 04:50:00 2012
@@ -46,7 +46,7 @@ import org.apache.cayenne.query.SortOrde
  * 
  * @since 1.1
  */
-public class EOQuery extends SelectQuery {
+public class EOQuery<T> extends SelectQuery<T> {
 
     protected Map<String, ?> plistMap;
     protected Map bindings;



Mime
View raw message