solomax commented on code in PR #144:
URL: https://github.com/apache/openjpa/pull/144#discussion_r3804649084
##########
openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/TestTypesafeCriteria.java:
##########
@@ -1781,5 +1789,168 @@ public void testIdClass() {
assertEquivalence(cq, jpql);
}
+
+ public void testLeft() {
+ if (getDictionary() instanceof DerbyDictionary) {
+ // TODO Derby DB does not support LEFT, RIGHT or REPLACE
functions
+ return;
+ }
+ String jpql = "select p from Person p where left(p.name, 4) = 'John'";
+ em.getTransaction().begin();
+ Person p = new Person();
+ p.setName("John Fitzgerald Doe");
+ em.persist(p);
+ em.getTransaction().commit();
+
+ CriteriaQuery<Person> cq = cb.createQuery(Person.class);
+ Root<Person> c = cq.from(Person.class);
+ cq.where(cb.equal(cb.left(c.get("name"), 4), "John"));
+ em.createQuery(cq).getResultList();
+
+ assertEquivalence(cq, jpql);
+ }
+
+ public void testRight() {
+ if (getDictionary() instanceof DerbyDictionary) {
+ // TODO Derby DB does not support LEFT, RIGHT or REPLACE
functions
+ return;
+ }
+ String jpql = "select p from Person p where RIGHT(p.name, 3) = 'Doe'";
+ em.getTransaction().begin();
+ Person p = new Person();
+ p.setName("John Fitzgerald Doe");
+ em.persist(p);
+ em.getTransaction().commit();
+
+ CriteriaQuery<Person> cq = cb.createQuery(Person.class);
+ Root<Person> c = cq.from(Person.class);
+ cq.where(cb.equal(cb.right(c.get("name"), 3), "Doe"));
+ em.createQuery(cq).getResultList();
+
+ assertEquivalence(cq, jpql);
+ }
+
+ public void testReplace() {
+ if (getDictionary() instanceof DerbyDictionary) {
+ // TODO Derby DB does not support LEFT, RIGHT or REPLACE
functions
+ return;
+ }
+ em.getTransaction().begin();
+ Person p = new Person();
+ p.setName("John Fitzgerald Doe");
+ em.persist(p);
+ em.getTransaction().commit();
+
+ String jpql = "select p from Person p where REPLACE(p.name, 'ohn',
'ack') = 'Jack Fitzgerald Doe'";
+ CriteriaQuery<Person> cq = cb.createQuery(Person.class);
+ Root<Person> c = cq.from(Person.class);
+ cq.where(cb.equal(cb.replace(c.get("name"), "ohn", "ack"), "Jack
Fitzgerald Doe"));
+ em.createQuery(cq).getResultList();
+
+ assertEquivalence(cq, jpql);
+ }
+
+ /**
+ * JPA 3.2 Criteria UNION must execute end-to-end and produce the
+ * same SQL as the JPQL UNION form. We don't compare row counts
+ * because TestTypesafeCriteria shares a static EMF with other test
+ * classes and we don't want to seed shared tables.
+ */
+ public void testCriteriaUnion() {
+ CriteriaQuery<String> q1 = cb.createQuery(String.class);
+ Root<CompUser> r1 = q1.from(CompUser.class);
+ q1.select(r1.<String>get("name"))
+ .where(cb.gt(r1.<Integer>get("age"), 30));
+
+ CriteriaQuery<String> q2 = cb.createQuery(String.class);
+ Root<CompUser> r2 = q2.from(CompUser.class);
+ q2.select(r2.<String>get("name"))
+ .where(cb.equal(r2.get("name"), "Ugo"));
+
+ jakarta.persistence.criteria.CriteriaSelect<String> union =
cb.union(q1, q2);
+ assertNotNull(em.createQuery(union).getResultList());
+ }
+
+ public void testCriteriaUnionAll() {
+ CriteriaQuery<String> q1 = cb.createQuery(String.class);
+ Root<CompUser> r1 = q1.from(CompUser.class);
+ q1.select(r1.<String>get("name"))
+ .where(cb.gt(r1.<Integer>get("age"), 25));
+
+ CriteriaQuery<String> q2 = cb.createQuery(String.class);
+ Root<CompUser> r2 = q2.from(CompUser.class);
+ q2.select(r2.<String>get("name"))
+ .where(cb.gt(r2.<Integer>get("age"), 30));
+
+ jakarta.persistence.criteria.CriteriaSelect<String> unionAll =
cb.unionAll(q1, q2);
+ assertNotNull(em.createQuery(unionAll).getResultList());
+ }
+
+ public void testCriteriaExcept() {
Review Comment:
I guess `CriteriaSelectImpl` need some hint on `dbDictionary == Oracle` (so
`MINUS` can be used instead of `EXCEPT`)
But so far I can't find the way to pass it ....
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]