* and lock the main object, do get an updated list
*/
public void testMtoNPolymorphUpdate() throws Exception
{
long timestamp = System.currentTimeMillis();
Fish tuna = new Fish("tuna_" + timestamp, 242, "salt");
Fish trout = new Fish("trout_" + timestamp, 52, "fresh water");
Fish goldfish = new Fish("goldfish_" + timestamp, 10, "brackish water");
ODMGGourmet paula = new ODMGGourmet("a_testMtoNTogether"+ timestamp);
ODMGGourmet candy = new ODMGGourmet("b_testMtoNTogether"+ timestamp);
ODMGGourmet james = new ODMGGourmet("c_testMtoNTogether"+ timestamp);
ODMGGourmet doris = new ODMGGourmet("d_testMtoNTogether"+ timestamp);
paula.addFavoriteFood(trout);
candy.addFavoriteFood(tuna);
james.addFavoriteFood(tuna);
doris.addFavoriteFood(tuna);
doris.addFavoriteFood(trout);
/*
we expect one created 'gourment' per store
*/
assertEquals(1, store(odmg, database, paula));
assertEquals(1, store(odmg, database, candy));
assertEquals(1, store(odmg, database, james));
assertEquals(1, store(odmg, database, doris));
OQLQuery query = odmg.newOQLQuery();
query.create("select fishs from " + Fish.class.getName() +
" where (name=$1 or name=$2)");
query.bind(tuna.getName());
query.bind(trout.getName());
List fishs = (List) query.execute();
/*
we expect 2 created 'fish'
*/
assertEquals(2, fishs.size());
Transaction tx = odmg.newTransaction();
tx.begin();
query = odmg.newOQLQuery();
query.create("select gourmets from " + ODMGGourmet.class.getName() +
" where name=$1");
query.bind(doris.getName());
List result = (List) query.execute();
assertEquals("We should found a gourmet", 1, result.size());
ODMGGourmet gourmet = (ODMGGourmet)result.get(0);
/*
now we lock main object and add a new reference object
*/
tx.lock(gourmet, Transaction.WRITE);
gourmet.addFavoriteFood(goldfish);
tx.commit();
query = odmg.newOQLQuery();
query.create("select fishs from " + Fish.class.getName() +
" where (name=$1 or name=$2 or name=$3)");
query.bind(tuna.getName());
query.bind(trout.getName());
query.bind(goldfish.getName());
tx = odmg.newTransaction();
tx.begin();
fishs = (List) query.execute();
tx.commit();