KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > db4o > db4ounit > jre12 > collections > SetCollectionOnUpdateTestCase


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.jre12.collections;
22
23 import java.util.*;
24
25 import com.db4o.*;
26
27 import db4ounit.*;
28 import db4ounit.extensions.*;
29
30 public class SetCollectionOnUpdateTestCase extends AbstractDb4oTestCase {
31     private static final String JavaDoc OLDNAME = "A";
32
33     public static class Data {
34         public String JavaDoc name;
35
36         public Data(String JavaDoc name) {
37             this.name = name;
38         }
39         
40         public String JavaDoc name() {
41             return name;
42         }
43         
44         public void name(String JavaDoc name) {
45             this.name=name;
46         }
47     }
48
49     public static class DataList {
50         public List list;
51         
52         public DataList(Data data) {
53             list=new ArrayList(1);
54             list.add(data);
55         }
56
57         public Data data() {
58             return (Data)list.get(0);
59         }
60         
61         public void objectOnUpdate(ObjectContainer container) {
62             container.ext().set(this.list, 1);
63         }
64     }
65
66     protected void store() {
67         Data data=new Data(OLDNAME);
68         DataList list=new DataList(data);
69         db().set(list);
70     }
71     
72     public void _testUpdateAndReread() throws Exception JavaDoc{
73         DataList list=readDataList();
74         db().ext().activate(list,Integer.MAX_VALUE);
75         list.data().name(OLDNAME+"X");
76         db().set(list);
77         db().commit();
78         
79         reopen();
80         
81         list=readDataList();
82         Assert.areEqual(OLDNAME, list.data().name());
83     }
84
85     private DataList readDataList() {
86         ObjectSet result = db().get(DataList.class);
87         return (DataList)result.next();
88     }
89
90 }
91
Popular Tags