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-2350 Expression: NotIn with empty collection returns empty result
Date Wed, 16 Aug 2017 12:05:09 GMT
Repository: cayenne
Updated Branches:
  refs/heads/STABLE-4.0 3ed2301bf -> be34db113


CAY-2350 Expression: NotIn with empty collection returns empty result


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

Branch: refs/heads/STABLE-4.0
Commit: be34db11309e03ccec72e091225143238b14b449
Parents: 3ed2301
Author: Nikita Timofeev <stariy95@gmail.com>
Authored: Wed Aug 16 15:00:04 2017 +0300
Committer: Nikita Timofeev <stariy95@gmail.com>
Committed: Wed Aug 16 15:00:04 2017 +0300

----------------------------------------------------------------------
 .../apache/cayenne/exp/ExpressionFactory.java   |  2 +-
 .../cayenne/exp/ExpressionFactoryTest.java      | 22 ++++++++++++++++++++
 .../exp/parser/ExpressionEvaluationIT.java      | 17 +++++++++++++++
 docs/doc/src/main/resources/RELEASE-NOTES.txt   |  1 +
 4 files changed, 41 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cayenne/blob/be34db11/cayenne-server/src/main/java/org/apache/cayenne/exp/ExpressionFactory.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/main/java/org/apache/cayenne/exp/ExpressionFactory.java b/cayenne-server/src/main/java/org/apache/cayenne/exp/ExpressionFactory.java
index b2770bc..6c227a9 100644
--- a/cayenne-server/src/main/java/org/apache/cayenne/exp/ExpressionFactory.java
+++ b/cayenne-server/src/main/java/org/apache/cayenne/exp/ExpressionFactory.java
@@ -610,7 +610,7 @@ public class ExpressionFactory {
 	 */
 	static Expression notInExp(Expression exp, Collection<?> values) {
 		if (values.isEmpty()) {
-			return new ASTFalse();
+			return new ASTTrue();
 		}
 		if(!(exp instanceof SimpleNode)) {
 			throw new IllegalArgumentException("exp should be instance of SimpleNode");

http://git-wip-us.apache.org/repos/asf/cayenne/blob/be34db11/cayenne-server/src/test/java/org/apache/cayenne/exp/ExpressionFactoryTest.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/exp/ExpressionFactoryTest.java
b/cayenne-server/src/test/java/org/apache/cayenne/exp/ExpressionFactoryTest.java
index 5e541f0..a41344c 100644
--- a/cayenne-server/src/test/java/org/apache/cayenne/exp/ExpressionFactoryTest.java
+++ b/cayenne-server/src/test/java/org/apache/cayenne/exp/ExpressionFactoryTest.java
@@ -191,6 +191,28 @@ public class ExpressionFactoryTest {
 	}
 
 	@Test
+	public void testNotInExp1() throws Exception {
+		Expression exp = ExpressionFactory.notInExp("abc", "a", "b");
+		assertEquals(Expression.NOT_IN, exp.getType());
+	}
+
+	@Test
+	public void testNotInExp2() throws Exception {
+		List<Object> v = new ArrayList<>();
+		v.add("a");
+		v.add("b");
+		Expression exp = ExpressionFactory.notInExp("abc", v);
+		assertEquals(Expression.NOT_IN, exp.getType());
+	}
+
+	@Test
+	public void testNotInExp3() throws Exception {
+		List<Object> v = new ArrayList<>();
+		Expression exp = ExpressionFactory.notInExp("abc", v);
+		assertEquals(Expression.TRUE, exp.getType());
+	}
+
+	@Test
 	public void testLikeExp() throws Exception {
 		String v = "abc";
 		Expression exp = ExpressionFactory.likeExp("abc", v);

http://git-wip-us.apache.org/repos/asf/cayenne/blob/be34db11/cayenne-server/src/test/java/org/apache/cayenne/exp/parser/ExpressionEvaluationIT.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/exp/parser/ExpressionEvaluationIT.java
b/cayenne-server/src/test/java/org/apache/cayenne/exp/parser/ExpressionEvaluationIT.java
index d8bc19d..c0b47e4 100644
--- a/cayenne-server/src/test/java/org/apache/cayenne/exp/parser/ExpressionEvaluationIT.java
+++ b/cayenne-server/src/test/java/org/apache/cayenne/exp/parser/ExpressionEvaluationIT.java
@@ -20,6 +20,7 @@
 package org.apache.cayenne.exp.parser;
 
 import java.math.BigDecimal;
+import java.util.Collections;
 import java.util.List;
 
 import org.apache.cayenne.access.DataContext;
@@ -223,6 +224,14 @@ public class ExpressionEvaluationIT extends ServerCase {
     }
 
     @Test
+    public void testInEmpty() {
+        Expression exp = Artist.PAINTING_ARRAY.dot(Painting.ESTIMATED_PRICE)
+                .in(Collections.<BigDecimal>emptyList());
+
+        compareSqlAndEval(exp, 0);
+    }
+
+    @Test
     public void testNotIn() {
         Expression exp = Artist.PAINTING_ARRAY.dot(Painting.ESTIMATED_PRICE)
                 .nin(new BigDecimal(800), new BigDecimal(200), new BigDecimal(300), new BigDecimal(400),
new BigDecimal(700));
@@ -231,6 +240,14 @@ public class ExpressionEvaluationIT extends ServerCase {
     }
 
     @Test
+    public void testNotInEmpty() {
+        Expression exp = Artist.PAINTING_ARRAY.dot(Painting.ESTIMATED_PRICE)
+                .nin(Collections.<BigDecimal>emptyList());
+
+        compareSqlAndEval(exp, 6);
+    }
+
+    @Test
     public void testLess() {
         Expression exp = Artist.PAINTING_ARRAY.dot(Painting.ESTIMATED_PRICE)
                 .lt(new BigDecimal(801));

http://git-wip-us.apache.org/repos/asf/cayenne/blob/be34db11/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 a8d263f..227d22a 100644
--- a/docs/doc/src/main/resources/RELEASE-NOTES.txt
+++ b/docs/doc/src/main/resources/RELEASE-NOTES.txt
@@ -18,6 +18,7 @@ CAY-2319 Modeler: Embeddable > Attributes. Undo does not cancel pasted
objects
 CAY-2323 Modeler: Graph. No warning while saving the image with existing name
 CAY-2331 cgen: broken templates for data map
 CAY-2349 Cache issue: 'SelectQuery' with prefetches loses relationships
+CAY-2350 Expression: NotIn with empty collection returns empty result
 
 ----------------------------------
 Release: 4.0.B1


Mime
View raw message