📄 translatorexample.java
字号:
package com.db4o.f1.chapter6;
import com.db4o.*;
import com.db4o.f1.*;
public class TranslatorExample extends Util {
public static void main(String[] args) {
tryStoreWithoutCallConstructors();
tryStoreWithCallConstructors();
storeWithTranslator();
}
public static void tryStoreWithoutCallConstructors() {
Db4o.configure().exceptionsOnNotStorable(false);
Db4o.configure().objectClass(NotStorable.class)
.callConstructor(false);
tryStoreAndRetrieve();
}
public static void tryStoreWithCallConstructors() {
Db4o.configure().exceptionsOnNotStorable(true);
Db4o.configure().objectClass(NotStorable.class)
.callConstructor(true);
tryStoreAndRetrieve();
}
public static void storeWithTranslator() {
Db4o.configure().objectClass(NotStorable.class)
.translate(new NotStorableTranslator());
tryStoreAndRetrieve();
}
public static void tryStoreAndRetrieve() {
ObjectContainer db=Db4o.openFile(YAPFILENAME);
try {
NotStorable notStorable = new NotStorable(42,"Test");
System.out.println("ORIGINAL: "+notStorable);
db.set(notStorable);
}
catch(Exception exc) {
System.out.println(exc.toString());
return;
}
finally {
db.close();
}
db=Db4o.openFile(YAPFILENAME);
try {
ObjectSet result=db.get(NotStorable.class);
while(result.hasNext()) {
NotStorable notStorable=(NotStorable)result.next();
System.out.println("RETRIEVED: "+notStorable);
db.delete(notStorable);
}
}
finally {
db.close();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -