cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r423645 - in /incubator/cayenne/main/trunk/cayenne/cayenne-java/src: cayenne/java/org/apache/cayenne/query/ tests/java/org/apache/cayenne/access/ tests/java/org/apache/cayenne/query/
Date Wed, 19 Jul 2006 22:43:24 GMT
Author: aadamchik
Date: Wed Jul 19 15:43:24 2006
New Revision: 423645

URL: http://svn.apache.org/viewvc?rev=423645&view=rev
Log:
CAY-603

Added:
    incubator/cayenne/main/trunk/cayenne/cayenne-java/src/tests/java/org/apache/cayenne/access/DataContextQueryChainTst.java
    incubator/cayenne/main/trunk/cayenne/cayenne-java/src/tests/java/org/apache/cayenne/query/QueryChainTst.java
Modified:
    incubator/cayenne/main/trunk/cayenne/cayenne-java/src/cayenne/java/org/apache/cayenne/query/QueryChain.java

Modified: incubator/cayenne/main/trunk/cayenne/cayenne-java/src/cayenne/java/org/apache/cayenne/query/QueryChain.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/cayenne/cayenne-java/src/cayenne/java/org/apache/cayenne/query/QueryChain.java?rev=423645&r1=423644&r2=423645&view=diff
==============================================================================
--- incubator/cayenne/main/trunk/cayenne/cayenne-java/src/cayenne/java/org/apache/cayenne/query/QueryChain.java
(original)
+++ incubator/cayenne/main/trunk/cayenne/cayenne-java/src/cayenne/java/org/apache/cayenne/query/QueryChain.java
Wed Jul 19 15:43:24 2006
@@ -28,7 +28,9 @@
 import org.apache.cayenne.map.EntityResolver;
 
 /**
- * A Query decorator for a collection of other queries.
+ * A Query decorator for a collection of other queries. Note that QueryChain will always
+ * return DataRows (that is if it returns data), as it has no way of knowing how to
+ * convert the results to objects.
  * 
  * @since 1.2
  * @author Andrus Adamchik
@@ -120,7 +122,9 @@
      * Returns default metadata.
      */
     public QueryMetadata getMetaData(EntityResolver resolver) {
-        return DefaultQueryMetadata.defaultMetadata;
+        QueryMetadataWrapper wrapper = new QueryMetadataWrapper(DefaultQueryMetadata.defaultMetadata);
+        wrapper.override(QueryMetadata.FETCHING_DATA_ROWS_PROPERTY, Boolean.TRUE);
+        return wrapper;
     }
 
     /**

Added: incubator/cayenne/main/trunk/cayenne/cayenne-java/src/tests/java/org/apache/cayenne/access/DataContextQueryChainTst.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/cayenne/cayenne-java/src/tests/java/org/apache/cayenne/access/DataContextQueryChainTst.java?rev=423645&view=auto
==============================================================================
--- incubator/cayenne/main/trunk/cayenne/cayenne-java/src/tests/java/org/apache/cayenne/access/DataContextQueryChainTst.java
(added)
+++ incubator/cayenne/main/trunk/cayenne/cayenne-java/src/tests/java/org/apache/cayenne/access/DataContextQueryChainTst.java
Wed Jul 19 15:43:24 2006
@@ -0,0 +1,55 @@
+/*****************************************************************
+ *   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.access;
+
+import java.util.List;
+
+import org.apache.art.Artist;
+import org.apache.cayenne.DataRow;
+import org.apache.cayenne.QueryResponse;
+import org.apache.cayenne.query.QueryChain;
+import org.apache.cayenne.query.SelectQuery;
+import org.apache.cayenne.unit.CayenneTestCase;
+
+public class DataContextQueryChainTst extends CayenneTestCase {
+
+    public void testSelectQuery() {
+        DataContext context = createDataContext();
+        Artist a1 = (Artist) context.newObject(Artist.class);
+        a1.setArtistName("X");
+        context.commitChanges();
+
+        QueryChain chain = new QueryChain();
+        chain.addQuery(new SelectQuery(Artist.class));
+        chain.addQuery(new SelectQuery(Artist.class));
+
+        QueryResponse r = context.performGenericQuery(chain);
+
+        // data comes back as datarows
+        assertEquals(2, r.size());
+        r.reset();
+        r.next();
+        List l1 = r.currentList();
+        r.next();
+        List l2 = r.currentList();
+        
+        assertTrue(l1.get(0) instanceof DataRow);
+        assertTrue(l2.get(0) instanceof DataRow);
+    }
+}

Added: incubator/cayenne/main/trunk/cayenne/cayenne-java/src/tests/java/org/apache/cayenne/query/QueryChainTst.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/cayenne/cayenne-java/src/tests/java/org/apache/cayenne/query/QueryChainTst.java?rev=423645&view=auto
==============================================================================
--- incubator/cayenne/main/trunk/cayenne/cayenne-java/src/tests/java/org/apache/cayenne/query/QueryChainTst.java
(added)
+++ incubator/cayenne/main/trunk/cayenne/cayenne-java/src/tests/java/org/apache/cayenne/query/QueryChainTst.java
Wed Jul 19 15:43:24 2006
@@ -0,0 +1,56 @@
+/*****************************************************************
+ *   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;
+
+import org.apache.art.Artist;
+import org.apache.cayenne.unit.CayenneTestCase;
+
+public class QueryChainTst extends CayenneTestCase {
+
+    public void testSelectQuery() {
+
+        QueryChain chain = new QueryChain();
+        chain.addQuery(new SelectQuery(Artist.class));
+        chain.addQuery(new SelectQuery(Artist.class));
+
+        QueryMetadata md = chain.getMetaData(getDomain().getEntityResolver());
+
+        assertNotNull(md);
+        assertTrue(md.isFetchingDataRows());
+        assertNull(md.getObjEntity());
+    }
+
+    public void testSelectQueryDataRows() {
+
+        QueryChain chain = new QueryChain();
+        SelectQuery q1 = new SelectQuery(Artist.class);
+        q1.setFetchingDataRows(true);
+        chain.addQuery(q1);
+        
+        SelectQuery q2 = new SelectQuery(Artist.class);
+        q2.setFetchingDataRows(true);
+        chain.addQuery(q2);
+
+        QueryMetadata md = chain.getMetaData(getDomain().getEntityResolver());
+
+        assertNotNull(md);
+        assertTrue(md.isFetchingDataRows());
+        assertNull(md.getObjEntity());
+    }
+}



Mime
View raw message