aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Data/NHibernate/NHibernateInventoryData.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Data/NHibernate/NHibernateInventoryData.cs')
-rw-r--r--OpenSim/Data/NHibernate/NHibernateInventoryData.cs146
1 files changed, 57 insertions, 89 deletions
diff --git a/OpenSim/Data/NHibernate/NHibernateInventoryData.cs b/OpenSim/Data/NHibernate/NHibernateInventoryData.cs
index 017759e..46dcbad 100644
--- a/OpenSim/Data/NHibernate/NHibernateInventoryData.cs
+++ b/OpenSim/Data/NHibernate/NHibernateInventoryData.cs
@@ -48,6 +48,7 @@ namespace OpenSim.Data.NHibernate
48 48
49 private Configuration cfg; 49 private Configuration cfg;
50 private ISessionFactory factory; 50 private ISessionFactory factory;
51 private ISession session;
51 52
52 /// <summary> 53 /// <summary>
53 /// Initialises the interface 54 /// Initialises the interface
@@ -76,6 +77,7 @@ namespace OpenSim.Data.NHibernate
76 cfg.AddAssembly("OpenSim.Data.NHibernate"); 77 cfg.AddAssembly("OpenSim.Data.NHibernate");
77 78
78 factory = cfg.BuildSessionFactory(); 79 factory = cfg.BuildSessionFactory();
80 session = factory.OpenSession();
79 81
80 // This actually does the roll forward assembly stuff 82 // This actually does the roll forward assembly stuff
81 Assembly assem = GetType().Assembly; 83 Assembly assem = GetType().Assembly;
@@ -99,17 +101,14 @@ namespace OpenSim.Data.NHibernate
99 /// <returns>A class containing item information</returns> 101 /// <returns>A class containing item information</returns>
100 public InventoryItemBase getInventoryItem(LLUUID item) 102 public InventoryItemBase getInventoryItem(LLUUID item)
101 { 103 {
102 using (ISession session = factory.OpenSession()) 104 try
103 { 105 {
104 try 106 return session.Load(typeof(InventoryItemBase), item) as InventoryItemBase;
105 { 107 }
106 return session.Load(typeof(InventoryItemBase), item) as InventoryItemBase; 108 catch
107 } 109 {
108 catch 110 m_log.ErrorFormat("Couldn't find inventory item: {0}", item);
109 { 111 return null;
110 m_log.ErrorFormat("Couldn't find inventory item: {0}", item);
111 return null;
112 }
113 } 112 }
114 } 113 }
115 114
@@ -121,13 +120,10 @@ namespace OpenSim.Data.NHibernate
121 { 120 {
122 if (!ExistsItem(item.ID)) 121 if (!ExistsItem(item.ID))
123 { 122 {
124 using (ISession session = factory.OpenSession()) 123 using (ITransaction transaction = session.BeginTransaction())
125 { 124 {
126 using (ITransaction transaction = session.BeginTransaction()) 125 session.Save(item);
127 { 126 transaction.Commit();
128 session.Save(item);
129 transaction.Commit();
130 }
131 } 127 }
132 } 128 }
133 else 129 else
@@ -145,13 +141,10 @@ namespace OpenSim.Data.NHibernate
145 { 141 {
146 if (ExistsItem(item.ID)) 142 if (ExistsItem(item.ID))
147 { 143 {
148 using (ISession session = factory.OpenSession()) 144 using (ITransaction transaction = session.BeginTransaction())
149 { 145 {
150 using (ITransaction transaction = session.BeginTransaction()) 146 session.Update(item);
151 { 147 transaction.Commit();
152 session.Update(item);
153 transaction.Commit();
154 }
155 } 148 }
156 } 149 }
157 else 150 else
@@ -166,13 +159,10 @@ namespace OpenSim.Data.NHibernate
166 /// <param name="item"></param> 159 /// <param name="item"></param>
167 public void deleteInventoryItem(LLUUID itemID) 160 public void deleteInventoryItem(LLUUID itemID)
168 { 161 {
169 using (ISession session = factory.OpenSession()) 162 using (ITransaction transaction = session.BeginTransaction())
170 { 163 {
171 using (ITransaction transaction = session.BeginTransaction()) 164 session.Delete(itemID);
172 { 165 transaction.Commit();
173 session.Delete(itemID);
174 transaction.Commit();
175 }
176 } 166 }
177 } 167 }
178 168
@@ -183,17 +173,14 @@ namespace OpenSim.Data.NHibernate
183 /// <returns>A class containing folder information</returns> 173 /// <returns>A class containing folder information</returns>
184 public InventoryFolderBase getInventoryFolder(LLUUID folder) 174 public InventoryFolderBase getInventoryFolder(LLUUID folder)
185 { 175 {
186 using (ISession session = factory.OpenSession()) 176 try
187 { 177 {
188 try 178 return session.Load(typeof(InventoryFolderBase), folder) as InventoryFolderBase;
189 { 179 }
190 return session.Load(typeof(InventoryFolderBase), folder) as InventoryFolderBase; 180 catch
191 } 181 {
192 catch 182 m_log.ErrorFormat("Couldn't find inventory item: {0}", folder);
193 { 183 return null;
194 m_log.ErrorFormat("Couldn't find inventory item: {0}", folder);
195 return null;
196 }
197 } 184 }
198 } 185 }
199 186
@@ -205,13 +192,10 @@ namespace OpenSim.Data.NHibernate
205 { 192 {
206 if (!ExistsFolder(folder.ID)) 193 if (!ExistsFolder(folder.ID))
207 { 194 {
208 using (ISession session = factory.OpenSession()) 195 using (ITransaction transaction = session.BeginTransaction())
209 { 196 {
210 using (ITransaction transaction = session.BeginTransaction()) 197 session.Save(folder);
211 { 198 transaction.Commit();
212 session.Save(folder);
213 transaction.Commit();
214 }
215 } 199 }
216 } 200 }
217 else 201 else
@@ -229,13 +213,10 @@ namespace OpenSim.Data.NHibernate
229 { 213 {
230 if (ExistsFolder(folder.ID)) 214 if (ExistsFolder(folder.ID))
231 { 215 {
232 using (ISession session = factory.OpenSession()) 216 using (ITransaction transaction = session.BeginTransaction())
233 { 217 {
234 using (ITransaction transaction = session.BeginTransaction()) 218 session.Update(folder);
235 { 219 transaction.Commit();
236 session.Update(folder);
237 transaction.Commit();
238 }
239 } 220 }
240 } 221 }
241 else 222 else
@@ -250,13 +231,10 @@ namespace OpenSim.Data.NHibernate
250 /// <param name="folder"></param> 231 /// <param name="folder"></param>
251 public void deleteInventoryFolder(LLUUID folderID) 232 public void deleteInventoryFolder(LLUUID folderID)
252 { 233 {
253 using (ISession session = factory.OpenSession()) 234 using (ITransaction transaction = session.BeginTransaction())
254 { 235 {
255 using (ITransaction transaction = session.BeginTransaction()) 236 session.Delete(folderID.ToString());
256 { 237 transaction.Commit();
257 session.Delete(folderID.ToString());
258 transaction.Commit();
259 }
260 } 238 }
261 } 239 }
262 240
@@ -329,23 +307,20 @@ namespace OpenSim.Data.NHibernate
329 /// <returns>A List of InventoryItemBase items</returns> 307 /// <returns>A List of InventoryItemBase items</returns>
330 public List<InventoryItemBase> getInventoryInFolder(LLUUID folderID) 308 public List<InventoryItemBase> getInventoryInFolder(LLUUID folderID)
331 { 309 {
332 using (ISession session = factory.OpenSession()) 310 // try {
311 ICriteria criteria = session.CreateCriteria(typeof(InventoryItemBase));
312 criteria.Add(Expression.Eq("Folder", folderID));
313 List<InventoryItemBase> list = new List<InventoryItemBase>();
314 foreach (InventoryItemBase item in criteria.List())
333 { 315 {
334 // try { 316 list.Add(item);
335 ICriteria criteria = session.CreateCriteria(typeof(InventoryItemBase));
336 criteria.Add(Expression.Eq("Folder", folderID));
337 List<InventoryItemBase> list = new List<InventoryItemBase>();
338 foreach (InventoryItemBase item in criteria.List())
339 {
340 list.Add(item);
341 }
342 return list;
343// }
344// catch
345// {
346// return new List<InventoryItemBase>();
347// }
348 } 317 }
318 return list;
319 // }
320 // catch
321 // {
322 // return new List<InventoryItemBase>();
323 // }
349 } 324 }
350 325
351 public List<InventoryFolderBase> getUserRootFolders(LLUUID user) 326 public List<InventoryFolderBase> getUserRootFolders(LLUUID user)
@@ -356,18 +331,15 @@ namespace OpenSim.Data.NHibernate
356 // see InventoryItemBase.getUserRootFolder 331 // see InventoryItemBase.getUserRootFolder
357 public InventoryFolderBase getUserRootFolder(LLUUID user) 332 public InventoryFolderBase getUserRootFolder(LLUUID user)
358 { 333 {
359 using (ISession session = factory.OpenSession()) 334 ICriteria criteria = session.CreateCriteria(typeof(InventoryFolderBase));
335 criteria.Add(Expression.Eq("ParentID", LLUUID.Zero));
336 criteria.Add(Expression.Eq("Owner", user));
337 foreach (InventoryFolderBase folder in criteria.List())
360 { 338 {
361 ICriteria criteria = session.CreateCriteria(typeof(InventoryFolderBase)); 339 return folder;
362 criteria.Add(Expression.Eq("ParentID", LLUUID.Zero));
363 criteria.Add(Expression.Eq("Owner", user));
364 foreach (InventoryFolderBase folder in criteria.List())
365 {
366 return folder;
367 }
368 m_log.ErrorFormat("No Inventory Root Folder Found for: {0}", user);
369 return null;
370 } 340 }
341 m_log.ErrorFormat("No Inventory Root Folder Found for: {0}", user);
342 return null;
371 } 343 }
372 344
373 /// <summary> 345 /// <summary>
@@ -377,15 +349,11 @@ namespace OpenSim.Data.NHibernate
377 /// <param name="parentID">ID of parent</param> 349 /// <param name="parentID">ID of parent</param>
378 private void getInventoryFolders(ref List<InventoryFolderBase> folders, LLUUID parentID) 350 private void getInventoryFolders(ref List<InventoryFolderBase> folders, LLUUID parentID)
379 { 351 {
380 using (ISession session = factory.OpenSession()) 352 ICriteria criteria = session.CreateCriteria(typeof(InventoryFolderBase));
353 criteria.Add(Expression.Eq("ParentID", parentID));
354 foreach (InventoryFolderBase item in criteria.List())
381 { 355 {
382 356 folders.Add(item);
383 ICriteria criteria = session.CreateCriteria(typeof(InventoryFolderBase));
384 criteria.Add(Expression.Eq("ParentID", parentID));
385 foreach (InventoryFolderBase item in criteria.List())
386 {
387 folders.Add(item);
388 }
389 } 357 }
390 } 358 }
391 359