From 5f634cc3e38767a5f8a2a9632841908fe3200279 Mon Sep 17 00:00:00 2001 From: Mark Struberg Date: Wed, 10 Apr 2019 20:13:15 +0200 Subject: [PATCH] OPENJPA-2668 adding copy to Expressions.In to avoid polluting CriteriaQuery --- openjpa-all/pom.xml | 2 +- openjpa-examples/image-gallery/pom.xml | 2 +- openjpa-examples/openbooks/pom.xml | 2 +- openjpa-examples/pom.xml | 2 +- openjpa-examples/simple/pom.xml | 2 +- openjpa-features/pom.xml | 2 +- openjpa-integration/daytrader/pom.xml | 2 +- openjpa-integration/examples/pom.xml | 2 +- openjpa-integration/jmx/pom.xml | 2 +- openjpa-integration/pom.xml | 2 +- openjpa-integration/slf4j/pom.xml | 2 +- openjpa-integration/tck/pom.xml | 2 +- openjpa-integration/validation/pom.xml | 2 +- openjpa-jdbc/pom.xml | 2 +- openjpa-jest/pom.xml | 2 +- openjpa-kernel/pom.xml | 2 +- openjpa-lib/pom.xml | 2 +- openjpa-persistence-jdbc/pom.xml | 2 +- .../persistence/criteria/TestCriteria.java | 23 +++++++++++++++++++ openjpa-persistence-locking/pom.xml | 2 +- openjpa-persistence/pom.xml | 2 +- .../persistence/criteria/Expressions.java | 12 +++++++++- openjpa-project/pom.xml | 2 +- openjpa-slice/pom.xml | 2 +- .../openjpa-fetch-statistics-was/pom.xml | 2 +- .../openjpa-fetch-statistics/pom.xml | 2 +- openjpa-tools/openjpa-maven-plugin/pom.xml | 2 +- openjpa-tools/pom.xml | 2 +- openjpa-xmlstore/pom.xml | 2 +- openjpa/pom.xml | 2 +- pom.xml | 4 ++-- 31 files changed, 64 insertions(+), 31 deletions(-) diff --git a/openjpa-all/pom.xml b/openjpa-all/pom.xml index 3df1dbdd78..d6cc78e6fb 100644 --- a/openjpa-all/pom.xml +++ b/openjpa-all/pom.xml @@ -28,7 +28,7 @@ org.apache.openjpa openjpa-parent - 3.1.0 + 3.1.1-SNAPSHOT openjpa-all diff --git a/openjpa-examples/image-gallery/pom.xml b/openjpa-examples/image-gallery/pom.xml index 48c33fc730..ead9d954bb 100644 --- a/openjpa-examples/image-gallery/pom.xml +++ b/openjpa-examples/image-gallery/pom.xml @@ -27,7 +27,7 @@ org.apache.openjpa openjpa-examples - 3.1.0 + 3.1.1-SNAPSHOT org.apache.openjpa.openjpa-examples diff --git a/openjpa-examples/openbooks/pom.xml b/openjpa-examples/openbooks/pom.xml index cf99d0cf61..eab6b05c7a 100644 --- a/openjpa-examples/openbooks/pom.xml +++ b/openjpa-examples/openbooks/pom.xml @@ -29,7 +29,7 @@ org.apache.openjpa openjpa-examples - 3.1.0 + 3.1.1-SNAPSHOT org.apache.openjpa.openjpa-examples diff --git a/openjpa-examples/pom.xml b/openjpa-examples/pom.xml index e1d626b410..e8cb65ec8f 100644 --- a/openjpa-examples/pom.xml +++ b/openjpa-examples/pom.xml @@ -28,7 +28,7 @@ org.apache.openjpa openjpa-parent - 3.1.0 + 3.1.1-SNAPSHOT openjpa-examples diff --git a/openjpa-examples/simple/pom.xml b/openjpa-examples/simple/pom.xml index 281b2f7989..1d92b3453e 100644 --- a/openjpa-examples/simple/pom.xml +++ b/openjpa-examples/simple/pom.xml @@ -28,7 +28,7 @@ org.apache.openjpa openjpa-examples - 3.1.0 + 3.1.1-SNAPSHOT org.apache.openjpa.openjpa-examples diff --git a/openjpa-features/pom.xml b/openjpa-features/pom.xml index f19e46221c..68c0b64a60 100644 --- a/openjpa-features/pom.xml +++ b/openjpa-features/pom.xml @@ -18,7 +18,7 @@ org.apache.openjpa openjpa-parent - 3.1.0 + 3.1.1-SNAPSHOT openjpa-features diff --git a/openjpa-integration/daytrader/pom.xml b/openjpa-integration/daytrader/pom.xml index 8e16c83e59..5ae69031bc 100644 --- a/openjpa-integration/daytrader/pom.xml +++ b/openjpa-integration/daytrader/pom.xml @@ -27,7 +27,7 @@ org.apache.openjpa openjpa-integration - 3.1.0 + 3.1.1-SNAPSHOT openjpa-integration-daytrader diff --git a/openjpa-integration/examples/pom.xml b/openjpa-integration/examples/pom.xml index 4dca6ed0f7..a90cf05503 100644 --- a/openjpa-integration/examples/pom.xml +++ b/openjpa-integration/examples/pom.xml @@ -37,7 +37,7 @@ org.apache.openjpa openjpa-integration - 3.1.0 + 3.1.1-SNAPSHOT openjpa-integration-examples diff --git a/openjpa-integration/jmx/pom.xml b/openjpa-integration/jmx/pom.xml index 7d40a43a52..72e15fbf2f 100644 --- a/openjpa-integration/jmx/pom.xml +++ b/openjpa-integration/jmx/pom.xml @@ -28,7 +28,7 @@ org.apache.openjpa openjpa-integration - 3.1.0 + 3.1.1-SNAPSHOT openjpa-integration-jmx diff --git a/openjpa-integration/pom.xml b/openjpa-integration/pom.xml index dbbebdde7e..9c1b95a179 100644 --- a/openjpa-integration/pom.xml +++ b/openjpa-integration/pom.xml @@ -28,7 +28,7 @@ org.apache.openjpa openjpa-parent - 3.1.0 + 3.1.1-SNAPSHOT openjpa-integration diff --git a/openjpa-integration/slf4j/pom.xml b/openjpa-integration/slf4j/pom.xml index 0296cc4a14..31bae0cf28 100644 --- a/openjpa-integration/slf4j/pom.xml +++ b/openjpa-integration/slf4j/pom.xml @@ -27,7 +27,7 @@ org.apache.openjpa openjpa-integration - 3.1.0 + 3.1.1-SNAPSHOT openjpa-integration-slf4j diff --git a/openjpa-integration/tck/pom.xml b/openjpa-integration/tck/pom.xml index f727c99489..efdf22e2c3 100644 --- a/openjpa-integration/tck/pom.xml +++ b/openjpa-integration/tck/pom.xml @@ -78,7 +78,7 @@ org.apache.openjpa openjpa-integration - 3.1.0 + 3.1.1-SNAPSHOT openjpa-integration-tck diff --git a/openjpa-integration/validation/pom.xml b/openjpa-integration/validation/pom.xml index aa0c6d41fc..b83dc3b93b 100644 --- a/openjpa-integration/validation/pom.xml +++ b/openjpa-integration/validation/pom.xml @@ -27,7 +27,7 @@ org.apache.openjpa openjpa-integration - 3.1.0 + 3.1.1-SNAPSHOT openjpa-integration-validation diff --git a/openjpa-jdbc/pom.xml b/openjpa-jdbc/pom.xml index e3c337993e..0f4aedbc86 100644 --- a/openjpa-jdbc/pom.xml +++ b/openjpa-jdbc/pom.xml @@ -27,7 +27,7 @@ org.apache.openjpa openjpa-parent - 3.1.0 + 3.1.1-SNAPSHOT openjpa-jdbc diff --git a/openjpa-jest/pom.xml b/openjpa-jest/pom.xml index 80a8857e7d..bb1f9fe294 100644 --- a/openjpa-jest/pom.xml +++ b/openjpa-jest/pom.xml @@ -28,7 +28,7 @@ org.apache.openjpa openjpa-parent - 3.1.0 + 3.1.1-SNAPSHOT openjpa-jest diff --git a/openjpa-kernel/pom.xml b/openjpa-kernel/pom.xml index cb9f5a1d5b..37f7757f45 100644 --- a/openjpa-kernel/pom.xml +++ b/openjpa-kernel/pom.xml @@ -27,7 +27,7 @@ org.apache.openjpa openjpa-parent - 3.1.0 + 3.1.1-SNAPSHOT openjpa-kernel diff --git a/openjpa-lib/pom.xml b/openjpa-lib/pom.xml index d0cd45a90c..8517f25c4d 100644 --- a/openjpa-lib/pom.xml +++ b/openjpa-lib/pom.xml @@ -27,7 +27,7 @@ org.apache.openjpa openjpa-parent - 3.1.0 + 3.1.1-SNAPSHOT openjpa-lib diff --git a/openjpa-persistence-jdbc/pom.xml b/openjpa-persistence-jdbc/pom.xml index 49d23704c3..47ad4d19d7 100644 --- a/openjpa-persistence-jdbc/pom.xml +++ b/openjpa-persistence-jdbc/pom.xml @@ -27,7 +27,7 @@ org.apache.openjpa openjpa-parent - 3.1.0 + 3.1.1-SNAPSHOT openjpa-persistence-jdbc diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/TestCriteria.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/TestCriteria.java index 18e116d933..84920e513d 100644 --- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/TestCriteria.java +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/TestCriteria.java @@ -19,6 +19,8 @@ package org.apache.openjpa.persistence.criteria; +import java.util.Arrays; +import java.util.Collection; import java.util.List; import javax.persistence.EntityManager; @@ -27,6 +29,7 @@ import javax.persistence.criteria.CriteriaBuilder; import javax.persistence.criteria.CriteriaQuery; import javax.persistence.criteria.Root; +import javax.persistence.criteria.ParameterExpression; import org.apache.openjpa.persistence.OpenJPAEntityManager; import org.apache.openjpa.persistence.query.DomainObject; @@ -646,5 +649,25 @@ void setParameters(Query q, Object...p) { q.setParameter(p[i].toString(), p[i+1]); } } + + public void testInCriteriaWithCollection() { + + OpenJPAEntityManager em = emf.createEntityManager(); + CriteriaBuilder builder = em.getCriteriaBuilder(); + + CriteriaQuery criteria = builder.createQuery(Customer.class); + Root root = criteria.from(Customer.class); + criteria.where(root.get("status").in(builder.parameter(Collection.class))); + + TypedQuery query = em.createQuery(criteria); + System.err.println(query); + for (ParameterExpression parameter : criteria.getParameters()) { + query.setParameter(parameter, Arrays.asList(1L, 2L)); + } + + assertEquals("SELECT * FROM Customer c WHERE c.status IN (:param)", criteria.toString()); + query.getResultList(); + assertEquals("SELECT * FROM Customer c WHERE c.status IN (:param)", criteria.toString()); + } } diff --git a/openjpa-persistence-locking/pom.xml b/openjpa-persistence-locking/pom.xml index cf709e113b..2526586322 100644 --- a/openjpa-persistence-locking/pom.xml +++ b/openjpa-persistence-locking/pom.xml @@ -27,7 +27,7 @@ org.apache.openjpa openjpa-parent - 3.1.0 + 3.1.1-SNAPSHOT openjpa-persistence-locking diff --git a/openjpa-persistence/pom.xml b/openjpa-persistence/pom.xml index c29328c1d5..0299972013 100644 --- a/openjpa-persistence/pom.xml +++ b/openjpa-persistence/pom.xml @@ -27,7 +27,7 @@ org.apache.openjpa openjpa-parent - 3.1.0 + 3.1.1-SNAPSHOT openjpa-persistence diff --git a/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/Expressions.java b/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/Expressions.java index d1ca11ded5..c22bb91a94 100644 --- a/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/Expressions.java +++ b/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/Expressions.java @@ -1440,6 +1440,12 @@ public In(Expression e) { this.e = (ExpressionImpl)e; } + private Expressions.In copy() { + In in = new Expressions.In<>(this.e); + in._exps.addAll(this._exps); + return in; + } + @Override public Expression getExpression() { return e; @@ -1468,7 +1474,11 @@ public PredicateImpl not() { } @Override - org.apache.openjpa.kernel.exps.Expression toKernelExpression( + org.apache.openjpa.kernel.exps.Expression toKernelExpression(ExpressionFactory factory, CriteriaQueryImpl q) { + return copy().toKernelExpression0(factory, q); + } + + org.apache.openjpa.kernel.exps.Expression toKernelExpression0( ExpressionFactory factory, CriteriaQueryImpl q) { org.apache.openjpa.kernel.exps.Expression inExpr = null; if (_exps.size() == 1) { diff --git a/openjpa-project/pom.xml b/openjpa-project/pom.xml index 0db6b52afc..8266c33042 100644 --- a/openjpa-project/pom.xml +++ b/openjpa-project/pom.xml @@ -39,7 +39,7 @@ org.apache.openjpa openjpa-parent - 3.1.0 + 3.1.1-SNAPSHOT apache-openjpa diff --git a/openjpa-slice/pom.xml b/openjpa-slice/pom.xml index 25b3479ba4..df670b9f10 100644 --- a/openjpa-slice/pom.xml +++ b/openjpa-slice/pom.xml @@ -27,7 +27,7 @@ org.apache.openjpa openjpa-parent - 3.1.0 + 3.1.1-SNAPSHOT openjpa-slice diff --git a/openjpa-tools/openjpa-fetch-statistics-was/pom.xml b/openjpa-tools/openjpa-fetch-statistics-was/pom.xml index 40bd4f8188..0cf52eed79 100644 --- a/openjpa-tools/openjpa-fetch-statistics-was/pom.xml +++ b/openjpa-tools/openjpa-fetch-statistics-was/pom.xml @@ -17,7 +17,7 @@ org.apache.openjpa openjpa-tools - 3.1.0 + 3.1.1-SNAPSHOT openjpa-fetch-statistics-was diff --git a/openjpa-tools/openjpa-fetch-statistics/pom.xml b/openjpa-tools/openjpa-fetch-statistics/pom.xml index db7104694e..32bede63e1 100644 --- a/openjpa-tools/openjpa-fetch-statistics/pom.xml +++ b/openjpa-tools/openjpa-fetch-statistics/pom.xml @@ -17,7 +17,7 @@ org.apache.openjpa openjpa-tools - 3.1.0 + 3.1.1-SNAPSHOT openjpa-fetch-statistics diff --git a/openjpa-tools/openjpa-maven-plugin/pom.xml b/openjpa-tools/openjpa-maven-plugin/pom.xml index 9894b3b547..40f487179b 100644 --- a/openjpa-tools/openjpa-maven-plugin/pom.xml +++ b/openjpa-tools/openjpa-maven-plugin/pom.xml @@ -27,7 +27,7 @@ org.apache.openjpa openjpa-tools - 3.1.0 + 3.1.1-SNAPSHOT ../pom.xml diff --git a/openjpa-tools/pom.xml b/openjpa-tools/pom.xml index 8edb3913cb..fd55dc169e 100644 --- a/openjpa-tools/pom.xml +++ b/openjpa-tools/pom.xml @@ -27,7 +27,7 @@ org.apache.openjpa openjpa-parent - 3.1.0 + 3.1.1-SNAPSHOT diff --git a/openjpa-xmlstore/pom.xml b/openjpa-xmlstore/pom.xml index e604c49b49..d3b2d33dbb 100644 --- a/openjpa-xmlstore/pom.xml +++ b/openjpa-xmlstore/pom.xml @@ -27,7 +27,7 @@ org.apache.openjpa openjpa-parent - 3.1.0 + 3.1.1-SNAPSHOT openjpa-xmlstore diff --git a/openjpa/pom.xml b/openjpa/pom.xml index e947e579a7..c3ed6d5937 100644 --- a/openjpa/pom.xml +++ b/openjpa/pom.xml @@ -28,7 +28,7 @@ org.apache.openjpa openjpa-parent - 3.1.0 + 3.1.1-SNAPSHOT openjpa diff --git a/pom.xml b/pom.xml index 436db2deae..6b075c635e 100644 --- a/pom.xml +++ b/pom.xml @@ -36,7 +36,7 @@ OpenJPA Parent POM Apache OpenJPA implementation of JSR-338 JPA 2.1 - 3.1.0 + 3.1.1-SNAPSHOT 1.8 @@ -160,7 +160,7 @@ scm:git:https://gitbox.apache.org/repos/asf/openjpa.git scm:git:https://gitbox.apache.org/repos/asf/openjpa.git https://gitbox.apache.org/repos/asf/openjpa.git - 3.1.0 + HEAD