cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r1425915 - in /cayenne/main/trunk: docs/doc/src/main/resources/ framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/query/ framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/
Date Wed, 26 Dec 2012 14:14:53 GMT
Author: aadamchik
Date: Wed Dec 26 14:14:52 2012
New Revision: 1425915

URL: http://svn.apache.org/viewvc?rev=1425915&view=rev
Log:
CAY-1785 SelectQuery<T> for DataRows

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/query/SelectQuery.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextTest.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=1425915&r1=1425914&r2=1425915&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 Wed Dec 26 14:14:52 2012
@@ -40,6 +40,7 @@ CAY-1778 TransactionManager to simplify 
 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
+CAY-1785 SelectQuery<T> for DataRows
 
 Bug Fixes:
 

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=1425915&r1=1425914&r2=1425915&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
Wed Dec 26 14:14:52 2012
@@ -24,6 +24,7 @@ import java.util.Collections;
 import java.util.List;
 import java.util.Map;
 
+import org.apache.cayenne.DataRow;
 import org.apache.cayenne.exp.Expression;
 import org.apache.cayenne.exp.ExpressionFactory;
 import org.apache.cayenne.map.DbEntity;
@@ -49,6 +50,42 @@ public class SelectQuery<T> extends Qual
     protected boolean distinct;
 
     SelectQueryMetadata metaData = new SelectQueryMetadata();
+    
+    /**
+     * 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.
+     * 
+     * @since 3.2
+     */
+    public static <T> SelectQuery<T> query(Class<T> rootClass, Expression
qualifier) {
+        return new SelectQuery<T>(rootClass, qualifier);
+    }
+    
+    /**
+     * Creates a SelectQuery that selects DataRows that correspond to a given
+     * persistent class that match supplied qualifier.
+     * 
+     * @param rootClass
+     *            the Class of objects that correspond to DataRows entity.
+     * @param qualifier
+     *            an Expression indicating which objects should be fetched.
+     * 
+     * @since 3.2
+     */
+    public static SelectQuery<DataRow> dataRowQuery(Class<?> rootClass, Expression
qualifier) {
+        // create a query replica that would fetch DataRows
+        SelectQuery<DataRow> query = new SelectQuery<DataRow>();
+
+        query.setRoot(rootClass);
+
+        query.setQualifier(qualifier);
+        query.metaData.setFetchingDataRows(true);
+
+        return query;
+    }
 
     /** Creates an empty SelectQuery. */
     public SelectQuery() {
@@ -96,17 +133,6 @@ public class SelectQuery<T> extends Qual
     public SelectQuery(Class<T> rootClass) {
         this(rootClass, null);
     }
-
-    /**
-     * 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 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
@@ -265,7 +291,7 @@ public class SelectQuery<T> extends Qual
 
         // must init defaults even if properties are empty
         if (properties == null) {
-            properties = Collections.EMPTY_MAP;
+            properties = Collections.emptyMap();
         }
 
         Object distinct = properties.get(DISTINCT_PROPERTY);
@@ -435,7 +461,7 @@ public class SelectQuery<T> extends Qual
      * Returns a list of orderings used by this query.
      */
     public List<Ordering> getOrderings() {
-        return (orderings != null) ? orderings : Collections.EMPTY_LIST;
+        return (orderings != null) ? orderings : Collections.<Ordering> emptyList();
     }
 
     /**
@@ -512,21 +538,27 @@ public class SelectQuery<T> extends Qual
     }
 
     /**
-     * Returns <code>true</code> if this query should produce a list of data
rows as
-     * opposed to DataObjects, <code>false</code> for DataObjects. This is a
hint to
-     * QueryEngine executing this query.
+     * Returns <code>true</code> if this query should produce a list of data
+     * rows as opposed to DataObjects, <code>false</code> for DataObjects. This
+     * is a hint to QueryEngine executing this query.
+     * 
+     * @deprecated since 3.2, use {@link #dataRowQuery(Class, Expression)}
+     *             to create DataRow query instead.
      */
     public boolean isFetchingDataRows() {
         return (root instanceof DbEntity) || metaData.isFetchingDataRows();
     }
 
     /**
-     * Sets query result type. If <code>flag</code> parameter is <code>true</code>,
then
-     * results will be in the form of data rows.
+     * Sets query result type. If <code>flag</code> parameter is
+     * <code>true</code>, then results will be in the form of data rows.
      * <p>
-     * <i>Note that if the root of this query is a {@link DbEntity}, this setting has
no
-     * effect, and data rows are always fetched. </i>
+     * <i>Note that if the root of this query is a {@link DbEntity}, this
+     * setting has no effect, and data rows are always fetched. </i>
      * </p>
+     * 
+     * @deprecated since 3.2, use {@link #dataRowQuery(Class, Expression)}
+     *             to create DataRow query instead.
      */
     public void setFetchingDataRows(boolean flag) {
         metaData.setFetchingDataRows(flag);

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextTest.java?rev=1425915&r1=1425914&r2=1425915&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextTest.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextTest.java
Wed Dec 26 14:14:52 2012
@@ -35,15 +35,12 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
-import javax.sql.DataSource;
-
 import org.apache.cayenne.Cayenne;
 import org.apache.cayenne.DataObject;
 import org.apache.cayenne.DataRow;
 import org.apache.cayenne.Fault;
 import org.apache.cayenne.ObjectId;
 import org.apache.cayenne.PersistenceState;
-import org.apache.cayenne.configuration.server.DataSourceFactory;
 import org.apache.cayenne.conn.PoolManager;
 import org.apache.cayenne.di.Inject;
 import org.apache.cayenne.exp.Expression;
@@ -343,6 +340,17 @@ public class DataContextTest extends Ser
         assertEquals("artISt4", objects.get(3).getArtistName());
         assertEquals("aRtist5", objects.get(4).getArtistName());
     }
+    
+    public void testSelect_DataRows() throws Exception {
+        createArtistsAndPaintingsDataSet();
+
+        SelectQuery<DataRow> query = SelectQuery.dataRowQuery(Artist.class, null);
+        List<DataRow> objects = context.select(query);
+
+        assertNotNull(objects);
+        assertEquals(7, objects.size());
+        assertTrue("DataRow expected, got " + objects.get(0).getClass(), objects.get(0) instanceof
DataRow);
+    }
 
     public void testPerformSelectQuery1() throws Exception {
         createArtistsAndPaintingsDataSet();
@@ -356,6 +364,8 @@ public class DataContextTest extends Ser
                 "Artist expected, got " + objects.get(0).getClass(),
                 objects.get(0) instanceof Artist);
     }
+    
+    
 
     public void testPerformSelectQuery2() throws Exception {
         createArtistsAndPaintingsDataSet();



Mime
View raw message