public void MultiTableCollections() { if( dialect is Dialect.MySQLDialect ) { return; } ISession s = OpenSession(); ITransaction t = s.BeginTransaction(); Assert.AreEqual( 0, s.Find("from s in class Top").Count ); Multi multi = new Multi(); multi.ExtraProp = "extra"; multi.Name = "name"; Top simp = new Top(); simp.Date = DateTime.Now; simp.Name = "simp"; object mid; object sid; if( (dialect is Dialect.SybaseDialect) || (dialect is Dialect.MsSql2000Dialect) ) { mid = s.Save(multi); sid = s.Save(simp); } else { mid = 123L; sid = 1234L; s.Save(multi, mid); s.Save(simp, sid); } Lower ls = new Lower(); ls.Other = ls; ls.Another = ls; ls.YetAnother = ls; ls.Name = "Less Simple"; Iesi.Collections.ISet dict = new Iesi.Collections.HashedSet(); ls.Set = dict; dict.Add( multi ); dict.Add( simp ); object id; if( (dialect is Dialect.SybaseDialect) || (dialect is Dialect.MsSql2000Dialect) ) { id = s.Save(ls); } else { id = 2L; s.Save(ls, id); } t.Commit(); s.Close(); Assert.AreSame( ls, ls.Other ); Assert.AreSame( ls, ls.Another ); Assert.AreSame( ls, ls.YetAnother ); s = OpenSession(); t = s.BeginTransaction(); ls = (Lower)s.Load( typeof(Lower), id ); Assert.AreSame( ls, ls.Other ); Assert.AreSame( ls, ls.Another ); Assert.AreSame( ls, ls.YetAnother ); Assert.AreEqual( 2, ls.Set.Count ); int foundMulti = 0; int foundSimple = 0; foreach(object obj in ls.Set) { if( obj is Top ) foundSimple++; if( obj is Multi ) foundMulti++; } Assert.AreEqual( 2, foundSimple ); Assert.AreEqual( 1, foundMulti ); Assert.AreEqual( 3, s.Delete("from s in class Top") ); t.Commit(); s.Close(); }
public void SetDefaults() { DateTime today = new DateTime( DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day ); StringSet = new Iesi.Collections.HashedSet(); StringSet.Add( "foo" ); StringSet.Add( "bar" ); StringSet.Add( "baz" ); StringDateMap = new SortedList(); StringDateMap.Add( "now", DateTime.Now ); StringDateMap.Add( "never", null ); // according to SQL Server the big bag happened in 1753 ;) StringDateMap.Add( "big bang", new DateTime( 1753, 01, 01) ); //StringDateMap.Add( "millenium", new DateTime( 2000, 01, 01 ) ); ArrayList list = new ArrayList(); list.AddRange( StringSet ); StringList = list; IntArray = new int[] { 1,3,3,7 }; FooArray =new Foo[0]; StringArray = (String[]) list.ToArray(typeof(string) ); Customs = new ArrayList(); Customs.Add( new String[] { "foo", "bar" } ); Customs.Add( new String[] { "A", "B" } ); Customs.Add( new String[] { "1", "2" } ); FooSet = new Iesi.Collections.HashedSet(); Components = new FooComponent[] { new FooComponent("foo", 42, null, null), new FooComponent("bar", 88, null, new FooComponent("sub", 69, null, null) ) }; TimeArray = new DateTime[] { new DateTime(), new DateTime(), new DateTime(), // H2.1 has null here, but it's illegal on .NET new DateTime(0) }; Count = 667; Name="Bazza"; TopComponents = new ArrayList(); TopComponents.Add( new FooComponent("foo", 11, new DateTime[] { today, new DateTime(2123,1,1) }, null) ); TopComponents.Add( new FooComponent("bar", 22, new DateTime[] { new DateTime(2007,2,3), new DateTime(1945,6,1) }, null) ); TopComponents.Add( null ); Bag = new ArrayList(); Bag.Add("duplicate"); Bag.Add("duplicate"); Bag.Add("duplicate"); Bag.Add("unique"); //TODO: SET - verify right implementation Cached = new Iesi.Collections.ListSet(); CompositeElement ce = new CompositeElement(); ce.Foo = "foo"; ce.Bar = "bar"; CompositeElement ce2 = new CompositeElement(); ce2.Foo = "fooxxx"; ce2.Bar = "barxxx"; Cached.Add( ce ); Cached.Add( ce2 ); CachedMap = new SortedList(); CachedMap.Add(this, ce); }
public void Container() { ISession s = OpenSession(); ITransaction t = s.BeginTransaction(); Container c = new Container(); Simple x = new Simple(); x.Count = 123; Simple y = new Simple(); y.Count = 456; s.Save( x, (long)1 ); s.Save( y, (long)0 ); IList o2m = new ArrayList(); o2m.Add(x); o2m.Add(null); o2m.Add(y); IList m2m = new ArrayList(); m2m.Add(x); m2m.Add(null); m2m.Add(y); c.OneToMany = o2m; c.ManyToMany = m2m; IList comps = new ArrayList(); Container.ContainerInnerClass ccic = new Container.ContainerInnerClass(); ccic.Name = "foo"; ccic.Simple = x; comps.Add(ccic); comps.Add(null); ccic = new Container.ContainerInnerClass(); ccic.Name = "bar"; ccic.Simple = y; comps.Add(ccic); Iesi.Collections.ISet compos = new Iesi.Collections.HashedSet(); compos.Add( ccic ); c.Composites = compos; c.Components = comps; One one = new One(); Many many = new Many(); Iesi.Collections.ISet manies = new Iesi.Collections.HashedSet(); manies.Add( many ); one.Manies = manies; many.One = one; ccic.Many = many; ccic.One = one; s.Save(one); s.Save(many); s.Save(c); t.Commit(); s.Close(); s = OpenSession(); t = s.BeginTransaction(); c = (Container)s.Load( typeof(Container), c.Id ); ccic = (Container.ContainerInnerClass)c.Components[2]; Assert.AreEqual( ccic.One, ccic.Many.One ); Assert.AreEqual( 3, c.Components.Count ); Assert.AreEqual( 1, c.Composites.Count ); Assert.AreEqual( 3, c.OneToMany.Count ); Assert.AreEqual( 3, c.ManyToMany.Count ); for( int i=0; i<3; i++ ) { Assert.AreEqual( c.ManyToMany[i], c.OneToMany[i] ); } object o1 = c.OneToMany[0]; object o2 = c.OneToMany[2]; c.OneToMany.RemoveAt(2); c.OneToMany[0] = o2; c.OneToMany[1] = o1; o1 = c.Components[2]; c.Components.RemoveAt(2); c.Components[0] = o1; c.ManyToMany[0] = c.ManyToMany[2]; c.Composites.Add( o1 ); t.Commit(); s.Close(); s = OpenSession(); t = s.BeginTransaction(); c = (Container)s.Load( typeof(Container), c.Id ); Assert.AreEqual( 1, c.Components.Count ); //WAS: 2 - h2.0.3 comment Assert.AreEqual( 2, c.Composites.Count ); Assert.AreEqual( 2, c.OneToMany.Count ); Assert.AreEqual( 3, c.ManyToMany.Count ); Assert.IsNotNull( c.OneToMany[0] ); Assert.IsNotNull( c.OneToMany[1] ); ( (Container.ContainerInnerClass)c.Components[0]).Name = "a different name"; IEnumerator enumer = c.Composites.GetEnumerator(); enumer.MoveNext(); ( (Container.ContainerInnerClass)enumer.Current).Name = "once again"; t.Commit(); s.Close(); s = OpenSession(); t = s.BeginTransaction(); c = (Container)s.Load( typeof(Container), c.Id ); Assert.AreEqual( 1, c.Components.Count ); //WAS: 2 -> h2.0.3 comment Assert.AreEqual( 2, c.Composites.Count ); Assert.AreEqual( "a different name", ((Container.ContainerInnerClass)c.Components[0]).Name ); enumer = c.Composites.GetEnumerator(); bool found = false; while( enumer.MoveNext() ) { if( ( (Container.ContainerInnerClass)enumer.Current).Name.Equals("once again") ) { found = true; } } Assert.IsTrue(found); c.OneToMany.Clear(); c.ManyToMany.Clear(); c.Composites.Clear(); c.Components.Clear(); s.Delete("from s in class Simple"); s.Delete("from m in class Many"); s.Delete("from o in class One"); t.Commit(); s.Close(); s = OpenSession(); t = s.BeginTransaction(); c = (Container)s.Load( typeof(Container), c.Id ); Assert.AreEqual( 0, c.Components.Count ); Assert.AreEqual( 0, c.Composites.Count ); Assert.AreEqual( 0, c.OneToMany.Count ); Assert.AreEqual( 0, c.ManyToMany.Count ); s.Delete(c); t.Commit(); s.Close(); }