From 750291447ea53f35f277ad9e79c09c77c8471b4d Mon Sep 17 00:00:00 2001 From: Sean Dague Date: Wed, 9 Apr 2008 13:43:35 +0000 Subject: changing around types a bit to make stuff more readable for me. --- OpenSim/Data/NHibernate/NHibernateInventoryData.cs | 64 +++++++++++----------- .../Data/NHibernate/Resources/AssetBase.hbm.xml | 2 +- .../Resources/InventoryFolderBase.hbm.xml | 6 +- .../NHibernate/Resources/InventoryItemBase.hbm.xml | 10 ++-- OpenSim/Data/NHibernate/Types/LLUUIDType.cs | 12 ++-- 5 files changed, 48 insertions(+), 46 deletions(-) diff --git a/OpenSim/Data/NHibernate/NHibernateInventoryData.cs b/OpenSim/Data/NHibernate/NHibernateInventoryData.cs index 8bc41c9..8043348 100644 --- a/OpenSim/Data/NHibernate/NHibernateInventoryData.cs +++ b/OpenSim/Data/NHibernate/NHibernateInventoryData.cs @@ -99,8 +99,9 @@ namespace OpenSim.Data.NHibernate { using(ISession session = factory.OpenSession()) { try { - return session.Load(typeof(InventoryItemBase), item.ToString()) as InventoryItemBase; + return session.Load(typeof(InventoryItemBase), item) as InventoryItemBase; } catch { + m_log.ErrorFormat("Couldn't find inventory item: {0}", item); return null; } } @@ -151,7 +152,7 @@ namespace OpenSim.Data.NHibernate { using(ISession session = factory.OpenSession()) { using(ITransaction transaction = session.BeginTransaction()) { - session.Delete(itemID.ToString()); + session.Delete(itemID); transaction.Commit(); } } @@ -167,8 +168,9 @@ namespace OpenSim.Data.NHibernate { using(ISession session = factory.OpenSession()) { try { - return session.Load(typeof(InventoryFolderBase), folder.ToString()) as InventoryFolderBase; + return session.Load(typeof(InventoryFolderBase), folder) as InventoryFolderBase; } catch { + m_log.ErrorFormat("Couldn't find inventory item: {0}", folder); return null; } } @@ -296,8 +298,8 @@ namespace OpenSim.Data.NHibernate { using(ISession session = factory.OpenSession()) { try { - IQuery query = session.CreateQuery("from InventoryItems i where i.parentFolderID = :parent"); - query.SetString("parent", folderID.ToString()); + IQuery query = session.CreateQuery("from InventoryItems i where i.Folder = :folder"); + query.SetString("folder", folderID.ToString()); List list = new List(); foreach (InventoryItemBase item in query.List()) { @@ -318,21 +320,21 @@ namespace OpenSim.Data.NHibernate // see InventoryItemBase.getUserRootFolder public InventoryFolderBase getUserRootFolder(LLUUID user) { -// using(ISession session = factory.OpenSession()) { -// try { -// IQuery query = session.CreateQuery("from InventoryItems i where i.parentFolderID = :parent"); -// query.SetString("parent", folderID.ToString()); -// List list = new List(); -// foreach (InventoryItemBase item in query.List()) -// { -// list.Add(item); -// } -// return list; -// } catch { -// return new List(); -// } -// } - return new InventoryFolderBase(); + using(ISession session = factory.OpenSession()) { + try { + IQuery query = session.CreateQuery("from InventoryFolders i where i.ParentID = :parent and i.Owner = :owner"); + query.SetParameter("parent", LLUUID.Zero, NHibernateUtil.Custom(typeof(LLUUIDUserType))); + query.SetParameter("owner", user, NHibernateUtil.Custom(typeof(LLUUIDUserType))); + foreach (InventoryFolderBase folder in query.List()) + { + return folder; + } + m_log.ErrorFormat("No Inventory Root Folder Found for: {0}", user); + return new InventoryFolderBase(); + } catch { + return new InventoryFolderBase(); + } + } } /// @@ -340,19 +342,19 @@ namespace OpenSim.Data.NHibernate /// /// list where folders will be appended /// ID of parent - protected void getInventoryFolders(ref List folders, LLUUID parentID) + private void getInventoryFolders(ref List folders, LLUUID parentID) { using(ISession session = factory.OpenSession()) { - try { - IQuery query = session.CreateQuery("from InventoryFolders i where i.parentFolderID = :parent"); - query.SetString("parent", parentID.ToString()); + // try { + IQuery query = session.CreateQuery("from InventoryFolders i where i.ParentID = :parent"); + query.SetParameter("parent", parentID, NHibernateUtil.Custom(typeof(LLUUIDUserType))); foreach (InventoryFolderBase item in query.List()) { folders.Add(item); } - } catch { - - } + // } catch { + // m_log.ErrorFormat("Can't run getInventoryFolders for Folder ID: {0}", parentID); + // } } } @@ -364,7 +366,7 @@ namespace OpenSim.Data.NHibernate public List getInventoryFolders(LLUUID parentID) { List folders = new List(); - getInventoryFolders(ref folders, Util.ToRawUuidString(parentID)); + getInventoryFolders(ref folders, parentID); return folders; } @@ -372,11 +374,11 @@ namespace OpenSim.Data.NHibernate public List getFolderHierarchy(LLUUID parentID) { List folders = new List(); - getInventoryFolders(ref folders, Util.ToRawUuidString(parentID)); + getInventoryFolders(ref folders, parentID); for (int i = 0; i < folders.Count; i++) - getInventoryFolders(ref folders, Util.ToRawUuidString(folders[i].ID)); - + getInventoryFolders(ref folders, folders[i].ID); + return folders; } } diff --git a/OpenSim/Data/NHibernate/Resources/AssetBase.hbm.xml b/OpenSim/Data/NHibernate/Resources/AssetBase.hbm.xml index 086fbc1..3c94d92 100644 --- a/OpenSim/Data/NHibernate/Resources/AssetBase.hbm.xml +++ b/OpenSim/Data/NHibernate/Resources/AssetBase.hbm.xml @@ -1,7 +1,7 @@ - + diff --git a/OpenSim/Data/NHibernate/Resources/InventoryFolderBase.hbm.xml b/OpenSim/Data/NHibernate/Resources/InventoryFolderBase.hbm.xml index 4de0b7c..71a6602 100644 --- a/OpenSim/Data/NHibernate/Resources/InventoryFolderBase.hbm.xml +++ b/OpenSim/Data/NHibernate/Resources/InventoryFolderBase.hbm.xml @@ -1,13 +1,13 @@ - + - - + + \ No newline at end of file diff --git a/OpenSim/Data/NHibernate/Resources/InventoryItemBase.hbm.xml b/OpenSim/Data/NHibernate/Resources/InventoryItemBase.hbm.xml index c4e9b01..851f5fc 100644 --- a/OpenSim/Data/NHibernate/Resources/InventoryItemBase.hbm.xml +++ b/OpenSim/Data/NHibernate/Resources/InventoryItemBase.hbm.xml @@ -1,15 +1,15 @@ - + - - - - + + + + diff --git a/OpenSim/Data/NHibernate/Types/LLUUIDType.cs b/OpenSim/Data/NHibernate/Types/LLUUIDType.cs index b8e5739..babc7fd 100644 --- a/OpenSim/Data/NHibernate/Types/LLUUIDType.cs +++ b/OpenSim/Data/NHibernate/Types/LLUUIDType.cs @@ -1,5 +1,6 @@ using System; using System.Data; +using NHibernate; using NHibernate.SqlTypes; using NHibernate.UserTypes; using libsecondlife; @@ -7,14 +8,14 @@ using libsecondlife; namespace OpenSim.Data.NHibernate { [Serializable] - public class LLUUIDString : IUserType + public class LLUUIDUserType: IUserType { public object Assemble(object cached, object owner) { return cached; } - bool IUserType.Equals(object uuid1, object uuid2) + public bool IUserType.Equals(object uuid1, object uuid2) { return uuid1.Equals(uuid2); } @@ -55,9 +56,8 @@ namespace OpenSim.Data.NHibernate public void NullSafeSet(System.Data.IDbCommand cmd, object obj, int index) { - LLUUID UUID = (LLUUID)obj; - ((IDataParameter)cmd.Parameters[index]).Value = UUID.ToString(); - System.Console.WriteLine("Setting UUID {0}", UUID.ToString()); + LLUUID uuid = (LLUUID)obj; + ((IDataParameter)cmd.Parameters[index]).Value = uuid.ToString(); } public object Replace(object original, object target, object owner) @@ -72,7 +72,7 @@ namespace OpenSim.Data.NHibernate public SqlType[] SqlTypes { - get { return new SqlType [] { SqlTypeFactory.GetString(32) }; } + get { return new SqlType [] { NHibernateUtil.String.SqlType }; } } } } -- cgit v1.1