Additional test case for enums in queries

git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@632404 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Patrick Linskey 2008-02-29 18:41:16 +00:00
parent 177111b559
commit 66d6230a41
2 changed files with 21 additions and 0 deletions

View File

@ -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<SampleEnum> enumList = new ArrayList<SampleEnum>();
// for OpenJPA
protected EnumFieldType() {
}
@ -49,4 +56,8 @@ public class EnumFieldType {
public SampleEnum getEnumField() {
return enumField;
}
public List<SampleEnum> getEnumList() {
return enumList;
}
}

View File

@ -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());
}
}