Esempio n. 1
0
 private SimpleObject GetSimpleObjectInstance(int i)
 {
     var so = new SimpleObject();
     so.SetDate(new DateTime());
     so.SetDuration(i);
     so.SetName("Bonjour, comment allez vous?" + i);
     return so;
 }
 private SimpleObject GetSimpleObjectInstance(int i)
 {
     var so = new SimpleObject();
     so.SetDate(new DateTime());
     so.SetDuration(i);
     so.SetName("ola chico, como vc esta?" + i);
     return so;
 }
        public virtual void TestInsertSimpleObjectODB()
        {
            DeleteBase(OdbFileName);
            long t1  = 0;
            long t2  = 0;
            long t3  = 0;
            long t4  = 0;
            long t5  = 0;
            long t6  = 0;
            long t7  = 0;
            long t77 = 0;
            long t8  = 0;
            IOdb odb = null;
            IObjectSet <SimpleObject> l = null;
            SimpleObject so             = null;

            t1  = OdbTime.GetCurrentTimeInTicks();
            odb = Open(OdbFileName);
            for (var i = 0; i < TestSize; i++)
            {
                object o = GetSimpleObjectInstance(i);
                odb.Store(o);
                if (i % 20000 == 0)
                {
                    Console.Out.Write(".");
                    Println("After insert=" + ((global::NDatabase.Odb)odb).GetStorageEngine().GetSession().GetCache().ToString());
                }
            }
            //
            var engine = ((global::NDatabase.Odb)odb).GetStorageEngine();

            // println("NB WA="+WriteAction.count);
            Println("NB WAs=" + engine.GetSession().GetTransaction().GetNumberOfWriteActions());
            t2 = OdbTime.GetCurrentTimeInTicks();
            odb.Commit();
            Println("after commit : NB WAs=" + engine.GetSession().GetTransaction().GetNumberOfWriteActions());
            // if(true)return;
            // println("After commit="+Dummy.getEngine(odb).getSession().getCache().toString());
            // println("NB WA="+WriteAction.count);
            t3 = OdbTime.GetCurrentTimeInTicks();
            // println("end of insert");
            var query = odb.Query <SimpleObject>();

            l = query.Execute <SimpleObject>(false);
            // println("end of getObjects ");
            t4 = OdbTime.GetCurrentTimeInTicks();
            // println("After getObjects ="+Dummy.getEngine(odb).getSession().getCache().toString());
            // println("NB WA="+WriteAction.count);

            Println("after select : NB WAs=" + engine.GetSession().GetTransaction().GetNumberOfWriteActions());
            var nbObjects = l.Count;

            Println(nbObjects + " objects ");
            var k = 0;

            while (l.HasNext())
            {
                object o = l.Next();
                if (k % 9999 == 0)
                {
                    Println(((SimpleObject)o).GetName());
                }
                k++;
            }
            // println("end of real get ");
            t5 = OdbTime.GetCurrentTimeInTicks();
            Println("select " + (t5 - t3) + " - " + (t5 - t4));
            so = null;
            k  = 0;
            l.Reset();
            while (l.HasNext())
            {
                so = l.Next();
                so.SetName(so.GetName() + " updated");
                odb.Store(so);
                if (k % 10000 == 0)
                {
                    Println("update " + k);
                    Println("after update : NB WAs=" +
                            engine.GetSession().GetTransaction().GetNumberOfWriteActions());
                    Println("After update=" + ((global::NDatabase.Odb)odb).GetStorageEngine().GetSession().GetCache().ToString());
                }
                k++;
            }
            Println("after update : NB WAs=" + engine.GetSession().GetTransaction().GetNumberOfWriteActions());
            t6 = OdbTime.GetCurrentTimeInTicks();
            odb.Close();
            t7  = OdbTime.GetCurrentTimeInTicks();
            odb = Open(OdbFileName);
            var query1 = odb.Query <SimpleObject>();

            l   = query1.Execute <SimpleObject>(false);
            t77 = OdbTime.GetCurrentTimeInTicks();
            var j = 0;

            while (l.HasNext())
            {
                so = l.Next();
                AssertTrue(so.GetName().EndsWith("updated"));
                odb.Delete(so);
                if (j % 10000 == 0)
                {
                    Println("delete " + j);
                }
                j++;
            }
            odb.Close();
            t8  = OdbTime.GetCurrentTimeInTicks();
            odb = Open(OdbFileName);
            var query2 = odb.Query <SimpleObject>();

            AssertEquals(0, query2.Execute <SimpleObject>().Count);
            odb.Close();
            DisplayResult("ODB " + TestSize + " SimpleObject objects ", t1, t2, t3, t4, t5, t6, t7, t77, t8);
        }
Esempio n. 4
0
        public virtual void TestInsertSimpleObjectODB()
        {
            //OdbConfiguration.setReconnectObjectsToSession(false);
            // Thread.sleep(20000);
            var doUpdate = true;
            var doDelete = true;
            // Configuration.setDatabaseCharacterEncoding(null);
            // LogUtil.logOn(FileSystemInterface.LOG_ID,true);
            // LogUtil.logOn(ObjectReader.LOG_ID,true);
            // Configuration.setUseLazyCache(true);
            var inMemory = true;

            // Configuration.monitorMemory(true);
            // Configuration.setUseModifiedClass(true);
            // Deletes the database file
            DeleteBase(OdbFileName);
            long t1  = 0;
            long t2  = 0;
            long t3  = 0;
            long t4  = 0;
            long t5  = 0;
            long t6  = 0;
            long t7  = 0;
            long t77 = 0;
            long t8  = 0;
            IOdb odb = null;
            IObjectSet <SimpleObject> l = null;
            SimpleObject so             = null;

            // Insert TEST_SIZE objects
            Println("Inserting " + TestSize + " objects");
            t1  = OdbTime.GetCurrentTimeInMs();
            odb = Open(OdbFileName);
            var i = 0;

            // odb.getClassRepresentation(SimpleObject.class).addFullInstantiationHelper(new
            // SimpleObjectFullInstantiationHelper());
            for (i = 0; i < TestSize; i++)
            {
                object o = GetSimpleObjectInstance(i);
                odb.Store(o);
                if (i % 10000 == 0)
                {
                }
            }
            // println("i="+i);
            // Monitor.displayCurrentMemory(""+i,true);
            // println("Cache="+Dummy.getEngine(odb).getSession().getCache().toString());
            t2 = OdbTime.GetCurrentTimeInMs();
            // Closes the database
            odb.Close();
            // if(true)return;
            t3 = OdbTime.GetCurrentTimeInMs();
            Println("Retrieving " + TestSize + " objects");
            // Reopen the database
            odb = Open(OdbFileName);
            // Gets the TEST_SIZE objects
            var query = odb.Query <SimpleObject>();

            l  = query.Execute <SimpleObject>(inMemory);
            t4 = OdbTime.GetCurrentTimeInMs();
            i  = 0;
            while (l.HasNext())
            {
                object o = l.Next();
                if (i % 10000 == 0)
                {
                }
                // Monitor.displayCurrentMemory("select "+i,true);
                i++;
            }
            t5 = OdbTime.GetCurrentTimeInMs();
            if (doUpdate)
            {
                Println("Updating " + TestSize + " objects");
                i  = 0;
                so = null;
                l.Reset();
                while (l.HasNext())
                {
                    so = l.Next();
                    so.SetName(so.GetName() + " updated");
                    odb.Store(so);
                    if (i % 10000 == 0)
                    {
                    }
                    // Monitor.displayCurrentMemory(""+i);
                    i++;
                }
            }
            t6 = OdbTime.GetCurrentTimeInMs();
            odb.Close();
            t7 = OdbTime.GetCurrentTimeInMs();
            if (doDelete)
            {
                Println("Deleting " + TestSize + " objects");
                odb = Open(OdbFileName);
                var query1 = odb.Query <SimpleObject>();
                l   = query1.Execute <SimpleObject>(inMemory);
                t77 = OdbTime.GetCurrentTimeInTicks();
                // println("After getting objects - before delete");
                i = 0;
                while (l.HasNext())
                {
                    so = l.Next();
                    if (!so.GetName().EndsWith("updated"))
                    {
                        throw new Exception("Update  not ok for " + so.GetName());
                    }
                    odb.Delete(so);
                    if (i % 10000 == 0)
                    {
                    }
                    // println("s="+i);
                    i++;
                }
                odb.Close();
            }
            t8 = OdbTime.GetCurrentTimeInMs();

            Thread.Sleep(500);

            DisplayResult("ODB " + TestSize + " SimpleObject objects ", t1, t2, t3, t4, t5, t6, t7, t77, t8);
        }
        public virtual void T1estInsertSimpleObjectODB(int size)
        {
            OdbFileName = "perf-" + size + ".ndb";
            TestSize    = size;
            var doUpdate = true;
            var doDelete = true;

            var inMemory = true;

            // Deletes the database file
            DeleteBase(OdbFileName);
            long t1  = 0;
            long t2  = 0;
            long t3  = 0;
            long t4  = 0;
            long t5  = 0;
            long t6  = 0;
            long t7  = 0;
            long t77 = 0;
            long t8  = 0;
            IOdb odb = null;
            IObjectSet <SimpleObject> l = null;
            SimpleObject so             = null;

            // Insert TEST_SIZE objects
            Println("Inserting " + TestSize + " objects");
            t1  = OdbTime.GetCurrentTimeInMs();
            odb = Open(OdbFileName);
            var fields = new[] { "name" };

            odb.IndexManagerFor <SimpleObject>().AddUniqueIndexOn("index1", fields);
            for (var i = 0; i < TestSize; i++)
            {
                object o = GetSimpleObjectInstance(i);
                odb.Store(o);
            }
            // println("Cache="+Dummy.getEngine(odb).getSession().getCache().toString());
            t2 = OdbTime.GetCurrentTimeInMs();
            // Closes the database
            odb.Close();
            // if(true)return;
            t3 = OdbTime.GetCurrentTimeInMs();
            Println("Retrieving " + TestSize + " objects");
            // Reopen the database
            odb = Open(OdbFileName);
            // Gets the TEST_SIZE objects
            t4 = OdbTime.GetCurrentTimeInMs();
            IQuery q = null;

            for (var j = 0; j < TestSize; j++)
            {
                // println("Bonjour, comment allez vous?" + j);
                q = odb.Query <SimpleObject>();
                q.Descend("name").Constrain((object)("Bonjour, comment allez vous?" + j)).Equal();
                var objects = q.Execute <SimpleObject>();
                so = objects.GetFirst();
                if (!so.GetName().Equals("Bonjour, comment allez vous?" + j))
                {
                    throw new Exception("error while getting object : expected = " + "Bonjour, comment allez vous?" + j +
                                        " / actual = " + so.GetName());
                }
                if (j % 1000 == 0)
                {
                    Println("got " + j + " objects");
                }
            }
            t5 = OdbTime.GetCurrentTimeInMs();
            odb.Close();
            odb = Open(OdbFileName);
            if (doUpdate)
            {
                Println("Updating " + TestSize + " objects");
                so = null;
                var query = odb.Query <SimpleObject>();
                l = query.Execute <SimpleObject>(inMemory);
                while (l.HasNext())
                {
                    so = l.Next();
                    so.SetName(so.GetName().ToUpper());
                    odb.Store(so);
                }
            }
            t6 = OdbTime.GetCurrentTimeInMs();
            odb.Close();
            // if(true)return;
            t7 = OdbTime.GetCurrentTimeInMs();
            if (doDelete)
            {
                Println("Deleting " + TestSize + " objects");
                odb = Open(OdbFileName);
                Println("After open - before delete");
                var query = odb.Query <SimpleObject>();
                l   = query.Execute <SimpleObject>(inMemory);
                t77 = OdbTime.GetCurrentTimeInMs();
                Println("After getting objects - before delete");
                var i = 0;
                while (l.HasNext())
                {
                    so = l.Next();
                    if (!so.GetName().StartsWith("BONJOUR"))
                    {
                        throw new Exception("Update  not ok for " + so.GetName());
                    }
                    odb.Delete(so);
                    if (i % 10000 == 0)
                    {
                        Println("s=" + i);
                    }
                    // println("Cache="+Dummy.getEngine(odb).getSession().getCache().toString());
                    i++;
                }
                odb.Close();
            }
            t8 = OdbTime.GetCurrentTimeInMs();
            // t4 2 times
            DisplayResult("ODB " + TestSize + " SimpleObject objects ", t1, t2, t4, t4, t5, t6, t7, t77, t8);
        }