public void testNrmAndDlists() throws Exception
{
// get facade instance
Implementation odmg = OJB.getInstance();
Database db = odmg.newDatabase();
//open database
try
{
db.open(databaseName, Database.OPEN_READ_WRITE);
}
catch (ODMGException ex)
{
fail("ODMGException: " + ex.getMessage());
}
Transaction tx = odmg.newTransaction();
//perform transaction
try
{
//=============================
// this test needs DList impl as oql query collection class
((ImplementationImpl) odmg).setOqlCollectionClass(DListImpl.class);
//=============================
tx.begin();
OQLQuery query = odmg.newOQLQuery();
query.create("select x from " + Article.class.getName() + " where productGroupId = 7");
List results = (List) query.execute();
int originalSize = results.size();
assertTrue("result count have to be > 0", originalSize > 0);
// OJB.getLogger().debug(results);
String name = "gimme fruits_" + System.currentTimeMillis();
db.bind(results, name);
tx.commit();
tx = odmg.newTransaction();
tx.begin();
((TransactionImpl) tx).getBroker().clearCache();
// look it up again
List newResults = (List) db.lookup(name);
assertEquals(originalSize, newResults.size());
Article art = (Article) newResults.get(0);
assertNotNull(art);
// OJB.getLogger().info(results);
tx.commit();
}
catch (Exception e)
{
tx.abort();
throw e;
}
// close database
try
{
db.close();
}
catch (ODMGException ex)
{
fail("ODMGException: " + ex.getMessage());
}