Search in sources :

Example 1 with FNameView

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);
    }
}
Also used : FNameView(org.jpox.samples.rdbms.views.FNameView) NameObject(org.jpox.samples.rdbms.views.NameObject) Transaction(javax.jdo.Transaction) Query(javax.jdo.Query) PersistenceManager(javax.jdo.PersistenceManager) List(java.util.List)

Aggregations

List (java.util.List)1 PersistenceManager (javax.jdo.PersistenceManager)1 Query (javax.jdo.Query)1 Transaction (javax.jdo.Transaction)1 FNameView (org.jpox.samples.rdbms.views.FNameView)1 NameObject (org.jpox.samples.rdbms.views.NameObject)1