private SimpleObject GetSimpleObjectInstance(int i) { SimpleObject so = new SimpleObject (); so.SetDate(new System.DateTime()); so.SetDuration(i); so.SetName("Bonjour, comment allez vous?" + 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; NeoDatis.Odb.ODB odb = null; NeoDatis.Odb.Objects <SimpleObject> l = null; SimpleObject so = null; t1 = NeoDatis.Tool.Wrappers.OdbTime.GetCurrentTimeInMs(); odb = Open(OdbFileName); for (int i = 0; i < TestSize; i++) { object o = GetSimpleObjectInstance(i); odb.Store(o); if (i % 20000 == 0) { System.Console.Out.Write("."); Println("After insert=" + NeoDatis.Odb.Impl.Core.Layers.Layer3.Engine.Dummy.GetEngine (odb).GetSession(true).GetCache().ToString()); } } // NeoDatis.Odb.Core.Layers.Layer3.IStorageEngine engine = NeoDatis.Odb.Impl.Core.Layers.Layer3.Engine.Dummy .GetEngine(odb); if (isLocal) { // println("NB WA="+WriteAction.count); Println("NB WAs=" + engine.GetSession(true).GetTransaction().GetNumberOfWriteActions ()); } t2 = NeoDatis.Tool.Wrappers.OdbTime.GetCurrentTimeInMs(); odb.Commit(); if (isLocal) { Println("after commit : NB WAs=" + engine.GetSession(true).GetTransaction().GetNumberOfWriteActions ()); } // if(true)return; // println("After commit="+Dummy.getEngine(odb).getSession().getCache().toString()); // println("NB WA="+WriteAction.count); t3 = NeoDatis.Tool.Wrappers.OdbTime.GetCurrentTimeInMs(); // println("end of insert"); l = odb.GetObjects <SimpleObject>(false); // println("end of getObjects "); t4 = NeoDatis.Tool.Wrappers.OdbTime.GetCurrentTimeInMs(); // println("After getObjects ="+Dummy.getEngine(odb).getSession().getCache().toString()); // println("NB WA="+WriteAction.count); if (isLocal) { Println("after select : NB WAs=" + engine.GetSession(true).GetTransaction().GetNumberOfWriteActions ()); } int nbObjects = l.Count; Println(nbObjects + " objects "); int k = 0; while (l.HasNext()) { object o = l.Next(); if (k % 9999 == 0) { Println(((SimpleObject)o).GetName()); } k++; } // println("end of real get "); t5 = NeoDatis.Tool.Wrappers.OdbTime.GetCurrentTimeInMs(); Println("select " + (t5 - t3) + " - " + (t5 - t4)); so = null; k = 0; l.Reset(); while (l.HasNext()) { so = (SimpleObject)l.Next(); so.SetName(so.GetName() + " updated"); odb.Store(so); if (k % 10000 == 0) { Println("update " + k); if (isLocal) { Println("after update : NB WAs=" + engine.GetSession(true).GetTransaction().GetNumberOfWriteActions ()); Println("After update=" + NeoDatis.Odb.Impl.Core.Layers.Layer3.Engine.Dummy.GetEngine (odb).GetSession(true).GetCache().ToString()); } } k++; } if (isLocal) { Println("after update : NB WAs=" + engine.GetSession(true).GetTransaction().GetNumberOfWriteActions ()); } t6 = NeoDatis.Tool.Wrappers.OdbTime.GetCurrentTimeInMs(); odb.Close(); t7 = NeoDatis.Tool.Wrappers.OdbTime.GetCurrentTimeInMs(); odb = Open(OdbFileName); l = odb.GetObjects <SimpleObject>(false); t77 = NeoDatis.Tool.Wrappers.OdbTime.GetCurrentTimeInMs(); int j = 0; while (l.HasNext()) { so = (SimpleObject)l.Next(); AssertTrue(so.GetName().EndsWith("updated")); odb.Delete(so); if (j % 10000 == 0) { Println("delete " + j); } j++; } odb.Close(); t8 = NeoDatis.Tool.Wrappers.OdbTime.GetCurrentTimeInMs(); odb = Open(OdbFileName); AssertEquals(0, odb.GetObjects <SimpleObject>().Count); odb.Close(); DisplayResult("ODB " + TestSize + " SimpleObject objects ", t1, t2, t3, t4, t5, t6 , t7, t77, t8); }
/// <exception cref="System.Exception"></exception> public virtual void T1estInsertSimpleObjectODB(int size) { OdbFileName = "perf-" + size + ".neodatis"; TestSize = size; bool doUpdate = true; bool doDelete = true; int commitInterval = 100; // Configuration.setUseLazyCache(true); bool 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; NeoDatis.Odb.ODB odb = null; NeoDatis.Odb.Objects <SimpleObject> l = null; SimpleObject so = null; // Insert TEST_SIZE objects Println("Inserting " + TestSize + " objects"); t1 = NeoDatis.Tool.Wrappers.OdbTime.GetCurrentTimeInMs(); odb = Open(OdbFileName); string[] fields = new string[] { "name" }; odb.GetClassRepresentation(typeof(SimpleObject)).AddUniqueIndexOn ("index1", fields, true); for (int i = 0; i < TestSize; i++) { object o = GetSimpleObjectInstance(i); odb.Store(o); if (i % 10000 == 0) { // println("i="+i); NeoDatis.Odb.Impl.Tool.MemoryMonitor.DisplayCurrentMemory(string.Empty + i, false ); } } // println("Cache="+Dummy.getEngine(odb).getSession().getCache().toString()); t2 = NeoDatis.Tool.Wrappers.OdbTime.GetCurrentTimeInMs(); // Closes the database odb.Close(); // if(true)return; t3 = NeoDatis.Tool.Wrappers.OdbTime.GetCurrentTimeInMs(); Println("Retrieving " + TestSize + " objects"); // Reopen the database odb = Open(OdbFileName); // Gets the TEST_SIZE objects t4 = NeoDatis.Tool.Wrappers.OdbTime.GetCurrentTimeInMs(); NeoDatis.Odb.Core.Query.IQuery q = null; for (int j = 0; j < TestSize; j++) { // println("Bonjour, comment allez vous?" + j); q = new CriteriaQuery(Where.Equal("name", "Bonjour, comment allez vous?" + j)); NeoDatis.Odb.Objects <SimpleObject> objects = odb.GetObjects <SimpleObject>(q); AssertTrue(q.GetExecutionPlan().UseIndex()); so = objects.GetFirst(); if (!so.GetName().Equals("Bonjour, comment allez vous?" + j)) { throw new System.Exception("error while getting object : expected = " + "Bonjour, comment allez vous?" + j + " / actual = " + so.GetName()); } if (j % 1000 == 0) { Println("got " + j + " objects"); } } t5 = NeoDatis.Tool.Wrappers.OdbTime.GetCurrentTimeInMs(); odb.Close(); odb = Open(OdbFileName); if (doUpdate) { Println("Updating " + TestSize + " objects"); so = null; l = odb.GetObjects <SimpleObject>(inMemory); while (l.HasNext()) { so = (SimpleObject)l.Next(); so.SetName(so.GetName().ToUpper()); odb.Store(so); } } t6 = NeoDatis.Tool.Wrappers.OdbTime.GetCurrentTimeInMs(); odb.Close(); // if(true)return; t7 = NeoDatis.Tool.Wrappers.OdbTime.GetCurrentTimeInMs(); if (doDelete) { Println("Deleting " + TestSize + " objects"); odb = Open(OdbFileName); Println("After open - before delete"); l = odb.GetObjects <SimpleObject>(inMemory); t77 = NeoDatis.Tool.Wrappers.OdbTime.GetCurrentTimeInMs(); Println("After getting objects - before delete"); int i = 0; while (l.HasNext()) { so = (SimpleObject)l.Next(); if (!so.GetName().StartsWith("BONJOUR")) { throw new System.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 = NeoDatis.Tool.Wrappers.OdbTime.GetCurrentTimeInMs(); // t4 2 times DisplayResult("ODB " + TestSize + " SimpleObject objects ", t1, t2, t4, t4, t5, t6 , t7, t77, t8); }
private SimpleObject GetSimpleObjectInstance(int i) { SimpleObject so = new SimpleObject (); so.SetDate(new System.DateTime()); so.SetDuration(i); so.SetName("ola chico, como vc esta?" + i); return so; }