cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From abulat...@apache.org
Subject [cayenne] 02/03: CAY-2588 IdRowReader: ArrayIndexOutOfBoundsException
Date Wed, 26 Jun 2019 13:27:34 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 01f3755859d5933971a9941a0ae25a8780904ff9
Author: Arseni Bulatski <ancarseni@gmail.com>
AuthorDate: Wed Jun 26 16:21:14 2019 +0300

    CAY-2588 IdRowReader: ArrayIndexOutOfBoundsException
---
 .../cayenne/access/jdbc/reader/IdRowReader.java    | 14 ++++-----
 .../org/apache/cayenne/query/ColumnSelectIT.java   | 34 ++++++++++++++++++++++
 2 files changed, 40 insertions(+), 8 deletions(-)

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 4005fae..2b4d79a 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,8 +19,6 @@
 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;
@@ -58,14 +56,14 @@ class IdRowReader<T> extends BaseRowReader<T> {
 
         ColumnDescriptor[] columns = descriptor.getColumns();
 
-        Set<DbAttribute> addedAttributes = new HashSet<>();
         int[] pk = new int[len];
-        int index = 0;
-        for(int i = 0; i < columns.length; i++) {
+        int offset = resultMetadata != null ?
+                resultMetadata.getColumnOffset() :
+                0;
+        for(int i = offset, j = 0; i < offset + len; i++) {
             DbAttribute a = dbEntity.getAttribute(columns[i].getName());
-            if(a != null && a.isPrimaryKey() && !addedAttributes.contains(a))
{
-                pk[index++] = i;
-                addedAttributes.add(a);
+            if(a != null && a.isPrimaryKey()) {
+                pk[j++] = i;
             }
         }
 
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 d275b51..3f31925 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
@@ -44,6 +44,8 @@ import org.apache.cayenne.exp.property.StringProperty;
 import org.apache.cayenne.test.jdbc.DBHelper;
 import org.apache.cayenne.test.jdbc.TableHelper;
 import org.apache.cayenne.testdo.testmap.Artist;
+import org.apache.cayenne.testdo.testmap.ArtistExhibit;
+import org.apache.cayenne.testdo.testmap.Exhibit;
 import org.apache.cayenne.testdo.testmap.Gallery;
 import org.apache.cayenne.testdo.testmap.Painting;
 import org.apache.cayenne.testdo.testmap.PaintingInfo;
@@ -1118,4 +1120,36 @@ public class ColumnSelectIT extends ServerCase {
         assertEquals("artist1", ((Artist)results.get(0)[0]).getArtistName());
         assertEquals(1, results.get(0)[1]);
     }
+
+    @Test
+    public void test2Objects2Pk() {
+        Artist artist = ObjectSelect.query(Artist.class)
+                .where(Artist.ARTIST_ID_PK_PROPERTY.eq(1L))
+                .selectFirst(context);
+        ArtistExhibit artistExhibit = context.newObject(ArtistExhibit.class);
+        Exhibit exhibit = context.newObject(Exhibit.class);
+        exhibit.setOpeningDate(new Date());
+        exhibit.setClosingDate(new Date());
+        artistExhibit.setToArtist(artist);
+        artistExhibit.setToExhibit(exhibit);
+        Gallery gallery = context.newObject(Gallery.class);
+        gallery.setGalleryName("Test");
+        exhibit.setToGallery(gallery);
+        context.commitChanges();
+
+        List<Object[]> results = ObjectSelect.columnQuery(Artist.class,
+                Artist.ARTIST_NAME,
+                PropertyFactory.createSelf(Artist.class),
+                PropertyFactory
+                        .createBase(ExpressionFactory
+                                        .dbPathExp("artistExhibitArray.ARTIST_ID"),
+                                Integer.class))
+                .where(Artist.ARTIST_ID_PK_PROPERTY.eq(1L))
+                .pageSize(1)
+                .select(context);
+        assertEquals(1, results.size());
+        assertEquals("artist1", results.get(0)[0]);
+        assertEquals("artist1", ((Artist)results.get(0)[1]).getArtistName());
+        assertEquals(1, results.get(0)[2]);
+    }
 }


Mime
View raw message