This diagnostic type provides information about classes in your persistent class hierarchy that have no persistent fields. The diagnostic message appears when the class is saved to the database. It is recommended to remove such classes from the database to avoid the overhead for the maintenance of class indexes.
Let's look at the following example:
01/* Copyright (C) 2004 - 2007 db4objects Inc. http://www.db4o.com */ 02
package com.db4odoc.diagnostics; 03
04
import java.util.Calendar; 05
import java.text.DateFormat; 06
07
08
public class Empty { 09
10
public Empty() { 11
} 12
13
public String CurrentTime() 14
{ 15
Calendar cl = Calendar.getInstance(); 16
DateFormat df = DateFormat.getDateTimeInstance(); 17
String time = df.format(cl.getTime()); 18
return time; 19
} 20
21
public String ToString() 22
{ 23
return CurrentTime(); 24
} 25
}
1private static void setEmptyObject(ObjectContainer container){ 2
Empty empty = new Empty(); 3
container.set(empty); 4
}
01private static void testEmpty() { 02
Configuration configuration = Db4o.newConfiguration(); 03
configuration.diagnostic().addListener(new DiagnosticToConsole()); 04
new File(DB4O_FILE_NAME).delete(); 05
ObjectContainer container=Db4o.openFile(configuration, DB4O_FILE_NAME); 06
try { 07
setEmptyObject(container); 08
} 09
finally { 10
container.close(); 11
} 12
}
>
Diagnostic message is produced when the execution point reaches
db.set(empty)
Empty class does not keep any information and can be left in the application code; there is no need to put it in the database.