1 21 package com.db4o.test; 22 23 import java.io.*; 24 25 import com.db4o.*; 26 import com.db4o.io.*; 27 import com.db4o.io.crypt.*; 28 import com.db4o.query.*; 29 30 public class XTEAEncryption { 31 private static final int NUMSTORED = 100; 32 public int id; 33 public String name; 34 public XTEAEncryption parent; 35 36 public XTEAEncryption() { 37 this(0,null,null); 38 } 39 40 public XTEAEncryption(int id, String name, XTEAEncryption parent) { 41 this.id = id; 42 this.name = name; 43 this.parent = parent; 44 } 45 46 public void test() { 47 Db4o.configure().blockSize(1); 48 Db4o.configure().io(new XTeaEncryptionFileAdapter("db4o")); 49 50 new File("encrypted.yap").delete(); 51 ObjectContainer db=Db4o.openFile("encrypted.yap"); 52 XTEAEncryption last=null; 53 for(int i=0;i<NUMSTORED;i++) { 54 XTEAEncryption current=new XTEAEncryption(i,"X"+i,last); 55 db.set(current); 56 last=current; 57 } 58 db.close(); 59 60 db=Db4o.openFile("encrypted.yap"); 61 Query query=db.query(); 62 query.constrain(getClass()); 63 query.descend("id").constrain(new Integer (50)); 64 Test.ensure(query.execute().size()==1); 65 db.close(); 66 67 Db4o.configure().io(new RandomAccessFileAdapter()); 68 } 69 } 70 | Popular Tags |