From: Kevin W. <kev...@us...> - 2004-12-31 23:55:11
|
Update of /cvsroot/nhibernate/nhibernate/src/NHibernate/Type In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24613 Modified Files: ObjectType.cs OneToOneType.cs PersistentCollectionType.cs PersistentEnumType.cs SByteType.cs Log Message: fixing xml comments and letting ReSharper do reformatting Index: PersistentCollectionType.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate/Type/PersistentCollectionType.cs,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** PersistentCollectionType.cs 22 Nov 2004 03:56:08 -0000 1.16 --- PersistentCollectionType.cs 31 Dec 2004 23:54:56 -0000 1.17 *************** *** 1,106 **** - using System; using System.Collections; using System.Data; - using NHibernate.Collection; using NHibernate.Engine; using NHibernate.SqlTypes; ! namespace NHibernate.Type { /// <summary> /// PersistentCollectionType. /// </summary> ! public abstract class PersistentCollectionType : AbstractType, IAssociationType { - private readonly string role; ! private static readonly SqlType[] NoSqlTypes = {}; ! protected PersistentCollectionType(string role) { this.role = role; } ! public virtual string Role { get { return role; } } ! public override bool IsPersistentCollectionType { get { return true; } } ! public override sealed bool Equals(object x, object y) { ! // proxies? - comment in h2.0.3 also ! return x==y; } ! public abstract PersistentCollection Instantiate(ISessionImplementor session, CollectionPersister persister); ! public override object NullSafeGet(IDataReader rs, string name, ISessionImplementor session, object owner) { ! throw new AssertionFailure("bug in PersistentCollectionType"); } ! ! public override object NullSafeGet(IDataReader rs, string[] name, ISessionImplementor session, object owner) { ! return ResolveIdentifier( Hydrate(rs, name, session, owner), session, owner ); } ! public override void NullSafeSet(IDbCommand cmd, object value, int index, ISessionImplementor session) { } ! public virtual object GetCollection(object id, object owner, ISessionImplementor session) { // added the owner PersistentCollection collection = session.GetLoadingCollection( role, id ); ! if(collection!=null) return collection.GetCachedValue(); //TODO: yuck... call another method - H2.0.3comment ! CollectionPersister persister = session.Factory.GetCollectionPersister(role); ! collection = persister.GetCachedCollection(id, owner, session); ! if(collection!=null) { ! session.AddInitializedCollection(collection, persister, id); return collection.GetCachedValue(); } ! else { ! collection = Instantiate(session, persister); ! session.AddUninitializedCollection(collection, persister, id); ! return collection.GetInitialValue(persister.IsLazy); } } ! public override SqlType[] SqlTypes(IMapping session) { return NoSqlTypes; } ! ! public override int GetColumnSpan(IMapping session) { return 0; ! } ! ! public override string ToXML(object value, ISessionFactoryImplementor factory) { ! return (value==null) ? null : value.ToString(); } ! ! public override object DeepCopy(object value) { return value; } ! ! public override string Name { get { return ReturnedClass.Name; } } ! /// <summary> /// Returns a reference to the elements in the collection. --- 1,176 ---- using System.Collections; using System.Data; using NHibernate.Collection; using NHibernate.Engine; using NHibernate.SqlTypes; ! namespace NHibernate.Type { /// <summary> /// PersistentCollectionType. /// </summary> ! public abstract class PersistentCollectionType : AbstractType, IAssociationType { private readonly string role; ! private static readonly SqlType[ ] NoSqlTypes = {}; ! /// <summary> ! /// ! /// </summary> ! /// <param name="role"></param> ! protected PersistentCollectionType( string role ) { this.role = role; } ! /// <summary></summary> ! public virtual string Role { get { return role; } } ! /// <summary></summary> ! public override bool IsPersistentCollectionType { get { return true; } } ! /// <summary> ! /// ! /// </summary> ! /// <param name="x"></param> ! /// <param name="y"></param> ! /// <returns></returns> ! public override sealed bool Equals( object x, object y ) { ! // proxies? - comment in h2.0.3 also ! return x == y; } ! /// <summary> ! /// ! /// </summary> ! /// <param name="session"></param> ! /// <param name="persister"></param> ! /// <returns></returns> ! public abstract PersistentCollection Instantiate( ISessionImplementor session, CollectionPersister persister ); ! /// <summary> ! /// ! /// </summary> ! /// <param name="rs"></param> ! /// <param name="name"></param> ! /// <param name="session"></param> ! /// <param name="owner"></param> ! /// <returns></returns> ! public override object NullSafeGet( IDataReader rs, string name, ISessionImplementor session, object owner ) { ! throw new AssertionFailure( "bug in PersistentCollectionType" ); } ! ! /// <summary> ! /// ! /// </summary> ! /// <param name="rs"></param> ! /// <param name="name"></param> ! /// <param name="session"></param> ! /// <param name="owner"></param> ! /// <returns></returns> ! public override object NullSafeGet( IDataReader rs, string[ ] name, ISessionImplementor session, object owner ) { ! return ResolveIdentifier( Hydrate( rs, name, session, owner ), session, owner ); } ! /// <summary> ! /// ! /// </summary> ! /// <param name="cmd"></param> ! /// <param name="value"></param> ! /// <param name="index"></param> ! /// <param name="session"></param> ! public override void NullSafeSet( IDbCommand cmd, object value, int index, ISessionImplementor session ) { } ! /// <summary> ! /// ! /// </summary> ! /// <param name="id"></param> ! /// <param name="owner"></param> ! /// <param name="session"></param> ! /// <returns></returns> ! public virtual object GetCollection( object id, object owner, ISessionImplementor session ) { // added the owner PersistentCollection collection = session.GetLoadingCollection( role, id ); ! if( collection != null ) ! { ! return collection.GetCachedValue(); ! } //TODO: yuck... call another method - H2.0.3comment ! CollectionPersister persister = session.Factory.GetCollectionPersister( role ); ! collection = persister.GetCachedCollection( id, owner, session ); ! if( collection != null ) { ! session.AddInitializedCollection( collection, persister, id ); return collection.GetCachedValue(); } ! else { ! collection = Instantiate( session, persister ); ! session.AddUninitializedCollection( collection, persister, id ); ! return collection.GetInitialValue( persister.IsLazy ); } } ! /// <summary> ! /// ! /// </summary> ! /// <param name="session"></param> ! /// <returns></returns> ! public override SqlType[ ] SqlTypes( IMapping session ) { return NoSqlTypes; } ! ! /// <summary> ! /// ! /// </summary> ! /// <param name="session"></param> ! /// <returns></returns> ! public override int GetColumnSpan( IMapping session ) { return 0; ! } ! ! /// <summary> ! /// ! /// </summary> ! /// <param name="value"></param> ! /// <param name="factory"></param> ! /// <returns></returns> ! public override string ToXML( object value, ISessionFactoryImplementor factory ) { ! return ( value == null ) ? null : value.ToString(); } ! ! /// <summary> ! /// ! /// </summary> ! /// <param name="value"></param> ! /// <returns></returns> ! public override object DeepCopy( object value ) { return value; } ! ! /// <summary></summary> ! public override string Name { get { return ReturnedClass.Name; } } ! /// <summary> /// Returns a reference to the elements in the collection. *************** *** 113,211 **** /// DictionaryEntry. /// </remarks> ! public virtual ICollection GetElementsCollection(object collection) { ! return ( (ICollection)collection ); } ! ! public override bool IsMutable { get { return false; } } ! ! public override object Disassemble(object value, ISessionImplementor session) { return null; // commented out in h2.0.3 also ! // if (value==null) { ! // return null; ! // } ! // else { ! // object id = session.GetLoadedCollectionKey( (PersistentCollection) value ); ! // if (id==null) ! // throw new AssertionFailure("Null collection id"); ! // return id; ! // } } ! public override object Assemble(object cached, ISessionImplementor session, object owner) { ! object id = session.GetEntityIdentifier(owner); ! if(id==null) { ! throw new AssertionFailure("bug re-assembling collection reference"); } ! return ResolveIdentifier(id, session, owner); } ! ! public override bool IsDirty(object old, object current, ISessionImplementor session) ! { ! System.Type ownerClass = session.Factory.GetCollectionPersister(role).OwnerClass; ! ! if ( !session.Factory.GetPersister(ownerClass).IsVersioned ) { // collections don't dirty an unversioned parent entity return false; } ! else { ! return base.IsDirty(old, current, session); } } ! public override bool HasNiceEquals { get { return false; } } ! ! public abstract PersistentCollection Wrap(ISessionImplementor session, object collection); ! /** * Note: return true because this type is castable to IAssociationType. Not because * all collections are associations. */ ! public override bool IsAssociationType { get { return true; } } ! ! public virtual ForeignKeyType ForeignKeyType { ! get { return ForeignKeyType.ForeignKeyToParent; } } ! ! public override object Hydrate(IDataReader rs, string[] name, ISessionImplementor session, object owner) { ! return session.GetEntityIdentifier(owner); } ! ! public override object ResolveIdentifier(object value, ISessionImplementor session, object owner) { ! if (value==null) { return null; } ! else { // h2.1 changed this to use sesion.GetCollection( role, value, owner ) and // move the impl of GetCollection from this class to the ISession. ! return GetCollection( value, owner, session); } } ! ! public virtual bool IsArrayType { get { return false; } } ! ! public abstract PersistentCollection AssembleCachedCollection(ISessionImplementor session, CollectionPersister persister, object disassembled, object owner); } } \ No newline at end of file --- 183,337 ---- /// DictionaryEntry. /// </remarks> ! public virtual ICollection GetElementsCollection( object collection ) { ! return ( ( ICollection ) collection ); } ! ! /// <summary></summary> ! public override bool IsMutable { get { return false; } } ! ! /// <summary> ! /// ! /// </summary> ! /// <param name="value"></param> ! /// <param name="session"></param> ! /// <returns></returns> ! public override object Disassemble( object value, ISessionImplementor session ) ! { return null; // commented out in h2.0.3 also ! // if (value==null) { ! // return null; ! // } ! // else { ! // object id = session.GetLoadedCollectionKey( (PersistentCollection) value ); ! // if (id==null) ! // throw new AssertionFailure("Null collection id"); ! // return id; ! // } } ! /// <summary> ! /// ! /// </summary> ! /// <param name="cached"></param> ! /// <param name="session"></param> ! /// <param name="owner"></param> ! /// <returns></returns> ! public override object Assemble( object cached, ISessionImplementor session, object owner ) { ! object id = session.GetEntityIdentifier( owner ); ! if( id == null ) { ! throw new AssertionFailure( "bug re-assembling collection reference" ); } ! return ResolveIdentifier( id, session, owner ); } ! ! /// <summary> ! /// ! /// </summary> ! /// <param name="old"></param> ! /// <param name="current"></param> ! /// <param name="session"></param> ! /// <returns></returns> ! public override bool IsDirty( object old, object current, ISessionImplementor session ) ! { ! System.Type ownerClass = session.Factory.GetCollectionPersister( role ).OwnerClass; ! ! if( !session.Factory.GetPersister( ownerClass ).IsVersioned ) { // collections don't dirty an unversioned parent entity return false; } ! else { ! return base.IsDirty( old, current, session ); } } ! /// <summary></summary> ! public override bool HasNiceEquals { get { return false; } } ! ! /// <summary> ! /// ! /// </summary> ! /// <param name="session"></param> ! /// <param name="collection"></param> ! /// <returns></returns> ! public abstract PersistentCollection Wrap( ISessionImplementor session, object collection ); ! /** * Note: return true because this type is castable to IAssociationType. Not because * all collections are associations. */ ! ! /// <summary></summary> ! public override bool IsAssociationType { get { return true; } } ! ! /// <summary></summary> ! public virtual ForeignKeyType ForeignKeyType { ! get { return ForeignKeyType.ForeignKeyToParent; } } ! ! /// <summary> ! /// ! /// </summary> ! /// <param name="rs"></param> ! /// <param name="name"></param> ! /// <param name="session"></param> ! /// <param name="owner"></param> ! /// <returns></returns> ! public override object Hydrate( IDataReader rs, string[ ] name, ISessionImplementor session, object owner ) { ! return session.GetEntityIdentifier( owner ); } ! ! /// <summary> ! /// ! /// </summary> ! /// <param name="value"></param> ! /// <param name="session"></param> ! /// <param name="owner"></param> ! /// <returns></returns> ! public override object ResolveIdentifier( object value, ISessionImplementor session, object owner ) { ! if( value == null ) { return null; } ! else { // h2.1 changed this to use sesion.GetCollection( role, value, owner ) and // move the impl of GetCollection from this class to the ISession. ! return GetCollection( value, owner, session ); } } ! ! /// <summary></summary> ! public virtual bool IsArrayType { get { return false; } } ! ! /// <summary> ! /// ! /// </summary> ! /// <param name="session"></param> ! /// <param name="persister"></param> ! /// <param name="disassembled"></param> ! /// <param name="owner"></param> ! /// <returns></returns> ! public abstract PersistentCollection AssembleCachedCollection( ISessionImplementor session, CollectionPersister persister, object disassembled, object owner ); } } \ No newline at end of file Index: SByteType.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate/Type/SByteType.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** SByteType.cs 11 Dec 2004 20:08:20 -0000 1.1 --- SByteType.cs 31 Dec 2004 23:54:56 -0000 1.2 *************** *** 1,9 **** using System; using System.Data; - - using NHibernate.Engine; using NHibernate.SqlTypes; ! namespace NHibernate.Type { /// <summary> --- 1,7 ---- using System; using System.Data; using NHibernate.SqlTypes; ! namespace NHibernate.Type { /// <summary> *************** *** 11,55 **** /// to a <see cref="DbType.SByte"/> column. /// </summary> ! public class SByteType : ValueTypeType, IDiscriminatorType { ! ! internal SByteType() : base( new SByteSqlType() ) { } ! public override object Get(IDataReader rs, int index) { ! return Convert.ToSByte(rs[index]); } ! public override object Get(IDataReader rs, string name) { ! return Convert.ToSByte(rs[name]); } ! public override System.Type ReturnedClass { ! get { return typeof(SByte); } } ! ! public override void Set(IDbCommand cmd, object value, int index) { ! ( (IDataParameter)cmd.Parameters[index] ).Value = (SByte) value; } ! public override string Name { get { return "SByte"; } } ! public override string ObjectToSQLString(object value) { return value.ToString(); } ! public virtual object StringToObject(string xml) { ! return SByte.Parse(xml); } } ! } --- 9,83 ---- /// to a <see cref="DbType.SByte"/> column. /// </summary> ! public class SByteType : ValueTypeType, IDiscriminatorType { ! /// <summary></summary> ! internal SByteType() : base( new SByteSqlType() ) { } ! /// <summary> ! /// ! /// </summary> ! /// <param name="rs"></param> ! /// <param name="index"></param> ! /// <returns></returns> ! public override object Get( IDataReader rs, int index ) { ! return Convert.ToSByte( rs[ index ] ); } ! /// <summary> ! /// ! /// </summary> ! /// <param name="rs"></param> ! /// <param name="name"></param> ! /// <returns></returns> ! public override object Get( IDataReader rs, string name ) { ! return Convert.ToSByte( rs[ name ] ); } ! /// <summary></summary> ! public override System.Type ReturnedClass { ! get { return typeof( SByte ); } } ! ! /// <summary> ! /// ! /// </summary> ! /// <param name="cmd"></param> ! /// <param name="value"></param> ! /// <param name="index"></param> ! public override void Set( IDbCommand cmd, object value, int index ) { ! ( ( IDataParameter ) cmd.Parameters[ index ] ).Value = ( SByte ) value; } ! /// <summary></summary> ! public override string Name { get { return "SByte"; } } ! /// <summary> ! /// ! /// </summary> ! /// <param name="value"></param> ! /// <returns></returns> ! public override string ObjectToSQLString( object value ) { return value.ToString(); } ! /// <summary> ! /// ! /// </summary> ! /// <param name="xml"></param> ! /// <returns></returns> ! public virtual object StringToObject( string xml ) { ! return SByte.Parse( xml ); } } ! } \ No newline at end of file Index: OneToOneType.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate/Type/OneToOneType.cs,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** OneToOneType.cs 20 Aug 2004 17:39:01 -0000 1.7 --- OneToOneType.cs 31 Dec 2004 23:54:56 -0000 1.8 *************** *** 1,67 **** using System; using System.Data; - - using NHibernate.SqlTypes; using NHibernate.Engine; ! using NHibernate.Type; ! ! ! namespace NHibernate.Type { /// <summary> /// A one-to-one association to an entity /// </summary> ! public class OneToOneType : EntityType, IAssociationType { ! ! private static readonly SqlType[] NoSqlTypes = new SqlType[0]; private readonly ForeignKeyType foreignKeyType; ! ! public override int GetColumnSpan(IMapping session) { return 0; } ! public override SqlType[] SqlTypes(IMapping session) { return NoSqlTypes; } ! ! public OneToOneType(System.Type persistentClass, ForeignKeyType foreignKeyType) : base(persistentClass) { this.foreignKeyType = foreignKeyType; } ! ! public override void NullSafeSet(IDbCommand cmd, object value, int index, ISessionImplementor session) { //nothing to do } ! ! public override bool IsOneToOne { get { return true; } } ! ! public override bool IsDirty(object old, object current, ISessionImplementor session) { return false; } ! ! public virtual ForeignKeyType ForeignKeyType { get { return foreignKeyType; } } ! ! public override object Hydrate(IDataReader rs, string[] names, ISessionImplementor session, object owner) { ! return session.GetEntityIdentifier(owner); } ! ! public override object ResolveIdentifier(object value, ISessionImplementor session, Object owner) { ! if (value==null) return null; ! System.Type clazz = PersistentClass; ! return IsNullable ? ! session.InternalLoadOneToOne(clazz, value) : ! session.InternalLoad(clazz, value); } ! ! public virtual bool IsNullable { ! get { return foreignKeyType==ForeignKeyType.ForeignKeyToParent; } } ! } ! } --- 1,124 ---- using System; using System.Data; using NHibernate.Engine; ! using NHibernate.SqlTypes; + namespace NHibernate.Type + { /// <summary> /// A one-to-one association to an entity /// </summary> ! public class OneToOneType : EntityType, IAssociationType ! { ! private static readonly SqlType[ ] NoSqlTypes = new SqlType[0]; private readonly ForeignKeyType foreignKeyType; ! ! /// <summary> ! /// ! /// </summary> ! /// <param name="session"></param> ! /// <returns></returns> ! public override int GetColumnSpan( IMapping session ) ! { return 0; } ! /// <summary> ! /// ! /// </summary> ! /// <param name="session"></param> ! /// <returns></returns> ! public override SqlType[ ] SqlTypes( IMapping session ) ! { return NoSqlTypes; } ! ! /// <summary> ! /// ! /// </summary> ! /// <param name="persistentClass"></param> ! /// <param name="foreignKeyType"></param> ! public OneToOneType( System.Type persistentClass, ForeignKeyType foreignKeyType ) : base( persistentClass ) ! { this.foreignKeyType = foreignKeyType; } ! ! /// <summary> ! /// ! /// </summary> ! /// <param name="cmd"></param> ! /// <param name="value"></param> ! /// <param name="index"></param> ! /// <param name="session"></param> ! public override void NullSafeSet( IDbCommand cmd, object value, int index, ISessionImplementor session ) ! { //nothing to do } ! ! /// <summary></summary> ! public override bool IsOneToOne ! { get { return true; } } ! ! /// <summary> ! /// ! /// </summary> ! /// <param name="old"></param> ! /// <param name="current"></param> ! /// <param name="session"></param> ! /// <returns></returns> ! public override bool IsDirty( object old, object current, ISessionImplementor session ) ! { return false; } ! ! /// <summary></summary> ! public virtual ForeignKeyType ForeignKeyType ! { get { return foreignKeyType; } } ! ! /// <summary> ! /// ! /// </summary> ! /// <param name="rs"></param> ! /// <param name="names"></param> ! /// <param name="session"></param> ! /// <param name="owner"></param> ! /// <returns></returns> ! public override object Hydrate( IDataReader rs, string[ ] names, ISessionImplementor session, object owner ) ! { ! return session.GetEntityIdentifier( owner ); } ! ! /// <summary> ! /// ! /// </summary> ! /// <param name="value"></param> ! /// <param name="session"></param> ! /// <param name="owner"></param> ! /// <returns></returns> ! public override object ResolveIdentifier( object value, ISessionImplementor session, Object owner ) ! { ! if( value == null ) ! { ! return null; ! } ! System.Type clazz = PersistentClass; ! return IsNullable ? ! session.InternalLoadOneToOne( clazz, value ) : ! session.InternalLoad( clazz, value ); } ! ! /// <summary></summary> ! public virtual bool IsNullable ! { ! get { return foreignKeyType == ForeignKeyType.ForeignKeyToParent; } } ! } ! } \ No newline at end of file Index: PersistentEnumType.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate/Type/PersistentEnumType.cs,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** PersistentEnumType.cs 20 Sep 2004 03:00:29 -0000 1.8 --- PersistentEnumType.cs 31 Dec 2004 23:54:56 -0000 1.9 *************** *** 1,27 **** using System; - using System.Collections; using System.Data; - using NHibernate.Engine; using NHibernate.SqlTypes; ! namespace NHibernate.Type { /// <summary> /// PersistentEnumType /// </summary> ! public class PersistentEnumType : ValueTypeType, ILiteralType { private readonly System.Type enumClass; ! ! public PersistentEnumType(System.Type enumClass) : base(GetUnderlyingSqlType(enumClass)) { ! if(enumClass.IsEnum) { this.enumClass = enumClass; } ! else { ! throw new MappingException(enumClass.Name + " did not inherit from System.Enum" ); } } --- 1,29 ---- using System; using System.Data; using NHibernate.Engine; using NHibernate.SqlTypes; ! namespace NHibernate.Type { /// <summary> /// PersistentEnumType /// </summary> ! public class PersistentEnumType : ValueTypeType, ILiteralType { private readonly System.Type enumClass; ! ! /// <summary> ! /// ! /// </summary> ! /// <param name="enumClass"></param> ! public PersistentEnumType( System.Type enumClass ) : base( GetUnderlyingSqlType( enumClass ) ) { ! if( enumClass.IsEnum ) { this.enumClass = enumClass; } ! else { ! throw new MappingException( enumClass.Name + " did not inherit from System.Enum" ); } } *************** *** 33,42 **** /// <param name="enumClass">The Enumeration class to get the values from.</param> /// <returns>The SqlType for this EnumClass</returns> ! public static SqlType GetUnderlyingSqlType (System.Type enumClass) ! { ! switch( Enum.GetUnderlyingType(enumClass).FullName ) { case "System.Byte": ! return SqlTypeFactory.GetByte();// DbType.Byte; case "System.Int16": return SqlTypeFactory.GetInt16(); // DbType.Int16; --- 35,44 ---- /// <param name="enumClass">The Enumeration class to get the values from.</param> /// <returns>The SqlType for this EnumClass</returns> ! public static SqlType GetUnderlyingSqlType( System.Type enumClass ) ! { ! switch( Enum.GetUnderlyingType( enumClass ).FullName ) { case "System.Byte": ! return SqlTypeFactory.GetByte(); // DbType.Byte; case "System.Int16": return SqlTypeFactory.GetInt16(); // DbType.Int16; *************** *** 54,60 **** return SqlTypeFactory.GetInt64(); //DbType.UInt64; default: ! throw new HibernateException( "Unknown UnderlyingDbType for Enum"); //Impossible exception } ! } --- 56,62 ---- return SqlTypeFactory.GetInt64(); //DbType.UInt64; default: ! throw new HibernateException( "Unknown UnderlyingDbType for Enum" ); //Impossible exception } ! } *************** *** 66,76 **** /// An instance of the Enum set to the <c>code</c> value. /// </returns> ! public virtual object GetInstance(object code) { ! try { ! return Enum.ToObject( enumClass, GetValue(code) ); } ! catch (ArgumentException ae) { throw new HibernateException( "ArgumentException occurred inside Enum.ToObject()", ae ); --- 68,78 ---- /// An instance of the Enum set to the <c>code</c> value. /// </returns> ! public virtual object GetInstance( object code ) { ! try { ! return Enum.ToObject( enumClass, GetValue( code ) ); } ! catch( ArgumentException ae ) { throw new HibernateException( "ArgumentException occurred inside Enum.ToObject()", ae ); *************** *** 88,92 **** /// convert it to the correct type. /// </remarks> ! public virtual object GetValue(object code) { // code is an enum instance. --- 90,94 ---- /// convert it to the correct type. /// </remarks> ! public virtual object GetValue( object code ) { // code is an enum instance. *************** *** 95,99 **** // type and I don't know why ! switch( Enum.GetUnderlyingType(enumClass).FullName ) { case "System.Byte": --- 97,101 ---- // type and I don't know why ! switch( Enum.GetUnderlyingType( enumClass ).FullName ) { case "System.Byte": *************** *** 114,139 **** return Convert.ToUInt64( code ); default: ! throw new HibernateException( "Unknown UnderlyingType for Enum"); //Impossible exception } } ! ! public override bool Equals(object x, object y) { ! return (x==y) || ( x!=null && y!=null && x.Equals(y) ) ; } ! ! public override System.Type ReturnedClass { get { return enumClass.GetType(); } } ! ! public override void Set(IDbCommand cmd, object value, int index) { ! IDataParameter par = (IDataParameter) cmd.Parameters[index]; ! if (value==null) { par.Value = DBNull.Value; } ! else { par.Value = value; --- 116,160 ---- return Convert.ToUInt64( code ); default: ! throw new HibernateException( "Unknown UnderlyingType for Enum" ); //Impossible exception } } ! ! /// <summary> ! /// ! /// </summary> ! /// <param name="x"></param> ! /// <param name="y"></param> ! /// <returns></returns> ! public override bool Equals( object x, object y ) { ! return ( x == y ) || ( x != null && y != null && x.Equals( y ) ); } ! ! /// <summary></summary> ! public override int GetHashCode() ! { ! return base.GetHashCode (); ! } ! ! /// <summary></summary> ! public override System.Type ReturnedClass { get { return enumClass.GetType(); } } ! ! /// <summary> ! /// ! /// </summary> ! /// <param name="cmd"></param> ! /// <param name="value"></param> ! /// <param name="index"></param> ! public override void Set( IDbCommand cmd, object value, int index ) { ! IDataParameter par = ( IDataParameter ) cmd.Parameters[ index ]; ! if( value == null ) { par.Value = DBNull.Value; } ! else { par.Value = value; *************** *** 141,192 **** } ! public override object Get(IDataReader rs, int index) { ! object code = rs[index]; ! if ( code==DBNull.Value || code==null) { return null; } ! else { ! return GetInstance(code); } } ! public override object Get(IDataReader rs, string name) { ! return Get(rs, rs.GetOrdinal(name)); } ! public override string Name { get { return enumClass.Name; } } ! ! public override string ToXML(object value) { ! return (value==null) ? null : GetValue(value).ToString(); } ! public override object Assemble(object cached, ISessionImplementor session, object owner) { ! if (cached==null) { return null; } ! else { ! return GetInstance(cached);; } } ! ! public override object Disassemble(object value, ISessionImplementor session) { ! return (value==null) ? null : GetValue(value); } ! ! public override string ObjectToSQLString(object value) { ! return GetValue(value).ToString(); } } --- 162,250 ---- } ! /// <summary> ! /// ! /// </summary> ! /// <param name="rs"></param> ! /// <param name="index"></param> ! /// <returns></returns> ! public override object Get( IDataReader rs, int index ) { ! object code = rs[ index ]; ! if( code == DBNull.Value || code == null ) { return null; } ! else { ! return GetInstance( code ); } } ! /// <summary> ! /// ! /// </summary> ! /// <param name="rs"></param> ! /// <param name="name"></param> ! /// <returns></returns> ! public override object Get( IDataReader rs, string name ) { ! return Get( rs, rs.GetOrdinal( name ) ); } ! /// <summary></summary> ! public override string Name { get { return enumClass.Name; } } ! ! /// <summary> ! /// ! /// </summary> ! /// <param name="value"></param> ! /// <returns></returns> ! public override string ToXML( object value ) { ! return ( value == null ) ? null : GetValue( value ).ToString(); } ! /// <summary> ! /// ! /// </summary> ! /// <param name="cached"></param> ! /// <param name="session"></param> ! /// <param name="owner"></param> ! /// <returns></returns> ! public override object Assemble( object cached, ISessionImplementor session, object owner ) { ! if( cached == null ) { return null; } ! else { ! return GetInstance( cached ); ! ; } } ! ! /// <summary> ! /// ! /// </summary> ! /// <param name="value"></param> ! /// <param name="session"></param> ! /// <returns></returns> ! public override object Disassemble( object value, ISessionImplementor session ) { ! return ( value == null ) ? null : GetValue( value ); } ! ! /// <summary> ! /// ! /// </summary> ! /// <param name="value"></param> ! /// <returns></returns> ! public override string ObjectToSQLString( object value ) { ! return GetValue( value ).ToString(); } } Index: ObjectType.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate/Type/ObjectType.cs,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** ObjectType.cs 20 Sep 2004 03:00:29 -0000 1.8 --- ObjectType.cs 31 Dec 2004 23:54:56 -0000 1.9 *************** *** 1,13 **** using System; using System.Data; - using NHibernate.Engine; - using NHibernate.Util; using NHibernate.Loader; using NHibernate.SqlTypes; ! namespace NHibernate.Type { ! ! ///<summary> /// Handles "any" mappings and the old deprecated "object" type. --- 1,11 ---- using System; using System.Data; using NHibernate.Engine; using NHibernate.Loader; using NHibernate.SqlTypes; + using NHibernate.Util; ! namespace NHibernate.Type ! { ///<summary> /// Handles "any" mappings and the old deprecated "object" type. *************** *** 38,139 **** /// ///</remarks> ! public class ObjectType : AbstractType, IAbstractComponentType, IAssociationType { ! private readonly IType identifierType; private readonly IType metaType; ! internal ObjectType(IType metaType, IType identifierType) { this.identifierType = identifierType; this.metaType = metaType; } ! ! internal ObjectType() : this(NHibernate.Class, NHibernate.Serializable) { } ! ! public override object DeepCopy(object value) { return value; } ! public override bool Equals(object x, object y) { return x == y; } ! public override int GetColumnSpan(IMapping session) { /* * This is set at 2 in Hibernate to support the old depreciated * version of using type="object". We are removing that support so * I don't know if we need to keep this in. ! */ return 2; } ! public override string Name { get { return "Object"; } } ! public override bool HasNiceEquals { get { return false; } } ! public override bool IsMutable { get { return false; } } ! public override object NullSafeGet(IDataReader rs, string name, ISessionImplementor session, object owner) { ! throw new NotSupportedException("object is a multicolumn type"); } ! public override object NullSafeGet(IDataReader rs, string[] names, ISessionImplementor session, object owner) { //if ( names.length!=2 ) throw new HibernateException("object type mapping must specify exactly two columns"); ! ! System.Type clazz = (System.Type) metaType.NullSafeGet(rs, names[0], session, owner); ! object id = identifierType.NullSafeGet(rs, names[1], session, owner); ! if (clazz==null || id==null) { return null; } ! else { ! return session.Load(clazz, id); } } ! public override void NullSafeSet(IDbCommand st, object value, int index, ISessionImplementor session) { object id; System.Type clazz; ! if (value == null) { id = null; clazz = null; ! } ! else { ! id = session.GetEntityIdentifierIfNotUnsaved(value); clazz = value.GetType(); } ! metaType.NullSafeSet(st, clazz, index, session); ! identifierType.NullSafeSet(st, id, index+1, session); // metaType must be single-column type } ! public override System.Type ReturnedClass { ! get { return typeof(object); } } ! ! public override SqlType[] SqlTypes(IMapping mapping) { return ArrayHelper.Join( ! metaType.SqlTypes(mapping), ! identifierType.SqlTypes(mapping)); ! } ! public override string ToXML(object value, ISessionFactoryImplementor factory) { ! return NHibernate.Entity( value.GetType() ).ToXML(value, factory); } [Serializable] ! public sealed class ObjectTypeCacheEntry { public System.Type clazz; public object id; ! public ObjectTypeCacheEntry(System.Type clazz, object id) { this.clazz = clazz; --- 36,221 ---- /// ///</remarks> ! public class ObjectType : AbstractType, IAbstractComponentType, IAssociationType ! { private readonly IType identifierType; private readonly IType metaType; ! /// <summary> ! /// ! /// </summary> ! /// <param name="metaType"></param> ! /// <param name="identifierType"></param> ! internal ObjectType( IType metaType, IType identifierType ) ! { this.identifierType = identifierType; this.metaType = metaType; } ! ! /// <summary></summary> ! internal ObjectType() : this( NHibernate.Class, NHibernate.Serializable ) { } ! ! /// <summary> ! /// ! /// </summary> ! /// <param name="value"></param> ! /// <returns></returns> ! public override object DeepCopy( object value ) ! { return value; } ! /// <summary> ! /// ! /// </summary> ! /// <param name="x"></param> ! /// <param name="y"></param> ! /// <returns></returns> ! public override bool Equals( object x, object y ) ! { return x == y; } ! /// <summary> ! /// ! /// </summary> ! /// <param name="session"></param> ! /// <returns></returns> ! public override int GetColumnSpan( IMapping session ) ! { /* * This is set at 2 in Hibernate to support the old depreciated * version of using type="object". We are removing that support so * I don't know if we need to keep this in. ! */ return 2; } ! /// <summary></summary> ! public override string Name ! { get { return "Object"; } } ! /// <summary></summary> ! public override bool HasNiceEquals ! { get { return false; } } ! /// <summary></summary> ! public override bool IsMutable ! { get { return false; } } ! /// <summary> ! /// ! /// </summary> ! /// <param name="rs"></param> ! /// <param name="name"></param> ! /// <param name="session"></param> ! /// <param name="owner"></param> ! /// <returns></returns> ! public override object NullSafeGet( IDataReader rs, string name, ISessionImplementor session, object owner ) ! { ! throw new NotSupportedException( "object is a multicolumn type" ); } ! /// <summary> ! /// ! /// </summary> ! /// <param name="rs"></param> ! /// <param name="names"></param> ! /// <param name="session"></param> ! /// <param name="owner"></param> ! /// <returns></returns> ! public override object NullSafeGet( IDataReader rs, string[ ] names, ISessionImplementor session, object owner ) ! { //if ( names.length!=2 ) throw new HibernateException("object type mapping must specify exactly two columns"); ! ! System.Type clazz = ( System.Type ) metaType.NullSafeGet( rs, names[ 0 ], session, owner ); ! object id = identifierType.NullSafeGet( rs, names[ 1 ], session, owner ); ! if( clazz == null || id == null ) ! { return null; } ! else ! { ! return session.Load( clazz, id ); } } ! /// <summary> ! /// ! /// </summary> ! /// <param name="st"></param> ! /// <param name="value"></param> ! /// <param name="index"></param> ! /// <param name="session"></param> ! public override void NullSafeSet( IDbCommand st, object value, int index, ISessionImplementor session ) ! { object id; System.Type clazz; ! if( value == null ) ! { id = null; clazz = null; ! } ! else ! { ! id = session.GetEntityIdentifierIfNotUnsaved( value ); clazz = value.GetType(); } ! metaType.NullSafeSet( st, clazz, index, session ); ! identifierType.NullSafeSet( st, id, index + 1, session ); // metaType must be single-column type } ! /// <summary></summary> ! public override System.Type ReturnedClass ! { ! get { return typeof( object ); } } ! /// <summary> ! /// ! /// </summary> ! /// <param name="mapping"></param> ! /// <returns></returns> ! public override SqlType[ ] SqlTypes( IMapping mapping ) ! { return ArrayHelper.Join( ! metaType.SqlTypes( mapping ), ! identifierType.SqlTypes( mapping ) ); } ! /// <summary> ! /// ! /// </summary> ! /// <param name="value"></param> ! /// <param name="factory"></param> ! /// <returns></returns> ! public override string ToXML( object value, ISessionFactoryImplementor factory ) ! { ! return NHibernate.Entity( value.GetType() ).ToXML( value, factory ); } + /// <summary></summary> [Serializable] ! public sealed class ObjectTypeCacheEntry { + /// <summary></summary> public System.Type clazz; + /// <summary></summary> public object id; ! ! /// <summary> ! /// ! /// </summary> ! /// <param name="clazz"></param> ! /// <param name="id"></param> ! public ObjectTypeCacheEntry( System.Type clazz, object id ) { this.clazz = clazz; *************** *** 142,223 **** } ! public override object Assemble(object cached, ISessionImplementor session, object owner) { ! ObjectTypeCacheEntry e = (ObjectTypeCacheEntry) cached; ! return (cached==null) ? null : session.Load(e.clazz, e.id); } ! public override object Disassemble(object value, ISessionImplementor session) { ! return (value==null) ? null : new ObjectTypeCacheEntry( value.GetType(), session.GetEntityIdentifier(value) ); } ! public override bool IsObjectType { get { return true; } } ! public Cascades.CascadeStyle Cascade(int i) { ! return Cascades.CascadeStyle.StyleNone; ! } ! ! public OuterJoinLoaderType EnableJoinedFetch(int i) { ! return OuterJoinLoaderType.Lazy; ! } ! ! private static readonly string[] PROPERTY_NAMES = new string[] { "class", "id" }; ! ! public string[] PropertyNames { ! get { ! return ObjectType.PROPERTY_NAMES; ! } } ! public object GetPropertyValue(Object component, int i, ISessionImplementor session) { ! return (i==0) ? ! component.GetType() : ! Id(component, session); ! } ! ! public object[] GetPropertyValues(Object component, ISessionImplementor session) { ! return new object[] { component.GetType(), Id(component, session) }; ! } ! ! private object Id(object component, ISessionImplementor session) { ! try { ! return session.GetEntityIdentifierIfNotUnsaved(component); ! } ! catch (TransientObjectException) { ! return null; ! } ! } ! ! public IType[] Subtypes { ! get { ! return new IType[] { metaType, identifierType }; } ! } ! ! public void SetPropertyValues(object component, object[] values) { ! throw new NotSupportedException(); ! } ! ! public override bool IsComponentType { ! get { ! return true; } } ! public ForeignKeyType ForeignKeyType { ! get { //return AssociationType.FOREIGN_KEY_TO_PARENT; //TODO: this is better but causes a transient object exception... ! return ForeignKeyType.ForeignKeyFromParent; } ! } ! public override bool IsAssociationType { ! get { ! return true; ! } } } ! } --- 224,365 ---- } ! /// <summary> ! /// ! /// </summary> ! /// <param name="cached"></param> ! /// <param name="session"></param> ! /// <param name="owner"></param> ! /// <returns></returns> ! public override object Assemble( object cached, ISessionImplementor session, object owner ) { ! ObjectTypeCacheEntry e = ( ObjectTypeCacheEntry ) cached; ! return ( cached == null ) ? null : session.Load( e.clazz, e.id ); } ! /// <summary> ! /// ! /// </summary> ! /// <param name="value"></param> ! /// <param name="session"></param> ! /// <returns></returns> ! public override object Disassemble( object value, ISessionImplementor session ) { ! return ( value == null ) ? null : new ObjectTypeCacheEntry( value.GetType(), session.GetEntityIdentifier( value ) ); } ! /// <summary></summary> ! public override bool IsObjectType ! { get { return true; } } ! /// <summary> ! /// ! /// </summary> ! /// <param name="i"></param> ! /// <returns></returns> ! public Cascades.CascadeStyle Cascade( int i ) ! { ! return Cascades.CascadeStyle.StyleNone; } ! /// <summary> ! /// ! /// </summary> ! /// <param name="i"></param> ! /// <returns></returns> ! public OuterJoinLoaderType EnableJoinedFetch( int i ) ! { ! return OuterJoinLoaderType.Lazy; ! } ! ! private static readonly string[ ] PROPERTY_NAMES = new string[ ] {"class", "id"}; ! ! /// <summary></summary> ! public string[ ] PropertyNames ! { ! get { return ObjectType.PROPERTY_NAMES; } ! } ! ! /// <summary> ! /// ! /// </summary> ! /// <param name="component"></param> ! /// <param name="i"></param> ! /// <param name="session"></param> ! /// <returns></returns> ! public object GetPropertyValue( Object component, int i, ISessionImplementor session ) ! { ! return ( i == 0 ) ? ! component.GetType() : ! Id( component, session ); ! } ! ! /// <summary> ! /// ! /// </summary> ! /// <param name="component"></param> ! /// <param name="session"></param> ! /// <returns></returns> ! public object[ ] GetPropertyValues( Object component, ISessionImplementor session ) ! { ! return new object[ ] {component.GetType(), Id( component, session )}; ! } ! ! /// <summary> ! /// ! /// </summary> ! /// <param name="component"></param> ! /// <param name="session"></param> ! /// <returns></returns> ! private object Id( object component, ISessionImplementor session ) ! { ! try ! { ! return session.GetEntityIdentifierIfNotUnsaved( component ); } ! catch( TransientObjectException ) ! { ! return null; } } ! /// <summary></summary> ! public IType[ ] Subtypes ! { ! get { return new IType[ ] {metaType, identifierType}; } ! } ! ! /// <summary> ! /// ! /// </summary> ! /// <param name="component"></param> ! /// <param name="values"></param> ! public void SetPropertyValues( object component, object[ ] values ) ! { ! throw new NotSupportedException(); ! } ! ! /// <summary></summary> ! public override bool IsComponentType ! { ! get { return true; } ! } ! ! /// <summary></summary> ! public ForeignKeyType ForeignKeyType ! { ! get ! { //return AssociationType.FOREIGN_KEY_TO_PARENT; //TODO: this is better but causes a transient object exception... ! return ForeignKeyType.ForeignKeyFromParent; } ! } ! /// <summary></summary> ! public override bool IsAssociationType ! { ! get { return true; } } } ! } \ No newline at end of file |