/// <exception cref="System.Exception"></exception> public virtual void Test4() { string baseName = GetBaseName(); NeoDatis.Odb.ODB odb = Open(baseName); string[] fields = new string[] { "object" }; odb.GetClassRepresentation(typeof(NeoDatis.Odb.Test.Index.IndexedObject2)).AddUniqueIndexOn ("index1", fields, true); string[] fields2 = new string[] { "name" }; odb.GetClassRepresentation(typeof(NeoDatis.Odb.Test.Index.IndexedObject)).AddUniqueIndexOn ("index2", fields2, true); int size = isLocal ? 5000 : 500; for (int i = 0; i < size; i++) { odb.Store(new NeoDatis.Odb.Test.Index.IndexedObject2("Object " + i, new NeoDatis.Odb.Test.Index.IndexedObject ("Inner Object " + i, i, new System.DateTime()))); } odb.Close(); odb = Open(baseName); NeoDatis.Odb.Core.Query.IQuery q = new NeoDatis.Odb.Impl.Core.Query.Criteria.CriteriaQuery (typeof(NeoDatis.Odb.Test.Index.IndexedObject), NeoDatis.Odb.Core.Query.Criteria.Where .Equal("name", "Inner Object " + (size - 1))); // First get the object used to index, the last one. There is no index // on the class and field long start0 = NeoDatis.Tool.Wrappers.OdbTime.GetCurrentTimeInMs(); NeoDatis.Odb.Objects objects = odb.GetObjects(q); long end0 = NeoDatis.Tool.Wrappers.OdbTime.GetCurrentTimeInMs(); // check if index has been used AssertTrue(q.GetExecutionPlan().UseIndex()); NeoDatis.Odb.Test.Index.IndexedObject io = (NeoDatis.Odb.Test.Index.IndexedObject )objects.GetFirst(); Println("d0=" + (end0 - start0)); Println(q.GetExecutionPlan().GetDetails()); q = odb.CriteriaQuery(typeof(NeoDatis.Odb.Test.Index.IndexedObject2), NeoDatis.Odb.Core.Query.Criteria.Where .Equal("object", io)); long start = NeoDatis.Tool.Wrappers.OdbTime.GetCurrentTimeInMs(); objects = odb.GetObjects(q); long end = NeoDatis.Tool.Wrappers.OdbTime.GetCurrentTimeInMs(); Println("d=" + (end - start)); NeoDatis.Odb.Test.Index.IndexedObject2 o2 = (NeoDatis.Odb.Test.Index.IndexedObject2 )objects.GetFirst(); odb.Close(); AssertEquals("Object " + (size - 1), o2.GetName()); Println(q.GetExecutionPlan().GetDetails()); AssertTrue(q.GetExecutionPlan().UseIndex()); DeleteBase(baseName); }
/// <summary> /// Create objects, then create index, then execute a select with index, then /// rebuild index e execute /// </summary> /// <exception cref="System.Exception">System.Exception</exception> public virtual void TestDeleteIndex() { string baseName = GetBaseName(); DeleteBase(baseName); NeoDatis.Odb.ODB @base = Open(baseName); for (int i = 0; i < 2500; i++) { NeoDatis.Odb.Test.Index.IndexedObject3 io = new NeoDatis.Odb.Test.Index.IndexedObject3 (1 + i, 2, 3, "1" + i, "2", "3", new System.DateTime(2009, i, 1), new System.DateTime (), new System.DateTime()); @base.Store(io); } @base.Close(); @base = Open(baseName); NeoDatis.Odb.ClassRepresentation clazz = @base.GetClassRepresentation(typeof(NeoDatis.Odb.Test.Index.IndexedObject3 )); string[] indexFields1 = new string[] { "i1", "i2", "i3" }; clazz.AddUniqueIndexOn("index1", indexFields1, true); @base.Close(); @base = Open(baseName); NeoDatis.Odb.Core.Transaction.ISession session = NeoDatis.Odb.Impl.Core.Layers.Layer3.Engine.Dummy .GetEngine(@base).GetSession(true); NeoDatis.Odb.Core.Layers.Layer2.Meta.MetaModel metaModel = session.GetStorageEngine ().GetSession(true).GetMetaModel(); NeoDatis.Odb.Core.Layers.Layer2.Meta.ClassInfo ci = metaModel.GetClassInfo(typeof( NeoDatis.Odb.Test.Index.IndexedObject3).FullName, true); AssertEquals(1, ci.GetNumberOfIndexes()); AssertEquals(ci.GetIndex(0).GetName(), "index1"); AssertEquals(3, ci.GetIndex(0).GetAttributeIds().Length); AssertEquals(NeoDatis.Odb.Core.Layers.Layer2.Meta.ClassInfoIndex.Enabled, ci.GetIndex (0).GetStatus()); NeoDatis.Odb.Core.Query.IQuery q = new NeoDatis.Odb.Impl.Core.Query.Criteria.CriteriaQuery (typeof(NeoDatis.Odb.Test.Index.IndexedObject3), NeoDatis.Odb.Core.Query.Criteria.Where .And().Add(NeoDatis.Odb.Core.Query.Criteria.Where.Equal("i1", 10)).Add(NeoDatis.Odb.Core.Query.Criteria.Where .Equal("i2", 2)).Add(NeoDatis.Odb.Core.Query.Criteria.Where.Equal("i3", 3))); NeoDatis.Odb.Objects <NeoDatis.Odb.Test.Index.IndexedObject3> objects = @base.GetObjects (q); AssertEquals(true, q.GetExecutionPlan().UseIndex()); @base.GetClassRepresentation(typeof(NeoDatis.Odb.Test.Index.IndexedObject3)).DeleteIndex ("index1", true); @base.Close(); @base = Open(baseName); objects = @base.GetObjects(q); AssertEquals(false, q.GetExecutionPlan().UseIndex()); @base.Close(); DeleteBase(baseName); }
/// <summary>Test index creation without commit</summary> /// <exception cref="System.Exception">System.Exception</exception> public virtual void TestCreateIndexWithoutCommit() { string baseName = GetBaseName(); DeleteBase(baseName); NeoDatis.Odb.ODB @base = Open(baseName); NeoDatis.Odb.ClassRepresentation clazz = @base.GetClassRepresentation(typeof(NeoDatis.Odb.Test.Index.IndexedObject3 )); string[] indexFields1 = new string[] { "i1" }; clazz.AddUniqueIndexOn("index1", indexFields1, true); for (int i = 0; i < 10; i++) { NeoDatis.Odb.Test.Index.IndexedObject3 io = new NeoDatis.Odb.Test.Index.IndexedObject3 (1 + i, 2, 3, "1" + i, "2", "3", new System.DateTime(2009, i, 1), new System.DateTime (), new System.DateTime()); @base.Store(io); } @base.Close(); @base = Open(baseName); NeoDatis.Odb.Core.Query.IQuery q = new NeoDatis.Odb.Impl.Core.Query.Criteria.CriteriaQuery (typeof(NeoDatis.Odb.Test.Index.IndexedObject3), NeoDatis.Odb.Core.Query.Criteria.Where .Equal("i1", 1)); NeoDatis.Odb.Objects <NeoDatis.Odb.Test.Index.IndexedObject3> iis = @base.GetObjects (q); @base.Close(); AssertEquals(1, iis.Count); AssertTrue(q.GetExecutionPlan().UseIndex()); DeleteBase(baseName); }
public virtual void Test1() { string baseName = GetBaseName(); NeoDatis.Odb.ODB odb = null; int size = 10000; try { odb = Open(baseName); odb.GetClassRepresentation(typeof(NeoDatis.Odb.Test.VO.Login.Function)).AddIndexOn ("index1", new string[] { "name" }, true); for (int i = 0; i < size; i++) { odb.Store(new NeoDatis.Odb.Test.VO.Login.Function("function " + i)); } odb.Close(); odb = Open(baseName); // build a value query to retrieve only the name of the function NeoDatis.Odb.Core.Query.IValuesQuery vq = new NeoDatis.Odb.Impl.Core.Query.Values.ValuesCriteriaQuery (typeof(NeoDatis.Odb.Test.VO.Login.Function), NeoDatis.Odb.Core.Query.Criteria.Where .Equal("name", "function " + (size - 1))).Field("name"); NeoDatis.Odb.Values values = odb.GetValues(vq); AssertEquals(1, values.Count); Println(vq.GetExecutionPlan().GetDetails()); AssertEquals(true, vq.GetExecutionPlan().UseIndex()); } finally { if (odb != null) { odb.Close(); } } }
public virtual void Test1() { NeoDatis.Tool.IOUtil.DeleteFile("base1.neodatis"); NeoDatis.Odb.ODB odb = NeoDatis.Odb.ODBFactory.Open("base1.neodatis"); string[] fields = new string[] { "int1" }; odb.GetClassRepresentation(typeof(NeoDatis.Odb.Test.VO.Attribute.TestClass)).AddUniqueIndexOn ("index1", fields, true); long start = NeoDatis.Tool.Wrappers.OdbTime.GetCurrentTimeInMs(); int size = 50; for (int i = 0; i < size; i++) { NeoDatis.Odb.Test.VO.Attribute.TestClass testClass = new NeoDatis.Odb.Test.VO.Attribute.TestClass (); testClass.SetBigDecimal1(new System.Decimal(i)); testClass.SetBoolean1(i % 3 == 0); testClass.SetChar1((char)(i % 5)); testClass.SetDate1(new System.DateTime(start + i)); testClass.SetDouble1(((double)(i % 10)) / size); testClass.SetInt1(size - i); testClass.SetString1("test class " + i); odb.Store(testClass); } // println(testClass.getDouble1() + " | " + testClass.getString1() + // " | " + testClass.getInt1()); odb.Close(); }
/// <exception cref="System.Exception"></exception> public virtual void Test1() { Println("************START OF TEST1***************"); string baseName = GetBaseName(); DeleteBase("index-object"); NeoDatis.Odb.ODB odb = Open("index-object"); string[] fields = new string[] { "object" }; odb.GetClassRepresentation(typeof(NeoDatis.Odb.Test.Index.IndexedObject2)).AddUniqueIndexOn ("index1", fields, true); NeoDatis.Odb.Test.Index.IndexedObject2 o1 = new NeoDatis.Odb.Test.Index.IndexedObject2 ("Object1", new NeoDatis.Odb.Test.Index.IndexedObject("Inner Object 1", 10, new System.DateTime())); odb.Store(o1); odb.Close(); odb = Open("index-object"); // First get the object used to index NeoDatis.Odb.Objects objects = odb.GetObjects(typeof(NeoDatis.Odb.Test.Index.IndexedObject )); NeoDatis.Odb.Test.Index.IndexedObject io = (NeoDatis.Odb.Test.Index.IndexedObject )objects.GetFirst(); NeoDatis.Odb.Core.Query.IQuery q = odb.CriteriaQuery(typeof(NeoDatis.Odb.Test.Index.IndexedObject2 ), NeoDatis.Odb.Core.Query.Criteria.Where.Equal("object", io)); objects = odb.GetObjects(q); NeoDatis.Odb.Test.Index.IndexedObject2 o2 = (NeoDatis.Odb.Test.Index.IndexedObject2 )objects.GetFirst(); odb.Close(); AssertEquals(o1.GetName(), o2.GetName()); Println(q.GetExecutionPlan().GetDetails()); AssertFalse(q.GetExecutionPlan().GetDetails().IndexOf("index1") == -1); DeleteBase("index-object"); Println("************END OF TEST1***************"); }
/// <summary>Test the creation of an index after having created objects.</summary> /// <remarks> /// Test the creation of an index after having created objects. In this case /// ODB should creates the index and update it with already existing objects /// </remarks> /// <exception cref="System.Exception">System.Exception</exception> public virtual void Test1Object() { string OdbFileName = "index2"; NeoDatis.Odb.ODB odb = null; try { DeleteBase(OdbFileName); odb = Open(OdbFileName); NeoDatis.Odb.Test.Index.IndexedObject io = new NeoDatis.Odb.Test.Index.IndexedObject ("name", 5, new System.DateTime()); odb.Store(io); odb.Close(); odb = Open(OdbFileName); string[] names = new string[] { "name" }; odb.GetClassRepresentation(typeof(NeoDatis.Odb.Test.Index.IndexedObject)).AddUniqueIndexOn ("index1", names, true); NeoDatis.Odb.Objects objects = odb.GetObjects(new NeoDatis.Odb.Impl.Core.Query.Criteria.CriteriaQuery (typeof(NeoDatis.Odb.Test.Index.IndexedObject), NeoDatis.Odb.Core.Query.Criteria.Where .Equal("name", "name")), true); AssertEquals(1, objects.Count); } catch (System.Exception e) { Sharpen.Runtime.PrintStackTrace(e); } finally { if (odb != null) { odb.Close(); } } }
/// <exception cref="System.Exception"></exception> public virtual void Test3_BadAttributeInIndex() { string baseName = GetBaseName(); NeoDatis.Odb.ODB odb = null; string fieldName = "fkjdsfkjdhfjkdhjkdsh"; try { odb = Open(baseName); string[] fields = new string[] { fieldName }; odb.GetClassRepresentation(typeof(NeoDatis.Odb.Test.Index.IndexedObject2)).AddUniqueIndexOn ("index1", fields, true); Fail("Should have thrown an exception because the field " + fieldName + " does not exist" ); } catch (System.Exception) { } finally { // normal odb.Close(); DeleteBase(baseName); } }
/// <summary> /// Opens a connection C1, then create the index in another connection C2 and /// then stores the object in connection C1 /// </summary> /// <exception cref="System.Exception">System.Exception</exception> public virtual void TestCreateIndexInOtherConnectionNoCommit2() { if (isLocal || !testNewFeature) { return; } string baseName = GetBaseName(); DeleteBase(baseName); NeoDatis.Odb.ODB odb1 = Open(baseName); NeoDatis.Odb.ODB odb2 = Open(baseName); NeoDatis.Odb.ClassRepresentation clazz = odb2.GetClassRepresentation(typeof(NeoDatis.Odb.Test.Index.IndexedObject3 )); string[] indexFields1 = new string[] { "i1" }; clazz.AddUniqueIndexOn("index1", indexFields1, true); for (int i = 0; i < 10; i++) { NeoDatis.Odb.Test.Index.IndexedObject3 io = new NeoDatis.Odb.Test.Index.IndexedObject3 (1 + i, 2, 3, "1" + i, "2", "3", new System.DateTime(2009, i, 1), new System.DateTime (), new System.DateTime()); odb1.Store(io); } odb1.Close(); odb2.Close(); NeoDatis.Odb.ODB odb = Open(baseName); NeoDatis.Odb.Core.Query.IQuery q = new NeoDatis.Odb.Impl.Core.Query.Criteria.CriteriaQuery (typeof(NeoDatis.Odb.Test.Index.IndexedObject3), NeoDatis.Odb.Core.Query.Criteria.Where .Equal("i1", 1)); NeoDatis.Odb.Objects <NeoDatis.Odb.Test.Index.IndexedObject3> iis = odb.GetObjects (q); odb.Close(); AssertEquals(1, iis.Count); AssertTrue(q.GetExecutionPlan().UseIndex()); DeleteBase(baseName); }
/// <summary>Test the creation of an index after having created objects.</summary> /// <remarks> /// Test the creation of an index after having created objects. In this case /// ODB should creates the index and update it with already existing objects /// </remarks> /// <exception cref="System.Exception">System.Exception</exception> public virtual void Test100000Objects() { string OdbFileName = "index2"; NeoDatis.Odb.ODB odb = null; int size = isLocal ? 100000 : 10001; long start = NeoDatis.Tool.Wrappers.OdbTime.GetCurrentTimeInMs(); NeoDatis.Odb.OdbConfiguration.MonitorMemory(true); NeoDatis.Odb.OdbConfiguration.SetReconnectObjectsToSession(false); try { Println("MaxNbObjects/cache = " + NeoDatis.Odb.OdbConfiguration.GetMaxNumberOfObjectInCache ()); DeleteBase(OdbFileName); odb = Open(OdbFileName); for (int i = 0; i < size; i++) { NeoDatis.Odb.Test.Index.IndexedObject io = new NeoDatis.Odb.Test.Index.IndexedObject ("name" + i, i, new System.DateTime()); odb.Store(io); if (i % 10000 == 0) { NeoDatis.Odb.Impl.Tool.MemoryMonitor.DisplayCurrentMemory(i + " objects created", true); } } odb.Close(); Println("\n\n END OF INSERT \n\n"); odb = Open(OdbFileName); string[] names = new string[] { "name" }; odb.GetClassRepresentation(typeof(NeoDatis.Odb.Test.Index.IndexedObject)).AddUniqueIndexOn ("index1", names, true); Println("\n\n after create index\n\n"); NeoDatis.Odb.Objects objects = odb.GetObjects(new NeoDatis.Odb.Impl.Core.Query.Criteria.CriteriaQuery (typeof(NeoDatis.Odb.Test.Index.IndexedObject), NeoDatis.Odb.Core.Query.Criteria.Where .Equal("name", "name0")), true); Println("\n\nafter get Objects\n\n"); AssertEquals(1, objects.Count); objects = odb.GetObjects(new NeoDatis.Odb.Impl.Core.Query.Criteria.CriteriaQuery( typeof(NeoDatis.Odb.Test.Index.IndexedObject), NeoDatis.Odb.Core.Query.Criteria.Where .Equal("duration", 9)), true); AssertEquals(1, objects.Count); objects = odb.GetObjects(new NeoDatis.Odb.Impl.Core.Query.Criteria.CriteriaQuery( typeof(NeoDatis.Odb.Test.Index.IndexedObject)), true); AssertEquals(size, objects.Count); } catch (System.Exception e) { throw; } finally { long end = NeoDatis.Tool.Wrappers.OdbTime.GetCurrentTimeInMs(); Println((end - start) + "ms"); NeoDatis.Odb.OdbConfiguration.MonitorMemory(false); odb.Close(); } }
/// <exception cref="System.Exception"></exception> public virtual void TestSaveIndex() { string baseName = GetBaseName(); DeleteBase(baseName); NeoDatis.Odb.ODB @base = Open(baseName); NeoDatis.Odb.ClassRepresentation clazz = @base.GetClassRepresentation(typeof(NeoDatis.Odb.Test.Index.IndexedObject3 )); string[] indexFields1 = new string[] { "i1", "i2", "i3" }; clazz.AddUniqueIndexOn("index1", indexFields1, true); string[] indexFields2 = new string[] { "s1", "s2", "s3" }; clazz.AddUniqueIndexOn("index2", indexFields2, true); string[] indexFields3 = new string[] { "dt1", "dt2", "dt3" }; clazz.AddUniqueIndexOn("index3", indexFields3, true); string[] indexFields4 = new string[] { "i1", "i2", "i3", "s1", "s2", "s3", "dt1", "dt2", "dt3" }; clazz.AddUniqueIndexOn("index4", indexFields4, true); @base.Close(); @base = Open(baseName); NeoDatis.Odb.Core.Transaction.ISession session = NeoDatis.Odb.Impl.Core.Layers.Layer3.Engine.Dummy .GetEngine(@base).GetSession(true); NeoDatis.Odb.Core.Layers.Layer2.Meta.MetaModel metaModel = session.GetStorageEngine ().GetSession(true).GetMetaModel(); NeoDatis.Odb.Core.Layers.Layer2.Meta.ClassInfo ci = metaModel.GetClassInfo(typeof( NeoDatis.Odb.Test.Index.IndexedObject3).FullName, true); AssertEquals(4, ci.GetNumberOfIndexes()); AssertEquals(ci.GetIndex(0).GetName(), "index1"); AssertEquals(3, ci.GetIndex(0).GetAttributeIds().Length); AssertEquals(NeoDatis.Odb.Core.Layers.Layer2.Meta.ClassInfoIndex.Enabled, ci.GetIndex (0).GetStatus()); AssertEquals(ci.GetIndex(1).GetName(), "index2"); AssertEquals(3, ci.GetIndex(1).GetAttributeIds().Length); AssertEquals(NeoDatis.Odb.Core.Layers.Layer2.Meta.ClassInfoIndex.Enabled, ci.GetIndex (1).GetStatus()); AssertEquals(ci.GetIndex(2).GetName(), "index3"); AssertEquals(3, ci.GetIndex(2).GetAttributeIds().Length); AssertEquals(NeoDatis.Odb.Core.Layers.Layer2.Meta.ClassInfoIndex.Enabled, ci.GetIndex (2).GetStatus()); AssertEquals(ci.GetIndex(3).GetName(), "index4"); AssertEquals(9, ci.GetIndex(3).GetAttributeIds().Length); AssertEquals(NeoDatis.Odb.Core.Layers.Layer2.Meta.ClassInfoIndex.Enabled, ci.GetIndex (3).GetStatus()); @base.Close(); @base = Open(baseName); for (int i = 0; i < 10; i++) { NeoDatis.Odb.Test.Index.IndexedObject3 io = new NeoDatis.Odb.Test.Index.IndexedObject3 (1 + i, 2, 3, "1" + i, "2", "3", new System.DateTime(2009, i, 1), new System.DateTime (), new System.DateTime()); @base.Store(io); } @base.Close(); DeleteBase(baseName); }
/// <summary>Create, store and try retrieve the object without default constructor</summary> /// <exception cref="System.Exception">System.Exception</exception> public virtual void TestUseInstanceHelper() { NeoDatis.Odb.OdbConfiguration.SetEnableEmptyConstructorCreation(false); try { NeoDatis.Odb.ClassRepresentation carRepresentation = odb.GetClassRepresentation(typeof( NeoDatis.Odb.Test.Instantiationhelper.Car)); // create a db and store a object that has not default constructor NeoDatis.Odb.Test.Instantiationhelper.Car car = new NeoDatis.Odb.Test.Instantiationhelper.Car ("Ranger", 2006); odb.Store(car); odb.Commit(); CloseAndReopenDb(); NeoDatis.Odb.Objects cars; try { CheckCarRetrieval(); Fail("Expected exception"); } catch (NeoDatis.Odb.ODBRuntimeException) { } // expected CloseAndReopenDb(); carRepresentation.AddInstantiationHelper(new _InstantiationHelper_76()); CheckCarRetrieval(); CloseAndReopenDb(); carRepresentation.RemoveInstantiationHelper(); carRepresentation.AddParameterHelper(new _ParameterHelper_84()); try { CheckCarRetrieval(); Fail("Expected Exception"); } catch (NeoDatis.Odb.ODBRuntimeException) { } // expected odb.Close(); } finally { NeoDatis.Odb.OdbConfiguration.SetEnableEmptyConstructorCreation(true); } }
/// <exception cref="System.Exception"></exception> public virtual void Populate() { NeoDatis.Odb.ODB odb = Open("perfOValuesVsCriteriaIndex"); string[] atts = new string[] { "name" }; try { odb.GetClassRepresentation(typeof(NeoDatis.Odb.Test.VO.Login.User2)).AddUniqueIndexOn ("Index", atts, true); } catch (System.Exception) { } // TODO: handle exception int nbProfiles = 200; int nbUsers = 500000; NeoDatis.Odb.Test.VO.Login.Profile[] profiles = new NeoDatis.Odb.Test.VO.Login.Profile [nbProfiles]; NeoDatis.Odb.Test.VO.Login.User2[] users = new NeoDatis.Odb.Test.VO.Login.User2[nbUsers ]; int userStart = 1500000; int profileStart = 600; // First creates profiles for (int i = 0; i < nbProfiles; i++) { profiles[i] = new NeoDatis.Odb.Test.VO.Login.Profile("profile " + (i + profileStart ), new NeoDatis.Odb.Test.VO.Login.Function("function Profile" + i)); odb.Store(profiles[i]); } // Then creates users for (int i = 0; i < nbUsers; i++) { users[i] = new NeoDatis.Odb.Test.VO.Login.User2("user" + (i + userStart), "user mail" + i, profiles[GetProfileIndex(nbProfiles)], i); odb.Store(users[i]); if (i % 10000 == 0) { Println(i); } } odb.Close(); }
/// <summary>Test the creation of an index after having created objects.</summary> /// <remarks> /// Test the creation of an index after having created objects. In this case /// ODB should creates the index and update it with already existing objects /// </remarks> /// <exception cref="System.Exception">System.Exception</exception> public virtual void Test20000Objects() { string OdbFileName = "index2"; long start = NeoDatis.Tool.Wrappers.OdbTime.GetCurrentTimeInMs(); NeoDatis.Odb.ODB odb = null; int size = isLocal ? 20000 : 2000; try { DeleteBase(OdbFileName); odb = Open(OdbFileName); for (int i = 0; i < size; i++) { NeoDatis.Odb.Test.Index.IndexedObject io = new NeoDatis.Odb.Test.Index.IndexedObject ("name" + i, i, new System.DateTime()); odb.Store(io); } odb.Close(); odb = Open(OdbFileName); string[] names = new string[] { "name" }; odb.GetClassRepresentation(typeof(NeoDatis.Odb.Test.Index.IndexedObject)).AddUniqueIndexOn ("index1", names, true); NeoDatis.Odb.Objects objects = odb.GetObjects(new NeoDatis.Odb.Impl.Core.Query.Criteria.CriteriaQuery (typeof(NeoDatis.Odb.Test.Index.IndexedObject), NeoDatis.Odb.Core.Query.Criteria.Where .Equal("name", "name0")), true); AssertEquals(1, objects.Count); objects = odb.GetObjects(new NeoDatis.Odb.Impl.Core.Query.Criteria.CriteriaQuery( typeof(NeoDatis.Odb.Test.Index.IndexedObject)), true); NeoDatis.Odb.Impl.Tool.MemoryMonitor.DisplayCurrentMemory("BTREE", true); AssertEquals(size, objects.Count); } finally { if (odb != null) { odb.Close(); } long end = NeoDatis.Tool.Wrappers.OdbTime.GetCurrentTimeInMs(); Println((end - start) + "ms"); } }
/// <exception cref="System.Exception"></exception> public virtual void TestIndexFail() { string baseName = GetBaseName(); DeleteBase(baseName); NeoDatis.Odb.ODB @base = Open(baseName); string indexName = "index1"; NeoDatis.Odb.ClassRepresentation clazz = @base.GetClassRepresentation(typeof(NeoDatis.Odb.Test.Index.IndexedObject3 )); string[] indexFields1 = new string[] { "i1", "i2", "i3" }; clazz.AddUniqueIndexOn(indexName, indexFields1, true); @base.Close(); @base = Open(baseName); NeoDatis.Odb.Test.Index.IndexedObject3 io = new NeoDatis.Odb.Test.Index.IndexedObject3 (1, 2, 3, "1", "2", "3", new System.DateTime(), new System.DateTime(), new System.DateTime ()); @base.Store(io); try { NeoDatis.Odb.Test.Index.IndexedObject3 io2 = new NeoDatis.Odb.Test.Index.IndexedObject3 (1, 2, 3, "1", "2", "3", new System.DateTime(), new System.DateTime(), new System.DateTime ()); @base.Store(io2); } catch (System.Exception e) { AssertTrue(e.Message.IndexOf(indexName) != -1); } // println(e.getMessage()); @base.Close(); @base = Open(baseName); NeoDatis.Odb.Objects <NeoDatis.Odb.Test.Index.IndexedObject3> oo3 = @base.GetObjects (typeof(NeoDatis.Odb.Test.Index.IndexedObject3)); @base.Close(); AssertEquals(0, oo3.Count); DeleteBase(baseName); }
/// <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); }
/// <exception cref="System.Exception"></exception> public virtual void TestInsertSimpleObjectODB() { bool inMemory = true; // Deletes the database file NeoDatis.Tool.IOUtil.DeleteFile(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 l = null; NeoDatis.Odb.Test.VO.Login.User so = null; // Insert TEST_SIZE objects System.Console.Out.WriteLine("Inserting " + TestSize + " objects"); t1 = NeoDatis.Tool.Wrappers.OdbTime.GetCurrentTimeInMs(); odb = NeoDatis.Odb.ODBFactory.Open(OdbFileName); odb.GetClassRepresentation(typeof(NeoDatis.Odb.Test.VO.Login.User)).AddFullInstantiationHelper (new NeoDatis.Odb.Test.Performance.UserFullInstantiationHelper()); for (int i = 0; i < TestSize; i++) { object o = GetUserInstance(i); odb.Store(o); } t2 = NeoDatis.Tool.Wrappers.OdbTime.GetCurrentTimeInMs(); // Closes the database odb.Close(); t3 = NeoDatis.Tool.Wrappers.OdbTime.GetCurrentTimeInMs(); System.Console.Out.WriteLine("Retrieving " + TestSize + " objects"); // Reopen the database odb = NeoDatis.Odb.ODBFactory.Open(OdbFileName); // Gets retrieve the TEST_SIZE objects l = odb.GetObjects(typeof(NeoDatis.Odb.Test.VO.Login.User), inMemory); t4 = NeoDatis.Tool.Wrappers.OdbTime.GetCurrentTimeInMs(); // Actually get objects while (l.HasNext()) { object o = l.Next(); } t5 = NeoDatis.Tool.Wrappers.OdbTime.GetCurrentTimeInMs(); System.Console.Out.WriteLine("Updating " + TestSize + " objects"); so = null; l.Reset(); // Actually get objects while (l.HasNext()) { so = (NeoDatis.Odb.Test.VO.Login.User)l.Next(); // so.setName(so.getName() + " updated"); // so.setName(so.getName() + " updated-updated-updated-updated"); so.GetProfile().SetName(so.GetName() + " updated-updated-updated"); odb.Store(so); } t6 = NeoDatis.Tool.Wrappers.OdbTime.GetCurrentTimeInMs(); odb.Close(); t7 = NeoDatis.Tool.Wrappers.OdbTime.GetCurrentTimeInMs(); System.Console.Out.WriteLine("Deleting " + TestSize + " objects"); odb = NeoDatis.Odb.ODBFactory.Open(OdbFileName); l = odb.GetObjects(typeof(NeoDatis.Odb.Test.VO.Login.User), inMemory); t77 = NeoDatis.Tool.Wrappers.OdbTime.GetCurrentTimeInMs(); // Actually get objects while (l.HasNext()) { so = (NeoDatis.Odb.Test.VO.Login.User)l.Next(); odb.Delete(so); } odb.Close(); t8 = NeoDatis.Tool.Wrappers.OdbTime.GetCurrentTimeInMs(); odb = NeoDatis.Odb.ODBFactory.Open(OdbFileName); odb.Close(); DisplayResult("ODB " + TestSize + " User objects ", t1, t2, t3, t4, t5, t6, t7, t77 , t8); }