KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > db4o > db4ounit > common > assorted > MultiDeleteTestCase


1 /* Copyright (C) 2004 - 2006 db4objects Inc. http://www.db4o.com
2
3 This file is part of the db4o open source object database.
4
5 db4o is free software; you can redistribute it and/or modify it under
6 the terms of version 2 of the GNU General Public License as published
7 by the Free Software Foundation and as clarified by db4objects' GPL
8 interpretation policy, available at
9 http://www.db4o.com/about/company/legalpolicies/gplinterpretation/
10 Alternatively you can write to db4objects, Inc., 1900 S Norfolk Street,
11 Suite 350, San Mateo, CA 94403, USA.
12
13 db4o is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 for more details.
17
18 You should have received a copy of the GNU General Public License along
19 with this program; if not, write to the Free Software Foundation, Inc.,
20 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */

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 JavaDoc[] args) {
34         new MultiDeleteTestCase().runSoloAndClientServer();
35     }
36     
37     public static class Item {
38         public Item child;
39         public String JavaDoc name;
40         public Object JavaDoc forLong;
41         public Long JavaDoc myLong;
42         public Object JavaDoc[] untypedArr;
43         public Long JavaDoc[] typedArr;
44         
45         public void setMembers() {
46             forLong = new Long JavaDoc(100);
47             myLong = new Long JavaDoc(100);
48             untypedArr = new Object JavaDoc[]{
49                 new Long JavaDoc(10),
50                 "hi",
51                 new Item()
52             };
53             typedArr = new Long JavaDoc[]{
54                 new Long JavaDoc(3),
55                 new Long JavaDoc(7),
56                 new Long JavaDoc(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 JavaDoc {
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 JavaDoc 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