public void CreateDataAndIterateDb(int numObj)
        {
            using (SessionNoServer session = new SessionNoServer(systemDir))
            {
                session.Verify();
                session.Commit();
                session.BeginUpdate();
                UInt32   dbNum = session.DatabaseNumberOf(typeof(NotSharingPage));
                Database db    = session.OpenDatabase(dbNum, true, false);
                if (db != null)
                {
                    session.DeleteDatabase(db);
                }
                dbNum = session.DatabaseNumberOf(typeof(SharingPageTypeA));
                db    = session.OpenDatabase(dbNum, true, false);
                if (db != null)
                {
                    session.DeleteDatabase(db);
                }
                dbNum = session.DatabaseNumberOf(typeof(SharingPageTypeB));
                db    = session.OpenDatabase(dbNum, true, false);
                if (db != null)
                {
                    session.DeleteDatabase(db);
                }
                session.Commit();
            }

            using (SessionNoServer session = new SessionNoServer(systemDir))
            {
                session.Verify();
                session.Commit();
                session.BeginUpdate();
                UInt32    dbNum = session.DatabaseNumberOf(typeof(SharingPageTypeB));
                Placement place = new Placement(dbNum, 100);
                for (int i = 0; i < numObj; i++)
                {
                    NotSharingPage ns = new NotSharingPage();
                    session.Persist(ns);
                    SharingPageTypeA sA = new SharingPageTypeA();
                    session.Persist(sA);
                    SharingPageTypeB sB = new SharingPageTypeB();
                    if (i % 5 == 0)
                    {
                        sB.Persist(session, place);
                    }
                    else if (i % 1001 == 0)
                    {
                        sB.Persist(session, sA);
                    }
                    else if (i % 3001 == 0)
                    {
                        sB.Persist(session, ns);
                    }
                    else
                    {
                        session.Persist(sB);
                    }
                }
                session.Commit();
            }

            using (SessionNoServer session = new SessionNoServer(systemDir))
            {
                session.Verify();
                UInt32   dbNum = session.DatabaseNumberOf(typeof(NotSharingPage));
                Database db    = session.OpenDatabase(dbNum);
                AllObjects <NotSharingPage> all = db.AllObjects <NotSharingPage>();
                int ct = all.Count();
                dbNum = session.DatabaseNumberOf(typeof(SharingPageTypeA));
                OfType ofType = db.OfType(typeof(NotSharingPage));
                int    ct2    = (int)ofType.Count;
                Assert.AreEqual(ct, ct2);
                Database dbA = session.OpenDatabase(dbNum);
                dbNum = session.DatabaseNumberOf(typeof(SharingPageTypeB));
                Database dbB = session.OpenDatabase(dbNum);
                AllObjects <SharingPageTypeA> allA = dbA.AllObjects <SharingPageTypeA>();
                AllObjects <SharingPageTypeB> allB = dbB.AllObjects <SharingPageTypeB>();
                OfType           allA2             = dbA.OfType(typeof(SharingPageTypeA));
                int              start             = numObj / 2;
                NotSharingPage   ns  = all.ElementAt(numObj);
                SharingPageTypeA sA  = allA.ElementAt(numObj);
                SharingPageTypeA sA2 = (SharingPageTypeA)allA2.ElementAt(numObj);
                Assert.AreEqual(sA, sA2);
                sA  = allA.ElementAt(10);
                sA2 = (SharingPageTypeA)allA2.ElementAt(10);
                Assert.AreEqual(sA, sA2);
                //MethodInfo method = typeof(Database).GetMethod("AllObjects");
                //MethodInfo generic = method.MakeGenericMethod(sA.GetType());
                //dynamic itr = generic.Invoke(dbA, new object[]{ true });
                //SharingPageTypeA sAb = itr.ElementAt(numObj);
                //Assert.AreEqual(sA, sAb);
                //SharingPageTypeA sAc = itr.ElementAt(numObj);
                SharingPageTypeB        sB = allB.ElementAt(numObj);
                List <NotSharingPage>   notSharingPageList = all.Skip(100).ToList();
                List <SharingPageTypeA> sharingPageTypeA   = allA.Take(5).Skip(100).ToList();
                for (int i = start; i < numObj; i++)
                {
                    sA = allA.ElementAt(i);
                }
                for (int i = start; i < numObj; i += 5)
                {
                    ns = all.ElementAt(i);
                }
                for (int i = start; i < numObj; i += 5)
                {
                    sB = allB.ElementAt(i);
                }
                for (int i = 0; i < numObj; i += 45000)
                {
                    ns = all.ElementAt(i);
                }
                int allB_count = allB.Count();
                for (int i = 0; i < allB_count - 1; i++)
                {
                    Assert.NotNull(allB.ElementAt(i));
                }
                session.Commit();
                session.BeginUpdate();
                session.DeleteDatabase(db);
                session.DeleteDatabase(dbA);
                session.DeleteDatabase(dbB);
                session.Commit();
            }
        }
Esempio n. 2
0
        public void DeleteObjectsTestCreate(bool standalone, int count, UInt32 dbNumber)
        {
            SessionBase session;

            if (standalone)
            {
                session = new SessionNoServer(systemDir);
            }
            else
            {
                session = new ServerClientSession(systemDir);
            }
            VelocityDbSchema.Samples.Sample1.Person person;
            session.BeginUpdate();
            //session.SetTraceDbActivity(7676);
            var tw = new Stopwatch();

            tw.Start();
            UInt64[]  ids   = new UInt64[count];
            Placement place = new Placement(dbNumber);

            for (int i = 0; i < count; i++)
            {
                person = new VelocityDbSchema.Samples.Sample1.Person("Bill" + i, "Gates", 56);
                person.Persist(place, session);
                ids[i] = person.Id;
            }
            tw.Stop();
            Console.WriteLine("{0} records created in {1} ms.", count, tw.ElapsedMilliseconds);
            session.Commit();
            tw.Reset();
            tw.Start();
            session.BeginUpdate();
            for (int i = 0; i < count; i++)
            {
                session.DeleteObject(ids[i]);
            }
            session.Commit();
            tw.Stop();
            Console.WriteLine("{0} records deleted by Id in {1} ms.", count, tw.ElapsedMilliseconds);
            session.BeginRead();
            Database db = session.OpenDatabase(dbNumber);
            AllObjects <VelocityDbSchema.Samples.Sample1.Person> allPersons = db.AllObjects <VelocityDbSchema.Samples.Sample1.Person>();
            ulong ct = allPersons.Count();
            List <VelocityDbSchema.Samples.Sample1.Person> personList = db.AllObjects <VelocityDbSchema.Samples.Sample1.Person>().ToList();

            Assert.IsEmpty(personList);
            session.Commit();
            tw.Reset();
            tw.Start();
            session.BeginUpdate();
            for (int i = 0; i < count; i++)
            {
                person = new VelocityDbSchema.Samples.Sample1.Person("Bill" + i, "Gates", 56);
                person.Persist(place, session);
                ids[i] = person.Id;
            }
            session.Commit();
            tw.Stop();
            Console.WriteLine("{0} records created in {1} ms.", count, tw.ElapsedMilliseconds);
            tw.Reset();
            tw.Start();
            session.BeginUpdate();
            db = session.OpenDatabase(dbNumber);
            foreach (VelocityDbSchema.Samples.Sample1.Person p in db.AllObjects <VelocityDbSchema.Samples.Sample1.Person>())
            {
                p.Unpersist(session);
            }
            session.Commit();
            tw.Stop();
            Console.WriteLine("{0} records deleted in {1} ms.", count, tw.ElapsedMilliseconds);
            session.BeginRead();
            db         = session.OpenDatabase(dbNumber);
            allPersons = db.AllObjects <VelocityDbSchema.Samples.Sample1.Person>();
            ct         = allPersons.Count();
            personList = allPersons.ToList();
            Assert.IsEmpty(personList);
            //session.Verify();
            session.Commit();
            session.Dispose();
        }