From 66d6230a417972e229a60375201f788e8085dde2 Mon Sep 17 00:00:00 2001 From: Patrick Linskey Date: Fri, 29 Feb 2008 18:41:16 +0000 Subject: [PATCH] Additional test case for enums in queries git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@632404 13f79535-47bb-0310-9956-ffa450edef68 --- .../openjpa/persistence/fields/EnumFieldType.java | 11 +++++++++++ .../openjpa/persistence/fields/TestEnumsInJPQL.java | 10 ++++++++++ 2 files changed, 21 insertions(+) diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/fields/EnumFieldType.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/fields/EnumFieldType.java index 03d60004e..d18f1762a 100644 --- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/fields/EnumFieldType.java +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/fields/EnumFieldType.java @@ -18,11 +18,15 @@ */ package org.apache.openjpa.persistence.fields; +import java.util.List; +import java.util.ArrayList; import javax.persistence.Id; import javax.persistence.GeneratedValue; import javax.persistence.Entity; import org.apache.openjpa.persistence.DetachedState; +import org.apache.openjpa.persistence.PersistentCollection; +import org.apache.openjpa.persistence.kernel.common.apps.PCDirectory; @Entity //@DetachedState(enabled = false) // ##### shouldn't need this @@ -33,6 +37,9 @@ public class EnumFieldType { private SampleEnum enumField; + @PersistentCollection + private List enumList = new ArrayList(); + // for OpenJPA protected EnumFieldType() { } @@ -49,4 +56,8 @@ public class EnumFieldType { public SampleEnum getEnumField() { return enumField; } + + public List getEnumList() { + return enumList; + } } diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/fields/TestEnumsInJPQL.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/fields/TestEnumsInJPQL.java index f6aae856b..d86635b93 100644 --- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/fields/TestEnumsInJPQL.java +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/fields/TestEnumsInJPQL.java @@ -30,6 +30,7 @@ public class TestEnumsInJPQL EnumFieldType o = new EnumFieldType(); o.setEnumField(SampleEnum.BAR); + o.getEnumList().add(SampleEnum.FOO); em.getTransaction().begin(); em.persist(o); @@ -115,4 +116,13 @@ public class TestEnumsInJPQL em.getTransaction().commit(); postUpdateCheck(false); } + + public void testMemberOf() { + assertEquals(Long.valueOf(1), + em.createQuery("select count(o) from EnumFieldType o where " + + "(:param member of o.enumList or :param2 member of o.enumList)") + .setParameter("param", SampleEnum.FOO) + .setParameter("param2", SampleEnum.BAR) + .getSingleResult()); + } } \ No newline at end of file