TNull translator is used to notify db4o engine that the class data should not be stored. Db4o uses this translator internally for delegates.
Let's look at an example:
01/* Copyright (C) 2007 db4objects Inc. http://www.db4o.com */ 02
03
package com.db4odoc.builtintranslators; 04
05
public class NotStorable { 06
String _name; 07
08
public NotStorable(String name) { 09
_name = name; 10
} 11
12
public String toString() { 13
return _name == null ? "null" : _name; 14
} 15
}
01public static void saveNotStorable() 02
{ 03
new File(DB4O_FILE_NAME).delete(); 04
Configuration configuration = Db4o.newConfiguration(); 05
// Configure NotStorable class with TNull translator to prevent its storage 06
configuration.objectClass(NotStorable.class).translate(new TNull()); 07
ObjectContainer container = database(configuration); 08
if (container != null) 09
{ 10
try 11
{ 12
NotStorable ns = new NotStorable("test1"); 13
container.set(ns); 14
ns = new NotStorable("test2"); 15
container.set(ns); 16
} 17
catch (Db4oException ex) 18
{ 19
ex.printStackTrace(); 20
} 21
catch (Exception ex) 22
{ 23
ex.printStackTrace(); 24
} 25
finally 26
{ 27
closeDatabase(); 28
} 29
} 30
}
01public static void testTNull() 02
{ 03
saveNotStorable(); 04
ObjectContainer container = database(); 05
if (container != null) 06
{ 07
try 08
{ 09
// Trying to retrieve 10
ObjectSet result = container.query(NotStorable.class); 11
// As the class is configured with TNull, the data should be null 12
listResult(result); 13
} 14
catch (Db4oException ex) 15
{ 16
ex.printStackTrace(); 17
} 18
catch (Exception ex) 19
{ 20
ex.printStackTrace(); 21
} 22
finally 23
{ 24
closeDatabase(); 25
} 26
} 27
}
If you will run this example you will see that though the information about the NotStorable class was saved to the database, the retrieved value is null.