KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > db4o > db4ounit > common > querying > CascadedDeleteUpdate


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.querying;
22
23 import com.db4o.*;
24 import com.db4o.config.*;
25 import com.db4o.query.*;
26
27 import db4ounit.*;
28 import db4ounit.extensions.*;
29
30 public class CascadedDeleteUpdate extends AbstractDb4oTestCase {
31     
32     public static class ParentItem {
33         public Object JavaDoc child;
34     }
35
36     public static class ChildItem {
37         public Object JavaDoc parent1;
38         public Object JavaDoc parent2;
39     }
40     
41     public static void main(String JavaDoc[] arguments) {
42 // new CascadedDeleteUpdate().runSolo();
43
new CascadedDeleteUpdate().runClientServer();
44     }
45     
46     protected void configure(Configuration config) {
47         config.objectClass(ParentItem.class).cascadeOnDelete(true);
48     }
49     
50     protected void store() {
51         ParentItem parentItem1 = new ParentItem();
52         ParentItem parentItem2 = new ParentItem();
53         
54         ChildItem child = new ChildItem();
55         child.parent1 = parentItem1;
56         child.parent2 = parentItem2;
57         parentItem1.child = child;
58         parentItem2.child = child;
59         
60         db().set(parentItem1);
61     }
62     
63     public void testAllObjectStored() throws Exception JavaDoc{
64         assertAllObjectStored();
65     }
66     
67     public void testUpdate() throws Exception JavaDoc{
68         Query q = newQuery(ParentItem.class);
69         ObjectSet objectSet = q.execute();
70         while(objectSet.hasNext()){
71             db().set(objectSet.next());
72         }
73         db().commit();
74         assertAllObjectStored();
75     }
76     
77     private void assertAllObjectStored() throws Exception JavaDoc{
78         reopen();
79         Query q = newQuery(ParentItem.class);
80         ObjectSet objectSet = q.execute();
81         while(objectSet.hasNext()){
82             ParentItem parentItem = (ParentItem) objectSet.next();
83             db().refresh(parentItem, 3);
84             Assert.isNotNull(parentItem.child);
85         }
86     }
87     
88 }
89
Popular Tags