From: Michael D. <mik...@us...> - 2004-06-11 20:08:55
|
Update of /cvsroot/nhibernate/nhibernate/src/NHibernate.DomainModel/NHSpecific In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10969/NHSpecific Added Files: ClassWithNullColumns.cs ClassWithNullColumns.hbm.xml NullInt32UserType.cs Log Message: Added a quick test for UserTypes to save an Int32 as a null to the db. --- NEW FILE: NullInt32UserType.cs --- using System; using System.Data; using NHibernate; using NHibernate.SqlTypes; using NHibernate.Type; namespace NHibernate.DomainModel.NHSpecific { /// <summary> /// Converts a value of 0 to a DbNull /// </summary> public class NullInt32UserType : IUserType { private static NullableType _int32Type = NHibernate.Int32; public NullInt32UserType() { } #region IUserType Members public new bool Equals(object x, object y) { if(x==y) return true; int lhs = (x==null) ? 0 : (int)x; int rhs = (y==null) ? 0 : (int)y; return _int32Type.Equals(lhs, rhs); } public SqlType[] SqlTypes { get { return new SqlType[] { _int32Type.SqlType }; } } public System.Data.DbType[] DbTypes { get { return new DbType[] { _int32Type.SqlType.DbType }; } } public object DeepCopy(object value) { return value; } public void NullSafeSet(System.Data.IDbCommand cmd, object value, int index) { if(value.Equals(0)) { ( (IDbDataParameter)cmd.Parameters[index]).Value = DBNull.Value; } else { _int32Type.Set(cmd, value, index); } } public System.Type ReturnedType { get { return typeof(System.Int32); } } public object NullSafeGet(System.Data.IDataReader rs, string[] names, object owner) { return _int32Type.NullSafeGet(rs, names); } public bool IsMutable { get { return _int32Type.IsMutable; } } #endregion } } --- NEW FILE: ClassWithNullColumns.cs --- using System; namespace NHibernate.DomainModel.NHSpecific { /// <summary> /// Summary description for ClassWithNullColumns. /// </summary> public class ClassWithNullColumns { private int _id; private int _firstInt32; private int _secondInt32; public int Id { get { return _id; } set { _id = value; } } public int FirstInt32 { get { return _firstInt32; } set { _firstInt32 = value; } } public int SecondInt32 { get { return _secondInt32; } set { _secondInt32 = value; } } } } --- NEW FILE: ClassWithNullColumns.hbm.xml --- (This appears to be a binary file; contents omitted.) |