KickJava   Java API By Example, From Geeks To Geeks.

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


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 CascadeOnActivate extends AbstractDb4oTestCase {
31
32     public String JavaDoc name;
33
34     public CascadeOnActivate child;
35
36     protected void configure(Configuration conf) {
37         conf.objectClass(this).cascadeOnActivate(true);
38     }
39
40     protected void store() {
41         CascadeOnActivate coa = new CascadeOnActivate();
42         coa.name = "1";
43         coa.child = new CascadeOnActivate();
44         coa.child.name = "2";
45         coa.child.child = new CascadeOnActivate();
46         coa.child.child.name = "3";
47
48         db().set(coa);
49     }
50
51     public void test() {
52         Query q = newQuery(getClass());
53         q.descend("name").constrain("1");
54         ObjectSet os = q.execute();
55
56         CascadeOnActivate coa = (CascadeOnActivate) os.next();
57         CascadeOnActivate coa3 = coa.child.child;
58
59         Assert.areEqual("3", coa3.name);
60
61         db().deactivate(coa, Integer.MAX_VALUE);
62
63         Assert.isNull(coa3.name);
64
65         db().activate(coa, 1);
66
67         Assert.areEqual("3", coa3.name);
68     }
69 }
70
Popular Tags