From: Michael D. <mik...@us...> - 2004-04-26 03:45:18
|
Update of /cvsroot/nhibernate/nhibernate/src/NHibernate/Impl In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1793/NHibernate/Impl Modified Files: SessionImpl.cs Log Message: Fixes for the problem of a Component containing a Collection causing multi data readers to be open. Fixed minor java-.net port bug with getting a range from a collection. Index: SessionImpl.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate/Impl/SessionImpl.cs,v retrieving revision 1.22 retrieving revision 1.23 diff -C2 -d -r1.22 -r1.23 *** SessionImpl.cs 21 Apr 2004 14:31:24 -0000 1.22 --- SessionImpl.cs 26 Apr 2004 03:45:09 -0000 1.23 *************** *** 1118,1121 **** --- 1118,1122 ---- //BEGIN YUCKINESS: if ( persister.HasCascades ) { + int start = deletions.Count; *************** *** 1146,1152 **** //move them earlier. this is yucky code: ! ! IList middle = deletions.GetRange( oldDeletions.Count, start ); ! IList tail = deletions.GetRange( start, end); oldDeletions.AddRange(tail); --- 1147,1155 ---- //move them earlier. this is yucky code: ! ! // in h203 they used SubList where it takes the start and end indexes, in nh GetRange ! // takes the start index and quantity to get. ! IList middle = deletions.GetRange( oldDeletions.Count, (start - oldDeletions.Count) ); ! IList tail = deletions.GetRange( start, (end - start) ); oldDeletions.AddRange(tail); *************** *** 3044,3047 **** --- 3047,3147 ---- } + #region - Session Helpers for handling PersistentCollections inside of a Component + + // key = ComponentCollectionKey(id, role) + // value = PersistentCollection + // contains the PersistentCollections that need to be resolved by a Component through + // the use of ResolveIdentifier. + private IDictionary unresolvedComponentCollections = new Hashtable(); + + /// <summary> + /// Key for the IDictionary that is storing the PersistentCollections that need to be + /// Resolved for a Component + /// </summary> + private class ComponentCollectionKey + { + private object id; + private string role; + + public ComponentCollectionKey(object id, string role) + { + this.id = id; + this.role = role; + } + + public override int GetHashCode() + { + unchecked + { + return id.GetHashCode() + role.GetHashCode(); + } + } + + public object Id + { + get { return id;} + } + + public string Role + { + get { return role; } + } + + public override bool Equals(object obj) + { + ComponentCollectionKey rhs = obj as ComponentCollectionKey; + + if(rhs==null) return false; + + return this.Equals(rhs); + } + + public bool Equals(ComponentCollectionKey obj) + { + // check for ref equality + if(this==obj) return true; + + return (this.id.Equals(obj.Id)) && (this.role==obj.role); + } + + public override string ToString() + { + return "Id=" + id.ToString() + " ; role=" + role; + } + + + } + + public void AddUnresolvedComponentCollection(object id, string role, PersistentCollection collection) + { + ComponentCollectionKey key = new ComponentCollectionKey(id, role); + + // I can't think of any valid reason that the same unresolved collection for a Component would + // get in here twice... + if( unresolvedComponentCollections.Contains(key) ) + { + throw new HibernateException("There is a problem adding the collection identified by " + key.ToString()); + } + + unresolvedComponentCollections[key] = collection; + + } + + public PersistentCollection GetUnresolvedComponentCollection(object id, string role) + { + ComponentCollectionKey key = new ComponentCollectionKey(id, role); + object returnValue = unresolvedComponentCollections[key]; + return returnValue==null ? null : (PersistentCollection) returnValue; + + } + + public void RemoveUnresolvedComponentCollection(object id, string role) + { + ComponentCollectionKey key = new ComponentCollectionKey(id, role); + unresolvedComponentCollections.Remove(key); + } + + #endregion + /// <summary> /// add a collection we just loaded up (still needs initializing) *************** *** 3050,3054 **** /// <param name="persister"></param> /// <param name="id"></param> ! public void AddUninitializedCollection(PersistentCollection collection, CollectionPersister persister, object id) { CollectionEntry ce = new CollectionEntry(persister, id, false); collections[collection] = ce; --- 3150,3155 ---- /// <param name="persister"></param> /// <param name="id"></param> ! public void AddUninitializedCollection(PersistentCollection collection, CollectionPersister persister, object id) ! { CollectionEntry ce = new CollectionEntry(persister, id, false); collections[collection] = ce; *************** *** 3371,3375 **** if ( log.IsDebugEnabled ) { log.Debug( "search: " + persistentClass.Name ); ! log.Debug( "criteria: " + criteria.ToString() ); } --- 3472,3476 ---- if ( log.IsDebugEnabled ) { log.Debug( "search: " + persistentClass.Name ); ! log.Debug( "criteria: " + criteria ); } |