aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Data/NHibernate/NHibernateRegionData.cs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenSim/Data/NHibernate/NHibernateRegionData.cs426
1 files changed, 0 insertions, 426 deletions
diff --git a/OpenSim/Data/NHibernate/NHibernateRegionData.cs b/OpenSim/Data/NHibernate/NHibernateRegionData.cs
deleted file mode 100644
index f19fda1..0000000
--- a/OpenSim/Data/NHibernate/NHibernateRegionData.cs
+++ /dev/null
@@ -1,426 +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 OpenSimulator 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.Reflection;
31using log4net;
32using NHibernate;
33using NHibernate.Criterion;
34using OpenMetaverse;
35using OpenSim.Framework;
36using OpenSim.Region.Framework.Interfaces;
37using OpenSim.Region.Framework.Scenes;
38
39namespace OpenSim.Data.NHibernate
40{
41 /// <summary>
42 /// A RegionData Interface to the NHibernate database
43 /// </summary>
44 public class NHibernateRegionData : IRegionDataStore
45 {
46 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
47
48 private NHibernateManager manager;
49 public NHibernateManager Manager
50 {
51 get
52 {
53 return manager;
54 }
55 }
56
57 public void Initialise(string connect)
58 {
59 m_log.InfoFormat("[NHIBERNATE] Initializing NHibernateRegionData");
60 manager = new NHibernateManager(connect, "RegionStore");
61 }
62
63 /***********************************************************************
64 *
65 * Public Interface Functions
66 *
67 **********************************************************************/
68
69 public void Dispose() {}
70
71 public void StoreRegionSettings(RegionSettings rs)
72 {
73 RegionSettings oldRegionSettings = (RegionSettings)manager.Get(typeof(RegionSettings), rs.RegionUUID);
74 if (oldRegionSettings != null)
75 {
76 manager.Update(rs);
77 }
78 else
79 {
80 manager.Insert(rs);
81 }
82 }
83
84 public RegionSettings LoadRegionSettings(UUID regionUUID)
85 {
86 RegionSettings regionSettings = (RegionSettings) manager.Get(typeof(RegionSettings), regionUUID);
87
88 if (regionSettings == null)
89 {
90 regionSettings = new RegionSettings();
91 regionSettings.RegionUUID = regionUUID;
92 manager.Insert(regionSettings);
93 }
94
95 regionSettings.OnSave += StoreRegionSettings;
96
97 return regionSettings;
98 }
99
100 // This looks inefficient, but it turns out that it isn't
101 // based on trial runs with nhibernate 1.2
102 private void SaveOrUpdate(SceneObjectPart p)
103 {
104 try
105 {
106 SceneObjectPart old = (SceneObjectPart)manager.Get(typeof(SceneObjectPart), p.UUID);
107 if (old != null)
108 {
109 m_log.InfoFormat("[NHIBERNATE] updating object {0}", p.UUID);
110 manager.Update(p);
111 }
112 else
113 {
114 m_log.InfoFormat("[NHIBERNATE] saving object {0}", p.UUID);
115 manager.Insert(p);
116 }
117
118 }
119 catch (Exception e)
120 {
121 m_log.Error("[NHIBERNATE] issue saving part", e);
122 }
123 }
124
125 private void SaveOrUpdate(Terrain t)
126 {
127 try
128 {
129
130 Terrain old = (Terrain)manager.Get(typeof(Terrain), t.RegionID);
131 if (old != null)
132 {
133 m_log.InfoFormat("[NHIBERNATE] updating terrain {0}", t.RegionID);
134 manager.Update(t);
135 }
136 else
137 {
138 m_log.InfoFormat("[NHIBERNATE] saving terrain {0}", t.RegionID);
139 manager.Insert(t);
140 }
141
142 }
143 catch (Exception e)
144 {
145 m_log.Error("[NHIBERNATE] issue saving terrain", e);
146 }
147 }
148
149
150 /// <summary>
151 /// Adds an object into region storage
152 /// </summary>
153 /// <param name="obj">the object</param>
154 /// <param name="regionUUID">the region UUID</param>
155 public void StoreObject(SceneObjectGroup obj, UUID regionUUID)
156 {
157 uint flags = obj.RootPart.GetEffectiveObjectFlags();
158
159 // Eligibility check
160 if ((flags & (uint)PrimFlags.Temporary) != 0)
161 return;
162 if ((flags & (uint)PrimFlags.TemporaryOnRez) != 0)
163 return;
164
165 try
166 {
167 foreach (SceneObjectPart part in obj.Children.Values)
168 {
169 m_log.InfoFormat("Storing part {0}", part.UUID);
170 SaveOrUpdate(part);
171 }
172 }
173 catch (Exception e)
174 {
175 m_log.Error("Can't save: ", e);
176 }
177 }
178
179 private SceneObjectGroup LoadObject(UUID uuid, UUID region)
180 {
181 ICriteria criteria = manager.GetSession().CreateCriteria(typeof(SceneObjectPart));
182 criteria.Add(Expression.Eq("RegionID", region));
183 criteria.Add(Expression.Eq("ParentUUID", uuid));
184 criteria.AddOrder(Order.Asc("ParentID"));
185
186 IList<SceneObjectPart> parts = criteria.List<SceneObjectPart>();
187
188 SceneObjectGroup group = null;
189
190 // Find the root part
191 for (int i = 0; i < parts.Count; i++)
192 {
193 if (parts[i].UUID == uuid)
194 {
195 group = new SceneObjectGroup(parts[i]);
196 break;
197 }
198 }
199
200 // Add the children parts
201 if (group != null)
202 {
203 for (int i = 0; i < parts.Count; i++)
204 {
205 if (parts[i].UUID != uuid)
206 group.AddPart(parts[i]);
207 }
208 }
209 else
210 {
211 m_log.Error("[NHIBERNATE]: LoadObject() Attempted to load a SceneObjectGroup with no root SceneObjectPart ");
212 }
213
214 return group;
215 }
216
217 /// <summary>
218 /// Removes an object from region storage
219 /// </summary>
220 /// <param name="obj">the object</param>
221 /// <param name="regionUUID">the region UUID</param>
222 public void RemoveObject(UUID obj, UUID regionUUID)
223 {
224 SceneObjectGroup g = LoadObject(obj, regionUUID);
225 foreach (SceneObjectPart p in g.Children.Values)
226 {
227 manager.Delete(p);
228 }
229
230 // m_log.InfoFormat("[REGION DB]: Removing obj: {0} from region: {1}", obj.Guid, regionUUID);
231
232 }
233
234 /// <summary>
235 /// Load persisted objects from region storage.
236 /// </summary>
237 /// <param name="regionUUID">The region UUID</param>
238 /// <returns>List of loaded groups</returns>
239 public List<SceneObjectGroup> LoadObjects(UUID regionUUID)
240 {
241 Dictionary<UUID, SceneObjectGroup> SOG = new Dictionary<UUID, SceneObjectGroup>();
242 List<SceneObjectGroup> ret = new List<SceneObjectGroup>();
243
244 ICriteria criteria = manager.GetSession().CreateCriteria(typeof(SceneObjectPart));
245 criteria.Add(Expression.Eq("RegionID", regionUUID));
246 criteria.AddOrder(Order.Asc("ParentID"));
247 criteria.AddOrder(Order.Asc("LinkNum"));
248 foreach (SceneObjectPart p in criteria.List())
249 {
250 // root part
251 if (p.UUID == p.ParentUUID)
252 {
253 SceneObjectGroup group = new SceneObjectGroup(p);
254 SOG.Add(p.ParentUUID, group);
255 }
256 else
257 {
258 SOG[p.ParentUUID].AddPart(p);
259 }
260 // get the inventory
261
262 ICriteria InvCriteria = manager.GetSession().CreateCriteria(typeof(TaskInventoryItem));
263 InvCriteria.Add(Expression.Eq("ParentPartID", p.UUID));
264 IList<TaskInventoryItem> inventory = new List<TaskInventoryItem>();
265 foreach (TaskInventoryItem i in InvCriteria.List())
266 {
267 inventory.Add(i);
268 }
269
270 if (inventory.Count > 0)
271 p.Inventory.RestoreInventoryItems(inventory);
272 }
273 foreach (SceneObjectGroup g in SOG.Values)
274 {
275 ret.Add(g);
276 }
277
278 return ret;
279 }
280
281 /// <summary>
282 /// Store a terrain revision in region storage
283 /// </summary>
284 /// <param name="ter">terrain heightfield</param>
285 /// <param name="regionID">region UUID</param>
286 public void StoreTerrain(double[,] ter, UUID regionID)
287 {
288 lock (this) {
289 Terrain t = new Terrain(regionID, ter);
290 SaveOrUpdate(t);
291 }
292 }
293
294 /// <summary>
295 /// Load the latest terrain revision from region storage
296 /// </summary>
297 /// <param name="regionID">the region UUID</param>
298 /// <returns>Heightfield data</returns>
299 public double[,] LoadTerrain(UUID regionID)
300 {
301 Terrain t = (Terrain)manager.Get(typeof(Terrain), regionID);
302 if (t != null)
303 {
304 return t.Doubles;
305 }
306
307 m_log.Info("No terrain yet");
308 return null;
309 }
310
311 /// <summary>
312 ///
313 /// </summary>
314 /// <param name="globalID"></param>
315 public void RemoveLandObject(UUID globalID)
316 {
317
318 }
319
320 /// <summary>
321 ///
322 /// </summary>
323 /// <param name="parcel"></param>
324 public void StoreLandObject(ILandObject parcel)
325 {
326
327 }
328
329 /// <summary>
330 ///
331 /// </summary>
332 /// <param name="regionUUID"></param>
333 /// <returns></returns>
334 public List<LandData> LoadLandObjects(UUID regionUUID)
335 {
336 List<LandData> landDataForRegion = new List<LandData>();
337
338 return landDataForRegion;
339 }
340
341
342 /// <summary>
343 /// See <see cref="Commit"/>
344 /// </summary>
345 public void Shutdown()
346 {
347 //session.Flush();
348 }
349
350 /// <summary>
351 /// Load a region banlist
352 /// </summary>
353 /// <param name="regionUUID">the region UUID</param>
354 /// <returns>The banlist</returns>
355 public List<EstateBan> LoadRegionBanList(UUID regionUUID)
356 {
357 List<EstateBan> regionbanlist = new List<EstateBan>();
358
359 return regionbanlist;
360 }
361
362 /// <summary>
363 /// Add en entry into region banlist
364 /// </summary>
365 /// <param name="item"></param>
366 public void AddToRegionBanlist(EstateBan item)
367 {
368
369 }
370
371 /// <summary>
372 /// remove an entry from the region banlist
373 /// </summary>
374 /// <param name="item"></param>
375 public void RemoveFromRegionBanlist(EstateBan item)
376 {
377
378 }
379
380 /// <summary>
381 ///
382 /// </summary>
383 /// <param name="val"></param>
384 /// <returns></returns>
385// private static Array serializeTerrain(double[,] val)
386// {
387// MemoryStream str = new MemoryStream(65536*sizeof (double));
388// BinaryWriter bw = new BinaryWriter(str);
389//
390// // TODO: COMPATIBILITY - Add byte-order conversions
391// for (int x = 0; x < (int)Constants.RegionSize; x++)
392// for (int y = 0; y < (int)Constants.RegionSize; y++)
393// bw.Write(val[x, y]);
394//
395// return str.ToArray();
396// }
397
398 /// <summary>
399 /// see IRegionDatastore
400 /// </summary>
401 /// <param name="primID"></param>
402 /// <param name="items"></param>
403 public void StorePrimInventory(UUID primID, ICollection<TaskInventoryItem> items)
404 {
405 ICriteria criteria = manager.GetSession().CreateCriteria(typeof(TaskInventoryItem));
406 criteria.Add(Expression.Eq("ParentPartID", primID));
407 try
408 {
409 foreach (TaskInventoryItem i in criteria.List())
410 {
411 manager.Delete(i);
412 }
413
414 foreach (TaskInventoryItem i in items)
415 {
416 manager.Insert(i);
417
418 }
419 }
420 catch (Exception e)
421 {
422 m_log.Error("[NHIBERNATE] StoreInvetory", e);
423 }
424 }
425 }
426}