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