예제 #1
0
        public async Task CascadeCompositeElementsAsync()
        {
            Container c = new Container();

            c.Cascades = new List <Container.ContainerInnerClass>();
            Container.ContainerInnerClass cic = new Container.ContainerInnerClass();
            cic.Many = new Many();
            cic.One  = new One();
            c.Cascades.Add(cic);
            ISession s = OpenSession();

            await(s.SaveAsync(c));
            await(s.FlushAsync());
            s.Close();

            s = OpenSession();
            foreach (Container obj in await(s.CreateQuery("from c in class ContainerX").EnumerableAsync()))
            {
                c = obj;
                break;
            }
            foreach (Container.ContainerInnerClass obj in c.Cascades)
            {
                cic = obj;
                break;
            }
            Assert.IsNotNull(cic.Many);
            Assert.IsNotNull(cic.One);
            Assert.AreEqual(1, c.Cascades.Count);
            await(s.DeleteAsync(c));
            await(s.FlushAsync());
            s.Close();

            c = new Container();
            s = OpenSession();
            await(s.SaveAsync(c));
            c.Cascades = new List <Container.ContainerInnerClass>();
            cic        = new Container.ContainerInnerClass();
            cic.Many   = new Many();
            cic.One    = new One();
            c.Cascades.Add(cic);
            await(s.FlushAsync());
            s.Close();

            s = OpenSession();
            foreach (Container obj in await(s.CreateQuery("from c in class ContainerX").EnumerableAsync()))
            {
                c = obj;
            }
            foreach (Container.ContainerInnerClass obj in c.Cascades)
            {
                cic = obj;
            }
            Assert.IsNotNull(cic.Many);
            Assert.IsNotNull(cic.One);
            Assert.AreEqual(1, c.Cascades.Count);
            await(s.DeleteAsync(c));
            await(s.FlushAsync());
            s.Close();
        }
        public void CascadeCompositeElements()
        {
            if (!TestDialect.SupportsEmptyInsertsOrHasNonIdentityNativeGenerator)
            {
                Assert.Ignore("Support of empty inserts is required");
            }

            Container c = new Container();

            c.Cascades = new List <Container.ContainerInnerClass>();
            Container.ContainerInnerClass cic = new Container.ContainerInnerClass();
            cic.Many = new Many();
            cic.One  = new One();
            c.Cascades.Add(cic);
            ISession s = OpenSession();

            s.Save(c);
            s.Flush();
            s.Close();

            s = OpenSession();
            foreach (Container obj in s.CreateQuery("from c in class ContainerX").Enumerable())
            {
                c = obj;
                break;
            }
            foreach (Container.ContainerInnerClass obj in c.Cascades)
            {
                cic = obj;
                break;
            }
            Assert.IsNotNull(cic.Many);
            Assert.IsNotNull(cic.One);
            Assert.AreEqual(1, c.Cascades.Count);
            s.Delete(c);
            s.Flush();
            s.Close();

            c = new Container();
            s = OpenSession();
            s.Save(c);
            c.Cascades = new List <Container.ContainerInnerClass>();
            cic        = new Container.ContainerInnerClass();
            cic.Many   = new Many();
            cic.One    = new One();
            c.Cascades.Add(cic);
            s.Flush();
            s.Close();

            s = OpenSession();
            foreach (Container obj in s.CreateQuery("from c in class ContainerX").Enumerable())
            {
                c = obj;
            }
            foreach (Container.ContainerInnerClass obj in c.Cascades)
            {
                cic = obj;
            }
            Assert.IsNotNull(cic.Many);
            Assert.IsNotNull(cic.One);
            Assert.AreEqual(1, c.Cascades.Count);
            s.Delete(c);
            s.Flush();
            s.Close();
        }
        public void Container()
        {
            if (!TestDialect.SupportsEmptyInsertsOrHasNonIdentityNativeGenerator)
            {
                Assert.Ignore("Support of empty inserts is required");
            }

            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 <Simple> o2m = new List <Simple>();

            o2m.Add(x);
            o2m.Add(null);
            o2m.Add(y);
            IList <Simple> m2m = new List <Simple>();

            m2m.Add(x);
            m2m.Add(null);
            m2m.Add(y);
            c.OneToMany  = o2m;
            c.ManyToMany = m2m;
            IList <Container.ContainerInnerClass> comps = new List <Container.ContainerInnerClass>();

            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);

            var compos = new HashSet <Container.ContainerInnerClass> {
                ccic
            };

            c.Composites = compos;
            c.Components = comps;
            One  one  = new One();
            Many many = new Many();

            one.Manies = new HashSet <Many> {
                many
            };
            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]);
            }
            Simple o1 = c.OneToMany[0];
            Simple o2 = c.OneToMany[2];

            c.OneToMany.RemoveAt(2);
            c.OneToMany[0] = o2;
            c.OneToMany[1] = o1;
            Container.ContainerInnerClass comp = c.Components[2];
            c.Components.RemoveAt(2);
            c.Components[0] = comp;
            c.ManyToMany[0] = c.ManyToMany[2];
            c.Composites.Add(comp);
            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();
        }
예제 #4
0
        public void CascadeCompositeElements()
        {
            Container c    = new Container();
            IList     list = new ArrayList();

            c.Cascades = list;
            Container.ContainerInnerClass cic = new Container.ContainerInnerClass();
            cic.Many = new Many();
            cic.One  = new One();
            list.Add(cic);
            ISession s = OpenSession();

            s.Save(c);
            s.Flush();
            s.Close();

            s = OpenSession();
            foreach (Container obj in s.CreateQuery("from c in class ContainerX").Enumerable())
            {
                c = obj;
                break;
            }
            foreach (Container.ContainerInnerClass obj in c.Cascades)
            {
                cic = obj;
                break;
            }
            Assert.IsNotNull(cic.Many);
            Assert.IsNotNull(cic.One);
            Assert.AreEqual(1, c.Cascades.Count);
            s.Delete(c);
            s.Flush();
            s.Close();

            c = new Container();
            s = OpenSession();
            s.Save(c);
            list       = new ArrayList();
            c.Cascades = list;
            cic        = new Container.ContainerInnerClass();
            cic.Many   = new Many();
            cic.One    = new One();
            list.Add(cic);
            s.Flush();
            s.Close();

            s = OpenSession();
            foreach (Container obj in s.CreateQuery("from c in class ContainerX").Enumerable())
            {
                c = obj;
            }
            foreach (Container.ContainerInnerClass obj in c.Cascades)
            {
                cic = obj;
            }
            Assert.IsNotNull(cic.Many);
            Assert.IsNotNull(cic.One);
            Assert.AreEqual(1, c.Cascades.Count);
            s.Delete(c);
            s.Flush();
            s.Close();
        }
예제 #5
0
        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);

            ISet compos = new HashedSet();

            compos.Add(ccic);
            c.Composites = compos;
            c.Components = comps;
            One  one    = new One();
            Many many   = new Many();
            ISet manies = new 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();
        }