use of org.jpox.samples.valuegeneration.UUIDStringGeneratorItem in project tests by datanucleus.
the class ValueGeneratorTest method xxxtestUUIDStringGenerator.
/**
* Test the use of "uuid-string" generator. This is for all datastores.
*/
public void xxxtestUUIDStringGenerator() throws Exception {
try {
HashSet idSet = new HashSet();
Class idClass = null;
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
// Create a few objects.
UUIDStringGeneratorItem item = null;
item = new UUIDStringGeneratorItem("First item");
pm.makePersistent(item);
idSet.add(item.getIdentifier());
item = new UUIDStringGeneratorItem("Second item");
pm.makePersistent(item);
idSet.add(item.getIdentifier());
item = new UUIDStringGeneratorItem("Third item");
pm.makePersistent(item);
idSet.add(item.getIdentifier());
item = new UUIDStringGeneratorItem("Fourth item");
pm.makePersistent(item);
idSet.add(item.getIdentifier());
idClass = JDOHelper.getObjectId(item).getClass();
tx.commit();
} catch (JDOUserException e) {
fail("Exception thrown during insert of objects in \"uuid-string\" generator test " + e.getMessage());
} finally {
if (tx.isActive()) {
tx.rollback();
}
pm.close();
}
pm = pmf.getPersistenceManager();
tx = pm.currentTransaction();
try {
tx.begin();
HashSet idSetCopy = new HashSet(idSet);
// Retrieve the items
Query q = pm.newQuery(pm.getExtent(UUIDStringGeneratorItem.class, true));
Collection c = (Collection) q.execute();
// Check on the number of items
assertTrue("Number of UUIDStringGeneratorItem's retrieved is incorrect (" + c.size() + ") : should have been 4", c.size() == 4);
Iterator iter = c.iterator();
while (iter.hasNext()) {
Object o = iter.next();
if (UUIDStringGeneratorItem.Oid.class.equals(idClass)) {
idSetCopy.remove(((UUIDStringGeneratorItem) o).getIdentifier());
}
}
tx.commit();
if (UUIDStringGeneratorItem.Oid.class.equals(idClass)) {
assertEquals("Wrong number of different IDs", 4, idSet.size());
assertTrue("Retrieved IDs did not match created IDs", 0 == idSetCopy.size());
}
} catch (JDOUserException ue) {
assertTrue("Exception thrown during test " + ue.getMessage(), false);
} finally {
if (tx.isActive()) {
tx.rollback();
}
pm.close();
}
} finally {
// Clean out any created data
clean(UUIDStringGeneratorItem.class);
}
}
use of org.jpox.samples.valuegeneration.UUIDStringGeneratorItem in project tests by datanucleus.
the class ValueGeneratorTest method testUUIDStringGenerator.
/**
* Test the use of "uuid-string" generator. This is for all datastores.
*/
public void testUUIDStringGenerator() throws Exception {
if (!storeMgr.supportsValueGenerationStrategy("uuid-string")) {
return;
}
try {
HashSet idSet = new HashSet();
Class idClass = null;
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
// Create a few objects.
UUIDStringGeneratorItem item = null;
item = new UUIDStringGeneratorItem("First item");
pm.makePersistent(item);
idSet.add(item.getIdentifier());
item = new UUIDStringGeneratorItem("Second item");
pm.makePersistent(item);
idSet.add(item.getIdentifier());
item = new UUIDStringGeneratorItem("Third item");
pm.makePersistent(item);
idSet.add(item.getIdentifier());
item = new UUIDStringGeneratorItem("Fourth item");
pm.makePersistent(item);
idSet.add(item.getIdentifier());
tx.commit();
idClass = JDOHelper.getObjectId(item).getClass();
} catch (JDOUserException e) {
fail("Exception thrown during insert of objects in \"uuid-string\" generator test " + e.getMessage());
} finally {
if (tx.isActive()) {
tx.rollback();
}
pm.close();
}
pm = pmf.getPersistenceManager();
tx = pm.currentTransaction();
try {
tx.begin();
HashSet idSetCopy = new HashSet(idSet);
// Retrieve the items
Query q = pm.newQuery(pm.getExtent(UUIDStringGeneratorItem.class, true));
Collection c = (Collection) q.execute();
// Check on the number of items
assertTrue("Number of UUIDStringGeneratorItem's retrieved is incorrect (" + c.size() + ") : should have been 4", c.size() == 4);
Iterator iter = c.iterator();
while (iter.hasNext()) {
Object o = iter.next();
if (UUIDStringGeneratorItem.Oid.class.equals(idClass)) {
idSetCopy.remove(((UUIDStringGeneratorItem) o).getIdentifier());
}
}
tx.commit();
if (UUIDStringGeneratorItem.Oid.class.equals(idClass)) {
assertEquals("Wrong number of different IDs", 4, idSet.size());
assertTrue("Retrieved IDs did not match created IDs", 0 == idSetCopy.size());
}
} catch (JDOUserException ue) {
assertTrue("Exception thrown during test " + ue.getMessage(), false);
} finally {
if (tx.isActive()) {
tx.rollback();
}
pm.close();
}
} finally {
// Clean out any created data
clean(UUIDStringGeneratorItem.class);
}
}
Aggregations