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 - 2006 db4objects Inc. http://www.db4o.com */ 02
using System; 03
04
namespace Db4objects.Db4odoc.Diagnostics 05
{ 06
public class Empty 07
{ 08
public Empty() 09
{ 10
} 11
12
public string CurrentTime() 13
{ 14
DateTime dt = DateTime.Now; 15
String time = dt.ToString("d"); 16
return time; 17
} 18
19
override public string ToString() 20
{ 21
return CurrentTime(); 22
} 23
} 24
}
01' Copyright (C) 2004 - 2006 db4objects Inc. http://www.db4o.com 02
Imports System 03
04
Namespace Db4objects.Db4odoc.Diagnostics 05
Public Class Empty 06
Public Sub New() 07
End Sub 08
09
Public Function CurrentTime() As String 10
Dim dt As DateTime = DateTime.Now 11
Dim time As String = dt.ToString("d") 12
Return time 13
End Function 14
15
Public Overrides Function ToString() As String 16
Return CurrentTime() 17
End Function 18
End Class 19
End Namespace
1private static void SetEmptyObject(IObjectContainer db){ 2
Empty empty = new Empty(); 3
db.Set(empty); 4
}
1Private Shared Sub SetEmptyObject(ByVal db As IObjectContainer) 2
Dim empty As Empty = New Empty() 3
db.Set(empty) 4
End Sub
01public static void TestEmpty() { 02
Db4oFactory.Configure().Diagnostic().AddListener(new DiagnosticToConsole()); 03
File.Delete(YapFileName); 04
IObjectContainer db=Db4oFactory.OpenFile(YapFileName); 05
try { 06
SetEmptyObject(db); 07
} 08
finally { 09
db.Close(); 10
} 11
}
01Public Shared Sub TestEmpty() 02
Db4oFactory.Configure().Diagnostic().AddListener(New DiagnosticToConsole()) 03
File.Delete(YapFileName) 04
Dim db As IObjectContainer = Db4oFactory.OpenFile(YapFileName) 05
Try 06
SetEmptyObject(db) 07
Finally 08
db.Close() 09
End Try 10
End Sub
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.