1 2 3 package com.db4odoc.f1.utility; 4 5 import java.io.File ; 6 7 import com.db4o.Db4o; 8 import com.db4o.ObjectContainer; 9 import com.db4o.ObjectSet; 10 import com.db4odoc.f1.Util; 11 import com.db4odoc.f1.activating.SensorPanel; 12 13 14 public class UtilityExample extends Util { 15 16 17 public static void main(String [] args) { 18 testDescend(); 19 checkActive(); 20 checkStored(); 21 } 22 24 public static void storeSensorPanel(){ 25 new File (Util.YAPFILENAME).delete(); 26 ObjectContainer db = Db4o.openFile(Util.YAPFILENAME); 27 try { 28 SensorPanel list = new SensorPanel().createList(10); 30 db.set(list); 32 } finally { 33 db.close(); 34 } 35 } 36 38 public static void testDescend(){ 39 storeSensorPanel(); 40 ObjectContainer db = Db4o.openFile(Util.YAPFILENAME); 41 try { 42 db.ext().configure().activationDepth(1); 43 System.out.println("Object container activation depth = 1"); 44 ObjectSet result = db.get(new SensorPanel(1)); 45 SensorPanel spParent = (SensorPanel)result.get(0); 46 SensorPanel spDescend = (SensorPanel)db.ext().descend((Object )spParent, new String []{"next","next","next","next","next"}); 47 db.ext().activate(spDescend, 5); 48 System.out.println(spDescend); 49 } finally { 50 db.close(); 51 } 52 } 53 55 public static void checkActive(){ 56 storeSensorPanel(); 57 ObjectContainer db = Db4o.openFile(Util.YAPFILENAME); 58 try { 59 db.ext().configure().activationDepth(2); 60 System.out.println("Object container activation depth = 2"); 61 ObjectSet result = db.get(new SensorPanel(1)); 62 SensorPanel sensor = (SensorPanel)result.get(0); 63 SensorPanel next = sensor.next; 64 while (next != null){ 65 System.out.println("Object " + next +" is active: " + db.ext().isActive(next)); 66 next = next.next; 67 } 68 } finally { 69 db.close(); 70 } 71 } 72 74 public static void checkStored(){ 75 SensorPanel list = new SensorPanel().createList(10); 77 new File (Util.YAPFILENAME).delete(); 78 ObjectContainer db = Db4o.openFile(Util.YAPFILENAME); 79 try { 80 db.set(list); 82 Object sensor = (Object )list.sensor; 83 SensorPanel sp5 = list.next.next.next.next; 84 System.out.println("Root element "+list+" isStored: " + db.ext().isStored(list)); 85 System.out.println("Simple type "+sensor+" isStored: " + db.ext().isStored(sensor)); 86 System.out.println("Descend element "+sp5+" isStored: " + db.ext().isStored(sp5)); 87 db.delete(list); 88 System.out.println("Root element "+list+" isStored: " + db.ext().isStored(list)); 89 } finally { 90 db.close(); 91 } 92 } 93 } 95 | Popular Tags |