mirror of https://github.com/apache/openjpa.git
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:
parent
177111b559
commit
66d6230a41
|
@ -18,11 +18,15 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.openjpa.persistence.fields;
|
package org.apache.openjpa.persistence.fields;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.ArrayList;
|
||||||
import javax.persistence.Id;
|
import javax.persistence.Id;
|
||||||
import javax.persistence.GeneratedValue;
|
import javax.persistence.GeneratedValue;
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
||||||
|
|
||||||
import org.apache.openjpa.persistence.DetachedState;
|
import org.apache.openjpa.persistence.DetachedState;
|
||||||
|
import org.apache.openjpa.persistence.PersistentCollection;
|
||||||
|
import org.apache.openjpa.persistence.kernel.common.apps.PCDirectory;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
//@DetachedState(enabled = false) // ##### shouldn't need this
|
//@DetachedState(enabled = false) // ##### shouldn't need this
|
||||||
|
@ -33,6 +37,9 @@ public class EnumFieldType {
|
||||||
|
|
||||||
private SampleEnum enumField;
|
private SampleEnum enumField;
|
||||||
|
|
||||||
|
@PersistentCollection
|
||||||
|
private List<SampleEnum> enumList = new ArrayList<SampleEnum>();
|
||||||
|
|
||||||
// for OpenJPA
|
// for OpenJPA
|
||||||
protected EnumFieldType() {
|
protected EnumFieldType() {
|
||||||
}
|
}
|
||||||
|
@ -49,4 +56,8 @@ public class EnumFieldType {
|
||||||
public SampleEnum getEnumField() {
|
public SampleEnum getEnumField() {
|
||||||
return enumField;
|
return enumField;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<SampleEnum> getEnumList() {
|
||||||
|
return enumList;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,6 +30,7 @@ public class TestEnumsInJPQL
|
||||||
|
|
||||||
EnumFieldType o = new EnumFieldType();
|
EnumFieldType o = new EnumFieldType();
|
||||||
o.setEnumField(SampleEnum.BAR);
|
o.setEnumField(SampleEnum.BAR);
|
||||||
|
o.getEnumList().add(SampleEnum.FOO);
|
||||||
|
|
||||||
em.getTransaction().begin();
|
em.getTransaction().begin();
|
||||||
em.persist(o);
|
em.persist(o);
|
||||||
|
@ -115,4 +116,13 @@ public class TestEnumsInJPQL
|
||||||
em.getTransaction().commit();
|
em.getTransaction().commit();
|
||||||
postUpdateCheck(false);
|
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());
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue