01: /* Copyright (C) 2004 - 2007 db4objects Inc. http://www.db4o.com
02:
03: This file is part of the db4o open source object database.
04:
05: db4o is free software; you can redistribute it and/or modify it under
06: the terms of version 2 of the GNU General Public License as published
07: by the Free Software Foundation and as clarified by db4objects' GPL
08: interpretation policy, available at
09: 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.*;
24: import com.db4o.config.*;
25: import com.db4o.ext.*;
26: import com.db4o.internal.*;
27: import com.db4o.query.*;
28:
29: import db4ounit.*;
30: import db4ounit.extensions.*;
31:
32: public class LazyObjectReferenceTestCase extends AbstractDb4oTestCase {
33:
34: public static void main(String[] arguments) {
35: new LazyObjectReferenceTestCase().runSolo();
36: }
37:
38: public static class Item {
39:
40: }
41:
42: protected void configure(Configuration config) throws Exception {
43: super .configure(config);
44: config.objectClass(Item.class).generateUUIDs(true);
45: }
46:
47: protected void store() throws Exception {
48: for (int i = 0; i < 10; i++) {
49: store(new Item());
50: }
51: }
52:
53: public void test() {
54: Query q = db().query();
55: q.constrain(Item.class);
56: ObjectSet objectSet = q.execute();
57: long[] ids = objectSet.ext().getIDs();
58:
59: ObjectInfo[] infos = new ObjectInfo[ids.length];
60: Item[] items = new Item[ids.length];
61:
62: for (int i = 0; i < items.length; i++) {
63: items[i] = (Item) db().getByID(ids[i]);
64: infos[i] = new LazyObjectReference(trans(), (int) ids[i]);
65: }
66:
67: assertInfosAreConsistent(ids, infos);
68:
69: for (int i = 0; i < items.length; i++) {
70: db().purge(items[i]);
71: }
72:
73: db().purge();
74:
75: assertInfosAreConsistent(ids, infos);
76:
77: }
78:
79: private void assertInfosAreConsistent(long[] ids, ObjectInfo[] infos) {
80: for (int i = 0; i < infos.length; i++) {
81: ObjectInfo info = db().getObjectInfo(db().getByID(ids[i]));
82: Assert.areEqual(info.getInternalID(), infos[i]
83: .getInternalID());
84: Assert.areEqual(info.getUUID().getLongPart(), infos[i]
85: .getUUID().getLongPart());
86: Assert.areSame(info.getObject(), infos[i].getObject());
87: }
88: }
89:
90: }
|