1 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 _object; 32 33 public Object [] _objectArray; 34 35 private static final int DEPTH = 5; 36 37 private static final int ELEMENTS = 3; 38 39 private static final String FILE = "nestedArrays.yap"; 40 41 42 public NestedArrays(){ 43 44 } 45 46 47 public static void main(String [] 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 [ELEMENTS]; 85 fill((Object [])_object, DEPTH); 86 87 _objectArray = new Object [ELEMENTS]; 88 fill(_objectArray, DEPTH); 89 } 90 91 private void fill(Object [] arr, int depth){ 92 93 if(depth <= 0){ 94 arr[0] = "somestring"; 95 arr[1] = new Integer (10); 96 return; 97 } 98 99 depth --; 100 101 for (int i = 0; i < ELEMENTS; i++) { 102 arr[i] = new Object [ELEMENTS]; 103 fill((Object [])arr[i], depth ); 104 } 105 } 106 107 public void testOne(){ 108 Test.objectContainer().activate(this, Integer.MAX_VALUE); 109 110 check((Object [])_object, DEPTH); 111 112 check((Object [])_objectArray, DEPTH); 113 114 115 } 116 117 private void check(Object [] arr, int depth){ 118 if(depth <= 0){ 119 Test.ensure(arr[0].equals("somestring")); 120 Test.ensure(arr[1].equals(new Integer (10))); 121 return; 122 } 123 124 depth --; 125 126 for (int i = 0; i < ELEMENTS; i++) { 127 check((Object [])arr[i], depth ); 128 } 129 130 } 131 132 } 133 | Popular Tags |