cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ntimof...@apache.org
Subject cayenne git commit: CAY-2365 SQLExec query tries to convert result set into objects
Date Thu, 21 Sep 2017 14:39:56 GMT
Repository: cayenne
Updated Branches:
  refs/heads/master f4627713c -> 6c17c0216


CAY-2365 SQLExec query tries to convert result set into objects


Project: http://git-wip-us.apache.org/repos/asf/cayenne/repo
Commit: http://git-wip-us.apache.org/repos/asf/cayenne/commit/6c17c021
Tree: http://git-wip-us.apache.org/repos/asf/cayenne/tree/6c17c021
Diff: http://git-wip-us.apache.org/repos/asf/cayenne/diff/6c17c021

Branch: refs/heads/master
Commit: 6c17c0216fa533d54eb77aa619aa263363a75dce
Parents: f462771
Author: Nikita Timofeev <stariy95@gmail.com>
Authored: Thu Sep 21 17:27:05 2017 +0300
Committer: Nikita Timofeev <stariy95@gmail.com>
Committed: Thu Sep 21 17:27:05 2017 +0300

----------------------------------------------------------------------
 .../org/apache/cayenne/access/ObjectResolver.java |  3 ++-
 .../java/org/apache/cayenne/query/SQLExec.java    |  1 +
 .../java/org/apache/cayenne/query/SQLExecIT.java  | 18 ++++++++++++++++++
 docs/doc/src/main/resources/RELEASE-NOTES.txt     |  1 +
 4 files changed, 22 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cayenne/blob/6c17c021/cayenne-server/src/main/java/org/apache/cayenne/access/ObjectResolver.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/main/java/org/apache/cayenne/access/ObjectResolver.java b/cayenne-server/src/main/java/org/apache/cayenne/access/ObjectResolver.java
index af5949b..dd1620b 100644
--- a/cayenne-server/src/main/java/org/apache/cayenne/access/ObjectResolver.java
+++ b/cayenne-server/src/main/java/org/apache/cayenne/access/ObjectResolver.java
@@ -61,7 +61,8 @@ class ObjectResolver {
 
 		// sanity check
 		if (descriptor == null || descriptor.getEntity() == null) {
-			throw new CayenneRuntimeException("Set up Object entity or use rowFetchingQuery");
+			// possible cause: query that is not expected to have result set somehow got it..
+			throw new CayenneRuntimeException("No ClassDescriptor. Maybe DataRows should be fetched
instead of objects.");
 		}
 
 		DbEntity dbEntity = descriptor.getEntity().getDbEntity();

http://git-wip-us.apache.org/repos/asf/cayenne/blob/6c17c021/cayenne-server/src/main/java/org/apache/cayenne/query/SQLExec.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/main/java/org/apache/cayenne/query/SQLExec.java b/cayenne-server/src/main/java/org/apache/cayenne/query/SQLExec.java
index d6b782f..57f7cc5 100644
--- a/cayenne-server/src/main/java/org/apache/cayenne/query/SQLExec.java
+++ b/cayenne-server/src/main/java/org/apache/cayenne/query/SQLExec.java
@@ -218,6 +218,7 @@ public class SQLExec extends IndirectQuery {
         SQLTemplate template = new SQLTemplate();
         template.setRoot(root);
         template.setDefaultTemplate(getSql());
+        template.setFetchingDataRows(true); // in case result set will be returned
 
         if (positionalParams != null) {
             template.setParamsList(positionalParams);

http://git-wip-us.apache.org/repos/asf/cayenne/blob/6c17c021/cayenne-server/src/test/java/org/apache/cayenne/query/SQLExecIT.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/query/SQLExecIT.java b/cayenne-server/src/test/java/org/apache/cayenne/query/SQLExecIT.java
index 17f909f..6da090b 100644
--- a/cayenne-server/src/test/java/org/apache/cayenne/query/SQLExecIT.java
+++ b/cayenne-server/src/test/java/org/apache/cayenne/query/SQLExecIT.java
@@ -19,7 +19,10 @@
 package org.apache.cayenne.query;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
 
+import org.apache.cayenne.DataRow;
+import org.apache.cayenne.QueryResult;
 import org.apache.cayenne.access.DataContext;
 import org.apache.cayenne.di.Inject;
 import org.apache.cayenne.test.jdbc.DBHelper;
@@ -61,6 +64,21 @@ public class SQLExecIT extends ServerCase {
     }
 
     @Test
+    public void test_ExecuteSelect() throws Exception {
+        int inserted = SQLExec.query("INSERT INTO ARTIST (ARTIST_ID, ARTIST_NAME) VALUES
(1, 'a')").update(context);
+        assertEquals(1, inserted);
+
+        QueryResult result = SQLExec.query("SELECT * FROM ARTIST").execute(context);
+        assertEquals(2, result.size());
+        assertTrue(result.isList());
+        assertEquals(1, result.firstList().size());
+
+        DataRow row = (DataRow)result.firstList().get(0);
+        assertEquals(1L, row.get("ARTIST_ID"));
+        assertEquals("a", row.get("ARTIST_NAME"));
+    }
+
+    @Test
     public void test_ParamsArray_Multiple() throws Exception {
 
         int inserted = SQLExec.query("INSERT INTO ARTIST (ARTIST_ID, ARTIST_NAME) VALUES
(#bind($id), #bind($name))")

http://git-wip-us.apache.org/repos/asf/cayenne/blob/6c17c021/docs/doc/src/main/resources/RELEASE-NOTES.txt
----------------------------------------------------------------------
diff --git a/docs/doc/src/main/resources/RELEASE-NOTES.txt b/docs/doc/src/main/resources/RELEASE-NOTES.txt
index 6ee9ba9..52ec865 100644
--- a/docs/doc/src/main/resources/RELEASE-NOTES.txt
+++ b/docs/doc/src/main/resources/RELEASE-NOTES.txt
@@ -43,6 +43,7 @@ CAY-2359 EJBQL: db path in not supported in ORDER BY
 CAY-2362 ColumnSelect: unable to use Property without type
 CAY-2363 ColumnSelect: unable to use from nested context
 CAY-2364 Wrong logging in SQLTemplate
+CAY-2365 SQLExec query tries to convert (unexpected) result set into objects
 
 ----------------------------------
 Release: 4.0.B1


Mime
View raw message