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();
   }
 }
Esempio n. 3
0
 public void testPaging() throws Exception {
   int bigEnoughSize = 70;
   // Create referrers
   createReferrers(bigEnoughSize);
   // Query
   Transaction tx = getStore().getTransactionTracker().getTransaction(TransactionTracker.TX_NEW);
   tx.begin();
   List result = getStore().find("find referrer");
   // Iterate forward
   for (int i = 0; i < bigEnoughSize; i++) result.get(i);
   // Iterate backward
   for (int i = bigEnoughSize; i > 0; i--) result.get(i - 1);
   tx.commit();
   // Check how many selects ran (1 count + 3 selects, or
   // sometimes, 2 selects, if the cache has enough memory)
   Assert.assertTrue(tx.getStats().getSelectCount() < 4);
 }
Esempio n. 4
0
 public void testSelectInTransaction() throws Exception {
   // Drop books
   removeAll(Book.class);
   // Create and select
   Book book = new Book("Title", "1-2-3-4");
   Transaction tx = getStore().getTransactionTracker().getTransaction(TransactionTracker.TX_NEW);
   tx.begin();
   List result = null;
   try {
     getStore().save(book);
     result = getStore().find("find book");
     Assert.assertEquals(result.size(), 1);
     Assert.assertEquals(result.get(0), book);
   } finally {
     tx.commit();
   }
   // List should contain the object still
   ((LazyListImpl) result).refresh();
   Assert.assertEquals(result.size(), 1);
   Assert.assertEquals(result.get(0), book);
 }