Search in sources :

Example 1 with NameObject

use of org.jpox.samples.rdbms.views.NameObject in project tests by datanucleus.

the class ViewTest method testNameViewWithId.

/**
 * Use of a simple view for an object, using application identity for the view objects.
 */
public void testNameViewWithId() {
    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 " + FNameView2.class.getName() + " ORDER BY id");
            List<FNameView2> fNames = ((List<FNameView2>) 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 FNameView2", thr);
            fail("Failed to persist data : " + thr.getMessage());
        } finally {
            if (tx.isActive()) {
                tx.rollback();
            }
            pm.close();
        }
    } finally {
        clean(NameObject.class);
    }
}
Also used : FNameView2(org.jpox.samples.rdbms.views.FNameView2) NameObject(org.jpox.samples.rdbms.views.NameObject) Transaction(javax.jdo.Transaction) Query(javax.jdo.Query) PersistenceManager(javax.jdo.PersistenceManager) List(java.util.List)

Example 2 with NameObject

use of org.jpox.samples.rdbms.views.NameObject 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)2 PersistenceManager (javax.jdo.PersistenceManager)2 Query (javax.jdo.Query)2 Transaction (javax.jdo.Transaction)2 NameObject (org.jpox.samples.rdbms.views.NameObject)2 FNameView (org.jpox.samples.rdbms.views.FNameView)1 FNameView2 (org.jpox.samples.rdbms.views.FNameView2)1