diff options
Diffstat (limited to 'OpenSim/Data/DB4o/DB4oManager.cs')
-rw-r--r-- | OpenSim/Data/DB4o/DB4oManager.cs | 171 |
1 files changed, 0 insertions, 171 deletions
diff --git a/OpenSim/Data/DB4o/DB4oManager.cs b/OpenSim/Data/DB4o/DB4oManager.cs deleted file mode 100644 index a9368d5..0000000 --- a/OpenSim/Data/DB4o/DB4oManager.cs +++ /dev/null | |||
@@ -1,171 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.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 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using Db4objects.Db4o; | ||
31 | using libsecondlife; | ||
32 | using OpenSim.Framework; | ||
33 | |||
34 | namespace OpenSim.Data.DB4o | ||
35 | { | ||
36 | /// <summary> | ||
37 | /// A Database manager for Db4o | ||
38 | /// </summary> | ||
39 | internal class DB4oGridManager | ||
40 | { | ||
41 | /// <summary> | ||
42 | /// A list of the current regions connected (in-memory cache) | ||
43 | /// </summary> | ||
44 | public Dictionary<LLUUID, RegionProfileData> simProfiles = new Dictionary<LLUUID, RegionProfileData>(); | ||
45 | |||
46 | /// <summary> | ||
47 | /// Database File Name | ||
48 | /// </summary> | ||
49 | private 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 (RegionProfileData)); | ||
61 | // Loads the file into the in-memory cache | ||
62 | foreach (RegionProfileData row in result) | ||
63 | { | ||
64 | simProfiles.Add(row.UUID, row); | ||
65 | } | ||
66 | database.Close(); | ||
67 | } | ||
68 | |||
69 | /// <summary> | ||
70 | /// Adds a new profile to the database (Warning: Probably slow.) | ||
71 | /// </summary> | ||
72 | /// <param name="row">The profile to add</param> | ||
73 | /// <returns>Successful?</returns> | ||
74 | public bool AddRow(RegionProfileData row) | ||
75 | { | ||
76 | if (simProfiles.ContainsKey(row.UUID)) | ||
77 | { | ||
78 | simProfiles[row.UUID] = row; | ||
79 | } | ||
80 | else | ||
81 | { | ||
82 | simProfiles.Add(row.UUID, row); | ||
83 | } | ||
84 | |||
85 | try | ||
86 | { | ||
87 | IObjectContainer database; | ||
88 | database = Db4oFactory.OpenFile(dbfl); | ||
89 | database.Set(row); | ||
90 | database.Close(); | ||
91 | return true; | ||
92 | } | ||
93 | catch (Exception) | ||
94 | { | ||
95 | return false; | ||
96 | } | ||
97 | } | ||
98 | } | ||
99 | |||
100 | /// <summary> | ||
101 | /// A manager for the DB4o database (user profiles) | ||
102 | /// </summary> | ||
103 | internal class DB4oUserManager | ||
104 | { | ||
105 | /// <summary> | ||
106 | /// A list of the user profiles (in memory cache) | ||
107 | /// </summary> | ||
108 | public Dictionary<LLUUID, UserProfileData> userProfiles = new Dictionary<LLUUID, UserProfileData>(); | ||
109 | |||
110 | /// <summary> | ||
111 | /// Database filename | ||
112 | /// </summary> | ||
113 | private 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 | if (userProfiles.ContainsKey(row.ID)) | ||
129 | userProfiles[row.ID] = row; | ||
130 | else | ||
131 | userProfiles.Add(row.ID, row); | ||
132 | } | ||
133 | database.Close(); | ||
134 | } | ||
135 | |||
136 | /// <summary> | ||
137 | /// Adds or updates a record to the user database. Do this when changes are needed | ||
138 | /// in the user profile that need to be persistant. | ||
139 | /// | ||
140 | /// TODO: the logic here is not ACID, the local cache will be | ||
141 | /// updated even if the persistant data is not. This may lead | ||
142 | /// to unexpected results. | ||
143 | /// </summary> | ||
144 | /// <param name="record">The profile to update</param> | ||
145 | /// <returns>true on success, false on fail to persist to db</returns> | ||
146 | public bool UpdateRecord(UserProfileData record) | ||
147 | { | ||
148 | if (userProfiles.ContainsKey(record.ID)) | ||
149 | { | ||
150 | userProfiles[record.ID] = record; | ||
151 | } | ||
152 | else | ||
153 | { | ||
154 | userProfiles.Add(record.ID, record); | ||
155 | } | ||
156 | |||
157 | try | ||
158 | { | ||
159 | IObjectContainer database; | ||
160 | database = Db4oFactory.OpenFile(dbfl); | ||
161 | database.Set(record); | ||
162 | database.Close(); | ||
163 | return true; | ||
164 | } | ||
165 | catch (Exception) | ||
166 | { | ||
167 | return false; | ||
168 | } | ||
169 | } | ||
170 | } | ||
171 | } | ||