aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/Data.DB4o/DB4oManager.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Framework/Data.DB4o/DB4oManager.cs')
-rw-r--r--OpenSim/Framework/Data.DB4o/DB4oManager.cs163
1 files changed, 163 insertions, 0 deletions
diff --git a/OpenSim/Framework/Data.DB4o/DB4oManager.cs b/OpenSim/Framework/Data.DB4o/DB4oManager.cs
new file mode 100644
index 0000000..0df6350
--- /dev/null
+++ b/OpenSim/Framework/Data.DB4o/DB4oManager.cs
@@ -0,0 +1,163 @@
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 Db4objects.Db4o;
31using libsecondlife;
32
33namespace OpenSim.Framework.Data.DB4o
34{
35 /// <summary>
36 /// A Database manager for Db4o
37 /// </summary>
38 class DB4oGridManager
39 {
40 /// <summary>
41 /// A list of the current regions connected (in-memory cache)
42 /// </summary>
43 public Dictionary<LLUUID, SimProfileData> simProfiles = new Dictionary<LLUUID, SimProfileData>();
44 /// <summary>
45 /// Database File Name
46 /// </summary>
47 string dbfl;
48
49 /// <summary>
50 /// Creates a new grid storage manager
51 /// </summary>
52 /// <param name="db4odb">Filename to the database file</param>
53 public DB4oGridManager(string db4odb)
54 {
55 dbfl = db4odb;
56 IObjectContainer database;
57 database = Db4oFactory.OpenFile(dbfl);
58 IObjectSet result = database.Get(typeof(SimProfileData));
59 // Loads the file into the in-memory cache
60 foreach(SimProfileData row in result) {
61 simProfiles.Add(row.UUID, row);
62 }
63 database.Close();
64 }
65
66 /// <summary>
67 /// Adds a new profile to the database (Warning: Probably slow.)
68 /// </summary>
69 /// <param name="row">The profile to add</param>
70 /// <returns>Successful?</returns>
71 public bool AddRow(SimProfileData row)
72 {
73 if (simProfiles.ContainsKey(row.UUID))
74 {
75 simProfiles[row.UUID] = row;
76 }
77 else
78 {
79 simProfiles.Add(row.UUID, row);
80 }
81
82 try
83 {
84 IObjectContainer database;
85 database = Db4oFactory.OpenFile(dbfl);
86 database.Set(row);
87 database.Close();
88 return true;
89 }
90 catch (Exception)
91 {
92 return false;
93 }
94 }
95
96
97 }
98
99 /// <summary>
100 /// A manager for the DB4o database (user profiles)
101 /// </summary>
102 class DB4oUserManager
103 {
104 /// <summary>
105 /// A list of the user profiles (in memory cache)
106 /// </summary>
107 public Dictionary<LLUUID, UserProfileData> userProfiles = new Dictionary<LLUUID, UserProfileData>();
108 /// <summary>
109 /// Database filename
110 /// </summary>
111 string dbfl;
112
113 /// <summary>
114 /// Initialises a new DB manager
115 /// </summary>
116 /// <param name="db4odb">The filename to the database</param>
117 public DB4oUserManager(string db4odb)
118 {
119 dbfl = db4odb;
120 IObjectContainer database;
121 database = Db4oFactory.OpenFile(dbfl);
122 // Load to cache
123 IObjectSet result = database.Get(typeof(UserProfileData));
124 foreach (UserProfileData row in result)
125 {
126 userProfiles.Add(row.UUID, row);
127 }
128 database.Close();
129 }
130
131 /// <summary>
132 /// Adds a new profile to the database (Warning: Probably slow.)
133 /// </summary>
134 /// <param name="row">The profile to add</param>
135 /// <returns>Successful?</returns>
136 public bool AddRow(UserProfileData row)
137 {
138 if (userProfiles.ContainsKey(row.UUID))
139 {
140 userProfiles[row.UUID] = row;
141 }
142 else
143 {
144 userProfiles.Add(row.UUID, row);
145 }
146
147 try
148 {
149 IObjectContainer database;
150 database = Db4oFactory.OpenFile(dbfl);
151 database.Set(row);
152 database.Close();
153 return true;
154 }
155 catch (Exception)
156 {
157 return false;
158 }
159 }
160
161
162 }
163}