Esempio n. 1
0
 public void testMemberListAddRemoveIndependentObjects() throws Exception {
   // Drop
   removeAll(ListHolder.class);
   // Create with many independent objects
   ListHolder holder = new ListHolder();
   holder.setList(new ArrayList());
   holder.getList().add(new Referrer(1));
   holder.getList().add(new Referrer(2));
   holder.getList().add(new Referrer(3));
   getStore().save(holder);
   // Now check
   Transaction tx =
       getStore().getTransactionTracker().getTransaction(TransactionTracker.TX_REQUIRED);
   tx.begin();
   ListHolder dbHolder = null;
   try {
     dbHolder = (ListHolder) getStore().findSingle("find listholder");
     // Check stats: 1 holder, +1 statement
     Assert.assertEquals(dbHolder.getList().size(), 3);
     Assert.assertEquals(tx.getStats().getSelectCount(), 2);
   } finally {
     tx.commit();
   }
   // Now insert independent
   Book book = new Book("Independent Object", "1");
   dbHolder.getList().add(book);
   getStore().save(dbHolder);
   // Now check
   tx = getStore().getTransactionTracker().getTransaction(TransactionTracker.TX_REQUIRED);
   tx.begin();
   try {
     dbHolder = (ListHolder) getStore().findSingle("find listholder");
     // Check stats: 1 holder, +2 statement
     Assert.assertEquals(dbHolder.getList().size(), 4);
     Assert.assertEquals(tx.getStats().getSelectCount(), 4);
   } finally {
     tx.commit();
   }
   // Now remove indep object
   dbHolder.getList().remove(book);
   getStore().save(dbHolder);
   // Add same class
   dbHolder.getList().add(new Referrer(6));
   getStore().save(dbHolder);
   // Now check
   tx = getStore().getTransactionTracker().getTransaction(TransactionTracker.TX_REQUIRED);
   tx.begin();
   try {
     dbHolder = (ListHolder) getStore().findSingle("find listholder");
     // Check stats: 1 holder, +2 statement
     Assert.assertEquals(dbHolder.getList().size(), 4);
     Assert.assertEquals(tx.getStats().getSelectCount(), 3);
   } finally {
     tx.commit();
   }
 }
Esempio n. 2
0
 public void testMemberListAddSuperclassObjects() throws Exception {
   // Drop
   removeAll(ListHolder.class);
   // Create with many independent objects
   ListHolder holder = new ListHolder();
   holder.setList(new ArrayList());
   holder.getList().add(new ReferrerSubclass(1, 1));
   holder.getList().add(new ReferrerSubclass(2, 2));
   holder.getList().add(new ReferrerSubclass(3, 3));
   getStore().save(holder);
   // Now check
   Transaction tx =
       getStore().getTransactionTracker().getTransaction(TransactionTracker.TX_REQUIRED);
   tx.begin();
   ListHolder dbHolder = null;
   try {
     dbHolder = (ListHolder) getStore().findSingle("find listholder");
     // Check stats: 1 holder, +1 statement
     Assert.assertEquals(dbHolder.getList().size(), 3);
     Assert.assertEquals(tx.getStats().getSelectCount(), 2);
   } finally {
     tx.commit();
   }
   // Now insert superclass
   dbHolder.getList().add(new Referrer(4));
   getStore().save(dbHolder);
   // Now check
   tx = getStore().getTransactionTracker().getTransaction(TransactionTracker.TX_REQUIRED);
   tx.begin();
   try {
     dbHolder = (ListHolder) getStore().findSingle("find listholder");
     // Check stats: 1 holder, +1 statement
     Assert.assertEquals(dbHolder.getList().size(), 4);
     Assert.assertEquals(tx.getStats().getSelectCount(), 2);
   } finally {
     tx.commit();
   }
 }