cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ntimof...@apache.org
Subject cayenne git commit: Fix broken DistinctResultIterator when result is a single scalar
Date Fri, 26 May 2017 14:34:32 GMT
Repository: cayenne
Updated Branches:
  refs/heads/master eac1f3107 -> c29981272


Fix broken DistinctResultIterator when result is a single scalar


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

Branch: refs/heads/master
Commit: c2998127275bba3d41ea0fd6dcffa7727516fe3d
Parents: eac1f31
Author: Nikita Timofeev <stariy95@gmail.com>
Authored: Fri May 26 16:48:45 2017 +0300
Committer: Nikita Timofeev <stariy95@gmail.com>
Committed: Fri May 26 16:48:45 2017 +0300

----------------------------------------------------------------------
 .../access/jdbc/DistinctResultIterator.java       |  4 ++--
 .../cayenne/access/jdbc/SelectActionIT.java       | 18 ++++++++++++++++++
 2 files changed, 20 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cayenne/blob/c2998127/cayenne-server/src/main/java/org/apache/cayenne/access/jdbc/DistinctResultIterator.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/main/java/org/apache/cayenne/access/jdbc/DistinctResultIterator.java
b/cayenne-server/src/main/java/org/apache/cayenne/access/jdbc/DistinctResultIterator.java
index 850b117..e6e5dab 100644
--- a/cayenne-server/src/main/java/org/apache/cayenne/access/jdbc/DistinctResultIterator.java
+++ b/cayenne-server/src/main/java/org/apache/cayenne/access/jdbc/DistinctResultIterator.java
@@ -44,7 +44,7 @@ import java.util.Set;
 public class DistinctResultIterator<T> implements ResultIterator<T> {
 
     protected ResultIterator<T> delegate;
-    protected Set<Map<String, Object>> fetchedIds;
+    protected Set<Object> fetchedIds;
     protected T nextDataRow;
     protected DbEntity defaultEntity;
     protected boolean compareFullRows;
@@ -144,7 +144,7 @@ public class DistinctResultIterator<T> implements ResultIterator<T>
{
         while (delegate.hasNextRow()) {
             T next = delegate.nextRow();
 
-            if (fetchedIds.add((DataRow)next)) {
+            if (fetchedIds.add(next)) {
                 this.nextDataRow = next;
                 break;
             }

http://git-wip-us.apache.org/repos/asf/cayenne/blob/c2998127/cayenne-server/src/test/java/org/apache/cayenne/access/jdbc/SelectActionIT.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/access/jdbc/SelectActionIT.java
b/cayenne-server/src/test/java/org/apache/cayenne/access/jdbc/SelectActionIT.java
index 865b823..b58f2fa 100644
--- a/cayenne-server/src/test/java/org/apache/cayenne/access/jdbc/SelectActionIT.java
+++ b/cayenne-server/src/test/java/org/apache/cayenne/access/jdbc/SelectActionIT.java
@@ -23,6 +23,7 @@ import org.apache.cayenne.access.DataContext;
 import org.apache.cayenne.di.Inject;
 import org.apache.cayenne.exp.Expression;
 import org.apache.cayenne.exp.ExpressionFactory;
+import org.apache.cayenne.query.ObjectSelect;
 import org.apache.cayenne.query.SelectQuery;
 import org.apache.cayenne.testdo.lob.ClobTestEntity;
 import org.apache.cayenne.testdo.lob.ClobTestRelation;
@@ -62,6 +63,23 @@ public class SelectActionIT extends ServerCase {
         }
     }
 
+    @Test
+    public void testColumnSelect_DistinctResultIterator() throws Exception {
+        if (accessStackAdapter.supportsLobs()) {
+
+            insertClobDb();
+
+            List<String> result = ObjectSelect.query(ClobTestEntity.class)
+                    .column(ClobTestEntity.CLOB_COL)
+                    .where(ClobTestEntity.CLOB_VALUE.dot(ClobTestRelation.VALUE).eq(100))
+                    .select(context);
+
+            // this should be 80, but we got only single values and we forcing distinct on
them
+            // so here will be only 21 elements that are unique
+            assertEquals(21, result.size());
+        }
+    }
+
     protected void insertClobDb() {
         ClobTestEntity obj;
         for (int i = 0; i < 80; i++) {


Mime
View raw message