From: Paul H. <pha...@us...> - 2005-03-14 18:54:31
|
Update of /cvsroot/nhibernate/nhibernate/src/NHibernate/Type In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7196/nhibernate/src/NHibernate/Type Modified Files: AbstractType.cs ArrayType.cs BooleanType.cs ComponentType.cs IType.cs ManyToOneType.cs ObjectType.cs OneToOneType.cs PersistentCollectionType.cs TypeFactory.cs Log Message: Refactored as per 2.1 Index: AbstractType.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate/Type/AbstractType.cs,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** AbstractType.cs 31 Dec 2004 23:50:57 -0000 1.10 --- AbstractType.cs 14 Mar 2005 18:54:20 -0000 1.11 *************** *** 1,3 **** --- 1,4 ---- using System; + using System.Collections; using System.Data; using NHibernate.Engine; *************** *** 59,62 **** --- 60,78 ---- /// <summary> + /// Says whether the value has been modified + /// </summary> + /// <param name="old"></param> + /// <param name="current"></param> + /// <param name="session"></param> + /// <returns></returns> + public virtual bool IsModified( + object old, + object current, + ISessionImplementor session ) + { + return IsDirty( old, current, session ); + } + + /// <summary> /// Disassembles the object into a cacheable representation. /// </summary> *************** *** 138,141 **** --- 154,177 ---- } + + /// <summary> + /// + /// </summary> + /// <param name="original"></param> + /// <param name="current"></param> + /// <param name="session"></param> + /// <param name="owner"></param> + /// <param name="copiedAlready"></param> + /// <returns></returns> + public virtual object Copy( object original, object current, ISessionImplementor session, object owner, IDictionary copiedAlready ) + { + if ( original == null ) + { + return null; + } + return Assemble( Disassemble( original, session ), session, owner ); + } + + /// <summary> /// Maps identifiers to Entities or Collections. Index: ObjectType.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate/Type/ObjectType.cs,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** ObjectType.cs 1 Mar 2005 16:24:50 -0000 1.11 --- ObjectType.cs 14 Mar 2005 18:54:20 -0000 1.12 *************** *** 4,7 **** --- 4,8 ---- using NHibernate.Loader; using NHibernate.Persister; + using NHibernate.Proxy; using NHibernate.SqlTypes; using NHibernate.Util; *************** *** 358,361 **** --- 359,384 ---- } + /// <summary> + /// + /// </summary> + /// <param name="old"></param> + /// <param name="current"></param> + /// <param name="session"></param> + /// <returns></returns> + public override bool IsModified(object old, object current, ISessionImplementor session) + { + if ( old == null ) + { + return current != null; + } + if ( current == null ) + { + return old != null; + } + ObjectTypeCacheEntry holder = (ObjectTypeCacheEntry) old; + + return holder.clazz != NHibernateProxyHelper.GetClass( current ) || identifierType.IsModified( holder.id, Id( current, session ), session ); + } + /// <summary></summary> public override bool IsAssociationType Index: IType.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate/Type/IType.cs,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** IType.cs 11 Feb 2005 21:01:17 -0000 1.12 --- IType.cs 14 Mar 2005 18:54:20 -0000 1.13 *************** *** 1,3 **** --- 1,4 ---- using System; + using System.Collections; using System.Data; using NHibernate.Engine; *************** *** 55,59 **** System.Type ReturnedClass { get; } - /// <include file='IType.cs.xmldoc' /// path='//members[@type="IType"]/member[@name="M:IType.Equals"]/*' --- 56,59 ---- *************** *** 66,69 **** --- 66,73 ---- bool IsDirty( object old, object current, ISessionImplementor session ); + /// <include file='IType.cs.xmldoc' + /// path='//members[@type="IType"]/member[@name="M:IType.IsModified"]/*' + /// /> + bool IsModified( object oldHydratedState, object currentState, ISessionImplementor session ); /// <include file='IType.cs.xmldoc' *************** *** 82,86 **** void NullSafeSet( IDbCommand st, object value, int index, ISessionImplementor session ); - /// <include file='IType.cs.xmldoc' /// path='//members[@type="IType"]/member[@name="M:IType.ToXML"]/*' --- 86,89 ---- *************** *** 88,92 **** string ToXML( object value, ISessionFactoryImplementor factory ); - /// <include file='IType.cs.xmldoc' /// path='//members[@type="IType"]/member[@name="P:IType.Name"]/*' --- 91,94 ---- *************** *** 129,132 **** --- 131,138 ---- object ResolveIdentifier( object value, ISessionImplementor session, object owner ); + /// <include file='IType.cs.xmldoc' + /// path='//members[@type="IType"]/member[@name="M:IType.Copy"]/*' + /// /> + object Copy( object original, object target, ISessionImplementor session, object owner, IDictionary copiedAlready ); } } \ No newline at end of file Index: TypeFactory.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate/Type/TypeFactory.cs,v retrieving revision 1.45 retrieving revision 1.46 diff -C2 -d -r1.45 -r1.46 *** TypeFactory.cs 5 Mar 2005 10:43:51 -0000 1.45 --- TypeFactory.cs 14 Mar 2005 18:54:20 -0000 1.46 *************** *** 1097,1119 **** } ! /* /// <summary> ! /// Return <tt>-1</tt> if non-dirty, or the index of the first dirty value otherwise /// </summary> /// <param name="types"></param> ! /// <param name="x"></param> ! /// <param name="y"></param> ! /// <param name="owner"></param> ! /// <param name="factory"></param> /// <returns></returns> ! public static int FindDirty(IType[] types, object[] x, object[] y, object owner, ISessionFactoryImplementor factory) { ! for (int i=0; i<types.Length; i++) { ! if ( types[i].IsDirty( x[i], y[i], owner, factory ) ) { ! return i; } } ! return -1; } - */ } } \ No newline at end of file --- 1097,1138 ---- } ! /// <summary> ! /// Determine if any of the given field values are modified, ! /// returning an array containing indexes of ! /// the dirty fields or null if no fields are modified. /// </summary> /// <param name="types"></param> ! /// <param name="old"></param> ! /// <param name="current"></param> ! /// <param name="check"></param> ! /// <param name="session"></param> /// <returns></returns> ! public static int[ ] FindModified( IType[ ] types, object[ ] old, object[ ] current, bool[ ] check, ISessionImplementor session ) ! { ! int[ ] results = null; ! int count = 0; ! for( int i = 0; i < types.Length; i++ ) ! { ! if( check[ i ] && types[ i ].IsModified( old[ i ], current[ i ], session ) ) ! { ! if( results == null ) ! { ! results = new int[types.Length]; ! } ! results[ count++ ] = i; } } ! if( count == 0 ) ! { ! return null; ! } ! else ! { ! int[ ] trimmed = new int[count]; ! System.Array.Copy( results, 0, trimmed, 0, count ); ! return trimmed; ! } } } } \ No newline at end of file Index: PersistentCollectionType.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate/Type/PersistentCollectionType.cs,v retrieving revision 1.22 retrieving revision 1.23 diff -C2 -d -r1.22 -r1.23 *** PersistentCollectionType.cs 1 Mar 2005 16:24:50 -0000 1.22 --- PersistentCollectionType.cs 14 Mar 2005 18:54:20 -0000 1.23 *************** *** 46,51 **** public override sealed bool Equals( object x, object y ) { ! // proxies? - comment in h2.0.3 also ! return x == y; } --- 46,52 ---- public override sealed bool Equals( object x, object y ) { ! return x == y || ! ( x is PersistentCollection && ( (PersistentCollection) x ).IsWrapper( y ) ) || ! ( y is PersistentCollection && ( (PersistentCollection) y ).IsWrapper( x ) ); } *************** *** 173,186 **** { 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; - // } } --- 174,177 ---- *************** *** 202,205 **** --- 193,203 ---- } + private bool IsOwnerVersioned( ISessionImplementor session ) + { + System.Type ownerClass = session.Factory.GetCollectionPersister( role ).OwnerClass; + + return session.Factory.GetPersister( ownerClass ).IsVersioned; + } + /// <summary> /// *************** *** 211,225 **** 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 ); ! } } --- 209,216 ---- public override bool IsDirty( object old, object current, ISessionImplementor session ) { ! // collections don't dirty an unversioned parent entity ! // TODO: I don't like this implementation; it would be better if this was handled by SearchForDirtyCollections(); ! return IsOwnerVersioned( session ) && base.IsDirty( old, current, session ); } *************** *** 262,268 **** public IJoinable GetJoinable( ISessionFactoryImplementor factory ) { ! // TODO: Uncomment once CollectionPersister knows about IJoinable ! //return (IJoinable) factory.GetCollectionPersister( role ); ! return null; } --- 253,257 ---- public IJoinable GetJoinable( ISessionFactoryImplementor factory ) { ! return (IJoinable) factory.GetCollectionPersister( role ); } *************** *** 326,329 **** --- 315,330 ---- /// /// </summary> + /// <param name="old"></param> + /// <param name="current"></param> + /// <param name="session"></param> + /// <returns></returns> + public override bool IsModified(object old, object current, ISessionImplementor session) + { + return false; + } + + /// <summary> + /// + /// </summary> /// <param name="factory"></param> /// <returns></returns> *************** *** 332,338 **** try { ! // TODO: Uncomment once CollectionPersister knows about IQueryableCollection ! //IQueryableCollection collectionPersister = (IQueryableCollection) factory.GetCollectionPersister( role ); ! IQueryableCollection collectionPersister = null; if ( collectionPersister.ElementType.IsEntityType ) { --- 333,337 ---- try { ! IQueryableCollection collectionPersister = (IQueryableCollection) factory.GetCollectionPersister( role ); if ( collectionPersister.ElementType.IsEntityType ) { *************** *** 341,349 **** return collectionPersister.ElementPersister.MappedClass; } ! catch ( InvalidCastException ) { ! // TODO: Change to a mapping error ! throw; } } } --- 340,389 ---- return collectionPersister.ElementPersister.MappedClass; } ! catch ( InvalidCastException ice) { ! throw new MappingException( "collection role is not queryable", ice ); ! } ! } ! ! /// <summary> ! /// ! /// </summary> ! /// <param name="original"></param> ! /// <param name="target"></param> ! /// <param name="session"></param> ! /// <param name="owner"></param> ! /// <param name="copiedAlready"></param> ! /// <returns></returns> ! public override object Copy( object original, object target, ISessionImplementor session, object owner, IDictionary copiedAlready ) ! { ! if ( original == null ) ! { ! return null; } + if ( !NHibernateUtil.IsInitialized( original ) ) + { + return target; + } + + IList originalCopy = new ArrayList( (IList) original ); + IList result = target == null ? (IList) Instantiate( session, session.Factory.GetCollectionPersister( role ) ) : (IList) target; + result.Clear(); + IType elemType = GetElementType( session.Factory ); + foreach ( object obj in originalCopy ) + { + result.Add( elemType.Copy( obj, null, session, owner, copiedAlready ) ); + } + + return result; + } + + /// <summary> + /// + /// </summary> + /// <param name="factory"></param> + /// <returns></returns> + public IType GetElementType( ISessionFactoryImplementor factory ) + { + return factory.GetCollectionPersister( Role ).ElementType; } } Index: ComponentType.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate/Type/ComponentType.cs,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** ComponentType.cs 1 Mar 2005 16:24:50 -0000 1.13 --- ComponentType.cs 14 Mar 2005 18:54:20 -0000 1.14 *************** *** 16,32 **** private static readonly ILog log = LogManager.GetLogger( typeof( ComponentType ) ); ! private System.Type componentClass; ! private ConstructorInfo contructor; ! private IType[ ] types; ! private IGetter[ ] getters; ! private ISetter[ ] setters; ! private string[ ] propertyNames; ! private int propertySpan; ! private Cascades.CascadeStyle[ ] cascade; ! private OuterJoinFetchStrategy[ ] joinedFetch; ! private string parentProperty; // not used !?! private ISetter parentSetter; ! //TODO: This is new... ! private IGetter parentGetter; // not used !?! /// <summary> --- 16,30 ---- private static readonly ILog log = LogManager.GetLogger( typeof( ComponentType ) ); ! private readonly System.Type componentClass; ! private readonly ConstructorInfo contructor; ! private readonly IType[ ] propertyTypes; ! private readonly IGetter[ ] getters; ! private readonly ISetter[ ] setters; ! private readonly string[ ] propertyNames; ! private readonly int propertySpan; ! private readonly Cascades.CascadeStyle[ ] cascade; ! private readonly OuterJoinFetchStrategy[ ] joinedFetch; private ISetter parentSetter; ! private IGetter parentGetter; /// <summary> *************** *** 38,46 **** { //not called at runtime so doesn't matter if its slow :) ! SqlType[ ] sqlTypes = new SqlType[GetColumnSpan( mapping )]; int n = 0; for( int i = 0; i < propertySpan; i++ ) { ! SqlType[ ] subtypes = types[ i ].SqlTypes( mapping ); for( int j = 0; j < subtypes.Length; j++ ) { --- 36,44 ---- { //not called at runtime so doesn't matter if its slow :) ! SqlType[ ] sqlTypes = new SqlType[ GetColumnSpan( mapping ) ]; int n = 0; for( int i = 0; i < propertySpan; i++ ) { ! SqlType[ ] subtypes = propertyTypes[ i ].SqlTypes( mapping ); for( int j = 0; j < subtypes.Length; j++ ) { *************** *** 61,65 **** for( int i = 0; i < propertySpan; i++ ) { ! span += types[ i ].GetColumnSpan( mapping ); } return span; --- 59,63 ---- for( int i = 0; i < propertySpan; i++ ) { ! span += propertyTypes[ i ].GetColumnSpan( mapping ); } return span; *************** *** 74,78 **** /// <param name="propertySetters"></param> /// <param name="foundCustomAcessor"></param> ! /// <param name="types"></param> /// <param name="joinedFetch"></param> /// <param name="cascade"></param> --- 72,76 ---- /// <param name="propertySetters"></param> /// <param name="foundCustomAcessor"></param> ! /// <param name="propertyTypes"></param> /// <param name="joinedFetch"></param> /// <param name="cascade"></param> *************** *** 84,88 **** ISetter[ ] propertySetters, bool foundCustomAcessor, // not used !?! ! IType[ ] types, OuterJoinFetchStrategy[ ] joinedFetch, Cascades.CascadeStyle[ ] cascade, --- 82,86 ---- ISetter[ ] propertySetters, bool foundCustomAcessor, // not used !?! ! IType[ ] propertyTypes, OuterJoinFetchStrategy[ ] joinedFetch, Cascades.CascadeStyle[ ] cascade, *************** *** 91,95 **** { this.componentClass = componentClass; ! this.types = types; propertySpan = properties.Length; getters = propertyGetters; --- 89,93 ---- { this.componentClass = componentClass; ! this.propertyTypes = propertyTypes; propertySpan = properties.Length; getters = propertyGetters; *************** *** 116,125 **** parentGetter = pa.GetGetter( componentClass, parentProperty ); } - this.parentProperty = parentProperty; this.propertyNames = properties; this.cascade = cascade; this.joinedFetch = joinedFetch; contructor = ReflectHelper.GetDefaultConstructor( componentClass ); - } --- 114,121 ---- *************** *** 166,170 **** for( int i = 0; i < propertySpan; i++ ) { ! if( !types[ i ].Equals( getters[ i ].Get( x ), getters[ i ].Get( y ) ) ) { return false; --- 162,166 ---- for( int i = 0; i < propertySpan; i++ ) { ! if( !propertyTypes[ i ].Equals( getters[ i ].Get( x ), getters[ i ].Get( y ) ) ) { return false; *************** *** 193,197 **** for( int i = 0; i < getters.Length; i++ ) { ! if( types[ i ].IsDirty( getters[ i ].Get( x ), getters[ i ].Get( y ), session ) ) { return true; --- 189,193 ---- for( int i = 0; i < getters.Length; i++ ) { ! if( propertyTypes[ i ].IsDirty( getters[ i ].Get( x ), getters[ i ].Get( y ), session ) ) { return true; *************** *** 216,222 **** for( int i = 0; i < propertySpan; i++ ) { ! int length = types[ i ].GetColumnSpan( session.Factory ); string[ ] range = ArrayHelper.Slice( names, begin, length ); ! object val = types[ i ].NullSafeGet( rs, range, session, owner ); if( val != null ) { --- 212,218 ---- for( int i = 0; i < propertySpan; i++ ) { ! int length = propertyTypes[ i ].GetColumnSpan( session.Factory ); string[ ] range = ArrayHelper.Slice( names, begin, length ); ! object val = propertyTypes[ i ].NullSafeGet( rs, range, session, owner ); if( val != null ) { *************** *** 255,260 **** for( int i = 0; i < propertySpan; i++ ) { ! types[ i ].NullSafeSet( st, subvalues[ i ], begin, session ); ! begin += types[ i ].GetColumnSpan( session.Factory ); } } --- 251,256 ---- for( int i = 0; i < propertySpan; i++ ) { ! propertyTypes[ i ].NullSafeSet( st, subvalues[ i ], begin, session ); ! begin += propertyTypes[ i ].GetColumnSpan( session.Factory ); } } *************** *** 350,354 **** public IType[ ] Subtypes { ! get { return types; } } --- 346,350 ---- public IType[ ] Subtypes { ! get { return propertyTypes; } } *************** *** 391,395 **** for( int i = 0; i < propertySpan; i++ ) { ! values[ i ] = types[ i ].DeepCopy( values[ i ] ); } --- 387,391 ---- for( int i = 0; i < propertySpan; i++ ) { ! values[ i ] = propertyTypes[ i ].DeepCopy( values[ i ] ); } *************** *** 466,472 **** { object[ ] values = GetPropertyValues( value ); ! for( int i = 0; i < types.Length; i++ ) { ! values[ i ] = types[ i ].Disassemble( values[ i ], session ); } return values; --- 462,468 ---- { object[ ] values = GetPropertyValues( value ); ! for( int i = 0; i < propertyTypes.Length; i++ ) { ! values[ i ] = propertyTypes[ i ].Disassemble( values[ i ], session ); } return values; *************** *** 491,497 **** object[ ] values = ( object[ ] ) obj; object[ ] assembled = new object[values.Length]; ! for( int i = 0; i < types.Length; i++ ) { ! assembled[ i ] = types[ i ].Assemble( values[ i ], session, owner ); } object result = Instantiate(); --- 487,493 ---- object[ ] values = ( object[ ] ) obj; object[ ] assembled = new object[values.Length]; ! for( int i = 0; i < propertyTypes.Length; i++ ) { ! assembled[ i ] = propertyTypes[ i ].Assemble( values[ i ], session, owner ); } object result = Instantiate(); *************** *** 517,521 **** --- 513,599 ---- } + /// <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 ) + { + int begin = 0; + bool notNull = false; + object[] values = new object[ propertySpan ]; + for ( int i = 0; i < propertySpan; i++ ) + { + int length = propertyTypes[ i ].GetColumnSpan( session.Factory ); + string[] range = ArrayHelper.Slice( names, begin, length ); //cache this + object val = propertyTypes[ i ].Hydrate( rs, range, session, owner ); + if ( val != null ) + { + notNull = true; + } + values[ i ] = val; + begin += length; + } + + return notNull ? values : null; + } + + /// <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 ) + { + object result = Instantiate( owner, session ); + object[] values = ( object[] ) value; + for ( int i = 0; i < values.Length; i++ ) + { + values[ i ] = propertyTypes[ i ].ResolveIdentifier( values[ i ], session, owner ); + } + SetPropertyValues( result, values ); + return result; + } + else + { + return null; + } + } + /// <summary> + /// + /// </summary> + /// <param name="old"></param> + /// <param name="current"></param> + /// <param name="session"></param> + /// <returns></returns> + public override bool IsModified( object old, object current, ISessionImplementor session ) + { + if ( current == null ) + { + return old != null; + } + if ( old == null ) + { + return current != null; + } + object[] currentValues = GetPropertyValues( current, session ); + object[] oldValues = ( object[] ) old; + for ( int i = 0; i < currentValues.Length; i++ ) + { + if ( propertyTypes[ i ].IsModified( oldValues[ i ], currentValues[ i ], session ) ) + { + return true; + } + } + return false; + } } } \ No newline at end of file Index: OneToOneType.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate/Type/OneToOneType.cs,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** OneToOneType.cs 1 Mar 2005 16:24:50 -0000 1.9 --- OneToOneType.cs 14 Mar 2005 18:54:20 -0000 1.10 *************** *** 76,79 **** --- 76,91 ---- } + /// <summary> + /// + /// </summary> + /// <param name="old"></param> + /// <param name="current"></param> + /// <param name="session"></param> + /// <returns></returns> + public override bool IsModified( object old, object current, ISessionImplementor session ) + { + return false; + } + /// <summary></summary> public override bool UsePrimaryKeyAsForeignKey Index: BooleanType.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate/Type/BooleanType.cs,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** BooleanType.cs 14 Feb 2005 03:38:45 -0000 1.12 --- BooleanType.cs 14 Mar 2005 18:54:20 -0000 1.13 *************** *** 60,63 **** --- 60,71 ---- /// /// </summary> + public System.Type PrimitiveClass + { + get { return typeof( bool ); } + } + + /// <summary> + /// + /// </summary> public override System.Type ReturnedClass { Index: ManyToOneType.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate/Type/ManyToOneType.cs,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** ManyToOneType.cs 8 Mar 2005 16:48:16 -0000 1.11 --- ManyToOneType.cs 14 Mar 2005 18:54:20 -0000 1.12 *************** *** 65,68 **** --- 65,82 ---- /// <summary></summary> + public override bool IsModified(object old, object current, ISessionImplementor session) + { + if ( current == null ) + { + return old != null; + } + if ( old == null ) + { + return current != null ; + } + return GetIdentifierOrUniqueKeyType( session.Factory ).IsModified( old, GetIdentifier( current, session ), session ); + } + + /// <summary></summary> public override ForeignKeyType ForeignKeyType { Index: ArrayType.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate/Type/ArrayType.cs,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** ArrayType.cs 1 Mar 2005 16:24:50 -0000 1.10 --- ArrayType.cs 14 Mar 2005 18:54:20 -0000 1.11 *************** *** 9,14 **** public class ArrayType : PersistentCollectionType { ! //private System.Type elementClass; ! private System.Type arrayClass; /// <summary> --- 9,14 ---- public class ArrayType : PersistentCollectionType { ! private readonly System.Type elementClass; ! private readonly System.Type arrayClass; /// <summary> *************** *** 19,23 **** public ArrayType( string role, System.Type elementClass ) : base( role ) { ! //this.elementClass = elementClass; arrayClass = System.Array.CreateInstance( elementClass, 0 ).GetType(); } --- 19,23 ---- public ArrayType( string role, System.Type elementClass ) : base( role ) { ! this.elementClass = elementClass; arrayClass = System.Array.CreateInstance( elementClass, 0 ).GetType(); } *************** *** 95,98 **** --- 95,129 ---- get { return true; } } + + /// <summary> + /// + /// </summary> + /// <param name="original"></param> + /// <param name="target"></param> + /// <param name="session"></param> + /// <param name="owner"></param> + /// <param name="copiedAlready"></param> + /// <returns></returns> + public override object Copy( object original, object target, ISessionImplementor session, object owner, IDictionary copiedAlready ) + { + if ( original == null ) + { + return null; + } + if ( original == target ) + { + return target; + } + object[] orig = (object[]) original; + int length = orig.Length; + object[] result = (object[]) System.Array.CreateInstance( elementClass, length ); + + IType elemType = GetElementType( session.Factory ); + for ( int i = 0; i < length; i++ ) + { + result[ i ] = elemType.Copy( orig[ i ], null, session, owner, copiedAlready ); + } + return result; + } } } \ No newline at end of file |