예제 #1
0
		public void UnflushedSessionSerialization()
		{
			///////////////////////////////////////////////////////////////////////////
			// Test insertions across serializations

			ISession s2;

			// NOTE: H2.1 has getSessions().openSession() here (and below),
			// instead of just the usual openSession()
			using (ISession s = sessions.OpenSession())
			{
				s.FlushMode = FlushMode.Never;

				Simple simple = new Simple();
				simple.Address = "123 Main St. Anytown USA";
				simple.Count = 1;
				simple.Date = new DateTime(2005, 1, 1);
				simple.Name = "My UnflushedSessionSerialization Simple";
				simple.Pay = 5000.0f;

				s.Save(simple, 10L);

				// Now, try to serialize session without flushing...
				s.Disconnect();

				s2 = SpoofSerialization(s);
			}

			Simple check, other;

			using (ISession s = s2)
			{
				s.Reconnect();

				Simple simple = (Simple) s.Load(typeof(Simple), 10L);
				other = new Simple();
				other.Init();
				s.Save(other, 11L);

				simple.Other = other;
				s.Flush();

				check = simple;
			}

			///////////////////////////////////////////////////////////////////////////
			// Test updates across serializations

			using (ISession s = sessions.OpenSession())
			{
				s.FlushMode = FlushMode.Never;
				Simple simple = (Simple) s.Get(typeof(Simple), 10L);
				Assert.AreEqual(check.Name, simple.Name, "Not same parent instances");
				Assert.AreEqual(check.Other.Name, other.Name, "Not same child instances");

				simple.Name = "My updated name";

				s.Disconnect();
				s2 = SpoofSerialization(s);

				check = simple;
			}

			using (ISession s = s2)
			{
				s.Reconnect();
				s.Flush();
			}

			///////////////////////////////////////////////////////////////////////////
			// Test deletions across serializations
			using (ISession s = sessions.OpenSession())
			{
				s.FlushMode = FlushMode.Never;
				Simple simple = (Simple) s.Get(typeof(Simple), 10L);
				Assert.AreEqual(check.Name, simple.Name, "Not same parent instances");
				Assert.AreEqual(check.Other.Name, other.Name, "Not same child instances");

				// Now, lets delete across serialization...
				s.Delete(simple);

				s.Disconnect();
				s2 = SpoofSerialization(s);
			}

			using (ISession s = s2)
			{
				s.Reconnect();
				s.Flush();
			}

			using (ISession s = OpenSession())
			{
				s.Delete("from Simple");
				s.Flush();
			}
		}
		public void FindBySQLStar()
		{
			ISession session = OpenSession();

			Category s = new Category();
			s.Name = nextLong.ToString();
			nextLong++;
			session.Save( s );

			Simple simple = new Simple();
			simple.Init();
			session.Save( simple, nextLong++ );

			A a = new A();
			session.Save( a );

			//B b = new B();
			//session.Save( b );

			session.CreateSQLQuery( "select {category.*} from Category {category}", "category", typeof( Category ) ).List();
			session.CreateSQLQuery( "select {simple.*} from Simple {simple}", "simple", typeof( Simple ) ).List();
			session.CreateSQLQuery( "select {a.*} from A {a}", "a", typeof( A ) ).List();

			session.Delete( s );
			session.Delete( simple );
			session.Delete( a );
			//session.Delete( b );
			session.Flush();
			session.Close();
		}