1 2 3 package com.db4odoc.f1.symbian; 4 5 6 import java.io.File ; 7 import java.io.IOException ; 8 9 10 import com.db4o.Db4o; 11 import com.db4o.ObjectContainer; 12 import com.db4o.ObjectSet; 13 14 15 16 public class SymbianTest { 17 18 public static final String YAPFILENAME = "formula1.yap"; 19 20 public static void main(String [] args) throws IOException { 21 setObjects(); 22 setObjectsSymbian(); 23 getObjects(); 24 getObjectsSymbian(); 25 } 26 28 public static void setObjects(){ 29 System.out.println("\nSetting objects using RandomAccessFileAdapter"); 30 new File (YAPFILENAME).delete(); 31 Db4o.configure().io(new com.db4o.io.RandomAccessFileAdapter()); 32 try { 33 ObjectContainer db = Db4o.openFile(YAPFILENAME); 34 try { 35 db.set(new SymbianTest()); 36 } finally { 37 db.close(); 38 } 39 } catch (Exception ex){ 40 System.out.println("Exception accessing file: " + ex.getMessage()); 41 } 42 } 43 45 public static void setObjectsSymbian(){ 46 System.out.println("\nSetting objects using SymbianIoAdapter"); 47 new File (YAPFILENAME).delete(); 48 Db4o.configure().io(new com.db4o.io.SymbianIoAdapter()); 49 try { 50 ObjectContainer db = Db4o.openFile(YAPFILENAME); 51 try { 52 db.set(new SymbianTest()); 53 } finally { 54 db.close(); 55 } 56 } catch (Exception ex){ 57 System.out.println("Exception accessing file: " + ex.getMessage()); 58 } 59 } 60 62 public static void getObjects(){ 63 System.out.println("\nRetrieving objects using RandomAccessFileAdapter"); 64 Db4o.configure().io(new com.db4o.io.RandomAccessFileAdapter()); 65 try { 66 ObjectContainer db = Db4o.openFile(YAPFILENAME); 67 try { 68 ObjectSet result=db.get(new Object ()); 69 System.out.println("Objects in the database: " + result.size()); 70 } finally { 71 db.close(); 72 } 73 } catch (Exception ex){ 74 System.out.println("Exception accessing file: " + ex.getMessage()); 75 } 76 } 77 79 public static void getObjectsSymbian(){ 80 System.out.println("\nRetrieving objects using SymbianIoAdapter"); 81 Db4o.configure().io(new com.db4o.io.SymbianIoAdapter()); 82 try { 83 ObjectContainer db = Db4o.openFile(YAPFILENAME); 84 try { 85 ObjectSet result=db.get(new Object ()); 86 System.out.println("Objects in the database: " + result.size()); 87 } finally { 88 db.close(); 89 } 90 } catch (Exception ex){ 91 System.out.println("Exception accessing file: " + ex.getMessage()); 92 } 93 } 94 } 96 97 | Popular Tags |