From b7a0855c3afea27f207655fca25651b19b41636a Mon Sep 17 00:00:00 2001
From: Jeff Ames
Date: Wed, 14 May 2008 06:09:39 +0000
Subject: More formatting cleanup. Minor refactoring.
---
OpenSim/Data/NHibernate/NHibernateInventoryData.cs | 132 ++++++++++++++-------
1 file changed, 91 insertions(+), 41 deletions(-)
(limited to 'OpenSim/Data/NHibernate/NHibernateInventoryData.cs')
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
// Split out the dialect, driver, and connect string
char[] split = {';'};
string[] parts = connect.Split(split, 3);
- if (parts.Length != 3) {
+ if (parts.Length != 3)
+ {
// TODO: make this a real exception type
throw new Exception("Malformed Inventory connection string '" + connect + "'");
}
@@ -94,15 +95,22 @@ namespace OpenSim.Data.NHibernate
{
string regex = @"no such table: Inventory";
Regex RE = new Regex(regex, RegexOptions.Multiline);
- try {
- using (ISession session = factory.OpenSession()) {
+ try
+ {
+ using (ISession session = factory.OpenSession())
+ {
session.Load(typeof(InventoryItemBase), LLUUID.Zero);
}
- } catch (ObjectNotFoundException) {
+ }
+ catch (ObjectNotFoundException)
+ {
// yes, we know it's not there, but that's ok
- } catch (ADOException e) {
+ }
+ catch (ADOException e)
+ {
Match m = RE.Match(e.ToString());
- if (m.Success) {
+ if (m.Success)
+ {
// We don't have this table, so create it.
new SchemaExport(cfg).Create(true, true);
}
@@ -125,10 +133,14 @@ namespace OpenSim.Data.NHibernate
/// A class containing item information
public InventoryItemBase getInventoryItem(LLUUID item)
{
- using (ISession session = factory.OpenSession()) {
- try {
+ using (ISession session = factory.OpenSession())
+ {
+ try
+ {
return session.Load(typeof(InventoryItemBase), item) as InventoryItemBase;
- } catch {
+ }
+ catch
+ {
m_log.ErrorFormat("Couldn't find inventory item: {0}", item);
return null;
}
@@ -141,14 +153,19 @@ namespace OpenSim.Data.NHibernate
/// The item to be created
public void addInventoryItem(InventoryItemBase item)
{
- if (!ExistsItem(item.ID)) {
- using (ISession session = factory.OpenSession()) {
- using (ITransaction transaction = session.BeginTransaction()) {
+ if (!ExistsItem(item.ID))
+ {
+ using (ISession session = factory.OpenSession())
+ {
+ using (ITransaction transaction = session.BeginTransaction())
+ {
session.Save(item);
transaction.Commit();
}
}
- } else {
+ }
+ else
+ {
m_log.ErrorFormat("Attempted to add Inventory Item {0} that already exists, updating instead", item.ID);
updateInventoryItem(item);
}
@@ -160,14 +177,19 @@ namespace OpenSim.Data.NHibernate
/// The updated item
public void updateInventoryItem(InventoryItemBase item)
{
- if (ExistsItem(item.ID)) {
- using (ISession session = factory.OpenSession()) {
- using (ITransaction transaction = session.BeginTransaction()) {
+ if (ExistsItem(item.ID))
+ {
+ using (ISession session = factory.OpenSession())
+ {
+ using (ITransaction transaction = session.BeginTransaction())
+ {
session.Update(item);
transaction.Commit();
}
}
- } else {
+ }
+ else
+ {
m_log.ErrorFormat("Attempted to add Inventory Item {0} that already exists", item.ID);
}
}
@@ -178,15 +200,16 @@ namespace OpenSim.Data.NHibernate
///
public void deleteInventoryItem(LLUUID itemID)
{
- using (ISession session = factory.OpenSession()) {
- using (ITransaction transaction = session.BeginTransaction()) {
+ using (ISession session = factory.OpenSession())
+ {
+ using (ITransaction transaction = session.BeginTransaction())
+ {
session.Delete(itemID);
transaction.Commit();
}
}
}
-
///
/// Returns an inventory folder by its UUID
///
@@ -194,10 +217,14 @@ namespace OpenSim.Data.NHibernate
/// A class containing folder information
public InventoryFolderBase getInventoryFolder(LLUUID folder)
{
- using (ISession session = factory.OpenSession()) {
- try {
+ using (ISession session = factory.OpenSession())
+ {
+ try
+ {
return session.Load(typeof(InventoryFolderBase), folder) as InventoryFolderBase;
- } catch {
+ }
+ catch
+ {
m_log.ErrorFormat("Couldn't find inventory item: {0}", folder);
return null;
}
@@ -210,14 +237,19 @@ namespace OpenSim.Data.NHibernate
/// The folder to be created
public void addInventoryFolder(InventoryFolderBase folder)
{
- if (!ExistsFolder(folder.ID)) {
- using (ISession session = factory.OpenSession()) {
- using (ITransaction transaction = session.BeginTransaction()) {
+ if (!ExistsFolder(folder.ID))
+ {
+ using (ISession session = factory.OpenSession())
+ {
+ using (ITransaction transaction = session.BeginTransaction())
+ {
session.Save(folder);
transaction.Commit();
}
}
- } else {
+ }
+ else
+ {
m_log.ErrorFormat("Attempted to add Inventory Folder {0} that already exists, updating instead", folder.ID);
updateInventoryFolder(folder);
}
@@ -229,14 +261,19 @@ namespace OpenSim.Data.NHibernate
/// The updated folder
public void updateInventoryFolder(InventoryFolderBase folder)
{
- if (ExistsFolder(folder.ID)) {
- using (ISession session = factory.OpenSession()) {
- using (ITransaction transaction = session.BeginTransaction()) {
+ if (ExistsFolder(folder.ID))
+ {
+ using (ISession session = factory.OpenSession())
+ {
+ using (ITransaction transaction = session.BeginTransaction())
+ {
session.Update(folder);
transaction.Commit();
}
}
- } else {
+ }
+ else
+ {
m_log.ErrorFormat("Attempted to add Inventory Folder {0} that already exists", folder.ID);
}
}
@@ -247,8 +284,10 @@ namespace OpenSim.Data.NHibernate
///
public void deleteInventoryFolder(LLUUID folderID)
{
- using (ISession session = factory.OpenSession()) {
- using (ITransaction transaction = session.BeginTransaction()) {
+ using (ISession session = factory.OpenSession())
+ {
+ using (ITransaction transaction = session.BeginTransaction())
+ {
session.Delete(folderID.ToString());
transaction.Commit();
}
@@ -324,7 +363,8 @@ namespace OpenSim.Data.NHibernate
/// A List of InventoryItemBase items
public List getInventoryInFolder(LLUUID folderID)
{
- using (ISession session = factory.OpenSession()) {
+ using (ISession session = factory.OpenSession())
+ {
// try {
ICriteria criteria = session.CreateCriteria(typeof(InventoryItemBase));
criteria.Add(Expression.Eq("Folder", folderID));
@@ -334,7 +374,9 @@ namespace OpenSim.Data.NHibernate
list.Add(item);
}
return list;
-// } catch {
+// }
+// catch
+// {
// return new List();
// }
}
@@ -348,8 +390,10 @@ namespace OpenSim.Data.NHibernate
// see InventoryItemBase.getUserRootFolder
public InventoryFolderBase getUserRootFolder(LLUUID user)
{
- using (ISession session = factory.OpenSession()) {
- // try {
+ using (ISession session = factory.OpenSession())
+ {
+ // try
+ // {
ICriteria criteria = session.CreateCriteria(typeof(InventoryFolderBase));
criteria.Add(Expression.Eq("ParentID", LLUUID.Zero));
criteria.Add(Expression.Eq("Owner", user));
@@ -359,7 +403,9 @@ namespace OpenSim.Data.NHibernate
}
m_log.ErrorFormat("No Inventory Root Folder Found for: {0}", user);
return new InventoryFolderBase();
-// } catch {
+// }
+// catch
+// {
// return new InventoryFolderBase();
// }
}
@@ -372,15 +418,19 @@ namespace OpenSim.Data.NHibernate
/// ID of parent
private void getInventoryFolders(ref List folders, LLUUID parentID)
{
- using (ISession session = factory.OpenSession()) {
- // try {
+ using (ISession session = factory.OpenSession())
+ {
+ // try
+// {
ICriteria criteria = session.CreateCriteria(typeof(InventoryFolderBase));
criteria.Add(Expression.Eq("ParentID", parentID));
foreach (InventoryFolderBase item in criteria.List())
{
folders.Add(item);
}
- // } catch {
+ // }
+ // catch
+ // {
// m_log.ErrorFormat("Can't run getInventoryFolders for Folder ID: {0}", parentID);
// }
}
--
cgit v1.1