This topic applies to .NET version only
01using System; 02
using System.Collections.Generic; 03
using System.IO; 04
using Db4objects.Db4o; 05
using Db4objects.Db4odoc.ReportsExample.Persistent; 06
07
namespace Db4objects.Db4odoc.ReportsExample.Modules 08
{ 09
class Db4oManager 10
{ 11
public const string DbFileName = "..//..//Data//formula1.db"; 12
public static IObjectContainer _db; 13
14
private Db4oManager() 15
{ 16
} 17
// end Db4oManager 18
19
public static void FillUpDB() 20
{ 21
Pilot pilot = new Pilot("Michael Schumacher", 100); 22
Db().Set(pilot); 23
pilot = new Pilot("David Barichello", 95); 24
Db().Set(pilot); 25
pilot = new Pilot("Kimi Raikkonen", 100); 26
Db().Set(pilot); 27
} 28
// end FillUpDB 29
30
public static IList<Pilot> GetAllPilots() 31
{ 32
IList<Pilot> result = Db().Query<Pilot>(typeof(Pilot)); 33
return result; 34
} 35
// end GetAllPilots 36
37
public static void StoreObject(Object obj) 38
{ 39
Db().Set(obj); 40
} 41
// end StoreObject 42
43
public static IObjectContainer Db() 44
{ 45
if (_db == null) 46
{ 47
_db = Db4oFactory.OpenFile(DbFileName); 48
} 49
return _db; 50
} 51
// end Db 52
53
public static void CloseDb() 54
{ 55
if (_db != null) 56
{ 57
_db.Close(); 58
} 59
} 60
// end CloseDb 61
} 62
}
01Imports System 02
Imports System.Collections.Generic 03
Imports System.IO 04
Imports Db4objects.Db4o 05
Imports Db4objects.Db4odoc.ReportsExample.Persistent 06
07
Namespace Modules 08
09
Class Db4oManager 10
Public Const DbFileName As String = "..//..//Data//formula1.db" 11
Public Shared _db As IObjectContainer 12
13
Private Sub New() 14
End Sub 15
16
Public Shared Sub FillUpDB() 17
Dim pilot As Pilot = New Pilot("Michael Schumacher", 100) 18
Db.Set(pilot) 19
pilot = New Pilot("David Barichello", 95) 20
Db.Set(pilot) 21
pilot = New Pilot("Kimi Raikkonen", 100) 22
Db.Set(pilot) 23
End Sub 24
' end FillUpDB 25
26
Public Shared Function GetAllPilots() As IList 27
Dim result As IList = Db.Query(GetType(Pilot)) 28
Return result 29
End Function 30
' end GetAllPilots 31
32
Public Shared Sub StoreObject(ByVal obj As Object) 33
Db.Set(obj) 34
End Sub 35
' end StoreObject 36
37
Public Shared Function Db() As IObjectContainer 38
If _db Is Nothing Then 39
_db = Db4oFactory.OpenFile(DbFileName) 40
End If 41
Return _db 42
End Function 43
' end Db 44
45
Public Shared Sub CloseDb() 46
If Not (_db Is Nothing) Then 47
_db.Close() 48
End If 49
End Sub 50
' end CloseDb 51
52
End Class 53
End Namespace