public virtual void TestCriteriaQueryQueryWithValueInList2() { string baseName = GetBaseName(); SetUp(baseName); NeoDatis.Odb.ODB odb = Open(baseName); Profile p0 = new Profile("profile0" ); p0.AddFunction(new Function("f1")); p0.AddFunction(new Function("f2")); Profile p1 = new Profile("profile1" ); p0.AddFunction(new Function("f12")); p0.AddFunction(new Function("f22")); User user = new User("The user" , "themail", p0); User user2 = new User("The user2" , "themail2", p1); odb.Store(user); odb.Store(user2); odb.Close(); odb = Open(baseName); Function f2bis = (Function) odb.GetObjects <Function>(new CriteriaQuery(Where.Equal("name", "f2"))).GetFirst(); CriteriaQuery query = odb.CriteriaQuery(typeof(Profile), Where.Contain("functions", f2bis)); NeoDatis.Odb.Objects <Profile> l = odb.GetObjects <Profile>(query); AssertEquals(1, l.Count); p1 = l.GetFirst(); AssertEquals("profile0", p1.GetName()); odb.Close(); }
public virtual void TestReuse() { string baseName = GetBaseName(); NeoDatis.Odb.ODB odb = Open(baseName); System.Collections.Generic.IList <Profile> profiles = new System.Collections.Generic.List <Profile>(); profiles.Add(new Profile("p1", new Function ("f1"))); profiles.Add(new Profile("p2", new Function ("f2"))); ClassB cb = new ClassB ("name", profiles); odb.Store(cb); odb.Close(); odb = Open(baseName); Profile p = (Profile)odb.GetObjects <Profile>().GetFirst(); CriteriaQuery query = odb.CriteriaQuery(typeof( ClassB), Where.Equal("profiles", p)); EqualCriterion ec = (EqualCriterion )query.GetCriteria(); try { NeoDatis.Odb.Objects <ClassB> l = odb.GetObjects <ClassB>( query); } catch (System.Exception e) { AssertTrue(NeoDatis.Tool.Wrappers.OdbString.ExceptionToString(e, true).IndexOf("1063" ) != -1); } odb.Close(); }
public virtual void Test1() { string baseName = GetBaseName(); NeoDatis.Odb.ODB odb = Open(baseName); System.Collections.Generic.IList <Profile> profiles = new System.Collections.Generic.List <Profile>(); profiles.Add(new Profile("p1", new Function ("f1"))); profiles.Add(new Profile("p2", new Function ("f2"))); ClassB cb = new ClassB ("name", profiles); odb.Store(cb); odb.Close(); odb = Open(baseName); // this object is not known y NeoDatis so the query will not return anything Profile p = new Profile("p1", (System.Collections.Generic.IList <Function>)null); CriteriaQuery query = odb.CriteriaQuery(typeof( ClassB), Where .Contain("profiles", p)); NeoDatis.Odb.Objects <ClassB> l = odb.GetObjects <ClassB>( query); odb.Close(); AssertEquals(0, l.Count); }
/// <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***************"); }
/// <exception cref="System.Exception"></exception> public virtual void Test2() { string baseName = GetBaseName(); NeoDatis.Odb.ODB odb = Open(baseName); System.Collections.Generic.IList <NeoDatis.Odb.Test.VO.Login.Profile> profiles = new System.Collections.Generic.List <NeoDatis.Odb.Test.VO.Login.Profile>(); profiles.Add(new NeoDatis.Odb.Test.VO.Login.Profile("p1", new NeoDatis.Odb.Test.VO.Login.Function ("f1"))); profiles.Add(new NeoDatis.Odb.Test.VO.Login.Profile("p2", new NeoDatis.Odb.Test.VO.Login.Function ("f2"))); NeoDatis.Odb.Test.Query.Criteria.ClassB cb = new NeoDatis.Odb.Test.Query.Criteria.ClassB ("name", profiles); odb.Store(cb); odb.Close(); odb = Open(baseName); NeoDatis.Odb.Test.VO.Login.Profile p = (NeoDatis.Odb.Test.VO.Login.Profile)odb.GetObjects (typeof(NeoDatis.Odb.Test.VO.Login.Profile)).GetFirst(); NeoDatis.Odb.Impl.Core.Query.Criteria.CriteriaQuery query = odb.CriteriaQuery(typeof( NeoDatis.Odb.Test.Query.Criteria.ClassB), NeoDatis.Odb.Core.Query.Criteria.Where .Contain("profiles", p)); NeoDatis.Odb.Objects <NeoDatis.Odb.Test.Query.Criteria.ClassB> l = odb.GetObjects( query); odb.Close(); AssertEquals(1, l.Count); }
/// <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); }