use of org.jpox.samples.interfaces.Triangle 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);
}
}
Aggregations