001: /* Copyright (C) 2004 - 2007 db4objects Inc. http://www.db4o.com
002:
003: This file is part of the db4o open source object database.
004:
005: db4o is free software; you can redistribute it and/or modify it under
006: the terms of version 2 of the GNU General Public License as published
007: by the Free Software Foundation and as clarified by db4objects' GPL
008: interpretation policy, available at
009: http://www.db4o.com/about/company/legalpolicies/gplinterpretation/
010: Alternatively you can write to db4objects, Inc., 1900 S Norfolk Street,
011: Suite 350, San Mateo, CA 94403, USA.
012:
013: db4o is distributed in the hope that it will be useful, but WITHOUT ANY
014: WARRANTY; without even the implied warranty of MERCHANTABILITY or
015: FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
016: for more details.
017:
018: You should have received a copy of the GNU General Public License along
019: with this program; if not, write to the Free Software Foundation, Inc.,
020: 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
021: package com.db4o.test.legacy;
022:
023: import java.io.*;
024:
025: import com.db4o.*;
026: import com.db4o.test.*;
027:
028: public class NestedArrays {
029:
030: public Object _object;
031:
032: public Object[] _objectArray;
033:
034: private static final int DEPTH = 5;
035:
036: private static final int ELEMENTS = 3;
037:
038: private static final String FILE = "nestedArrays.yap";
039:
040: public NestedArrays() {
041:
042: }
043:
044: public static void main(String[] arguments) {
045:
046: new File(FILE).delete();
047: ObjectContainer oc = Db4o.openFile(FILE);
048: NestedArrays nr = new NestedArrays();
049: nr.storeOne();
050:
051: long storeStart = System.currentTimeMillis();
052: oc.set(nr);
053: long storeStop = System.currentTimeMillis();
054: oc.commit();
055: long commitStop = System.currentTimeMillis();
056:
057: oc.close();
058: Db4o.configure().activationDepth(0);
059: oc = Db4o.openFile(FILE);
060: long loadStart = System.currentTimeMillis();
061: nr = (NestedArrays) oc.get(new NestedArrays()).next();
062: oc.activate(nr, Integer.MAX_VALUE);
063: long loadStop = System.currentTimeMillis();
064:
065: oc.close();
066:
067: long store = storeStop - storeStart;
068: long commit = commitStop - storeStop;
069: long load = loadStop - loadStart;
070:
071: System.out.println(Db4o.version()
072: + " running com.db4o.test.NestedArrays");
073: System.out.println("store: " + store + "ms");
074: System.out.println("commit: " + commit + "ms");
075: System.out.println("load: " + load + "ms");
076:
077: }
078:
079: public void storeOne() {
080:
081: _object = new Object[ELEMENTS];
082: fill((Object[]) _object, DEPTH);
083:
084: _objectArray = new Object[ELEMENTS];
085: fill(_objectArray, DEPTH);
086: }
087:
088: private void fill(Object[] arr, int depth) {
089:
090: if (depth <= 0) {
091: arr[0] = "somestring";
092: arr[1] = new Integer(10);
093: return;
094: }
095:
096: depth--;
097:
098: for (int i = 0; i < ELEMENTS; i++) {
099: arr[i] = new Object[ELEMENTS];
100: fill((Object[]) arr[i], depth);
101: }
102: }
103:
104: public void testOne() {
105: Test.objectContainer().activate(this , Integer.MAX_VALUE);
106:
107: check((Object[]) _object, DEPTH);
108:
109: check((Object[]) _objectArray, DEPTH);
110:
111: }
112:
113: private void check(Object[] arr, int depth) {
114: if (depth <= 0) {
115: Test.ensure(arr[0].equals("somestring"));
116: Test.ensure(arr[1].equals(new Integer(10)));
117: return;
118: }
119:
120: depth--;
121:
122: for (int i = 0; i < ELEMENTS; i++) {
123: check((Object[]) arr[i], depth);
124: }
125:
126: }
127:
128: }
|