aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Common/OpenGrid.Framework.Data.DB4o/DB4oManager.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Common/OpenGrid.Framework.Data.DB4o/DB4oManager.cs')
-rw-r--r--Common/OpenGrid.Framework.Data.DB4o/DB4oManager.cs165
1 files changed, 165 insertions, 0 deletions
diff --git a/Common/OpenGrid.Framework.Data.DB4o/DB4oManager.cs b/Common/OpenGrid.Framework.Data.DB4o/DB4oManager.cs
new file mode 100644
index 0000000..356a49c
--- /dev/null
+++ b/Common/OpenGrid.Framework.Data.DB4o/DB4oManager.cs
@@ -0,0 +1,165 @@
1/*
2* Copyright (c) Contributors, http://www.openmetaverse.org/
3* See CONTRIBUTORS.TXT for a full list of copyright holders.
4*
5* Redistribution and use in source and binary forms, with or without
6* modification, are permitted provided that the following conditions are met:
7* * Redistributions of source code must retain the above copyright
8* notice, this list of conditions and the following disclaimer.
9* * Redistributions in binary form must reproduce the above copyright
10* notice, this list of conditions and the following disclaimer in the
11* documentation and/or other materials provided with the distribution.
12* * Neither the name of the OpenSim Project nor the
13* names of its contributors may be used to endorse or promote products
14* derived from this software without specific prior written permission.
15*
16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26*
27*/
28using System;
29using System.Collections.Generic;
30using System.Text;
31using Db4objects.Db4o;
32using OpenGrid.Framework.Data;
33using libsecondlife;
34
35namespace OpenGrid.Framework.Data.DB4o
36{
37 /// <summary>
38 /// A Database manager for Db4o
39 /// </summary>
40 class DB4oGridManager
41 {
42 /// <summary>
43 /// A list of the current regions connected (in-memory cache)
44 /// </summary>
45 public Dictionary<LLUUID, SimProfileData> simProfiles = new Dictionary<LLUUID, SimProfileData>();
46 /// <summary>
47 /// Database File Name
48 /// </summary>
49 string dbfl;
50
51 /// <summary>
52 /// Creates a new grid storage manager
53 /// </summary>
54 /// <param name="db4odb">Filename to the database file</param>
55 public DB4oGridManager(string db4odb)
56 {
57 dbfl = db4odb;
58 IObjectContainer database;
59 database = Db4oFactory.OpenFile(dbfl);
60 IObjectSet result = database.Get(typeof(SimProfileData));
61 // Loads the file into the in-memory cache
62 foreach(SimProfileData row in result) {
63 simProfiles.Add(row.UUID, row);
64 }
65 database.Close();
66 }
67
68 /// <summary>
69 /// Adds a new profile to the database (Warning: Probably slow.)
70 /// </summary>
71 /// <param name="row">The profile to add</param>
72 /// <returns>Successful?</returns>
73 public bool AddRow(SimProfileData row)
74 {
75 if (simProfiles.ContainsKey(row.UUID))
76 {
77 simProfiles[row.UUID] = row;
78 }
79 else
80 {
81 simProfiles.Add(row.UUID, row);
82 }
83
84 try
85 {
86 IObjectContainer database;
87 database = Db4oFactory.OpenFile(dbfl);
88 database.Set(row);
89 database.Close();
90 return true;
91 }
92 catch (Exception e)
93 {
94 return false;
95 }
96 }
97
98
99 }
100
101 /// <summary>
102 /// A manager for the DB4o database (user profiles)
103 /// </summary>
104 class DB4oUserManager
105 {
106 /// <summary>
107 /// A list of the user profiles (in memory cache)
108 /// </summary>
109 public Dictionary<LLUUID, UserProfileData> userProfiles = new Dictionary<LLUUID, UserProfileData>();
110 /// <summary>
111 /// Database filename
112 /// </summary>
113 string dbfl;
114
115 /// <summary>
116 /// Initialises a new DB manager
117 /// </summary>
118 /// <param name="db4odb">The filename to the database</param>
119 public DB4oUserManager(string db4odb)
120 {
121 dbfl = db4odb;
122 IObjectContainer database;
123 database = Db4oFactory.OpenFile(dbfl);
124 // Load to cache
125 IObjectSet result = database.Get(typeof(UserProfileData));
126 foreach (UserProfileData row in result)
127 {
128 userProfiles.Add(row.UUID, row);
129 }
130 database.Close();
131 }
132
133 /// <summary>
134 /// Adds a new profile to the database (Warning: Probably slow.)
135 /// </summary>
136 /// <param name="row">The profile to add</param>
137 /// <returns>Successful?</returns>
138 public bool AddRow(UserProfileData row)
139 {
140 if (userProfiles.ContainsKey(row.UUID))
141 {
142 userProfiles[row.UUID] = row;
143 }
144 else
145 {
146 userProfiles.Add(row.UUID, row);
147 }
148
149 try
150 {
151 IObjectContainer database;
152 database = Db4oFactory.OpenFile(dbfl);
153 database.Set(row);
154 database.Close();
155 return true;
156 }
157 catch (Exception e)
158 {
159 return false;
160 }
161 }
162
163
164 }
165}