KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > db4o > test > legacy > NestedArrays


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.test.legacy;
22
23 import java.io.*;
24
25 import com.db4o.*;
26 import com.db4o.test.*;
27
28
29 public class NestedArrays {
30     
31     public Object JavaDoc _object;
32     
33     public Object JavaDoc[] _objectArray;
34     
35     private static final int DEPTH = 5;
36     
37     private static final int ELEMENTS = 3;
38     
39     private static final String JavaDoc FILE = "nestedArrays.yap";
40     
41     
42     public NestedArrays(){
43         
44     }
45     
46     
47     public static void main(String JavaDoc[] arguments) {
48         
49         new File(FILE).delete();
50         ObjectContainer oc = Db4o.openFile(FILE);
51         NestedArrays nr = new NestedArrays();
52         nr.storeOne();
53         
54         long storeStart = System.currentTimeMillis();
55         oc.set(nr);
56         long storeStop = System.currentTimeMillis();
57         oc.commit();
58         long commitStop = System.currentTimeMillis();
59         
60         oc.close();
61         Db4o.configure().activationDepth(0);
62         oc = Db4o.openFile(FILE);
63         long loadStart = System.currentTimeMillis();
64         nr = (NestedArrays)oc.get(new NestedArrays()).next();
65         oc.activate(nr, Integer.MAX_VALUE);
66         long loadStop = System.currentTimeMillis();
67         
68         oc.close();
69         
70         long store = storeStop - storeStart;
71         long commit = commitStop - storeStop;
72         long load = loadStop - loadStart;
73         
74         System.out.println(Db4o.version() + " running com.db4o.test.NestedArrays");
75         System.out.println("store: " + store + "ms");
76         System.out.println("commit: " + commit + "ms");
77         System.out.println("load: " + load + "ms");
78         
79     }
80     
81     
82     public void storeOne(){
83         
84         _object = new Object JavaDoc[ELEMENTS];
85         fill((Object JavaDoc[])_object, DEPTH);
86         
87         _objectArray = new Object JavaDoc[ELEMENTS];
88         fill(_objectArray, DEPTH);
89     }
90     
91     private void fill(Object JavaDoc[] arr, int depth){
92         
93         if(depth <= 0){
94             arr[0] = "somestring";
95             arr[1] = new Integer JavaDoc(10);
96             return;
97         }
98         
99         depth --;
100         
101         for (int i = 0; i < ELEMENTS; i++) {
102             arr[i] = new Object JavaDoc[ELEMENTS];
103             fill((Object JavaDoc[])arr[i], depth );
104         }
105     }
106     
107     public void testOne(){
108         Test.objectContainer().activate(this, Integer.MAX_VALUE);
109         
110         check((Object JavaDoc[])_object, DEPTH);
111         
112         check((Object JavaDoc[])_objectArray, DEPTH);
113         
114         
115     }
116     
117     private void check(Object JavaDoc[] arr, int depth){
118         if(depth <= 0){
119             Test.ensure(arr[0].equals("somestring"));
120             Test.ensure(arr[1].equals(new Integer JavaDoc(10)));
121             return;
122         }
123         
124         depth --;
125         
126         for (int i = 0; i < ELEMENTS; i++) {
127             check((Object JavaDoc[])arr[i], depth );
128         }
129         
130     }
131     
132 }
133
Popular Tags