use of org.jpox.samples.rdbms.views.FNameView in project tests by datanucleus.
the class ViewTest method testNameView.
/**
* Use of a simple view for an object, using "nondurable" identity.
*/
public void testNameView() {
try {
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
pm.makePersistent(new NameObject(1, "FIRST"));
pm.makePersistent(new NameObject(2, "SECOND"));
pm.makePersistent(new NameObject(3, "THIRD"));
pm.makePersistent(new NameObject(4, "FOURTH"));
tx.commit();
tx.begin();
Query q = pm.newQuery("SELECT FROM " + NameObject.class.getName() + " ORDER BY id");
List<NameObject> persons = (List<NameObject>) q.execute();
assertEquals(4, persons.size());
assertEquals("FIRST", persons.get(0).getName());
Query q1 = pm.newQuery("SELECT FROM " + FNameView.class.getName() + " ORDER BY id");
List<FNameView> fNames = ((List<FNameView>) q1.execute());
assertEquals(2, fNames.size());
assertEquals("FIRST", fNames.get(0).getName());
assertEquals("FOURTH", fNames.get(1).getName());
tx.commit();
} catch (Throwable thr) {
LOG.error(">> Exception thrown persist/view data with FNameView", thr);
fail("Failed to persist data : " + thr.getMessage());
} finally {
if (tx.isActive()) {
tx.rollback();
}
pm.close();
}
} finally {
clean(NameObject.class);
}
}
Aggregations