Пример #1
1
 public virtual void Test2()
 {
     DeleteBase("t2.ndb");
     var odb = Open("t2.ndb");
     var query8 = odb.Query<User>();
     var nbUsers = query8.Execute<User>().Count;
     var query = odb.Query<Profile>();
     var nbProfiles = query.Execute<Profile>(true).Count;
     var query1 = odb.Query<VO.Login.Function>();
     var nbFunctions = query1.Execute<VO.Login.Function>(true).Count;
     var login = new VO.Login.Function("login");
     var logout = new VO.Login.Function("logout");
     IList<VO.Login.Function> list = new List<VO.Login.Function>();
     list.Add(login);
     list.Add(logout);
     var profile = new Profile("operator", list);
     var olivier = new User("olivier smadja", "*****@*****.**", profile);
     var aisa = new User("Aísa Galvão Smadja", "*****@*****.**", profile);
     odb.Store(olivier);
     odb.Store(aisa);
     odb.Commit();
     var query2 = odb.Query<User>();
     var users = query2.Execute<User>(true);
     var query3 = odb.Query<Profile>();
     var profiles = query3.Execute<Profile>(true);
     var query4 = odb.Query<VO.Login.Function>();
     var functions = query4.Execute<VO.Login.Function>(true);
     odb.Close();
     // println("Users:"+users);
     Println("Profiles:" + profiles);
     Println("Functions:" + functions);
     odb = Open("t2.ndb");
     var query5 = odb.Query<User>();
     var l = query5.Execute<User>(true);
     odb.Close();
     AssertEquals(nbUsers + 2, users.Count);
     var user2 = users.GetFirst();
     AssertEquals(olivier.ToString(), user2.ToString());
     AssertEquals(nbProfiles + 1, profiles.Count);
     AssertEquals(nbFunctions + 2, functions.Count);
     var odb2 = Open("t2.ndb");
     var query6 = odb2.Query<VO.Login.Function>();
     var l2 = query6.Execute<VO.Login.Function>(true);
     var function = l2.GetFirst();
     function.SetName("login function");
     odb2.Store(function);
     odb2.Close();
     var odb3 = Open("t2.ndb");
     var query7 = odb3.Query<User>();
     var l3 = query7.Execute<User>(true);
     var i = 0;
     while (l3.HasNext() && i < Math.Min(2, l3.Count))
     {
         var user = l3.Next();
         AssertEquals("login function", string.Empty + user.GetProfile().GetFunctions()[0]);
         i++;
     }
     odb3.Close();
     DeleteBase("t2.ndb");
 }
Пример #2
0
 public virtual void Test8()
 {
     DeleteBase(Name);
     var odb = Open(Name);
     var user = new User("name", "email", new Profile("p1", new VO.Login.Function("function")));
     odb.Store(user);
     odb.Close();
     odb = Open(Name);
     var query = odb.Query<Profile>();
     var p = query.Execute<Profile>().GetFirst();
     odb.Delete(p);
     odb.Close();
     odb = Open(Name);
     var query1 = odb.Query<User>();
     var user3 = query1.Execute<User>().GetFirst();
     AssertNull(user3.GetProfile());
     user3.SetProfile(new Profile("new profile", new VO.Login.Function("f1")));
     user3.SetEmail("email2");
     user3.SetName("name2");
     odb.Store(user3);
     odb.Close();
     odb = Open(Name);
     var query2 = odb.Query<User>();
     var user4 = query2.Execute<User>().GetFirst();
     odb.Close();
     DeleteBase(Name);
     AssertEquals("new profile", user4.GetProfile().GetName());
     AssertEquals("email2", user4.GetEmail());
     AssertEquals("name2", user4.GetName());
 }
Пример #3
0
 public virtual void TestSelectTrigger()
 {
     IOdb odb = null;
     DeleteBase("trigger.ndb");
     var myTrigger = new MySelectTrigger();
     try
     {
         odb = Open("trigger.ndb");
         var f1 = new VO.Login.Function("function1");
         var f2 = new VO.Login.Function("function2");
         var profile = new Profile("profile1", f1);
         var user = new User("oli", "*****@*****.**", profile);
         odb.Store(user);
         odb.Store(f2);
     }
     finally
     {
         if (odb != null)
             odb.Close();
     }
     odb = Open("trigger.ndb");
     odb.TriggerManagerFor<VO.Login.Function>().AddSelectTrigger(myTrigger);
     var query = odb.Query<VO.Login.Function>();
     var functions = query.Execute<VO.Login.Function>();
     odb.Close();
     DeleteBase("trigger.ndb");
     AssertEquals(2, functions.Count);
     AssertEquals(2, myTrigger.nbCalls);
 }
Пример #4
0
 public virtual void TestComplexInstance()
 {
     DeleteBase("t-complex-instance.ndb");
     var odb = Open("t-complex-instance.ndb");
     var login = new VO.Login.Function("login");
     var logout = new VO.Login.Function("logout");
     var functions = new List<VO.Login.Function>();
     functions.Add(login);
     functions.Add(logout);
     var profile = new Profile("profile1", functions);
     var user = new User("oliver", "*****@*****.**", profile);
     var user22 = new User("oliver2", "*****@*****.**", profile);
     odb.Store(user);
     odb.Store(user22);
     odb.Close();
     odb = Open("t-complex-instance.ndb");
     var query = odb.Query<User>();
     var l = query.Execute<User>(true);
     var user2 = l.GetFirst();
     // println("#### " + l.size() + " : " + l);
     AssertEquals(user.GetName(), user2.GetName());
     AssertEquals(user.GetEmail(), user2.GetEmail());
     AssertEquals(user.GetProfile().GetName(), user2.GetProfile().GetName());
     AssertEquals(user.GetProfile().GetFunctions()[0].ToString(), user2.GetProfile().GetFunctions()[0].ToString());
     odb.Close();
     DeleteBase("t-complex-instance.ndb");
 }
Пример #5
0
 public virtual void Test1()
 {
     DeleteBase("null.ndb");
     var odb = Open("null.ndb");
     var user1 = new User("oli", "oli@sdsadf", null);
     var user2 = new User("karine", "karine@sdsadf", null);
     var user3 = new User(null, null, null);
     odb.Store(user1);
     odb.Store(user2);
     odb.Store(user3);
     odb.Close();
     odb = Open("null.ndb");
     var query = odb.Query<User>();
     var l = query.Execute<User>(true);
     AssertEquals(3, l.Count);
     user1 = l.Next();
     AssertEquals("oli", user1.GetName());
     AssertEquals("oli@sdsadf", user1.GetEmail());
     AssertEquals(null, user1.GetProfile());
     user2 = l.Next();
     AssertEquals("karine", user2.GetName());
     AssertEquals("karine@sdsadf", user2.GetEmail());
     AssertEquals(null, user2.GetProfile());
     user3 = l.Next();
     AssertEquals(null, user3.GetName());
     AssertEquals(null, user3.GetEmail());
     AssertEquals(null, user3.GetProfile());
     odb.Close();
     DeleteBase("null.ndb");
 }
Пример #6
0
 public virtual void TestCriteriaQueryQueryWithValueInList()
 {
     var baseName = GetBaseName();
     Init(baseName);
     var odb = Open(baseName);
     var p0 = new Profile("profile0");
     p0.AddFunction(null);
     p0.AddFunction(new VO.Login.Function("f1"));
     p0.AddFunction(new VO.Login.Function("f2"));
     var p1 = new Profile("profile1");
     p1.AddFunction(null);
     p1.AddFunction(new VO.Login.Function("f12"));
     p1.AddFunction(new VO.Login.Function("f22"));
     var user = new User("The user", "themail", p0);
     var user2 = new User("The user2", "themail2", p1);
     odb.Store(user);
     odb.Store(user2);
     odb.Close();
     odb = Open(baseName);
     var criteriaQuery = odb.Query<VO.Login.Function>();
     criteriaQuery.Descend("name").Constrain((object) "f2").Equal();
     var f2bis = criteriaQuery.Execute<VO.Login.Function>().GetFirst();
     var query = odb.Query<User>();
     query.Descend("profile.functions").Constrain(f2bis).Contains();
     var l = query.Execute<User>();
     AssertEquals(1, l.Count());
     user = l.GetFirst();
     AssertEquals("The user", user.GetName());
     odb.Close();
 }
Пример #7
0
 public virtual void Test2()
 {
     IOdb odb = null;
     DeleteBase("trigger.ndb");
     var myTrigger = new MyTrigger();
     try
     {
         odb = Open("trigger.ndb");
         odb.TriggerManagerFor<VO.Login.Function>().AddInsertTrigger(myTrigger);
         var f1 = new VO.Login.Function("function1");
         var f2 = new VO.Login.Function("function2");
         var profile = new Profile("profile1", f1);
         var user = new User("oli", "*****@*****.**", profile);
         odb.Store(user);
         odb.Store(f2);
     }
     finally
     {
         if (odb != null)
             odb.Close();
     }
     odb = Open("trigger.ndb");
     odb.Close();
     DeleteBase("trigger.ndb");
     AssertEquals(2, myTrigger.nbInsertsBefore);
     AssertEquals(2, myTrigger.nbInsertsAfter);
 }
Пример #8
0
 public void TestClassInfo()
 {
     var user = new User("olivier smadja", "*****@*****.**",
                         new Profile("operator", new VO.Login.Function("login")));
     var classInfoList = ClassIntrospector.Introspect(user.GetType(), true);
     AssertEquals(OdbClassNameResolver.GetFullName(user.GetType()), classInfoList.GetMainClassInfo().FullClassName);
     AssertEquals(3, classInfoList.GetMainClassInfo().Attributes.Count);
     AssertEquals(3, classInfoList.GetClassInfos().Count);
 }
Пример #9
0
 private object GetUserInstance()
 {
     var login = new VO.Login.Function("login");
     var logout = new VO.Login.Function("logout");
     IList<VO.Login.Function> list = new List<VO.Login.Function>();
     list.Add(login);
     list.Add(logout);
     var profile = new Profile("operator", list);
     var user = new User("olivier smadja", "*****@*****.**", profile);
     return user;
 }
Пример #10
0
 private object GetInstance(int i)
 {
     var login = new VO.Login.Function("login " + i);
     var logout = new VO.Login.Function("logout" + i);
     IList<VO.Login.Function> list = new List<VO.Login.Function>();
     list.Add(login);
     list.Add(logout);
     var profile = new Profile("operator" + i, list);
     var user = new User("kiko" + i, "*****@*****.**" + i, profile);
     return user;
 }
Пример #11
0
        public void TestCompareCollection1()
        {
            const string dbName = "introspectortest1.odb";
            DeleteBase(dbName);
            var odb = OdbFactory.Open(dbName);

            var user = new User("olivier smadja", "*****@*****.**",
                                new Profile("operator", new VO.Login.Function("login")));
            IObjectInfoComparator comparator = new ObjectInfoComparator();

            var storageEngine = ((global::NDatabase.Odb)odb).GetStorageEngine();

            var instanceInfo =
                (NonNativeObjectInfo)
                new ObjectIntrospector(storageEngine.GetClassInfoProvider()).GetMetaRepresentation(user, true, null,
                                                                            new InstrumentationCallbackForStore(null,
                                                                                                                false));
            // Sets attributes offsets - this is normally done by reading then from
            // disk, but in this junit,
            // we must set them manually
            var offsets = new[] {1L, 2L, 3L};
            var ids = new[] {1, 2, 3};
            instanceInfo.GetHeader().SetAttributesIdentification(offsets);
            instanceInfo.GetHeader().SetAttributesIds(ids);
            instanceInfo.GetHeader().SetOid(OIDFactory.BuildObjectOID(1));
            var nnoiProfile = (NonNativeObjectInfo) instanceInfo.GetAttributeValueFromId(3);
            nnoiProfile.SetOid(OIDFactory.BuildObjectOID(2));

            var nnoiFunctions = (NonNativeObjectInfo) nnoiProfile.GetAttributeValueFromId(1);
            nnoiFunctions.SetOid(OIDFactory.BuildObjectOID(3));

            user.SetName("Olivier Smadja");
            var instanceInfo3 =
                (NonNativeObjectInfo)
                new ObjectIntrospector(storageEngine.GetClassInfoProvider()).GetMetaRepresentation(user, true, null,
                                                                            new InstrumentationCallbackForStore(null,
                                                                                                                false));
            instanceInfo3.GetHeader().SetOid(OIDFactory.BuildObjectOID(1));
            nnoiProfile = (NonNativeObjectInfo) instanceInfo3.GetAttributeValueFromId(3);
            nnoiProfile.SetOid(OIDFactory.BuildObjectOID(2));

            nnoiFunctions = (NonNativeObjectInfo)nnoiProfile.GetAttributeValueFromId(1);
            nnoiFunctions.SetOid(OIDFactory.BuildObjectOID(3));

            AssertTrue(comparator.HasChanged(instanceInfo, instanceInfo3));
            AssertEquals(1, comparator.GetNbChanges());

            odb.Close();
        }
Пример #12
0
        public virtual void Test3()
        {
            DeleteBase(OdbFileName1);
            DeleteBase(OdbFileName2);

            var odb = Open(OdbFileName1);
            for (var i = 0; i < 1500; i++)
            {
                var user = new User("olivier " + i, "[email protected] " + i, new Profile("profile" + i));
                odb.Store(user);
            }
            odb.Close();
            odb = Open(OdbFileName1);
            odb.DefragmentTo(OdbFileName2);
            var newOdb = Open(OdbFileName2);
            AssertEquals(odb.Query<User>().Count(), odb.Query<User>().Count());
            odb.Close();
            newOdb.Close();
            DeleteBase(OdbFileName1);
            DeleteBase(OdbFileName2);
        }
Пример #13
0
 private void Init(string baseName)
 {
     DeleteBase(baseName);
     var odb = Open(baseName);
     var start = OdbTime.GetCurrentTimeInTicks();
     var size = 10;
     for (var i = 0; i < size; i++)
     {
         var u = new User("user" + i, "email" + i,
                          new Profile("profile" + i, new VO.Login.Function("function " + i)));
         odb.Store(u);
     }
     var user = new User("big user", "big email",
                         new Profile("big profile", new VO.Login.Function("big function 1")));
     user.GetProfile().AddFunction(new VO.Login.Function("big function 2"));
     user.GetProfile().AddFunction(new VO.Login.Function("big function 3"));
     user.GetProfile().AddFunction(new VO.Login.Function("big function 4"));
     odb.Store(user);
     user = new User("user no function", "email no function", new Profile("profile no function"));
     odb.Store(user);
     odb.Close();
 }
Пример #14
0
 public virtual void Test1()
 {
     DeleteBase("t1.ndb");
     // LogUtil.allOn(true);
     var odb = Open("t1.ndb");
     // LogUtil.objectWriterOn(true);
     var login = new VO.Login.Function("login");
     IList<VO.Login.Function> list = new List<VO.Login.Function>();
     list.Add(login);
     var profile1 = new Profile("operator 1", list);
     var user = new User("olivier smadja", "*****@*****.**", profile1);
     odb.Store(user);
     odb.Close();
     odb = Open("t1.ndb");
     var query = odb.Query<User>();
     var users = query.Execute<User>(true);
     // assertEquals(nbUsers+2,users.size());
     var user2 = users.GetFirst();
     odb.Close();
     AssertEquals(user.ToString(), user2.ToString());
     DeleteBase("t1.ndb");
 }
Пример #15
0
        public void TestInstanceInfo2()
        {
            const string dbName = "TestInstanceInfo2.odb";
            DeleteBase(dbName);
            var odb = OdbFactory.Open(dbName);

            var user = new User("olivier smadja", "*****@*****.**",
                                new Profile("operator", new VO.Login.Function("login")));
            var ci = ClassIntrospector.Introspect(user.GetType(), true).GetMainClassInfo();

            var storageEngine = ((global::NDatabase.Odb)odb).GetStorageEngine();

            var instanceInfo =
                (NonNativeObjectInfo)
                new ObjectIntrospector(storageEngine.GetClassInfoProvider()).GetMetaRepresentation(user, true, null,
                                                                            new InstrumentationCallbackForStore(null,
                                                                                                                false));
            AssertEquals(instanceInfo.GetClassInfo().FullClassName, OdbClassNameResolver.GetFullName(user.GetType()));
            AssertEquals(instanceInfo.GetAttributeValueFromId(ci.GetAttributeId("name")).ToString(), "olivier smadja");

            odb.Close();
        }
Пример #16
0
        public virtual void Test1()
        {
            DeleteBase(OdbFileName1);
            DeleteBase(OdbFileName2);
            var odb = Open(OdbFileName1);
            var user = new User("olivier", "*****@*****.**", null);
            odb.Store(user);
            odb.Close();

            odb = Open(OdbFileName1);
            odb.DefragmentTo(OdbFileName2);
            var newOdb = Open(OdbFileName2);

            Decimal nbUser = odb.Query<User>().Count();
            Decimal nbNewUser = odb.Query<User>().Count();
            AssertEquals(nbUser, nbNewUser);
            AssertEquals(odb.Query<Profile>().Count(),
                         odb.Query<Profile>().Count());
            odb.Close();
            newOdb.Close();
            DeleteBase(OdbFileName1);
            DeleteBase(OdbFileName2);
        }
Пример #17
0
 public virtual void Test1WithCommit3()
 {
     var stopWatch = new StopWatch();
     stopWatch.Start();
     DeleteBase(FileName);
     var odb = Open(FileName);
     var f1 = new VO.Login.Function("function 1");
     Println(odb.Query<User>().Count());
     var p = new Profile("profile number 0", f1);
     p.AddFunction(new VO.Login.Function("f1"));
     var user = new User("user name 0", "user email 0", p);
     odb.Store(user);
     var p2 = new Profile("profile number 0", f1);
     p2.AddFunction(new VO.Login.Function("f2"));
     var user2 = new User("user name 0", "user email 0", p2);
     odb.Store(user2);
     odb.Close();
     odb = Open(FileName);
     IObjectSet<User> objectSet = null;
     for (var k = 0; k < 2; k++)
     {
         Console.Out.WriteLine(":" + k);
         var query = odb.Query<User>();
         objectSet = query.Execute<User>();
         while (objectSet.HasNext())
         {
             user = objectSet.Next();
             user.GetProfile().SetName(user.GetProfile().GetName() + "-updated");
             Println(user.GetProfile().GetName());
             odb.Store(user);
         }
     }
     odb.Close();
     odb = Open(FileName);
     var query1 = odb.Query<User>();
     objectSet = query1.Execute<User>();
     AssertEquals(2, objectSet.Count);
     odb.Close();
 }
Пример #18
0
        public void TestCopy()
        {
            const string dbName = "introspectortest2.odb";
            DeleteBase(dbName);
            var odb = OdbFactory.Open(dbName);

            var function = new VO.Login.Function("login");
            var profile = new Profile("operator", function);
            var user = new User("olivier smadja", "*****@*****.**", profile);

            var storageEngine = ((global::NDatabase.Odb)odb).GetStorageEngine();

            var instanceInfo =
                (NonNativeObjectInfo)
                new ObjectIntrospector(storageEngine.GetClassInfoProvider()).GetMetaRepresentation(user, true, null,
                                                                            new InstrumentationCallbackForStore(null,
                                                                                                                false));
            var copy = (NonNativeObjectInfo) instanceInfo.CreateCopy(new OdbHashMap<OID, AbstractObjectInfo>(), true);
            AssertEquals(3, copy.GetAttributeValues().Length);
            var aois = copy.GetAttributeValues();
            for (var i = 0; i < aois.Length; i++)
            {
                var aoi = aois[i];
                AssertEquals(instanceInfo.GetAttributeValues()[i].GetOdbTypeId(), aoi.GetOdbTypeId());
            }

            odb.Close();
        }
Пример #19
0
 public virtual void Test7()
 {
     DeleteBase(FileName);
     var odb = Open(FileName);
     var function = new VO.Login.Function("login");
     var profile = new Profile("operator", function);
     var user = new User("olivier smadja", "*****@*****.**", profile);
     odb.Store(user);
     odb.Close();
     odb = Open(FileName);
     var query = odb.Query<User>();
     var user2 = query.Execute<User>().GetFirst();
     user2.GetProfile().AddFunction(new VO.Login.Function("new Function"));
     odb.Store(user2);
     odb.Close();
     odb = Open(FileName);
     var query1 = odb.Query<User>();
     var user3 = query1.Execute<User>().GetFirst();
     AssertEquals(2, user3.GetProfile().GetFunctions().Count);
     var f1 = user3.GetProfile().GetFunctions()[0];
     var f2 = user3.GetProfile().GetFunctions()[1];
     AssertEquals("login", f1.GetName());
     AssertEquals("new Function", f2.GetName());
     odb.Close();
 }
Пример #20
0
 public virtual void Test8()
 {
     DeleteBase(FileName);
     var odb = Open(FileName);
     var function = new VO.Login.Function("login");
     var profile = new Profile("operator", function);
     var user = new User("olivier smadja", "*****@*****.**", profile);
     odb.Store(user);
     odb.Close();
     odb = Open(FileName);
     var query = odb.Query<User>();
     var user2 = query.Execute<User>().GetFirst();
     user2.SetProfile(null);
     odb.Store(user2);
     odb.Close();
     odb = Open(FileName);
     var query1 = odb.Query<User>();
     var user3 = query1.Execute<User>().GetFirst();
     AssertNull(user3.GetProfile());
     odb.Close();
 }
Пример #21
0
 public virtual void TestCompositeCollection4()
 {
     DeleteBase("t5.ndb");
     var odb = Open("t5.ndb");
     var query = odb.Query<User>();
     var nbUsers = query.Execute<User>(true).Count;
     var query1 = odb.Query<Profile>();
     var nbProfiles = query1.Execute<Profile>(true).Count;
     var query2 = odb.Query<VO.Login.Function>();
     var nbFunctions = query2.Execute<VO.Login.Function>(true).Count;
     var login = new VO.Login.Function("login");
     var logout = new VO.Login.Function("logout");
     IList<VO.Login.Function> list = new List<VO.Login.Function>();
     list.Add(login);
     list.Add(logout);
     var profile1 = new Profile("operator 1", list);
     var user = new User("olivier smadja", "*****@*****.**", profile1);
     var userB = new User("Aísa Galvão Smadja", "*****@*****.**", profile1);
     odb.Store(user);
     odb.Store(userB);
     odb.Commit();
     var query3 = odb.Query<User>();
     var users = query3.Execute<User>(true);
     var query4 = odb.Query<Profile>();
     var profiles = query4.Execute<Profile>(true);
     var query5 = odb.Query<VO.Login.Function>();
     var functions = query5.Execute<VO.Login.Function>(true);
     odb.Close();
     // assertEquals(nbUsers+2,users.size());
     var user2 = users.GetFirst();
     AssertEquals(user.ToString(), user2.ToString());
     AssertEquals(nbProfiles + 1, profiles.Count);
     AssertEquals(nbFunctions + 2, functions.Count);
 }
Пример #22
0
 public virtual void TestUpdateObjectReference4()
 {
     DeleteBase(FileName);
     var odb = Open(FileName);
     var function = new VO.Login.Function("login");
     var user = new User("olivier smadja", "*****@*****.**", null);
     odb.Store(user);
     odb.Close();
     var profile2 = new Profile("new operator", function);
     odb = Open(FileName);
     odb.Store(profile2);
     var query = odb.Query<User>();
     var user2 = query.Execute<User>().GetFirst();
     user2.SetProfile(profile2);
     odb.Store(user2);
     odb.Close();
     odb = Open(FileName);
     var query1 = odb.Query<User>();
     user2 = query1.Execute<User>().GetFirst();
     AssertEquals("new operator", user2.GetProfile().GetName());
     var query2 = odb.Query<Profile>();
     AssertEquals(1, query2.Execute<Profile>().Count);
     odb.Close();
 }
Пример #23
0
        public virtual void TestCriteriaQueryQueryWithValueInList2_with_null_object()
        {
            var baseName = GetBaseName();
            Init(baseName);
            var odb = Open(baseName);
            var p0 = new Profile("profile0");
            p0.AddFunction(new VO.Login.Function("f1"));
            p0.AddFunction(new VO.Login.Function("f2"));
            p0.AddFunction(new VO.Login.Function("f12"));
            p0.AddFunction(new VO.Login.Function("f22"));

            var p1 = new Profile("profile1");

            var user = new User("The user", "themail", p0);
            var user2 = new User("The user2", "themail2", p1);
            odb.Store(user);
            odb.Store(user2);
            odb.Close();
            odb = Open(baseName);
            var f2bis = new VO.Login.Function("f2");
            var query = odb.Query<Profile>();
            query.Descend("functions").Constrain(null).Contains();
            var l = query.Execute<Profile>();
            //One from test, one from init
            AssertEquals(2, l.Count());
            p1 = l.First(x => x.GetName().Equals("profile1"));
            AssertEquals("profile1", p1.GetName());
            odb.Close();
        }
Пример #24
0
        public void Test4()
        {
            DeleteBase(SublistDbName);

            int i;
            using (var odb = Open(SublistDbName))
            {
                IList<VO.Login.Function> functions1 = new List<VO.Login.Function>();

                for (i = 0; i < 30; i++)
                    functions1.Add(new VO.Login.Function("f1-" + i));

                IList<VO.Login.Function> functions2 = new List<VO.Login.Function>();

                for (i = 0; i < 60; i++)
                    functions2.Add(new VO.Login.Function("f2-" + i));

                IList<VO.Login.Function> functions3 = new List<VO.Login.Function>();

                for (i = 0; i < 90; i++)
                    functions3.Add(new VO.Login.Function("f3-" + i));

                var user1 = new User("User1", "*****@*****.**", new Profile("profile1", functions1));
                var user2 = new User("User2", "*****@*****.**", new Profile("profile2", functions2));
                var user3 = new User("User3", "*****@*****.**", new Profile("profile3", functions3));

                odb.Store(user1);
                odb.Store(user2);
                odb.Store(user3);
            }

            using (var odb = Open(SublistDbName))
            {
                var query = odb.Query<User>();
                var u = query.Execute<User>().GetFirst();
                Console.WriteLine(u);

                var q =
                    odb.ValuesQuery<Profile>().Field("name").Sublist("functions", 1, 2, false).Size(
                        "functions", "fsize");

                var v = q.Execute();

                i = 0;
                while (v.HasNext())
                {
                    var ov = v.NextValues();
                    var profileName = (string) ov.GetByAlias("name");
                    Println(profileName);

                    AssertEquals("profile" + (i + 1), profileName);
                    AssertEquals(Convert.ToInt64(30 * (i + 1)), ov.GetByAlias("fsize"));

                    var l = (IList) ov.GetByAlias("functions");
                    Println(l);
                    AssertEquals(2, l.Count);
                    i++;
                }
            }
        }
Пример #25
0
 public virtual void Test1WithCommit()
 {
     var stopWatch = new StopWatch();
     stopWatch.Start();
     var size = 10000;
     var size2 = 5000;
     var nbFunctions = 2;
     DeleteBase(FileName);
     var odb = Open(FileName);
     var f1 = new VO.Login.Function("function 1");
     // Create Objects
     for (var i = 0; i < size; i++)
     {
         var p = new Profile("profile number " + i, f1);
         for (var j = 0; j < nbFunctions; j++)
             p.AddFunction(new VO.Login.Function(" inner function of profile : number " + i + " - " + j));
         var user = new User("user name " + i, "user email " + i, p);
         odb.Store(user);
         if (i % 100 == 0)
         {
         }
     }
     // println("insert " + i);
     odb.Close();
     Println("created");
     // Updates 10 times the objects
     odb = Open(FileName);
     var query = odb.Query<User>();
     var objects = query.Execute<User>();
     Println("got the object " + objects.Count);
     for (var k = 0; k < 10; k++)
     {
         objects.Reset();
         var start = OdbTime.GetCurrentTimeInMs();
         for (var i = 0; i < size2; i++)
         {
             var user = objects.Next();
             user.GetProfile().SetName(user.GetProfile().GetName() + "-updated");
             odb.Store(user);
             if (i % 100 == 0)
             {
             }
         }
         // println("update " + i + " - " + k);
         Println("Update " + k + " - " + (OdbTime.GetCurrentTimeInMs() - start) + " ms");
     }
     Println("updated");
     // Delete the rest of the objects
     for (var i = size2; i < size; i++)
     {
         odb.Delete(objects.Next());
         if (i % 100 == 0)
             Println("delete " + i);
     }
     Println("deleted");
     odb.Close();
     // Check object count
     odb = Open(FileName);
     var query1 = odb.Query<User>();
     objects = query1.Execute<User>();
     AssertEquals(size2, objects.Count);
     // Check data of the objects
     var a = 0;
     while (objects.HasNext())
     {
         var user = objects.Next();
         AssertEquals("user name " + a, user.GetName());
         AssertEquals("user email " + a, user.GetEmail());
         AssertEquals(
             "profile number " + a +
             "-updated-updated-updated-updated-updated-updated-updated-updated-updated-updated",
             user.GetProfile().GetName());
         a++;
     }
     Println("checked");
     for (var k = 0; k < 10; k++)
     {
         objects.Reset();
         for (var i = 0; i < size2; i++)
         {
             var user = objects.Next();
             user.GetProfile().SetName(user.GetProfile().GetName() + "-updated" + "-");
             odb.Store(user);
         }
     }
     Println("re-updated");
     odb.Close();
     // delete objects
     odb = Open(FileName);
     var query2 = odb.Query<User>();
     objects = query2.Execute<User>();
     a = 0;
     while (objects.HasNext())
     {
         odb.Delete(objects.Next());
         a++;
     }
     AssertEquals(size2, a);
     odb.Close();
     odb = Open(FileName);
     var query3 = odb.Query<User>();
     AssertEquals(0, query3.Execute<User>().Count);
     AssertEquals(0, odb.Query<User>().Count());
     Println("deleted");
     odb.Close();
     stopWatch.End();
     Println("Total time 1 = " + stopWatch.GetDurationInMiliseconds());
     if (stopWatch.GetDurationInMiliseconds() > 90700)
         Fail("time is > than " + 90700 + " = " + stopWatch.GetDurationInMiliseconds());
 }
Пример #26
0
 public virtual void Test1WithoutCommit()
 {
     var stopWatch = new StopWatch();
     stopWatch.Start();
     var size = 10000;
     var size2 = 5000;
     var nbFunctions = 10;
     DeleteBase(FileName);
     var odb = Open(FileName);
     var f1 = new VO.Login.Function("function 1");
     // Create Objects
     for (var i = 0; i < size; i++)
     {
         var p = new Profile("profile number " + i, f1);
         for (var j = 0; j < nbFunctions; j++)
             p.AddFunction(new VO.Login.Function(" inner function of profile : number " + i + " - " + j));
         var user = new User("user name " + i, "user email " + i, p);
         odb.Store(user);
     }
     Println("created");
     // Updates 10 times the objects
     var query = odb.Query<User>();
     var objects = query.Execute<User>();
     for (var k = 0; k < 10; k++)
     {
         objects.Reset();
         for (var i = 0; i < size2; i++)
         {
             var user = objects.Next();
             user.GetProfile().SetName(user.GetProfile().GetName() + "-updated");
             odb.Store(user);
         }
     }
     Println("updated");
     // Delete the rest of the objects
     for (var i = size2; i < size; i++)
         odb.Delete(objects.Next());
     Println("deleted");
     // Check object count
     var query1 = odb.Query<User>();
     objects = query1.Execute<User>();
     AssertEquals(size2, objects.Count);
     // Check data of the objects
     var a = 0;
     while (objects.HasNext())
     {
         var user = objects.Next();
         AssertEquals("user name " + a, user.GetName());
         AssertEquals("user email " + a, user.GetEmail());
         AssertEquals(
             "profile number " + a +
             "-updated-updated-updated-updated-updated-updated-updated-updated-updated-updated",
             user.GetProfile().GetName());
         a++;
     }
     Println("checked");
     for (var k = 0; k < 10; k++)
     {
         objects.Reset();
         for (var i = 0; i < size2; i++)
         {
             var user = objects.Next();
             user.GetProfile().SetName(user.GetProfile().GetName() + "-updated" + "-");
             odb.Store(user);
         }
     }
     Println("re-updated");
     var query2 = odb.Query<User>();
     objects = query2.Execute<User>();
     var engine = ((global::NDatabase.Odb)odb).GetStorageEngine();
     var uncommited =
         engine.GetSession().GetMetaModel().GetClassInfo(typeof (User).FullName, true).UncommittedZoneInfo;
     CIZoneInfo commited =
         engine.GetSession().GetMetaModel().GetClassInfo(typeof (User).FullName, true).CommitedZoneInfo;
     Println("Before commit : uncommited=" + uncommited);
     Println("Before commit : commited=" + commited);
     a = 0;
     while (objects.HasNext())
     {
         // println("a="+a);
         odb.Delete(objects.Next());
         a++;
     }
     AssertEquals(size2, a);
     var query3 = odb.Query<User>();
     AssertEquals(0, query3.Execute<User>().Count);
     AssertEquals(0, odb.Query<User>().Count());
     Println("deleted");
     odb.Close();
     stopWatch.End();
     Println("Total time 2 = " + stopWatch.GetDurationInMiliseconds());
     if (stopWatch.GetDurationInMiliseconds() > 108438)
         Fail("time is > than " + 108438 + " = " + stopWatch.GetDurationInMiliseconds());
 }
Пример #27
0
 public virtual void Test5()
 {
     DeleteBase("t5.ndb");
     var odb = Open("t5.ndb");
     var nbFunctions = odb.Query<VO.Login.Function>().Count();
     var nbProfiles = odb.Query<Profile>().Count();
     var nbUsers = odb.Query<User>().Count();
     var login = new VO.Login.Function("login");
     var logout = new VO.Login.Function("logout");
     var list = new List<VO.Login.Function>();
     list.Add(login);
     list.Add(logout);
     var profile = new Profile("operator", list);
     var olivier = new User("olivier smadja", "*****@*****.**", profile);
     var aisa = new User("Aísa Galvão Smadja", "*****@*****.**", profile);
     odb.Store(olivier);
     odb.Store(profile);
     odb.Commit();
     odb.Close();
     odb = Open("t5.ndb");
     var query = odb.Query<User>();
     var users = query.Execute<User>(true);
     var query1 = odb.Query<Profile>();
     var profiles = query1.Execute<Profile>(true);
     var query2 = odb.Query<VO.Login.Function>();
     var functions = query2.Execute<VO.Login.Function>(true);
     odb.Close();
     AssertEquals(nbUsers + 1, users.Count);
     AssertEquals(nbProfiles + 1, profiles.Count);
     AssertEquals(nbFunctions + 2, functions.Count);
 }
Пример #28
0
 public virtual void Test9()
 {
     DeleteBase(Name);
     var odb = Open(Name);
     var user = new User("name", "email", new Profile("p1", new VO.Login.Function("function")));
     odb.Store(user);
     odb.Store(new Profile("new profile"));
     odb.Close();
     odb = Open(Name);
     var query = odb.Query<Profile>();
     query.Descend("name").Constrain((object) "new profile").Equal();
     var p = query.Execute<Profile>().GetFirst();
     p.SetName("new profile2");
     var query2 = odb.Query<User>();
     var user2 = query2.Execute<User>().GetFirst();
     user2.SetProfile(p);
     odb.Store(user2);
     odb.Close();
     odb = Open(Name);
     var query1 = odb.Query<User>();
     var user3 = query1.Execute<User>().GetFirst();
     AssertNotNull(user3.GetProfile());
     odb.Close();
     DeleteBase(Name);
     AssertEquals("new profile2", user3.GetProfile().GetName());
 }
Пример #29
0
 public virtual void Test6()
 {
     // LogUtil.objectWriterOn(true);
     DeleteBase("t6.ndb");
     var odb = Open("t6.ndb");
     var login = new VO.Login.Function("login");
     var logout = new VO.Login.Function("logout");
     var list = new List<VO.Login.Function>();
     list.Add(login);
     list.Add(logout);
     var profile = new Profile("operator", list);
     var olivier = new User("olivier smadja", "*****@*****.**", profile);
     odb.Store(olivier);
     odb.Close();
     Println("----------");
     odb = Open("t6.ndb");
     var query = odb.Query<User>();
     var users = query.Execute<User>(true);
     var u1 = users.GetFirst();
     u1.GetProfile().SetName("operator 234567891011121314");
     odb.Store(u1);
     odb.Close();
     odb = Open("t6.ndb");
     var query1 = odb.Query<Profile>();
     var profiles = query1.Execute<Profile>(true);
     AssertEquals(1, profiles.Count);
     var p1 = profiles.GetFirst();
     AssertEquals(u1.GetProfile().GetName(), p1.GetName());
 }