From: Michael D. <mik...@us...> - 2004-04-27 15:49:31
|
Update of /cvsroot/nhibernate/nhibernate/src/NHibernate/Collection In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28813/NHibernate/Collection Modified Files: Map.cs Set.cs SortedMap.cs SortedSet.cs Log Message: Added support for the attributes "order-by" and "sort" attribute on <set> and <map> elements. Index: SortedSet.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate/Collection/SortedSet.cs,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** SortedSet.cs 8 Apr 2004 21:11:33 -0000 1.3 --- SortedSet.cs 27 Apr 2004 15:49:21 -0000 1.4 *************** *** 6,11 **** using NHibernate.Type; ! namespace NHibernate.Collection { ! /// <summary> /// A Persistent wrapper for a <c>System.Collections.IDictionary</c> that has --- 6,11 ---- using NHibernate.Type; ! namespace NHibernate.Collection ! { /// <summary> /// A Persistent wrapper for a <c>System.Collections.IDictionary</c> that has *************** *** 19,29 **** /// element. /// </remarks> ! public class SortedSet : Set, IDictionary { ! private IComparer comparer; ! protected override object Snapshot(CollectionPersister persister) { SortedList clonedSet = new SortedList(comparer, map.Count); ! foreach(DictionaryEntry de in map) { object copy = persister.ElementType.DeepCopy(de.Key); clonedSet.Add(copy, copy); --- 19,31 ---- /// element. /// </remarks> ! public class SortedSet : Set, IDictionary ! { private IComparer comparer; ! protected override object Snapshot(CollectionPersister persister) ! { SortedList clonedSet = new SortedList(comparer, map.Count); ! foreach(DictionaryEntry de in map) ! { object copy = persister.ElementType.DeepCopy(de.Key); clonedSet.Add(copy, copy); *************** *** 33,57 **** } ! public IComparer Comparer { get { return comparer;} - //set { comparer = value;} } ! public override void BeforeInitialize(CollectionPersister persister) { ! this.map = new SortedList(comparer); // new Hashtable(null, comparer); } - // changed the Comparer to a readonly property because you can't change it on SortedList after - // it has been created - so there is no point in being able to change it on this class. - // public SortedSet(ISessionImplementor session) : base(session) - // { - // } - /// <summary> ! /// Constuct a new empty SortedSet /// </summary> /// <param name="session"></param> ! /// <param name="comparer"></param> public SortedSet(ISessionImplementor session, IComparer comparer) : base(session, new SortedList(comparer)) { --- 35,57 ---- } ! public IComparer Comparer ! { get { return comparer;} } ! public override void BeforeInitialize(CollectionPersister persister) ! { ! this.map = new SortedList(comparer); ! // an ArrayList of the identifiers is what Set uses because there is not ! // both a Key & Value to worry about - just the Key. ! this.tempIdentifierList = new ArrayList(); } /// <summary> ! /// Constuct a new empty SortedSet that uses a IComparer to perform the sorting. /// </summary> /// <param name="session"></param> ! /// <param name="comparer">The IComparer to user for Sorting.</param> public SortedSet(ISessionImplementor session, IComparer comparer) : base(session, new SortedList(comparer)) { Index: Map.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate/Collection/Map.cs,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** Map.cs 28 Mar 2004 06:01:29 -0000 1.7 --- Map.cs 27 Apr 2004 15:49:21 -0000 1.8 *************** *** 51,58 **** public override void BeforeInitialize(CollectionPersister persister) { ! //TODO: check this ! //this.map = persister.HasOrdering ? LinkedHashCollectionHelper.CreateLinkedHashMap() : new Hashtable(); ! this.map = new Hashtable(); ! this.mapIdentifiers = new Hashtable(); } --- 51,68 ---- public override void BeforeInitialize(CollectionPersister persister) { ! ! if(persister.HasOrdering) ! { ! // if this Persister has an Ordering then use the ListDictionary because ! // it maintains items in the Dictionary in the same order as they were ! // added. ! this.map = new System.Collections.Specialized.ListDictionary(); ! this.mapIdentifiers = new System.Collections.Specialized.ListDictionary(); ! } ! else ! { ! this.map = new Hashtable(); ! this.mapIdentifiers = new Hashtable(); ! } } Index: SortedMap.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate/Collection/SortedMap.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** SortedMap.cs 20 Feb 2003 21:42:06 -0000 1.1 --- SortedMap.cs 27 Apr 2004 15:49:21 -0000 1.2 *************** *** 1,17 **** using System; namespace NHibernate.Collection { /// <summary> ! /// Summary description for SortedMap. /// </summary> ! public class SortedMap { ! public SortedMap() { ! // ! // TODO: Add constructor logic here ! // } } } --- 1,97 ---- using System; + using System.Collections; + + using NHibernate.Engine; namespace NHibernate.Collection { /// <summary> ! /// A Persistent wrapper for a <c>System.Collections.IDictionary</c> that has ! /// sorting. /// </summary> ! /// <remarks> ! /// This class uses the SortedList as the underlying map for the SortedMap. The SortedList ! /// is not really an IList at all. It actually is a Hashtable that provides methods to get ! /// to a Key by its index. Since it is sorted the indexes can change based on what is added ! /// to the Dictionary. In my opinion, the index is not useful except to get the first or last ! /// element. ! /// </remarks> ! public class SortedMap : Map, IDictionary { ! ! private IComparer comparer; ! ! protected override object Snapshot(CollectionPersister persister) { ! SortedList clonedMap = new SortedList(comparer, map.Count); ! foreach(DictionaryEntry de in map) ! { ! object copy = persister.ElementType.DeepCopy(de.Value); ! clonedMap.Add(de.Key, copy); ! } ! ! return clonedMap; ! } ! ! public IComparer Comparer ! { ! get { return comparer; } ! } ! ! ! public SortedMap(ISessionImplementor session, CollectionPersister persister, IComparer comparer, object disassembled, object owner) : this(session, comparer) ! { ! BeforeInitialize(persister); ! object[] array = (object[])disassembled; ! ! for(int i=0; i<array.Length; i+=2) ! { ! object key = persister.IndexType.Assemble(array[i], session, owner); ! object val = persister.ElementType.Assemble(array[i+1], session, owner); ! ! map[key] = val; ! } ! ! initialized = true; ! ! } ! ! /// <summary> ! /// Constuct a new empty SortedMap that uses a IComparer to perform the sorting. ! /// </summary> ! /// <param name="session"></param> ! /// <param name="comparer">The IComparer to user for Sorting.</param> ! public SortedMap(ISessionImplementor session, IComparer comparer) : base(session, new SortedList(comparer)) ! { ! this.comparer = comparer; ! } ! ! /// <summary> ! /// Construct a new SortedMap initialized with the map values. ! /// </summary> ! /// <param name="session">The Session to be bound to.</param> ! /// <param name="map">The initial values.</param> ! /// <param name="comparer">The IComparer to use for Sorting.</param> ! public SortedMap(ISessionImplementor session, IDictionary map, IComparer comparer) : base(session, new SortedList(map, comparer)) ! { ! this.comparer = comparer; } + + + public override void BeforeInitialize(CollectionPersister persister) + { + this.map = new SortedList(comparer); + // it should be okay to use just a hashtable to store the MapIdentifier because + // when the Identifiers are converted to actual entries then the Comparer should + // take care of putting them in the correct order... + this.mapIdentifiers = new Hashtable(); + } + + + + + //TODO: H2.0.3 - there are many more methods - probably because Java has a much + // better set of interfaces for Collections than .NET does. + } } Index: Set.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate/Collection/Set.cs,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** Set.cs 28 Mar 2004 06:01:29 -0000 1.6 --- Set.cs 27 Apr 2004 15:49:21 -0000 1.7 *************** *** 28,32 **** protected IDictionary map; ! private IList tempIdentifierList; /// <summary> --- 28,32 ---- protected IDictionary map; ! protected IList tempIdentifierList; /// <summary> *************** *** 94,99 **** public override void BeforeInitialize(CollectionPersister persister) { ! //this.map = persister.HasOrdering ? LinkedHashCollectionHelper.CreateLinkedHashMap() : new Hashtable(); ! this.map = new Hashtable(); } --- 94,105 ---- public override void BeforeInitialize(CollectionPersister persister) { ! if(persister.HasOrdering) ! { ! this.map = new System.Collections.Specialized.ListDictionary(); ! } ! else ! { ! this.map = new Hashtable(); ! } } |