public void testLookup() throws Exception
{
String bindingName = "binding_for_testLookup";
// get facade instance
Implementation odmg = OJB.getInstance();
Database db = odmg.newDatabase();
db.open(databaseName, Database.OPEN_READ_WRITE);
// clear named roots.
clearNRM();
Transaction tx = odmg.newTransaction();
//bind object to name
tx.begin();
Article example = createArticle();
Identity oid = new Identity(example, ((HasBroker)tx).getBroker());
try
{
db.bind(example, bindingName);
tx.commit();
}
catch (ObjectNameNotUniqueException ex)
{
tx.abort();
fail(ex.getMessage());
}
// TestThreadsNLocks look up
Article lookedUp1 = null;
tx = odmg.newTransaction();
tx.begin();
try
{
// lookup by name binding
lookedUp1 = (Article) db.lookup(bindingName);
}
catch (ObjectNameNotFoundException ex)
{
fail("lookup by name: " + bindingName + " should not be unknown");
}
tx.commit();
// looking up object by OID should return same Object as by name
assertEquals("lookups should return identical object", example, lookedUp1);
try
{
tx.begin();
db.unbind(bindingName);
tx.commit();
}
catch (ObjectNameNotFoundException ex)
{
fail("Can't unbind " + bindingName + ": "+ex.getMessage());
}
db.close();
}