use of org.jpox.samples.types.enums.AlternativePalette in project tests by datanucleus.
the class EnumTest method testEnumWithOwnValue.
/**
* Test persistence of an enum that uses its own internal value.
*/
public void testEnumWithOwnValue() {
AlternativePalette p;
Object id = null;
try {
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
p = new AlternativePalette();
p.setAmount(100);
p.setColour(AlternativeColour.GREEN);
pm.makePersistent(p);
id = JDOHelper.getObjectId(p);
tx.commit();
} finally {
if (tx.isActive()) {
tx.rollback();
}
pm.close();
}
pmf.getDataStoreCache().evictAll();
pm = pmf.getPersistenceManager();
tx = pm.currentTransaction();
try {
tx.begin();
p = (AlternativePalette) pm.getObjectById(id, true);
assertEquals(100, p.getAmount());
assertEquals(AlternativeColour.GREEN, p.getColour());
tx.commit();
} finally {
if (tx.isActive()) {
tx.rollback();
}
pm.close();
}
pmf.getDataStoreCache().evictAll();
pm = pmf.getPersistenceManager();
tx = pm.currentTransaction();
try {
tx.begin();
Query<AlternativePalette> q = pm.newQuery(AlternativePalette.class, "this.colour == org.jpox.samples.types.enums.AlternativeColour.GREEN");
List<AlternativePalette> result = q.executeList();
assertEquals(1, result.size());
p = result.get(0);
assertEquals(100, p.getAmount());
assertEquals(AlternativeColour.GREEN, p.getColour());
tx.commit();
} finally {
if (tx.isActive()) {
tx.rollback();
}
pm.close();
}
} finally {
clean(AlternativePalette.class);
}
}
Aggregations