1 21 package com.db4o.db4ounit.common.assorted; 22 23 import com.db4o.config.*; 24 import com.db4o.query.Query; 25 26 import db4ounit.Assert; 27 import db4ounit.extensions.AbstractDb4oTestCase; 28 import db4ounit.extensions.fixtures.*; 29 30 31 public class MultiDeleteTestCase extends AbstractDb4oTestCase implements OptOutDefragSolo { 32 33 public static void main(String [] args) { 34 new MultiDeleteTestCase().runSoloAndClientServer(); 35 } 36 37 public static class Item { 38 public Item child; 39 public String name; 40 public Object forLong; 41 public Long myLong; 42 public Object [] untypedArr; 43 public Long [] typedArr; 44 45 public void setMembers() { 46 forLong = new Long (100); 47 myLong = new Long (100); 48 untypedArr = new Object []{ 49 new Long (10), 50 "hi", 51 new Item() 52 }; 53 typedArr = new Long []{ 54 new Long (3), 55 new Long (7), 56 new Long (9), 57 }; 58 } 59 } 60 61 protected void configure(Configuration config) { 62 ObjectClass itemClass = config.objectClass(Item.class); 63 itemClass.cascadeOnDelete(true); 64 itemClass.cascadeOnUpdate(true); 65 } 66 67 protected void store() throws Exception { 68 Item md = new Item(); 69 md.name = "killmefirst"; 70 md.setMembers(); 71 md.child = new Item(); 72 md.child.setMembers(); 73 db().set(md); 74 } 75 76 public void testDeleteCanBeCalledTwice(){ 77 Item item = itemByName("killmefirst"); 78 Assert.isNotNull(item); 79 long id = db().getID(item); 80 db().delete(item); 81 82 Assert.areSame(item, itemById(id)); 83 84 db().delete(item); 85 Assert.areSame(item, itemById(id)); 86 } 87 88 private Item itemByName(String name) { 89 Query q = newQuery(Item.class); 90 q.descend("name").constrain(name); 91 return (Item)q.execute().next(); 92 } 93 94 private Item itemById(long id) { 95 return (Item)db().getByID(id); 96 } 97 } 98 | Popular Tags |