Exemple #1
0
 public void testMemberListIndependentObjects() 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 Book("Independent Book", "1"));
   getStore().save(holder);
   // Now check
   Transaction tx =
       getStore().getTransactionTracker().getTransaction(TransactionTracker.TX_REQUIRED);
   tx.begin();
   try {
     ListHolder dbHolder = (ListHolder) getStore().findSingle("find listholder");
     // Check stats: 1 holder, +2 statements
     Assert.assertEquals(dbHolder.getList().size(), 2);
     Assert.assertEquals(tx.getStats().getSelectCount(), 4);
   } finally {
     tx.commit();
   }
 }
Exemple #2
0
 public void testMemberListAddSubclassObjects() 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 superclass
   dbHolder.getList().add(new ReferrerSubclass(4, 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();
   }
 }