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.cs132
1 files changed, 91 insertions, 41 deletions
diff --git a/OpenSim/Data/NHibernate/NHibernateInventoryData.cs b/OpenSim/Data/NHibernate/NHibernateInventoryData.cs
index 6ee1b4a..8305646 100644
--- a/OpenSim/Data/NHibernate/NHibernateInventoryData.cs
+++ b/OpenSim/Data/NHibernate/NHibernateInventoryData.cs
@@ -57,7 +57,8 @@ namespace OpenSim.Data.NHibernate
57 // Split out the dialect, driver, and connect string 57 // Split out the dialect, driver, and connect string
58 char[] split = {';'}; 58 char[] split = {';'};
59 string[] parts = connect.Split(split, 3); 59 string[] parts = connect.Split(split, 3);
60 if (parts.Length != 3) { 60 if (parts.Length != 3)
61 {
61 // TODO: make this a real exception type 62 // TODO: make this a real exception type
62 throw new Exception("Malformed Inventory connection string '" + connect + "'"); 63 throw new Exception("Malformed Inventory connection string '" + connect + "'");
63 } 64 }
@@ -94,15 +95,22 @@ namespace OpenSim.Data.NHibernate
94 { 95 {
95 string regex = @"no such table: Inventory"; 96 string regex = @"no such table: Inventory";
96 Regex RE = new Regex(regex, RegexOptions.Multiline); 97 Regex RE = new Regex(regex, RegexOptions.Multiline);
97 try { 98 try
98 using (ISession session = factory.OpenSession()) { 99 {
100 using (ISession session = factory.OpenSession())
101 {
99 session.Load(typeof(InventoryItemBase), LLUUID.Zero); 102 session.Load(typeof(InventoryItemBase), LLUUID.Zero);
100 } 103 }
101 } catch (ObjectNotFoundException) { 104 }
105 catch (ObjectNotFoundException)
106 {
102 // yes, we know it's not there, but that's ok 107 // yes, we know it's not there, but that's ok
103 } catch (ADOException e) { 108 }
109 catch (ADOException e)
110 {
104 Match m = RE.Match(e.ToString()); 111 Match m = RE.Match(e.ToString());
105 if (m.Success) { 112 if (m.Success)
113 {
106 // We don't have this table, so create it. 114 // We don't have this table, so create it.
107 new SchemaExport(cfg).Create(true, true); 115 new SchemaExport(cfg).Create(true, true);
108 } 116 }
@@ -125,10 +133,14 @@ namespace OpenSim.Data.NHibernate
125 /// <returns>A class containing item information</returns> 133 /// <returns>A class containing item information</returns>
126 public InventoryItemBase getInventoryItem(LLUUID item) 134 public InventoryItemBase getInventoryItem(LLUUID item)
127 { 135 {
128 using (ISession session = factory.OpenSession()) { 136 using (ISession session = factory.OpenSession())
129 try { 137 {
138 try
139 {
130 return session.Load(typeof(InventoryItemBase), item) as InventoryItemBase; 140 return session.Load(typeof(InventoryItemBase), item) as InventoryItemBase;
131 } catch { 141 }
142 catch
143 {
132 m_log.ErrorFormat("Couldn't find inventory item: {0}", item); 144 m_log.ErrorFormat("Couldn't find inventory item: {0}", item);
133 return null; 145 return null;
134 } 146 }
@@ -141,14 +153,19 @@ namespace OpenSim.Data.NHibernate
141 /// <param name="item">The item to be created</param> 153 /// <param name="item">The item to be created</param>
142 public void addInventoryItem(InventoryItemBase item) 154 public void addInventoryItem(InventoryItemBase item)
143 { 155 {
144 if (!ExistsItem(item.ID)) { 156 if (!ExistsItem(item.ID))
145 using (ISession session = factory.OpenSession()) { 157 {
146 using (ITransaction transaction = session.BeginTransaction()) { 158 using (ISession session = factory.OpenSession())
159 {
160 using (ITransaction transaction = session.BeginTransaction())
161 {
147 session.Save(item); 162 session.Save(item);
148 transaction.Commit(); 163 transaction.Commit();
149 } 164 }
150 } 165 }
151 } else { 166 }
167 else
168 {
152 m_log.ErrorFormat("Attempted to add Inventory Item {0} that already exists, updating instead", item.ID); 169 m_log.ErrorFormat("Attempted to add Inventory Item {0} that already exists, updating instead", item.ID);
153 updateInventoryItem(item); 170 updateInventoryItem(item);
154 } 171 }
@@ -160,14 +177,19 @@ namespace OpenSim.Data.NHibernate
160 /// <param name="item">The updated item</param> 177 /// <param name="item">The updated item</param>
161 public void updateInventoryItem(InventoryItemBase item) 178 public void updateInventoryItem(InventoryItemBase item)
162 { 179 {
163 if (ExistsItem(item.ID)) { 180 if (ExistsItem(item.ID))
164 using (ISession session = factory.OpenSession()) { 181 {
165 using (ITransaction transaction = session.BeginTransaction()) { 182 using (ISession session = factory.OpenSession())
183 {
184 using (ITransaction transaction = session.BeginTransaction())
185 {
166 session.Update(item); 186 session.Update(item);
167 transaction.Commit(); 187 transaction.Commit();
168 } 188 }
169 } 189 }
170 } else { 190 }
191 else
192 {
171 m_log.ErrorFormat("Attempted to add Inventory Item {0} that already exists", item.ID); 193 m_log.ErrorFormat("Attempted to add Inventory Item {0} that already exists", item.ID);
172 } 194 }
173 } 195 }
@@ -178,15 +200,16 @@ namespace OpenSim.Data.NHibernate
178 /// <param name="item"></param> 200 /// <param name="item"></param>
179 public void deleteInventoryItem(LLUUID itemID) 201 public void deleteInventoryItem(LLUUID itemID)
180 { 202 {
181 using (ISession session = factory.OpenSession()) { 203 using (ISession session = factory.OpenSession())
182 using (ITransaction transaction = session.BeginTransaction()) { 204 {
205 using (ITransaction transaction = session.BeginTransaction())
206 {
183 session.Delete(itemID); 207 session.Delete(itemID);
184 transaction.Commit(); 208 transaction.Commit();
185 } 209 }
186 } 210 }
187 } 211 }
188 212
189
190 /// <summary> 213 /// <summary>
191 /// Returns an inventory folder by its UUID 214 /// Returns an inventory folder by its UUID
192 /// </summary> 215 /// </summary>
@@ -194,10 +217,14 @@ namespace OpenSim.Data.NHibernate
194 /// <returns>A class containing folder information</returns> 217 /// <returns>A class containing folder information</returns>
195 public InventoryFolderBase getInventoryFolder(LLUUID folder) 218 public InventoryFolderBase getInventoryFolder(LLUUID folder)
196 { 219 {
197 using (ISession session = factory.OpenSession()) { 220 using (ISession session = factory.OpenSession())
198 try { 221 {
222 try
223 {
199 return session.Load(typeof(InventoryFolderBase), folder) as InventoryFolderBase; 224 return session.Load(typeof(InventoryFolderBase), folder) as InventoryFolderBase;
200 } catch { 225 }
226 catch
227 {
201 m_log.ErrorFormat("Couldn't find inventory item: {0}", folder); 228 m_log.ErrorFormat("Couldn't find inventory item: {0}", folder);
202 return null; 229 return null;
203 } 230 }
@@ -210,14 +237,19 @@ namespace OpenSim.Data.NHibernate
210 /// <param name="folder">The folder to be created</param> 237 /// <param name="folder">The folder to be created</param>
211 public void addInventoryFolder(InventoryFolderBase folder) 238 public void addInventoryFolder(InventoryFolderBase folder)
212 { 239 {
213 if (!ExistsFolder(folder.ID)) { 240 if (!ExistsFolder(folder.ID))
214 using (ISession session = factory.OpenSession()) { 241 {
215 using (ITransaction transaction = session.BeginTransaction()) { 242 using (ISession session = factory.OpenSession())
243 {
244 using (ITransaction transaction = session.BeginTransaction())
245 {
216 session.Save(folder); 246 session.Save(folder);
217 transaction.Commit(); 247 transaction.Commit();
218 } 248 }
219 } 249 }
220 } else { 250 }
251 else
252 {
221 m_log.ErrorFormat("Attempted to add Inventory Folder {0} that already exists, updating instead", folder.ID); 253 m_log.ErrorFormat("Attempted to add Inventory Folder {0} that already exists, updating instead", folder.ID);
222 updateInventoryFolder(folder); 254 updateInventoryFolder(folder);
223 } 255 }
@@ -229,14 +261,19 @@ namespace OpenSim.Data.NHibernate
229 /// <param name="folder">The updated folder</param> 261 /// <param name="folder">The updated folder</param>
230 public void updateInventoryFolder(InventoryFolderBase folder) 262 public void updateInventoryFolder(InventoryFolderBase folder)
231 { 263 {
232 if (ExistsFolder(folder.ID)) { 264 if (ExistsFolder(folder.ID))
233 using (ISession session = factory.OpenSession()) { 265 {
234 using (ITransaction transaction = session.BeginTransaction()) { 266 using (ISession session = factory.OpenSession())
267 {
268 using (ITransaction transaction = session.BeginTransaction())
269 {
235 session.Update(folder); 270 session.Update(folder);
236 transaction.Commit(); 271 transaction.Commit();
237 } 272 }
238 } 273 }
239 } else { 274 }
275 else
276 {
240 m_log.ErrorFormat("Attempted to add Inventory Folder {0} that already exists", folder.ID); 277 m_log.ErrorFormat("Attempted to add Inventory Folder {0} that already exists", folder.ID);
241 } 278 }
242 } 279 }
@@ -247,8 +284,10 @@ namespace OpenSim.Data.NHibernate
247 /// <param name="folder"></param> 284 /// <param name="folder"></param>
248 public void deleteInventoryFolder(LLUUID folderID) 285 public void deleteInventoryFolder(LLUUID folderID)
249 { 286 {
250 using (ISession session = factory.OpenSession()) { 287 using (ISession session = factory.OpenSession())
251 using (ITransaction transaction = session.BeginTransaction()) { 288 {
289 using (ITransaction transaction = session.BeginTransaction())
290 {
252 session.Delete(folderID.ToString()); 291 session.Delete(folderID.ToString());
253 transaction.Commit(); 292 transaction.Commit();
254 } 293 }
@@ -324,7 +363,8 @@ namespace OpenSim.Data.NHibernate
324 /// <returns>A List of InventoryItemBase items</returns> 363 /// <returns>A List of InventoryItemBase items</returns>
325 public List<InventoryItemBase> getInventoryInFolder(LLUUID folderID) 364 public List<InventoryItemBase> getInventoryInFolder(LLUUID folderID)
326 { 365 {
327 using (ISession session = factory.OpenSession()) { 366 using (ISession session = factory.OpenSession())
367 {
328 // try { 368 // try {
329 ICriteria criteria = session.CreateCriteria(typeof(InventoryItemBase)); 369 ICriteria criteria = session.CreateCriteria(typeof(InventoryItemBase));
330 criteria.Add(Expression.Eq("Folder", folderID)); 370 criteria.Add(Expression.Eq("Folder", folderID));
@@ -334,7 +374,9 @@ namespace OpenSim.Data.NHibernate
334 list.Add(item); 374 list.Add(item);
335 } 375 }
336 return list; 376 return list;
337// } catch { 377// }
378// catch
379// {
338// return new List<InventoryItemBase>(); 380// return new List<InventoryItemBase>();
339// } 381// }
340 } 382 }
@@ -348,8 +390,10 @@ namespace OpenSim.Data.NHibernate
348 // see InventoryItemBase.getUserRootFolder 390 // see InventoryItemBase.getUserRootFolder
349 public InventoryFolderBase getUserRootFolder(LLUUID user) 391 public InventoryFolderBase getUserRootFolder(LLUUID user)
350 { 392 {
351 using (ISession session = factory.OpenSession()) { 393 using (ISession session = factory.OpenSession())
352 // try { 394 {
395 // try
396 // {
353 ICriteria criteria = session.CreateCriteria(typeof(InventoryFolderBase)); 397 ICriteria criteria = session.CreateCriteria(typeof(InventoryFolderBase));
354 criteria.Add(Expression.Eq("ParentID", LLUUID.Zero)); 398 criteria.Add(Expression.Eq("ParentID", LLUUID.Zero));
355 criteria.Add(Expression.Eq("Owner", user)); 399 criteria.Add(Expression.Eq("Owner", user));
@@ -359,7 +403,9 @@ namespace OpenSim.Data.NHibernate
359 } 403 }
360 m_log.ErrorFormat("No Inventory Root Folder Found for: {0}", user); 404 m_log.ErrorFormat("No Inventory Root Folder Found for: {0}", user);
361 return new InventoryFolderBase(); 405 return new InventoryFolderBase();
362// } catch { 406// }
407// catch
408// {
363// return new InventoryFolderBase(); 409// return new InventoryFolderBase();
364// } 410// }
365 } 411 }
@@ -372,15 +418,19 @@ namespace OpenSim.Data.NHibernate
372 /// <param name="parentID">ID of parent</param> 418 /// <param name="parentID">ID of parent</param>
373 private void getInventoryFolders(ref List<InventoryFolderBase> folders, LLUUID parentID) 419 private void getInventoryFolders(ref List<InventoryFolderBase> folders, LLUUID parentID)
374 { 420 {
375 using (ISession session = factory.OpenSession()) { 421 using (ISession session = factory.OpenSession())
376 // try { 422 {
423 // try
424// {
377 ICriteria criteria = session.CreateCriteria(typeof(InventoryFolderBase)); 425 ICriteria criteria = session.CreateCriteria(typeof(InventoryFolderBase));
378 criteria.Add(Expression.Eq("ParentID", parentID)); 426 criteria.Add(Expression.Eq("ParentID", parentID));
379 foreach (InventoryFolderBase item in criteria.List()) 427 foreach (InventoryFolderBase item in criteria.List())
380 { 428 {
381 folders.Add(item); 429 folders.Add(item);
382 } 430 }
383 // } catch { 431 // }
432 // catch
433 // {
384 // m_log.ErrorFormat("Can't run getInventoryFolders for Folder ID: {0}", parentID); 434 // m_log.ErrorFormat("Can't run getInventoryFolders for Folder ID: {0}", parentID);
385 // } 435 // }
386 } 436 }