attempt to introduce custom LLUUIDString type for

NHibernate
0.6.0-stable
Sean Dague 2008-04-08 02:50:44 +00:00
parent d0f7784101
commit 32b8dd70d6
2 changed files with 79 additions and 1 deletions

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<class name="OpenSim.Framework.AssetBase, OpenSim.Framework" table="Assets" lazy="false">
<id name="ID" column="UUID" type="String" length="40" >
<id name="FullID" column="UUID" type="OpenSim.Data.NHibernate.LLUUIDString">
<generator class="assigned" />
</id>
<property name="Type" type="SByte" />

View File

@ -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) }; }
}
}
}