aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Data/NHibernate/NHibernateRegionData.cs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenSim/Data/NHibernate/NHibernateRegionData.cs124
1 files changed, 42 insertions, 82 deletions
diff --git a/OpenSim/Data/NHibernate/NHibernateRegionData.cs b/OpenSim/Data/NHibernate/NHibernateRegionData.cs
index 475cd71..0aba58c 100644
--- a/OpenSim/Data/NHibernate/NHibernateRegionData.cs
+++ b/OpenSim/Data/NHibernate/NHibernateRegionData.cs
@@ -34,10 +34,7 @@ using System.Text.RegularExpressions;
34using OpenMetaverse; 34using OpenMetaverse;
35using log4net; 35using log4net;
36using NHibernate; 36using NHibernate;
37using NHibernate.Cfg; 37using NHibernate.Criterion;
38using NHibernate.Expression;
39using NHibernate.Mapping.Attributes;
40using NHibernate.Tool.hbm2ddl;
41using OpenSim.Framework; 38using OpenSim.Framework;
42using OpenSim.Region.Environment.Interfaces; 39using OpenSim.Region.Environment.Interfaces;
43using OpenSim.Region.Environment.Scenes; 40using OpenSim.Region.Environment.Scenes;
@@ -52,51 +49,12 @@ namespace OpenSim.Data.NHibernate
52 { 49 {
53 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 50 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
54 51
55 private Configuration cfg; 52 private NHibernateManager manager;
56 private ISessionFactory factory;
57 private ISession session;
58
59 // public void Initialise()
60 // {
61 // Initialise("SQLiteDialect;SqliteClientDriver;URI=file:OpenSim.db,version=3", true);
62 // }
63 53
64 public void Initialise(string connect) 54 public void Initialise(string connect)
65 { 55 {
66 // Split out the dialect, driver, and connect string 56 m_log.InfoFormat("[NHIBERNATE] Initializing NHibernateRegionData");
67 char[] split = {';'}; 57 manager = new NHibernateManager(connect, "RegionStore");
68 string[] parts = connect.Split(split, 3);
69 if (parts.Length != 3)
70 {
71 // TODO: make this a real exception type
72 throw new Exception("Malformed Region connection string '" + connect + "'");
73 }
74
75 string dialect = parts[0];
76
77 // NHibernate setup
78 cfg = new Configuration();
79 cfg.SetProperty(Environment.ConnectionProvider,
80 "NHibernate.Connection.DriverConnectionProvider");
81 cfg.SetProperty(Environment.Dialect,
82 "NHibernate.Dialect." + dialect);
83 cfg.SetProperty(Environment.ConnectionDriver,
84 "NHibernate.Driver." + parts[1]);
85 cfg.SetProperty(Environment.ConnectionString, parts[2]);
86 cfg.AddAssembly("OpenSim.Data.NHibernate");
87
88 HbmSerializer.Default.Validate = true;
89 using (MemoryStream stream =
90 HbmSerializer.Default.Serialize(Assembly.GetExecutingAssembly()))
91 cfg.AddInputStream(stream);
92
93 factory = cfg.BuildSessionFactory();
94 session = factory.OpenSession();
95
96 // This actually does the roll forward assembly stuff
97 Assembly assem = GetType().Assembly;
98 Migration m = new Migration((System.Data.Common.DbConnection)factory.ConnectionProvider.GetConnection(), assem, dialect, "RegionStore");
99 m.Update();
100 } 58 }
101 59
102 /*********************************************************************** 60 /***********************************************************************
@@ -122,15 +80,18 @@ namespace OpenSim.Data.NHibernate
122 { 80 {
123 try 81 try
124 { 82 {
125 SceneObjectPart old = session.Load(typeof(SceneObjectPart), p.UUID) as SceneObjectPart; 83 SceneObjectPart old = (SceneObjectPart)manager.Load(typeof(SceneObjectPart), p.UUID);
126 session.Evict(old); 84 if (old != null)
127 session.Update(p); 85 {
128 m_log.InfoFormat("[NHIBERNATE] updating object {0}", p.UUID); 86 m_log.InfoFormat("[NHIBERNATE] updating object {0}", p.UUID);
129 } 87 manager.Update(old);
130 catch (ObjectNotFoundException) 88 }
131 { 89 else
132 m_log.InfoFormat("[NHIBERNATE] saving object {0}", p.UUID); 90 {
133 session.Save(p); 91 m_log.InfoFormat("[NHIBERNATE] saving object {0}", p.UUID);
92 manager.Save(p);
93 }
94
134 } 95 }
135 catch (Exception e) 96 catch (Exception e)
136 { 97 {
@@ -142,15 +103,19 @@ namespace OpenSim.Data.NHibernate
142 { 103 {
143 try 104 try
144 { 105 {
145 Terrain old = session.Load(typeof(Terrain), t.RegionID) as Terrain; 106
146 session.Evict(old); 107 Terrain old = (Terrain)manager.Load(typeof(Terrain), t.RegionID);
147 session.Update(t); 108 if (old != null)
148 session.Flush(); 109 {
149 } 110 m_log.InfoFormat("[NHIBERNATE] updating terrain {0}", t.RegionID);
150 catch (ObjectNotFoundException) 111 manager.Update(old);
151 { 112 }
152 session.Save(t); 113 else
153 session.Flush(); 114 {
115 m_log.InfoFormat("[NHIBERNATE] saving terrain {0}", t.RegionID);
116 manager.Save(t);
117 }
118
154 } 119 }
155 catch (Exception e) 120 catch (Exception e)
156 { 121 {
@@ -173,7 +138,6 @@ namespace OpenSim.Data.NHibernate
173 m_log.InfoFormat("Storing part {0}", part.UUID); 138 m_log.InfoFormat("Storing part {0}", part.UUID);
174 SaveOrUpdate(part); 139 SaveOrUpdate(part);
175 } 140 }
176 session.Flush();
177 } 141 }
178 catch (Exception e) 142 catch (Exception e)
179 { 143 {
@@ -185,7 +149,7 @@ namespace OpenSim.Data.NHibernate
185 { 149 {
186 SceneObjectGroup group = new SceneObjectGroup(); 150 SceneObjectGroup group = new SceneObjectGroup();
187 151
188 ICriteria criteria = session.CreateCriteria(typeof(SceneObjectPart)); 152 ICriteria criteria = manager.GetSession().CreateCriteria(typeof(SceneObjectPart));
189 criteria.Add(Expression.Eq("RegionID", region)); 153 criteria.Add(Expression.Eq("RegionID", region));
190 criteria.Add(Expression.Eq("ParentUUID", uuid)); 154 criteria.Add(Expression.Eq("ParentUUID", uuid));
191 criteria.AddOrder( Order.Asc("ParentID") ); 155 criteria.AddOrder( Order.Asc("ParentID") );
@@ -216,9 +180,8 @@ namespace OpenSim.Data.NHibernate
216 SceneObjectGroup g = LoadObject(obj, regionUUID); 180 SceneObjectGroup g = LoadObject(obj, regionUUID);
217 foreach (SceneObjectPart p in g.Children.Values) 181 foreach (SceneObjectPart p in g.Children.Values)
218 { 182 {
219 session.Delete(p); 183 manager.Delete(p);
220 } 184 }
221 session.Flush();
222 185
223 m_log.InfoFormat("[REGION DB]: Removing obj: {0} from region: {1}", obj.Guid, regionUUID); 186 m_log.InfoFormat("[REGION DB]: Removing obj: {0} from region: {1}", obj.Guid, regionUUID);
224 187
@@ -234,7 +197,7 @@ namespace OpenSim.Data.NHibernate
234 Dictionary<UUID, SceneObjectGroup> SOG = new Dictionary<UUID, SceneObjectGroup>(); 197 Dictionary<UUID, SceneObjectGroup> SOG = new Dictionary<UUID, SceneObjectGroup>();
235 List<SceneObjectGroup> ret = new List<SceneObjectGroup>(); 198 List<SceneObjectGroup> ret = new List<SceneObjectGroup>();
236 199
237 ICriteria criteria = session.CreateCriteria(typeof(SceneObjectPart)); 200 ICriteria criteria = manager.GetSession().CreateCriteria(typeof(SceneObjectPart));
238 criteria.Add(Expression.Eq("RegionID", regionUUID)); 201 criteria.Add(Expression.Eq("RegionID", regionUUID));
239 criteria.AddOrder( Order.Asc("ParentID") ); 202 criteria.AddOrder( Order.Asc("ParentID") );
240 foreach (SceneObjectPart p in criteria.List()) 203 foreach (SceneObjectPart p in criteria.List())
@@ -252,7 +215,7 @@ namespace OpenSim.Data.NHibernate
252 } 215 }
253 // get the inventory 216 // get the inventory
254 217
255 ICriteria InvCriteria = session.CreateCriteria(typeof(TaskInventoryItem)); 218 ICriteria InvCriteria = manager.GetSession().CreateCriteria(typeof(TaskInventoryItem));
256 InvCriteria.Add(Expression.Eq("ParentPartID", p.UUID)); 219 InvCriteria.Add(Expression.Eq("ParentPartID", p.UUID));
257 IList<TaskInventoryItem> inventory = new List<TaskInventoryItem>(); 220 IList<TaskInventoryItem> inventory = new List<TaskInventoryItem>();
258 foreach (TaskInventoryItem i in InvCriteria.List()) 221 foreach (TaskInventoryItem i in InvCriteria.List())
@@ -291,16 +254,14 @@ namespace OpenSim.Data.NHibernate
291 /// <returns>Heightfield data</returns> 254 /// <returns>Heightfield data</returns>
292 public double[,] LoadTerrain(UUID regionID) 255 public double[,] LoadTerrain(UUID regionID)
293 { 256 {
294 try 257 Terrain t = (Terrain)manager.Load(typeof(Terrain), regionID);
258 if (t != null)
295 { 259 {
296 Terrain t = session.Load(typeof(Terrain), regionID) as Terrain;
297 return t.Doubles; 260 return t.Doubles;
298 } 261 }
299 catch (ObjectNotFoundException) 262
300 { 263 m_log.Info("No terrain yet");
301 m_log.Info("No terrain yet"); 264 return null;
302 return null;
303 }
304 } 265 }
305 266
306 /// <summary> 267 /// <summary>
@@ -339,7 +300,7 @@ namespace OpenSim.Data.NHibernate
339 /// </summary> 300 /// </summary>
340 public void Shutdown() 301 public void Shutdown()
341 { 302 {
342 session.Flush(); 303 //session.Flush();
343 } 304 }
344 305
345 /// <summary> 306 /// <summary>
@@ -397,21 +358,20 @@ namespace OpenSim.Data.NHibernate
397 /// <param name="items"></param> 358 /// <param name="items"></param>
398 public void StorePrimInventory(UUID primID, ICollection<TaskInventoryItem> items) 359 public void StorePrimInventory(UUID primID, ICollection<TaskInventoryItem> items)
399 { 360 {
400 ICriteria criteria = session.CreateCriteria(typeof(TaskInventoryItem)); 361 ICriteria criteria = manager.GetSession().CreateCriteria(typeof(TaskInventoryItem));
401 criteria.Add(Expression.Eq("ParentPartID", primID)); 362 criteria.Add(Expression.Eq("ParentPartID", primID));
402 try 363 try
403 { 364 {
404 foreach (TaskInventoryItem i in criteria.List()) 365 foreach (TaskInventoryItem i in criteria.List())
405 { 366 {
406 session.Delete(i); 367 manager.Delete(i);
407 } 368 }
408 369
409 foreach (TaskInventoryItem i in items) 370 foreach (TaskInventoryItem i in items)
410 { 371 {
411 session.Save(i); 372 manager.Save(i);
412 373
413 } 374 }
414 session.Flush();
415 } 375 }
416 catch (Exception e) 376 catch (Exception e)
417 { 377 {