Search in sources :

Example 1 with UnorderedPrimaryKeyFields

use of org.jpox.samples.identity.application.UnorderedPrimaryKeyFields in project tests by datanucleus.

the class ApplicationIdentityTest method verifyUPKFieldsByQuery.

private void verifyUPKFieldsByQuery(PersistenceManager pm, boolean retainValues) {
    Query query;
    Collection c;
    Iterator it;
    UnorderedPrimaryKeyFields obj;
    pm.currentTransaction().setRetainValues(retainValues);
    pm.currentTransaction().begin();
    query = pm.newQuery(pm.getExtent(UnorderedPrimaryKeyFields.class, true));
    query.setOrdering("firstField ascending");
    c = (Collection) query.execute();
    it = c.iterator();
    obj = (UnorderedPrimaryKeyFields) it.next();
    assertUPKFields1(obj);
    obj = (UnorderedPrimaryKeyFields) it.next();
    assertUPKFields2(obj);
    pm.currentTransaction().commit();
    assertUPKFields2AfterCommit(obj, retainValues);
}
Also used : Query(javax.jdo.Query) UnorderedPrimaryKeyFields(org.jpox.samples.identity.application.UnorderedPrimaryKeyFields) Iterator(java.util.Iterator) Collection(java.util.Collection)

Example 2 with UnorderedPrimaryKeyFields

use of org.jpox.samples.identity.application.UnorderedPrimaryKeyFields in project tests by datanucleus.

the class ApplicationIdentityTest method verifyUPKFieldsByQueryInMakePersistentTransaction.

private void verifyUPKFieldsByQueryInMakePersistentTransaction(PersistenceManager pm) {
    Query query;
    Collection c;
    Iterator it;
    UnorderedPrimaryKeyFields obj;
    query = pm.newQuery(pm.getExtent(UnorderedPrimaryKeyFields.class, true));
    query.setOrdering("firstField ascending");
    c = (Collection) query.execute();
    it = c.iterator();
    obj = (UnorderedPrimaryKeyFields) it.next();
    assertUPKFields1(obj);
    obj = (UnorderedPrimaryKeyFields) it.next();
    assertUPKFields2(obj);
}
Also used : Query(javax.jdo.Query) UnorderedPrimaryKeyFields(org.jpox.samples.identity.application.UnorderedPrimaryKeyFields) Iterator(java.util.Iterator) Collection(java.util.Collection)

Example 3 with UnorderedPrimaryKeyFields

use of org.jpox.samples.identity.application.UnorderedPrimaryKeyFields in project tests by datanucleus.

the class ApplicationIdentityTest method testNonNullPrimaryKeyFieldsAfterQuery.

/**
 * check if primary key fields are never null after loading from database
 */
public void testNonNullPrimaryKeyFieldsAfterQuery() {
    try {
        Object tid1;
        Object tid2;
        Object upkfid1;
        Object upkfid2;
        boolean retainValues;
        PersistenceManager pm = pmf.getPersistenceManager();
        try {
            retainValues = false;
            pm.currentTransaction().setRetainValues(retainValues);
            pm.currentTransaction().begin();
            Triangle t1 = new Triangle(1, "t1", 7.0, 8.0);
            Triangle t2 = new Triangle(2, "t2", 9.0, 7.0);
            pm.makePersistent(t1);
            pm.makePersistent(t2);
            pm.flush();
            UnorderedPrimaryKeyFields upkf1 = new UnorderedPrimaryKeyFields(1, "upkf1", "first1", "medium1", "last1");
            UnorderedPrimaryKeyFields upkf2 = new UnorderedPrimaryKeyFields(2, "upkf2", "first2", "medium2", "last2");
            pm.makePersistent(upkf1);
            pm.makePersistent(upkf2);
            pm.flush();
            verifyTriangleByQueryInMakePersistentTransaction(pm);
            verifyUPKFieldsByQueryInMakePersistentTransaction(pm);
            pm.currentTransaction().commit();
            assertTriangleT2AfterCommit(t2, retainValues);
            assertUPKFields2AfterCommit(upkf2, retainValues);
            tid1 = pm.getObjectId(t1);
            tid2 = pm.getObjectId(t2);
            upkfid1 = pm.getObjectId(upkf1);
            upkfid2 = pm.getObjectId(upkf2);
            // ///////////////
            // retainValues = false
            // ///////////////
            retainValues = false;
            // try 1
            verifyTriangleByQuery(pm, retainValues);
            verifyUPKFieldsByQuery(pm, retainValues);
            // do iy again
            verifyTriangleByQuery(pm, retainValues);
            verifyUPKFieldsByQuery(pm, retainValues);
            // by objectid validate=false
            verifyTriangleByGetObjectById(pm, tid1, tid2, false, retainValues);
            verifyUPKFieldsByGetObjectById(pm, upkfid1, upkfid2, false, retainValues);
            // by objectid validate=true
            verifyTriangleByGetObjectById(pm, tid1, tid2, true, retainValues);
            verifyUPKFieldsByGetObjectById(pm, upkfid1, upkfid2, true, retainValues);
            System.gc();
            // verify after garbage collector
            verifyTriangleByQuery(pm, retainValues);
            // try 1
            verifyTriangleByQuery(pm, retainValues);
            verifyUPKFieldsByQuery(pm, retainValues);
            // do iy again
            verifyTriangleByQuery(pm, retainValues);
            verifyUPKFieldsByQuery(pm, retainValues);
            // by objectid validate=false
            verifyTriangleByGetObjectById(pm, tid1, tid2, false, retainValues);
            verifyUPKFieldsByGetObjectById(pm, upkfid1, upkfid2, false, retainValues);
            // by objectid validate=true
            verifyTriangleByGetObjectById(pm, tid1, tid2, true, retainValues);
            verifyUPKFieldsByGetObjectById(pm, upkfid1, upkfid2, true, retainValues);
            // ///////////////
            // retainValues = true
            // ///////////////
            retainValues = true;
            // try 1
            verifyTriangleByQuery(pm, retainValues);
            verifyUPKFieldsByQuery(pm, retainValues);
            // do iy again
            verifyTriangleByQuery(pm, retainValues);
            verifyUPKFieldsByQuery(pm, retainValues);
            // by objectid validate=false
            verifyTriangleByGetObjectById(pm, tid1, tid2, false, retainValues);
            verifyUPKFieldsByGetObjectById(pm, upkfid1, upkfid2, false, retainValues);
            // by objectid validate=true
            verifyTriangleByGetObjectById(pm, tid1, tid2, true, retainValues);
            verifyUPKFieldsByGetObjectById(pm, upkfid1, upkfid2, true, retainValues);
            System.gc();
            // verify after garbage collector
            verifyTriangleByQuery(pm, retainValues);
            // try 1
            verifyTriangleByQuery(pm, retainValues);
            verifyUPKFieldsByQuery(pm, retainValues);
            // do iy again
            verifyTriangleByQuery(pm, retainValues);
            verifyUPKFieldsByQuery(pm, retainValues);
            // by objectid validate=false
            verifyTriangleByGetObjectById(pm, tid1, tid2, false, retainValues);
            verifyUPKFieldsByGetObjectById(pm, upkfid1, upkfid2, false, retainValues);
            // by objectid validate=true
            verifyTriangleByGetObjectById(pm, tid1, tid2, true, retainValues);
            verifyUPKFieldsByGetObjectById(pm, upkfid1, upkfid2, true, retainValues);
        } finally {
            if (pm.currentTransaction().isActive()) {
                pm.currentTransaction().rollback();
            }
            pm.close();
        }
        System.gc();
        // test it all again with a new PM
        pm = pmf.getPersistenceManager();
        try {
            // ///////////////
            // retainValues = false
            // ///////////////
            retainValues = false;
            // try 1
            verifyTriangleByQuery(pm, retainValues);
            verifyUPKFieldsByQuery(pm, retainValues);
            // do iy again
            verifyTriangleByQuery(pm, retainValues);
            verifyUPKFieldsByQuery(pm, retainValues);
            // by objectid validate=false
            verifyTriangleByGetObjectById(pm, tid1, tid2, false, retainValues);
            verifyUPKFieldsByGetObjectById(pm, upkfid1, upkfid2, false, retainValues);
            // by objectid validate=true
            verifyTriangleByGetObjectById(pm, tid1, tid2, true, retainValues);
            verifyUPKFieldsByGetObjectById(pm, upkfid1, upkfid2, true, retainValues);
            System.gc();
            // verify after garbage collector
            verifyTriangleByQuery(pm, retainValues);
            // try 1
            verifyTriangleByQuery(pm, retainValues);
            verifyUPKFieldsByQuery(pm, retainValues);
            // do iy again
            verifyTriangleByQuery(pm, retainValues);
            verifyUPKFieldsByQuery(pm, retainValues);
            // by objectid validate=false
            verifyTriangleByGetObjectById(pm, tid1, tid2, false, retainValues);
            verifyUPKFieldsByGetObjectById(pm, upkfid1, upkfid2, false, retainValues);
            // by objectid validate=true
            verifyTriangleByGetObjectById(pm, tid1, tid2, true, retainValues);
            verifyUPKFieldsByGetObjectById(pm, upkfid1, upkfid2, true, retainValues);
            // ///////////////
            // retainValues = true
            // ///////////////
            retainValues = true;
            // try 1
            verifyTriangleByQuery(pm, retainValues);
            verifyUPKFieldsByQuery(pm, retainValues);
            // do iy again
            verifyTriangleByQuery(pm, retainValues);
            verifyUPKFieldsByQuery(pm, retainValues);
            // by objectid validate=false
            verifyTriangleByGetObjectById(pm, tid1, tid2, false, retainValues);
            verifyUPKFieldsByGetObjectById(pm, upkfid1, upkfid2, false, retainValues);
            // by objectid validate=true
            verifyTriangleByGetObjectById(pm, tid1, tid2, true, retainValues);
            verifyUPKFieldsByGetObjectById(pm, upkfid1, upkfid2, true, retainValues);
            System.gc();
            // verify after garbage collector
            verifyTriangleByQuery(pm, retainValues);
            // try 1
            verifyTriangleByQuery(pm, retainValues);
            verifyUPKFieldsByQuery(pm, retainValues);
            // do iy again
            verifyTriangleByQuery(pm, retainValues);
            verifyUPKFieldsByQuery(pm, retainValues);
            // by objectid validate=false
            verifyTriangleByGetObjectById(pm, tid1, tid2, false, retainValues);
            verifyUPKFieldsByGetObjectById(pm, upkfid1, upkfid2, false, retainValues);
            // by objectid validate=true
            verifyTriangleByGetObjectById(pm, tid1, tid2, true, retainValues);
            verifyUPKFieldsByGetObjectById(pm, upkfid1, upkfid2, true, retainValues);
        } finally {
            if (pm.currentTransaction().isActive()) {
                pm.currentTransaction().rollback();
            }
            pm.close();
        }
    } finally {
        clean(Triangle.class);
        clean(UnorderedPrimaryKeyFields.class);
    }
}
Also used : UnorderedPrimaryKeyFields(org.jpox.samples.identity.application.UnorderedPrimaryKeyFields) PersistenceManager(javax.jdo.PersistenceManager) Triangle(org.jpox.samples.interfaces.Triangle)

Example 4 with UnorderedPrimaryKeyFields

use of org.jpox.samples.identity.application.UnorderedPrimaryKeyFields in project tests by datanucleus.

the class ApplicationIdentityTest method verifyUPKFieldsByGetObjectById.

private void verifyUPKFieldsByGetObjectById(PersistenceManager pm, Object id1, Object id2, boolean validate, boolean retainValues) {
    UnorderedPrimaryKeyFields obj;
    pm.currentTransaction().setRetainValues(retainValues);
    pm.currentTransaction().begin();
    obj = (UnorderedPrimaryKeyFields) pm.getObjectById(id1, validate);
    assertUPKFields1(obj);
    obj = (UnorderedPrimaryKeyFields) pm.getObjectById(id2, validate);
    assertUPKFields2(obj);
    pm.currentTransaction().commit();
    assertUPKFields2AfterCommit(obj, retainValues);
}
Also used : UnorderedPrimaryKeyFields(org.jpox.samples.identity.application.UnorderedPrimaryKeyFields)

Aggregations

UnorderedPrimaryKeyFields (org.jpox.samples.identity.application.UnorderedPrimaryKeyFields)4 Collection (java.util.Collection)2 Iterator (java.util.Iterator)2 Query (javax.jdo.Query)2 PersistenceManager (javax.jdo.PersistenceManager)1 Triangle (org.jpox.samples.interfaces.Triangle)1