public FooComponent(String name, int count, DateTime[] dates, FooComponent subcomponent, Fee fee) { _name = name; _count = count; _importantDates = dates; _subcomponent = subcomponent; _fee = fee; }
public void UpdateFromTransient() { ISession s = OpenSession(); Fee fee1 = new Fee(); s.Save(fee1); Fee fee2 = new Fee(); fee1.TheFee = fee2; fee2.TheFee = fee1; fee2.Fees = new HashedSet(); Fee fee3 = new Fee(); fee3.TheFee = fee1; fee3.AnotherFee = fee2; fee2.AnotherFee = fee3; s.Save(fee3); s.Save(fee2); s.Flush(); s.Close(); fee1.Fi = "changed"; s = OpenSession(); s.SaveOrUpdate(fee1); s.Flush(); s.Close(); Qux q = new Qux("quxxy"); fee1.Qux = q; s = OpenSession(); s.SaveOrUpdate(fee1); s.Flush(); s.Close(); s = OpenSession(); fee1 = (Fee) s.Load(typeof(Fee), fee1.Key); Assert.AreEqual("changed", fee1.Fi, "updated from transient"); Assert.IsNotNull(fee1.Qux, "unsaved-value"); s.Delete(fee1.Qux); fee1.Qux = null; s.Flush(); s.Close(); fee2.Fi = "CHANGED"; fee2.Fees.Add("an element"); fee1.Fi = "changed again"; s = OpenSession(); s.SaveOrUpdate(fee2); s.Update(fee1, fee1.Key); s.Flush(); s.Close(); s = OpenSession(); Fee fee = new Fee(); s.Load(fee, fee2.Key); fee1 = (Fee) s.Load(typeof(Fee), fee1.Key); Assert.AreEqual("changed again", fee1.Fi, "updated from transient"); Assert.AreEqual("CHANGED", fee.Fi, "updated from transient"); Assert.IsTrue(fee.Fees.Contains("an element"), "updated collection"); s.Flush(); s.Close(); fee.Fees.Clear(); fee.Fees.Add("new element"); fee1.TheFee = null; s = OpenSession(); s.SaveOrUpdate(fee); s.SaveOrUpdate(fee1); s.Flush(); s.Close(); s = OpenSession(); s.Load(fee, fee.Key); Assert.IsNotNull(fee.AnotherFee, "update"); Assert.IsNotNull(fee.TheFee, "update"); Assert.AreSame(fee.AnotherFee.TheFee, fee.TheFee, "update"); Assert.IsTrue(fee.Fees.Contains("new element"), "updated collection"); Assert.IsFalse(fee.Fees.Contains("an element"), "updated collection"); s.Flush(); s.Close(); fee.Qux = new Qux("quxy"); s = OpenSession(); s.SaveOrUpdate(fee); s.Flush(); s.Close(); fee.Qux.Stuff = "xxx"; s = OpenSession(); s.SaveOrUpdate(fee); s.Flush(); s.Close(); s = OpenSession(); s.Load(fee, fee.Key); Assert.IsNotNull(fee.Qux, "cascade update"); Assert.AreEqual("xxx", fee.Qux.Stuff, "cascade update"); Assert.IsNotNull(fee.AnotherFee, "update"); Assert.IsNotNull(fee.TheFee, "update"); Assert.AreSame(fee.AnotherFee.TheFee, fee.TheFee, "update"); fee.AnotherFee.AnotherFee = null; s.Delete(fee); s.Delete("from fee in class NHibernate.DomainModel.Fee"); s.Flush(); s.Close(); }
public void UpdateOrder() { Fee fee1, fee2, fee3; using (ISession s = OpenSession()) { fee1 = new Fee(); s.Save(fee1); fee2 = new Fee(); fee1.TheFee = fee2; fee2.TheFee = fee1; fee2.Fees = new HashedSet(); fee3 = new Fee(); fee3.TheFee = fee1; fee3.AnotherFee = fee2; fee2.AnotherFee = fee3; s.Save(fee3); s.Save(fee2); s.Flush(); } using (ISession s = OpenSession()) { fee1.Count = 10; fee2.Count = 20; fee3.Count = 30; s.Update(fee1); s.Update(fee2); s.Update(fee3); s.Flush(); s.Delete(fee1); s.Delete(fee2); s.Delete(fee3); s.Flush(); } using (ISession s = OpenSession()) { using (ITransaction tx = s.BeginTransaction()) { Assert.AreEqual(0, s.CreateQuery("from fee in class Fee").List().Count); tx.Commit(); } } }
public void DeleteUpdatedTransient() { Fee fee = new Fee(); Fee fee2 = new Fee(); fee2.AnotherFee = fee; using (ISession s = OpenSession()) { using (ITransaction tx = s.BeginTransaction()) { s.Save(fee); s.Save(fee2); s.Flush(); fee.Count = 123; tx.Commit(); } } using (ISession s = OpenSession()) { using (ITransaction tx = s.BeginTransaction()) { s.Update(fee); //fee2.AnotherFee = null; s.Update(fee2); s.Delete(fee); s.Delete(fee2); tx.Commit(); } } using (ISession s = OpenSession()) { using (ITransaction tx = s.BeginTransaction()) { Assert.AreEqual(0, s.CreateQuery("from fee in class Fee").List().Count); tx.Commit(); } } }
public void DeleteTransient() { Fee fee = new Fee(); ISession s = OpenSession(); ITransaction tx = s.BeginTransaction(); s.Save(fee); s.Flush(); fee.Count = 123; tx.Commit(); s.Close(); s = OpenSession(); tx = s.BeginTransaction(); s.Delete(fee); tx.Commit(); s.Close(); s = OpenSession(); tx = s.BeginTransaction(); Assert.AreEqual(0, s.CreateQuery("from fee in class Fee").List().Count); tx.Commit(); s.Close(); }
public void SaveFlush() { ISession s = OpenSession(); Fee fee = new Fee(); s.Save(fee, "key"); fee.Fi = "blah"; s.Flush(); s.Close(); s = OpenSession(); fee = (Fee) s.Load(typeof(Fee), fee.Key); Assert.AreEqual("blah", fee.Fi); Assert.AreEqual("key", fee.Key); s.Delete(fee); s.Flush(); s.Close(); }
public void FetchList() { ISession s = OpenSession(); Baz baz = new Baz(); s.Save(baz); Foo foo = new Foo(); s.Save(foo); Foo foo2 = new Foo(); s.Save(foo2); s.Flush(); IList list = new ArrayList(); for (int i = 0; i < 5; i++) { Fee fee = new Fee(); list.Add(fee); } baz.Fees = list; list = s.CreateQuery("from Foo foo, Baz baz left join fetch baz.Fees").List(); Assert.IsTrue(NHibernateUtil.IsInitialized(((Baz) ((object[]) list[0])[1]).Fees)); s.Delete(foo); s.Delete(foo2); s.Delete(baz); s.Flush(); s.Close(); }
public LifecycleVeto OnSave(ISession s) { _string = "a string"; _date = new DateTime( 1970, 01, 01 ); _timestamp = DateTime.Now; _integer = -666; _long = 696969696969696969L - count++; _short = 42; _float = 6666.66f; //_double = new Double( 1.33e-69 ); // this double is too big for the sap db jdbc driver // _double = 1.12e-36; _boolean = true; _byte = 127; _int = 2; _char = '@'; _bytes = System.Text.Encoding.ASCII.GetBytes(_string); _status=FooStatus.ON; custom = new string[] { "foo", "bar" }; //_component = new FooComponent("foo", 12, new DateTime[] { _date, _timestamp, DateTime.MinValue, new DateTime( DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day ) }, new FooComponent("bar", 666, new DateTime[] { new DateTime(1999,12,3), DateTime.MinValue }, null ) ); _component = new FooComponent("foo", 12, new DateTime[] { _date, _timestamp, new DateTime( DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day ) }, new FooComponent("bar", 666, new DateTime[] { new DateTime(1999,12,3) }, null ) ); _component.Glarch = new Glarch(); _dependent = new Fee(); _dependent.Fi = "belongs to foo # " + Key; _locale = System.Threading.Thread.CurrentThread.CurrentCulture; return LifecycleVeto.NoVeto; }