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/NHibernateAssetData.cs | 48 +++++--- OpenSim/Data/NHibernate/NHibernateInventoryData.cs | 132 ++++++++++++++------- OpenSim/Data/NHibernate/NHibernateUserData.cs | 107 +++++++++++------ 3 files changed, 196 insertions(+), 91 deletions(-) (limited to 'OpenSim/Data') diff --git a/OpenSim/Data/NHibernate/NHibernateAssetData.cs b/OpenSim/Data/NHibernate/NHibernateAssetData.cs index 875f4e5..4eb9eef 100644 --- a/OpenSim/Data/NHibernate/NHibernateAssetData.cs +++ b/OpenSim/Data/NHibernate/NHibernateAssetData.cs @@ -60,7 +60,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 + "'"); } @@ -96,15 +97,22 @@ namespace OpenSim.Data.NHibernate { string regex = @"no such table: Assets"; Regex RE = new Regex(regex, RegexOptions.Multiline); - try { - using (ISession session = factory.OpenSession()) { + try + { + using (ISession session = factory.OpenSession()) + { session.Load(typeof(AssetBase), 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); } @@ -113,10 +121,14 @@ namespace OpenSim.Data.NHibernate override public AssetBase FetchAsset(LLUUID uuid) { - using (ISession session = factory.OpenSession()) { - try { + using (ISession session = factory.OpenSession()) + { + try + { return session.Load(typeof(AssetBase), uuid) as AssetBase; - } catch { + } + catch + { return null; } } @@ -124,9 +136,12 @@ namespace OpenSim.Data.NHibernate override public void CreateAsset(AssetBase asset) { - if (!ExistsAsset(asset.FullID)) { - using (ISession session = factory.OpenSession()) { - using (ITransaction transaction = session.BeginTransaction()) { + if (!ExistsAsset(asset.FullID)) + { + using (ISession session = factory.OpenSession()) + { + using (ITransaction transaction = session.BeginTransaction()) + { session.Save(asset); transaction.Commit(); } @@ -136,9 +151,12 @@ namespace OpenSim.Data.NHibernate override public void UpdateAsset(AssetBase asset) { - if (ExistsAsset(asset.FullID)) { - using (ISession session = factory.OpenSession()) { - using (ITransaction transaction = session.BeginTransaction()) { + if (ExistsAsset(asset.FullID)) + { + using (ISession session = factory.OpenSession()) + { + using (ITransaction transaction = session.BeginTransaction()) + { session.Update(asset); transaction.Commit(); } 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); // } } diff --git a/OpenSim/Data/NHibernate/NHibernateUserData.cs b/OpenSim/Data/NHibernate/NHibernateUserData.cs index 2c84ef9..43d8c32 100644 --- a/OpenSim/Data/NHibernate/NHibernateUserData.cs +++ b/OpenSim/Data/NHibernate/NHibernateUserData.cs @@ -56,7 +56,8 @@ namespace OpenSim.Data.NHibernate { 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 + "'"); } @@ -87,15 +88,22 @@ namespace OpenSim.Data.NHibernate { string regex = @"no such table: UserProfiles"; Regex RE = new Regex(regex, RegexOptions.Multiline); - try { - using (ISession session = factory.OpenSession()) { + try + { + using (ISession session = factory.OpenSession()) + { session.Load(typeof(UserProfileData), 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); } @@ -105,12 +113,15 @@ namespace OpenSim.Data.NHibernate private bool ExistsUser(LLUUID uuid) { UserProfileData user = null; - try { - using (ISession session = factory.OpenSession()) { + try + { + using (ISession session = factory.OpenSession()) + { user = session.Load(typeof(UserProfileData), uuid) as UserProfileData; } // BUG: CATCHALL IS BAD. - } catch (Exception) {} + } + catch (Exception) {} return (user != null); } @@ -119,7 +130,8 @@ namespace OpenSim.Data.NHibernate { UserProfileData user; // TODO: I'm sure I'll have to do something silly here - using (ISession session = factory.OpenSession()) { + using (ISession session = factory.OpenSession()) + { user = session.Load(typeof(UserProfileData), uuid) as UserProfileData; user.CurrentAgent = GetAgentByUUID(uuid); } @@ -128,16 +140,21 @@ namespace OpenSim.Data.NHibernate override public void AddNewUserProfile(UserProfileData profile) { - if (!ExistsUser(profile.ID)) { - using (ISession session = factory.OpenSession()) { - using (ITransaction transaction = session.BeginTransaction()) { + if (!ExistsUser(profile.ID)) + { + using (ISession session = factory.OpenSession()) + { + using (ITransaction transaction = session.BeginTransaction()) + { session.Save(profile); SetAgentData(profile.ID, profile.CurrentAgent, session); // TODO: save agent transaction.Commit(); } } - } else { + } + else + { m_log.ErrorFormat("Attempted to add User {0} {1} that already exists, updating instead", profile.FirstName, profile.SurName); UpdateUserProfile(profile); } @@ -165,16 +182,21 @@ namespace OpenSim.Data.NHibernate } override public bool UpdateUserProfile(UserProfileData profile) { - if (ExistsUser(profile.ID)) { - using (ISession session = factory.OpenSession()) { - using (ITransaction transaction = session.BeginTransaction()) { + if (ExistsUser(profile.ID)) + { + using (ISession session = factory.OpenSession()) + { + using (ITransaction transaction = session.BeginTransaction()) + { session.Update(profile); SetAgentData(profile.ID, profile.CurrentAgent, session); transaction.Commit(); return true; } } - } else { + } + else + { m_log.ErrorFormat("Attempted to update User {0} {1} that doesn't exist, updating instead", profile.FirstName, profile.SurName); AddNewUserProfile(profile); return true; @@ -183,8 +205,10 @@ namespace OpenSim.Data.NHibernate override public void AddNewUserAgent(UserAgentData agent) { - using (ISession session = factory.OpenSession()) { - using (ITransaction transaction = session.BeginTransaction()) { + using (ISession session = factory.OpenSession()) + { + using (ITransaction transaction = session.BeginTransaction()) + { session.Save(agent); transaction.Commit(); } @@ -193,30 +217,35 @@ namespace OpenSim.Data.NHibernate public void UpdateUserAgent(UserAgentData agent) { - using (ISession session = factory.OpenSession()) { - using (ITransaction transaction = session.BeginTransaction()) { + using (ISession session = factory.OpenSession()) + { + using (ITransaction transaction = session.BeginTransaction()) + { session.Update(agent); transaction.Commit(); } } } - - override public UserAgentData GetAgentByUUID(LLUUID uuid) { - try { - using (ISession session = factory.OpenSession()) { + try + { + using (ISession session = factory.OpenSession()) + { return session.Load(typeof(UserAgentData), uuid) as UserAgentData; } - } catch { + } + catch + { return null; } } override public UserProfileData GetUserByName(string fname, string lname) { - using (ISession session = factory.OpenSession()) { + using (ISession session = factory.OpenSession()) + { ICriteria criteria = session.CreateCriteria(typeof(UserProfileData)); criteria.Add(Expression.Eq("FirstName", fname)); criteria.Add(Expression.Eq("SurName", lname)); @@ -247,7 +276,8 @@ namespace OpenSim.Data.NHibernate if (querysplit.Length == 2) { - using (ISession session = factory.OpenSession()) { + using (ISession session = factory.OpenSession()) + { ICriteria criteria = session.CreateCriteria(typeof(UserProfileData)); criteria.Add(Expression.Like("FirstName", querysplit[0])); criteria.Add(Expression.Like("SurName", querysplit[1])); @@ -280,7 +310,8 @@ namespace OpenSim.Data.NHibernate { UserAppearance appearance; // TODO: I'm sure I'll have to do something silly here - using (ISession session = factory.OpenSession()) { + using (ISession session = factory.OpenSession()) + { appearance = session.Load(typeof(UserAppearance), user) as UserAppearance; } return appearance; @@ -289,7 +320,8 @@ namespace OpenSim.Data.NHibernate private bool ExistsAppearance(LLUUID uuid) { UserAppearance appearance; - using (ISession session = factory.OpenSession()) { + using (ISession session = factory.OpenSession()) + { appearance = session.Load(typeof(UserAppearance), uuid) as UserAppearance; } return (appearance == null) ? false : true; @@ -299,11 +331,16 @@ namespace OpenSim.Data.NHibernate override public void UpdateUserAppearance(LLUUID user, UserAppearance appearance) { bool exists = ExistsAppearance(user); - using (ISession session = factory.OpenSession()) { - using (ITransaction transaction = session.BeginTransaction()) { - if (exists) { + using (ISession session = factory.OpenSession()) + { + using (ITransaction transaction = session.BeginTransaction()) + { + if (exists) + { session.Update(appearance); - } else { + } + else + { session.Save(appearance); } transaction.Commit(); -- cgit v1.1