コード例 #1
0
ファイル: ASanityTests.cs プロジェクト: timotrob/VelocityDB
        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();
        }