Example #1
0
        public void TestBiDirectionalOneToManyMappingUsingSet()
        {
            ITransaction transaction = null;
            ISession     session     = null;

            try
            {
                session     = factory.OpenSession();
                transaction = session.BeginTransaction();

                BiDirectional.BDog someDog = new BiDirectional.BDog();
                someDog.Name = "Fido";

                BiDirectional.BLeg frontLeftLeg = new BiDirectional.BLeg();
                frontLeftLeg.Position = BiDirectional.BLeg.LegPosition.FrontLeft;
                frontLeftLeg.Owner    = someDog;
                BiDirectional.BLeg frontRightLeg = new BiDirectional.BLeg();
                frontRightLeg.Position = BiDirectional.BLeg.LegPosition.FrontRight;
                frontRightLeg.Owner    = someDog;
                BiDirectional.BLeg backLeftLeg = new BiDirectional.BLeg();
                backLeftLeg.Position = BiDirectional.BLeg.LegPosition.BackLeft;
                backLeftLeg.Owner    = someDog;
                BiDirectional.BLeg backRightLeg = new BiDirectional.BLeg();
                backRightLeg.Position = BiDirectional.BLeg.LegPosition.BackRight;
                backRightLeg.Owner    = someDog;
                Iesi.Collections.ListSet dogLegs = new Iesi.Collections.ListSet();
                dogLegs.Add(frontLeftLeg);
                dogLegs.Add(frontRightLeg);
                dogLegs.Add(backLeftLeg);
                dogLegs.Add(backRightLeg);

                someDog.Legs = (Iesi.Collections.ISet)dogLegs;

                session.Save(someDog);

                transaction.Commit();

                session.Close();
                session = null;

                Console.WriteLine("Dog.Id:{0}", someDog.Id);
                Console.WriteLine("Leg FrontLeftLeg.Id:{0}", frontLeftLeg.Id);
                Console.WriteLine("Leg FrontRightLeg.Id:{0}", frontRightLeg.Id);
                Console.WriteLine("Leg BackLeftLeg.Id:{0}", backLeftLeg.Id);
                Console.WriteLine("Leg BackRightLeg.Id:{0}", backRightLeg.Id);

                session = factory.OpenSession();

                string querySting = "from BiDirectional.BDog as aDog where aDog.Id=" + someDog.Id;
                IQuery query      = session.CreateQuery(querySting);
                IList  dogList    = query.List();
                foreach (BiDirectional.BDog aDog in dogList)
                {
                    Console.WriteLine("Dog Id:{0} - Name:{1}", aDog.Id, aDog.Name);
                    Console.WriteLine("Dog.Legs.Count:{0}", aDog.Legs.Count);
                    foreach (BiDirectional.BLeg aLeg in aDog.Legs)
                    {
                        Console.WriteLine("- Leg Id:{0} - Position:{1}", aLeg.Id, aLeg.Position);
                        if (aLeg.Owner != null)
                        {
                            Console.WriteLine("- Leg Owner Id:{0} - Name:{1}", aLeg.Owner.Id, aLeg.Owner.Name);
                            Console.WriteLine("- Leg ObjectIdentity: Dog == Leg.Owner ? {0}", Object.ReferenceEquals(aDog, aLeg.Owner));
                        }
                        else
                        {
                            Console.WriteLine("- Order Owner (No Owner)");
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                transaction.Rollback();
            }
            finally
            {
                session.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);
		}
Example #3
0
        public void TestUniDirectionalOneToManyMappingUsingSet()
        {
            ITransaction transaction = null;
            ISession     session     = null;

            try
            {
                session     = factory.OpenSession();
                transaction = session.BeginTransaction();

                UniDirectional.ULeg frontLeftLeg = new UniDirectional.ULeg();
                frontLeftLeg.Position = UniDirectional.ULeg.LegPosition.FrontLeft;
                UniDirectional.ULeg frontRightLeg = new UniDirectional.ULeg();
                frontRightLeg.Position = UniDirectional.ULeg.LegPosition.FrontRight;
                UniDirectional.ULeg backLeftLeg = new UniDirectional.ULeg();
                backLeftLeg.Position = UniDirectional.ULeg.LegPosition.BackLeft;
                UniDirectional.ULeg backRightLeg = new UniDirectional.ULeg();
                backRightLeg.Position = UniDirectional.ULeg.LegPosition.BackRight;
                Iesi.Collections.ListSet dogLegs = new Iesi.Collections.ListSet();
                dogLegs.Add(frontLeftLeg);
                dogLegs.Add(frontRightLeg);
                dogLegs.Add(backLeftLeg);
                dogLegs.Add(backRightLeg);

                UniDirectional.UDog someDog = new UniDirectional.UDog();
                someDog.Name = "Fido";
                someDog.Legs = (Iesi.Collections.ISet)dogLegs;

                session.Save(someDog);

                transaction.Commit();

                Console.WriteLine("Dog.Id:{0}", someDog.Id);
                Console.WriteLine("Leg FrontLeftLeg.Id:{0}", frontLeftLeg.Id);
                Console.WriteLine("Leg FrontRightLeg.Id:{0}", frontRightLeg.Id);
                Console.WriteLine("Leg BackLeftLeg.Id:{0}", backLeftLeg.Id);
                Console.WriteLine("Leg BackRightLeg.Id:{0}", backRightLeg.Id);


                string querySting = "from UniDirectional.UDog as aDog where aDog.Id=" + someDog.Id;
                IQuery query      = session.CreateQuery(querySting);
                IList  dogList    = query.List();
                foreach (UniDirectional.UDog aDog in dogList)
                {
                    Console.WriteLine("Dog Id:{0} - Name:{1}", aDog.Id, aDog.Name);
                    Console.WriteLine("Dog.Legs.Count:{0}", aDog.Legs.Count);
                    foreach (UniDirectional.ULeg aLeg in aDog.Legs)
                    {
                        Console.WriteLine("- Leg Id:{0} - Position:{1}", aLeg.Id, aLeg.Position);
                    }
                }
            }
            catch (Exception ex)
            {
                transaction.Rollback();
            }
            finally
            {
                session.Close();
            }
        }