From 32b8dd70d69e500e38c4bd7ae146a36767061979 Mon Sep 17 00:00:00 2001 From: Sean Dague Date: Tue, 8 Apr 2008 02:50:44 +0000 Subject: attempt to introduce custom LLUUIDString type for NHibernate --- .../Data/NHibernate/Resources/AssetBase.hbm.xml | 2 +- OpenSim/Data/NHibernate/Types/LLUUIDType.cs | 78 ++++++++++++++++++++++ 2 files changed, 79 insertions(+), 1 deletion(-) create mode 100644 OpenSim/Data/NHibernate/Types/LLUUIDType.cs (limited to 'OpenSim/Data/NHibernate') diff --git a/OpenSim/Data/NHibernate/Resources/AssetBase.hbm.xml b/OpenSim/Data/NHibernate/Resources/AssetBase.hbm.xml index bf2cda7..71f498c 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/Types/LLUUIDType.cs b/OpenSim/Data/NHibernate/Types/LLUUIDType.cs new file mode 100644 index 0000000..21d3774 --- /dev/null +++ b/OpenSim/Data/NHibernate/Types/LLUUIDType.cs @@ -0,0 +1,78 @@ +using System; +using System.Data; +using NHibernate.SqlTypes; +using NHibernate.UserTypes; +using libsecondlife; + +namespace OpenSim.Data.NHibernate +{ + [Serializable] + public class LLUUIDString : IUserType + { + public object Assemble(object cached, object owner) + { + return cached; + } + + bool IUserType.Equals(object uuid1, object uuid2) + { + return uuid1.Equals(uuid2); + } + + public object DeepCopy(object uuid) + { + return uuid; + } + + public object Disassemble(object uuid) + { + return uuid; + } + + public int GetHashCode(object uuid) + { + return (uuid == null) ? 0 : uuid.GetHashCode(); + } + + public bool IsMutable + { + get { return false; } + } + + public object NullSafeGet(System.Data.IDataReader rs, string[] names, object owner) + { + object uuid = null; + + int ord = rs.GetOrdinal(names[0]); + if (!rs.IsDBNull(ord)) + { + string first = (string)rs.GetString(ord); + uuid = new LLUUID(first); + } + + return uuid; + } + + public void NullSafeSet(System.Data.IDbCommand cmd, object obj, int index) + { + LLUUID UUID = (LLUUID)obj; + ((IDataParameter)cmd.Parameters[index]).Value = UUID.ToString(); + } + + public object Replace(object original, object target, object owner) + { + return original; + } + + public Type ReturnedType + { + get { return typeof(LLUUID); } + } + + public SqlType[] SqlTypes + { + // I think we're up to 36 + get { return new SqlType [] { SqlTypeFactory.GetString(36) }; } + } + } +} -- cgit v1.1