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-2368 ColumnSelect: Property.self() translates into wrong SQL code
Date Tue, 26 Sep 2017 14:31:47 GMT
Repository: cayenne
Updated Branches:
  refs/heads/master 8b4e3bc60 -> b34c76b24


CAY-2368 ColumnSelect: Property.self() translates into wrong SQL code


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

Branch: refs/heads/master
Commit: b34c76b24a73355fb4c1085dfc10c4741668ea60
Parents: 8b4e3bc
Author: Nikita Timofeev <stariy95@gmail.com>
Authored: Tue Sep 26 17:31:39 2017 +0300
Committer: Nikita Timofeev <stariy95@gmail.com>
Committed: Tue Sep 26 17:31:39 2017 +0300

----------------------------------------------------------------------
 .../select/DefaultSelectTranslator.java         | 10 ++-----
 .../apache/cayenne/query/ColumnSelectIT.java    | 31 ++++++++++++++++++++
 docs/doc/src/main/resources/RELEASE-NOTES.txt   |  1 +
 3 files changed, 35 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cayenne/blob/b34c76b2/cayenne-server/src/main/java/org/apache/cayenne/access/translator/select/DefaultSelectTranslator.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/main/java/org/apache/cayenne/access/translator/select/DefaultSelectTranslator.java
b/cayenne-server/src/main/java/org/apache/cayenne/access/translator/select/DefaultSelectTranslator.java
index 39eda02..adcf71a 100644
--- a/cayenne-server/src/main/java/org/apache/cayenne/access/translator/select/DefaultSelectTranslator.java
+++ b/cayenne-server/src/main/java/org/apache/cayenne/access/translator/select/DefaultSelectTranslator.java
@@ -402,16 +402,12 @@ public class DefaultSelectTranslator extends QueryAssembler implements
SelectTra
 		QualifierTranslator qualifierTranslator = adapter.getQualifierTranslator(this);
 		AccumulatingBindingListener bindingListener = new AccumulatingBindingListener();
 		final String[] joinTableAliasForProperty = {null};
-		joinListener = new AddJoinListener() {
-			@Override
-			public void joinAdded() {
-				// capture last alias for joined table, will use it to resolve object columns
-				joinTableAliasForProperty[0] = getCurrentAlias();
-			}
-		};
+		// capture last alias for joined table, will use it to resolve object columns
+		joinListener = () -> joinTableAliasForProperty[0] = getCurrentAlias();
 		setAddBindingListener(bindingListener);
 
 		for(Property<?> property : query.getColumns()) {
+			joinTableAliasForProperty[0] = null;
 			int expressionType = property.getExpression().getType();
 
 			// forbid direct selection of toMany relationships columns

http://git-wip-us.apache.org/repos/asf/cayenne/blob/b34c76b2/cayenne-server/src/test/java/org/apache/cayenne/query/ColumnSelectIT.java
----------------------------------------------------------------------
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 21e3d9e..fe4edba 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
@@ -477,6 +477,37 @@ public class ColumnSelectIT extends ServerCase {
         assertEquals("ng1 artist1", a);
     }
 
+    @Test
+    public void testAliasOrder() {
+        // test that all table aliases are correct
+        List<Object[]> result = ObjectSelect.columnQuery(Artist.class,
+                Artist.PAINTING_ARRAY.outer().count(),
+                Property.createSelf(Artist.class),
+                Artist.PAINTING_ARRAY.dot(Painting.PAINTING_TITLE),
+                Property.createSelf(Artist.class),
+                Artist.PAINTING_ARRAY.dot(Painting.TO_GALLERY).dot(Gallery.GALLERY_NAME),
+                Artist.ARTIST_NAME,
+                Property.createSelf(Artist.class)
+        ).select(context);
+        assertEquals(21, result.size());
+        for(Object[] next : result) {
+            long count = (Long)next[0];
+            Artist artist = (Artist)next[1];
+            String paintingTitle = (String)next[2];
+            Artist artist2 = (Artist)next[3];
+            String galleryName = (String)next[4];
+            String artistName = (String)next[5];
+            Artist artist3 = (Artist)next[6];
+
+            assertTrue(paintingTitle.startsWith("painting"));
+            assertTrue(count == 4L || count == 5L);
+            assertEquals("tate modern", galleryName);
+            assertEquals(PersistenceState.COMMITTED, artist.getPersistenceState());
+            assertEquals(PersistenceState.COMMITTED, artist2.getPersistenceState());
+            assertEquals(PersistenceState.COMMITTED, artist3.getPersistenceState());
+        }
+    }
+
     /*
      *  Test iterated select
      */

http://git-wip-us.apache.org/repos/asf/cayenne/blob/b34c76b2/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 fed9e08..e8400e4 100644
--- a/docs/doc/src/main/resources/RELEASE-NOTES.txt
+++ b/docs/doc/src/main/resources/RELEASE-NOTES.txt
@@ -45,6 +45,7 @@ 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
 CAY-2366 Incorrect EJBQL COUNT translation
+CAY-2368 ColumnSelect: Property.self() translates into wrong SQL code
 
 ----------------------------------
 Release: 4.0.B1


Mime
View raw message