cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From abulat...@apache.org
Subject [cayenne] 01/03: CAY-2588 IdRowReader: ArrayIndexOutOfBoundsException
Date Wed, 26 Jun 2019 13:27:33 GMT
This is an automated email from the ASF dual-hosted git repository.

abulatski pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cayenne.git

commit c7c8ef44b14257ae4fd7b35514b9349e9b874472
Author: Arseni Bulatski <ancarseni@gmail.com>
AuthorDate: Tue Jun 25 13:48:49 2019 +0300

    CAY-2588 IdRowReader: ArrayIndexOutOfBoundsException
---
 RELEASE-NOTES.txt                                       |  1 +
 .../apache/cayenne/access/jdbc/reader/IdRowReader.java  | 14 ++++++++++----
 .../java/org/apache/cayenne/query/ColumnSelectIT.java   | 17 +++++++++++++++++
 3 files changed, 28 insertions(+), 4 deletions(-)

diff --git a/RELEASE-NOTES.txt b/RELEASE-NOTES.txt
index 1fa3317..39f91cd 100644
--- a/RELEASE-NOTES.txt
+++ b/RELEASE-NOTES.txt
@@ -60,6 +60,7 @@ CAY-2577 Between property with extended type failure
 CAY-2578 Wrong bindings in select of related entity by compound FK
 CAY-2580 Cgen: Can't use custom templates for client mode
 CAY-2582 Double insert of manyToMany relationship mapped to Set
+CAY-2588 IdRowReader: ArrayIndexOutOfBoundsException
 
 ----------------------------------
 Release: 4.1.B1
diff --git a/cayenne-server/src/main/java/org/apache/cayenne/access/jdbc/reader/IdRowReader.java
b/cayenne-server/src/main/java/org/apache/cayenne/access/jdbc/reader/IdRowReader.java
index 528417a..4005fae 100644
--- a/cayenne-server/src/main/java/org/apache/cayenne/access/jdbc/reader/IdRowReader.java
+++ b/cayenne-server/src/main/java/org/apache/cayenne/access/jdbc/reader/IdRowReader.java
@@ -19,6 +19,8 @@
 package org.apache.cayenne.access.jdbc.reader;
 
 import java.sql.ResultSet;
+import java.util.HashSet;
+import java.util.Set;
 
 import org.apache.cayenne.CayenneRuntimeException;
 import org.apache.cayenne.DataRow;
@@ -54,12 +56,16 @@ class IdRowReader<T> extends BaseRowReader<T> {
             throw new CayenneRuntimeException("Root DBEntity has no PK defined: %s", dbEntity);
         }
 
-        int[] pk = new int[len];
         ColumnDescriptor[] columns = descriptor.getColumns();
-        for (int i = 0, j = 0; i < columns.length; i++) {
+
+        Set<DbAttribute> addedAttributes = new HashSet<>();
+        int[] pk = new int[len];
+        int index = 0;
+        for(int i = 0; i < columns.length; i++) {
             DbAttribute a = dbEntity.getAttribute(columns[i].getName());
-            if (a != null && a.isPrimaryKey()) {
-                pk[j++] = i;
+            if(a != null && a.isPrimaryKey() && !addedAttributes.contains(a))
{
+                pk[index++] = i;
+                addedAttributes.add(a);
             }
         }
 
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/query/ColumnSelectIT.java b/cayenne-server/src/test/java/org/apache/cayenne/query/ColumnSelectIT.java
index 53b25a3..d275b51 100644
--- a/cayenne-server/src/test/java/org/apache/cayenne/query/ColumnSelectIT.java
+++ b/cayenne-server/src/test/java/org/apache/cayenne/query/ColumnSelectIT.java
@@ -36,6 +36,7 @@ import org.apache.cayenne.ResultBatchIterator;
 import org.apache.cayenne.access.DataContext;
 import org.apache.cayenne.configuration.server.ServerRuntime;
 import org.apache.cayenne.di.Inject;
+import org.apache.cayenne.exp.ExpressionFactory;
 import org.apache.cayenne.exp.property.EntityProperty;
 import org.apache.cayenne.exp.property.NumericProperty;
 import org.apache.cayenne.exp.property.PropertyFactory;
@@ -1101,4 +1102,20 @@ public class ColumnSelectIT extends ServerCase {
         assertNotNull(artist);
         assertTrue(artist.getArtistName().startsWith("artist"));
     }
+
+    @Test
+    public void test2PkSelect() {
+        List<Object[]> results = ObjectSelect.columnQuery(Artist.class,
+                PropertyFactory.createSelf(Artist.class),
+                PropertyFactory
+                        .createBase(ExpressionFactory
+                                .dbPathExp("paintingArray.toArtist.ARTIST_ID"),
+                                Integer.class))
+                .where(Artist.ARTIST_ID_PK_PROPERTY.eq(1L))
+                .pageSize(1)
+                .select(context);
+        assertEquals(1, results.size());
+        assertEquals("artist1", ((Artist)results.get(0)[0]).getArtistName());
+        assertEquals(1, results.get(0)[1]);
+    }
 }


Mime
View raw message