Example #1
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);
        }
Example #2
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);
        }
        public virtual void Test2()
        {
            DeleteBase("map-with-collections");
            IOdb odb = null;

            odb = Open("map-with-collections");
            var o = new MyMapObject("test");
            IList <MyMapObject> c = new List <MyMapObject>();

            c.Add(o);
            o.GetMap().Add("c", c);
            odb.Store(o);
            odb.Close();
            odb = Open("map-with-collections");
            var query = odb.Query <MyMapObject>();
            var os    = query.Execute <MyMapObject>();
            var mmo   = os.GetFirst();

            odb.Close();
            DeleteBase("map-with-collections");
            AssertEquals(o.GetName(), mmo.GetName());
            AssertEquals(o.GetMap().Count, mmo.GetMap().Count);
            var c1 = (ICollection)o.GetMap()["c"];
            var c2 = (ICollection)mmo.GetMap()["c"];

            AssertEquals(c1.Count, c2.Count);
            var enumerator = c2.GetEnumerator();

            enumerator.MoveNext();
            AssertEquals(mmo, enumerator.Current);
        }
Example #4
0
        public void test4()
        {
            try
            {
                int    size = 1000;
                string file = "Test.NDatabase";
                Console.WriteLine("Oi");
                OdbFactory.Delete(file);
                IOdb odb = OdbFactory.Open(file);
                for (int i = 0; i < size; i++)
                {
                    OID oid = odb.Store(new Function("function " + i));
                }
                odb.Close();

                odb = OdbFactory.Open(file);
                var query = odb.Query <Function>();

                query.Descend("name").Constrain((object)"function 199").Equal();

                var functions = query.Execute <Function>();
                Console.WriteLine(" Number of functions = " + functions.Count);

                odb.Close();
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
            Console.ReadLine();
        }
Example #5
0
        public virtual void Test1()
        {
            IOdb odb      = null;
            var  baseName = GetBaseName();

            DeleteBase(baseName);
            var myTrigger = new MyTriggerBefore();

            try
            {
                odb = Open(baseName);
                odb.TriggerManagerFor <SimpleObject>().AddInsertTrigger(myTrigger);
                var so  = new SimpleObject(5);
                var oid = odb.Store(so);
                AssertEquals(6, so.GetId());
                odb.Close();
                odb = Open(baseName);
                var so2 = (SimpleObject)odb.GetObjectFromId(oid);
                AssertEquals(6, so2.GetId());
            }
            finally
            {
                if (odb != null)
                {
                    odb.Close();
                }
            }
            DeleteBase(baseName);
        }
Example #6
0
        public virtual void Test7()
        {
            var  baseName = GetBaseName();
            IOdb odb      = null;

            odb = Open(baseName);
            var f1 = new VO.Login.Function("function1");
            var f2 = new VO.Login.Function("function2");
            var f3 = new VO.Login.Function("function3");

            odb.Store(f1);
            odb.Store(f2);
            odb.Store(f3);
            var id = odb.GetObjectId(f3);

            odb.Close();
            try
            {
                odb = Open(baseName);
                var f3bis = (VO.Login.Function)odb.GetObjectFromId(id);
                odb.Delete(f3bis);
                odb.Close();
                odb = Open(baseName);
                var query = odb.Query <VO.Login.Function>();
                var l     = query.Execute <VO.Login.Function>();
                odb.Close();
                AssertEquals(2, l.Count);
            }
            catch (OdbRuntimeException)
            {
                odb.Close();
                DeleteBase(baseName);
            }
        }
Example #7
0
        public virtual void Test20()
        {
            var  baseName = GetBaseName();
            IOdb odb      = null;

            odb = Open(baseName);
            var f0 = new VO.Login.Function("1function0");

            odb.Store(f0);
            odb.Close();
            odb = Open(baseName);
            var f1 = new VO.Login.Function("function1");

            odb.Store(f1);
            odb.Commit();
            var query = odb.Query <VO.Login.Function>();

            query.Descend("name").Constrain("func%").Like();
            var objects = query.Execute <VO.Login.Function>();

            AssertEquals(1, objects.Count);
            var f2  = objects.GetFirst();
            var oid = odb.GetObjectId(f2);

            odb.DeleteObjectWithId(oid);
            var query1 = odb.Query <VO.Login.Function>();

            AssertEquals(1, query1.Execute <VO.Login.Function>().Count);
            odb.Close();
            odb = Open(baseName);
            var query2 = odb.Query <VO.Login.Function>();

            objects = query2.Execute <VO.Login.Function>();
            AssertEquals(1, objects.Count);
        }
        public virtual void Test2()
        {
            var  baseName = GetBaseName();
            IOdb odb      = null;
            var  k        = 10;
            var  t1       = OdbTime.GetCurrentTimeInMs();
            var  fields   = new[] { "ok", "id", "name" };

            odb = Open(baseName);
            for (var i = 0; i < k; i++)
            {
                odb.Store(new User("john" + (k - i), "*****@*****.**", "ny 875", k - i + 1, new DateTime(t1 - i * 1000),
                                   i % 2 == 0));
                odb.Store(new User("john" + (k - i), "*****@*****.**", "ny 875", k - i, new DateTime(t1 - i * 1000),
                                   (i + 1) % 2 == 0));
            }
            odb.Close();
            odb = Open(baseName);
            var q = odb.Query <User>();

            q.Descend("ok").OrderAscending();
            q.Descend("id").OrderAscending();
            q.Descend("name").OrderAscending();
            var users = q.Execute <User>();

            odb.Close();
            if (k < 11)
            {
                //NDatabase.Tool.DisplayUtility.Display("test1", users);
            }
            var user = users.GetFirst();

            AssertTrue(user.GetName().StartsWith("john1"));
            AssertEquals(2, user.GetId());
        }
Example #9
0
        public void test1()
        {
            try
            {
                string file = "Test.NDatabase";
                OdbFactory.Delete(file);
                IOdb odb = OdbFactory.Open(file);
                OID  oid = odb.Store(new Function("f1"));
                odb.Close();
                Console.WriteLine("Write Done!");

                odb = OdbFactory.Open(file);
                var query = odb.Query <Function>();
                IObjectSet <Function> functions = query.Execute <Function>();
                Console.WriteLine(" Number of functions = " + functions.Count);
                Function f = (Function)odb.GetObjectFromId(oid);
                Console.WriteLine(f.ToString());
                odb.Close();
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
            Console.ReadLine();
        }
Example #10
0
        public virtual void Test9()
        {
            var  baseName = GetBaseName();
            IOdb odb      = null;

            odb = Open(baseName);
            var f1 = new VO.Login.Function("function1");
            var f2 = new VO.Login.Function("function2");
            var f3 = new VO.Login.Function("function3");

            odb.Store(f1);
            odb.Store(f2);
            odb.Store(f3);
            var id = odb.GetObjectId(f3);

            odb.Close();
            odb = Open(baseName);
            var f3bis = (VO.Login.Function)odb.GetObjectFromId(id);

            odb.Delete(f3bis);
            odb.Close();
            odb = Open(baseName);
            odb.Store(new VO.Login.Function("last function"));
            odb.Close();
            odb = Open(baseName);
            var query = odb.Query <VO.Login.Function>();
            var l     = query.Execute <VO.Login.Function>();

            odb.Close();
            AssertEquals(3, l.Count);
        }
Example #11
0
        public virtual void TestStringPersistence()
        {
            IOdb odb = null;

            DeleteBase("date.ndb");
            try
            {
                odb = Open("date.ndb");
                var tc1 = new TestClass();
                tc1.SetString1(string.Empty);
                odb.Store(tc1);
                odb.Close();
                odb = Open("date.ndb");
                var query = odb.Query <TestClass>();
                var l     = query.Execute <TestClass>();
                AssertEquals(1, l.Count);
                var tc2 = l.GetFirst();
                AssertEquals(string.Empty, (string)tc2.GetString1());
                AssertEquals(0m, tc2.GetBigDecimal1());
                AssertEquals(0d, tc2.GetDouble1());
            }
            finally
            {
                if (odb != null)
                {
                    odb.Close();
                }
            }
        }
Example #12
0
        public virtual void TestDatePersistence()
        {
            IOdb odb = null;

            DeleteBase("date.ndb");
            try
            {
                odb = Open("date.ndb");
                var tc1 = new TestClass();
                tc1.SetDate1(new DateTime());
                long t1 = tc1.GetDate1().Millisecond;
                odb.Store(tc1);
                odb.Close();
                odb = Open("date.ndb");
                var query = odb.Query <TestClass>();
                var l     = query.Execute <TestClass>();
                AssertEquals(1, l.Count);
                var tc2 = l.GetFirst();
                AssertEquals(t1, (long)tc2.GetDate1().Millisecond);
                AssertEquals(tc1.GetDate1(), tc2.GetDate1());
            }
            finally
            {
                if (odb != null)
                {
                    odb.Close();
                }
            }
            DeleteBase("date.ndb");
        }
Example #13
0
        public virtual void TestSelectUnCommitedObject()
        {
            IOdb odb = null;

            try
            {
                DeleteBase(BaseName);
                odb = Open(BaseName);
                for (var i = 0; i < 4; i++)
                {
                    odb.Store(new VO.Login.Function("function " + i));
                }
                odb.Close();
                // reopen the database
                odb = Open(BaseName);
                // stores a new function
                odb.Store(new VO.Login.Function("function uncommited"));
                var query     = odb.Query <VO.Login.Function>();
                var functions = query.Execute <VO.Login.Function>();
                AssertEquals(5, functions.Count);
            }
            finally
            {
                if (odb != null)
                {
                    odb.Close();
                    DeleteBase(BaseName);
                }
            }
        }
Example #14
0
        public virtual void Test21()
        {
            IOdb odb      = null;
            var  baseName = GetBaseName();

            odb = Open(baseName);
            var f0 = new VO.Login.Function("function0");

            odb.Store(f0);
            odb.Close();
            odb = Open(baseName);
            var f1 = new VO.Login.Function("function1");

            odb.Store(f1);
            var f2 = new VO.Login.Function("function2");

            odb.Store(f2);
            odb.Delete(f1);
            odb.Close();
            odb = Open(baseName);
            var objects = odb.Query <VO.Login.Function>().Execute <VO.Login.Function>();

            AssertEquals(2, objects.Count);
            odb.Close();
        }
Example #15
0
        public virtual void Test1()
        {
            IOdb odb = null;

            try
            {
                DeleteBase("mydb.ndb");
                // Open the database
                odb = Open("mydb.ndb");
                var t0       = OdbTime.GetCurrentTimeInTicks();
                var nRecords = 10000;
                for (var i = 0; i < nRecords; i++)
                {
                    var ao = new Class1(189, "csdcsdc");
                    odb.Store(ao);
                }
                odb.Close();
                var t1 = OdbTime.GetCurrentTimeInTicks();
                odb = Open("mydb.ndb");
                var query = odb.Query <Class1>();
                var ssss  = query.Execute <Class1>();
                var t2    = OdbTime.GetCurrentTimeInTicks();
                Println("Elapsed time for inserting " + nRecords + " records: " + (t1 - t0) + " / select = " + (t2 - t1));
            }
            finally
            {
                if (odb != null)
                {
                    // Close the database
                    odb.Close();
                }
            }
        }
        public virtual void Test1000Objects()
        {
            IOdb odb = null;

            DeleteBase(Base);
            try
            {
                odb = Open(Base);
                odb.TriggerManagerFor <ObjectWithAutoIncrementId>().AddInsertTrigger(new LocalAutoIncrementTrigger());
                for (var i = 0; i < 1000; i++)
                {
                    var o = new ObjectWithAutoIncrementId("Object " + (i + 1));
                    odb.Store(o);
                    AssertEquals(i + 1, o.GetId());
                }
                odb.Close();
                odb = Open(Base);
                odb.TriggerManagerFor <ObjectWithAutoIncrementId>().AddInsertTrigger(new LocalAutoIncrementTrigger());
                for (var i = 0; i < 1000; i++)
                {
                    var o = new ObjectWithAutoIncrementId("Object - bis - " + (i + 1));
                    odb.Store(o);
                    AssertEquals(1000 + i + 1, o.GetId());
                }
                odb.Close();
            }
            finally
            {
            }
        }
Example #17
0
        public virtual void Test19()
        {
            var  baseName = GetBaseName();
            IOdb odb      = null;

            odb = Open(baseName);
            var f1 = new VO.Login.Function("function1");

            odb.Store(f1);
            odb.Close();
            odb = Open(baseName);
            var query   = odb.Query <VO.Login.Function>();
            var objects = query.Execute <VO.Login.Function>();

            AssertEquals(1, objects.Count);
            var f2  = objects.GetFirst();
            var oid = odb.GetObjectId(f2);

            odb.DeleteObjectWithId(oid);
            var query1 = odb.Query <VO.Login.Function>();

            AssertEquals(0, query1.Execute <VO.Login.Function>().Count);
            odb.Close();
            odb = Open(baseName);
            var query2 = odb.Query <VO.Login.Function>();

            objects = query2.Execute <VO.Login.Function>();
            AssertEquals(0, objects.Count);
        }
Example #18
0
        public virtual void Test10()
        {
            var  baseName = GetBaseName();
            IOdb odb      = null;

            odb = Open(baseName);
            var  query = odb.Query <VO.Login.Function>();
            long size  = query.Execute <VO.Login.Function>().Count;
            var  f1    = new VO.Login.Function("function1");

            odb.Store(f1);
            odb.Close();
            odb = Open(baseName);
            var query1 = odb.Query <VO.Login.Function>();
            var f1bis  = query1.Execute <VO.Login.Function>().GetFirst();

            odb.Delete(f1bis);
            odb.Close();
            odb = Open(baseName);
            var query3 = odb.Query <VO.Login.Function>();

            AssertEquals(size, query3.Execute <VO.Login.Function>().Count);
            odb.Store(new VO.Login.Function("last function"));
            odb.Close();
            odb = Open(baseName);
            var query2 = odb.Query <VO.Login.Function>();
            var l      = query2.Execute <VO.Login.Function>();

            odb.Close();
            AssertEquals(size + 1, l.Count);
        }
Example #19
0
        public virtual void Test16()
        {
            var  baseName = GetBaseName();
            var  size     = 10000;
            IOdb odb      = null;

            DeleteBase(baseName);
            odb = Open(baseName);
            var oids = new OID[size];

            for (var i = 0; i < size; i++)
            {
                oids[i] = odb.Store(new VO.Login.Function("function" + i));
            }
            AssertEquals(size, odb.Query <VO.Login.Function>().Count());
            for (var i = 0; i < size; i++)
            {
                odb.DeleteObjectWithId(oids[i]);
            }
            AssertEquals(0, odb.Query <VO.Login.Function>().Count());
            for (var i = 0; i < size; i++)
            {
                oids[i] = odb.Store(new VO.Login.Function("function" + i));
            }
            AssertEquals(size, odb.Query <VO.Login.Function>().Count());
            odb.Close();
            odb = Open(baseName);
            var query = odb.Query <VO.Login.Function>();

            AssertEquals(size, query.Execute <VO.Login.Function>().Count);
            odb.Close();
            DeleteBase(baseName);
        }
Example #20
0
        public virtual void Test18()
        {
            var  baseName = GetBaseName();
            IOdb odb      = null;

            DeleteBase(baseName);
            odb = Open(baseName);
            var f1   = new VO.Login.Function("function1");
            var f2   = new VO.Login.Function("function2");
            var f3   = new VO.Login.Function("function2");
            var oid1 = odb.Store(f1);
            var oid2 = odb.Store(f2);
            var oid3 = odb.Store(f3);

            AssertEquals(3, odb.Query <VO.Login.Function>().Count());
            odb.Close();
            odb = Open(baseName);
            odb.DeleteObjectWithId(oid2);
            AssertEquals(2, odb.Query <VO.Login.Function>().Count());
            // odb.store(f1);
            odb.Store(new VO.Login.Function("f11"));
            odb.Store(new VO.Login.Function("f12"));
            odb.Store(new VO.Login.Function("f13"));
            // odb.store(f3);
            AssertEquals(5, odb.Query <VO.Login.Function>().Count());
            odb.Close();
            odb = Open(baseName);
            var query = odb.Query <VO.Login.Function>();

            AssertEquals(5, query.Execute <VO.Login.Function>().Count);
            odb.Close();
            DeleteBase(baseName);
        }
Example #21
0
        public virtual void Test15()
        {
            var  baseName = GetBaseName();
            IOdb odb      = null;

            odb = Open(baseName);
            var f1 = new VO.Login.Function("function1");
            var f2 = new VO.Login.Function("function2");

            odb.Store(f1);
            odb.Store(f2);
            AssertEquals(2, odb.Query <VO.Login.Function>().Count());
            odb.Delete(f1);
            odb.Delete(f2);
            AssertEquals(0, odb.Query <VO.Login.Function>().Count());
            odb.Store(f1);
            odb.Store(f2);
            AssertEquals(2, odb.Query <VO.Login.Function>().Count());
            odb.Close();
            odb = Open(baseName);
            var query = odb.Query <VO.Login.Function>();

            AssertEquals(2, query.Execute <VO.Login.Function>().Count);
            odb.Close();
            DeleteBase(baseName);
        }
        public virtual void Test2Objects()
        {
            IOdb odb = null;

            DeleteBase(Base);
            try
            {
                odb = Open(Base);
                odb.TriggerManagerFor <ObjectWithAutoIncrementId>().AddInsertTrigger(new LocalAutoIncrementTrigger());
                var o = new ObjectWithAutoIncrementId("Object 1");
                odb.Store(o);
                AssertEquals(1, o.GetId());
                odb.Close();
                odb = Open(Base);
                odb.TriggerManagerFor <ObjectWithAutoIncrementId>().AddInsertTrigger(new LocalAutoIncrementTrigger());
                o = new ObjectWithAutoIncrementId("Object 2");
                odb.Store(o);
                AssertEquals(2, o.GetId());
            }
            finally
            {
                if (odb != null)
                {
                    odb.Close();
                }
            }
        }
Example #23
0
        public virtual void Test14()
        {
            var  baseName = GetBaseName();
            IOdb odb      = null;

            odb = Open(baseName);
            var f1 = new VO.Login.Function("function1");
            var f2 = new VO.Login.Function("function2");
            var f3 = new VO.Login.Function("function3");
            var f4 = new VO.Login.Function("function4");
            var f5 = new VO.Login.Function("function5");

            odb.Store(f1);
            odb.Store(f2);
            odb.Store(f3);
            odb.Store(f4);
            odb.Store(f5);
            AssertEquals(5, odb.Query <VO.Login.Function>().Count());
            odb.Close();
            try
            {
                odb = Open(baseName);
                var f6 = new VO.Login.Function("function6");
                var f7 = new VO.Login.Function("function7");
                odb.Store(f6);
                odb.Store(f7);
                AssertEquals(7, odb.Query <VO.Login.Function>().Count());
                var query   = odb.Query <VO.Login.Function>();
                var objects = query.Execute <VO.Login.Function>();
                var i       = 0;
                while (objects.HasNext() && i < 4)
                {
                    odb.Delete <VO.Login.Function>(objects.Next());
                    i++;
                }
                AssertEquals(3, odb.Query <VO.Login.Function>().Count());
                odb.Close();
                odb = Open(baseName);
                AssertEquals(3, odb.Query <VO.Login.Function>().Count());
                var query1 = odb.Query <VO.Login.Function>();
                objects = query1.Execute <VO.Login.Function>();
                // println(objects);
                AssertEquals((string)"function5", (string)(objects.Next()).GetName());
                AssertEquals((string)"function6", (string)(objects.Next()).GetName());
                AssertEquals((string)"function7", (string)(objects.Next()).GetName());
                odb.Close();
            }
            catch (OdbRuntimeException)
            {
                DeleteBase(baseName);
                throw;
            }
            DeleteBase(baseName);
        }
Example #24
0
        public virtual void TestInsertWithCommitsSimpleObject()
        {
            DeleteBase("commits");
            IOdb odb            = null;
            var  size           = 10000;
            var  commitInterval = 1000;

            try
            {
                odb = Open("commits");
                for (var i = 0; i < size; i++)
                {
                    odb.Store(new VO.Login.Function("function " + i));
                    if (i % commitInterval == 0)
                    {
                        odb.Commit();
                        Console.WriteLine(i);
                    }
                }
            }
            finally
            {
                // println("commiting "+i);
                odb.Close();
            }
            odb = Open("commits");
            var query     = odb.Query <VO.Login.Function>();
            var objects   = query.Execute <VO.Login.Function>();
            var nbObjects = objects.Count;
            var map       = new OdbHashMap <VO.Login.Function, int>();

            VO.Login.Function function = null;
            var j = 0;

            while (objects.HasNext())
            {
                function = objects.Next();
                var ii = map[function];
                if (ii != 0)
                {
                    Println(j + ":" + function.GetName() + " already exist at " + ii);
                }
                else
                {
                    map.Add(function, j);
                }
                j++;
            }
            odb.Close();
            DeleteBase("commits");
            Println("Nb objects=" + nbObjects);
            AssertEquals(size, nbObjects);
        }
Example #25
0
        public virtual void TestSelectUnCommitedObject3()
        {
            DeleteBase(BaseName);
            // Create instance
            var  sport = new Sport("volley-ball");
            IOdb odb   = null;

            try
            {
                // Open the database
                odb = Open(BaseName);
                // Store the object
                odb.Store(sport);
            }
            finally
            {
                if (odb != null)
                {
                    // Close the database
                    odb.Close();
                }
            }
            try
            {
                // Open the database
                odb = Open(BaseName);
                // Let's insert a tennis player
                var agassi = new Player("André Agassi", new DateTime(), new Sport("Tennis"));
                odb.Store(agassi);
                IQuery query = odb.Query <Player>();
                query.Descend("favoriteSport.name").Constrain((object)"volley-ball").Equal();
                var players = query.Execute <Player>();
                Println("\nStep 4 : Players of Voller-ball");
                var i = 1;
                // display each object
                while (players.HasNext())
                {
                    Println((i++) + "\t: " + players.Next());
                }
            }
            finally
            {
                if (odb != null)
                {
                    // Close the database
                    odb.Close();
                }
            }
            DeleteBase(BaseName);
        }
Example #26
0
        public virtual void TestArray61()
        {
            IOdb odb  = null;
            var  size = 50;

            try
            {
                DeleteBase("array9.ndb");
                odb = Open("array9.ndb");
                var array = new int[size];
                for (var i = 0; i < size; i++)
                {
                    array[i] = i;
                }
                var owna = new ObjectWithNativeArrayOfInt("t1", array);
                odb.Store(owna);
                odb.Close();
                odb = Open("array9.ndb");
                var query = odb.Query <ObjectWithNativeArrayOfInt>();
                var l     = query.Execute <ObjectWithNativeArrayOfInt>();
                var owna2 = l.GetFirst();
                owna2.SetNumber(1, 78);
                odb.Store <ObjectWithNativeArrayOfInt>(owna2);
                odb.Close();
                odb = Open("array9.ndb");
                var query1 = odb.Query <ObjectWithNativeArrayOfInt>();
                l = query1.Execute <ObjectWithNativeArrayOfInt>();
                var o = l.GetFirst();
                AssertEquals((int)0, (int)o.GetNumber(0));
                AssertEquals((int)78, (int)o.GetNumber(1));
            }
            catch (Exception)
            {
                if (odb != null)
                {
                    odb.Rollback();
                    odb = null;
                }
                throw;
            }
            finally
            {
                if (odb != null)
                {
                    odb.Close();
                }
                DeleteBase("array9.ndb");
            }
        }
Example #27
0
        public virtual void TestInsertWithCommitsComplexObject()
        {
            DeleteBase("commits");
            IOdb odb            = null;
            var  size           = 5300;
            var  commitInterval = 400;

            try
            {
                odb = Open("commits");
                for (var i = 0; i < size; i++)
                {
                    odb.Store(GetInstance(i));
                    if (i % commitInterval == 0)
                    {
                        odb.Commit();
                    }
                    // println("commiting "+i);
                    if (i % 1000 == 0)
                    {
                        Println(i);
                    }
                }
            }
            finally
            {
                odb.Close();
            }
            odb = Open("commits");
            var query2      = odb.Query <User>();
            var users       = query2.Execute <User>();
            var query1      = odb.Query <Profile>();
            var profiles    = query1.Execute <Profile>();
            var query       = odb.Query <VO.Login.Function>();
            var functions   = query.Execute <VO.Login.Function>();
            var nbUsers     = users.Count;
            var nbProfiles  = profiles.Count;
            var nbFunctions = functions.Count;

            odb.Close();
            DeleteBase("commits");
            Println("Nb users=" + nbUsers);
            Println("Nb profiles=" + nbProfiles);
            Println("Nb functions=" + nbFunctions);
            AssertEquals(size, nbUsers);
            AssertEquals(size, nbProfiles);
            AssertEquals(size * 2, nbFunctions);
        }
        public void GetWarriorsByLikeOrContains()
        {
            IOdb odb = OdbFactory.Open(DbName);

            try
            {
                IQuery query2 = odb.Query <Warrior>();

                query2.Descend("_name").Constrain("rior").Contains();
                IObjectSet <Warrior> result1 = query2.Execute <Warrior>();
                Assert.That(result1.Count, Is.EqualTo(2));
                PrintResult(result1);


                IQuery query3 = odb.Query <Warrior>();

                query3.Descend("_name").Constrain("rior").Like();
                IObjectSet <Warrior> result2 = query3.Execute <Warrior>();
                Assert.That(result2.Count, Is.EqualTo(2));
                PrintResult(result2);
            }
            finally
            {
                odb.Close();
            }
        }
Example #29
0
        public virtual void TestListSize4()
        {
            IOdb odb = null;

            try
            {
                var baseName = GetBaseName();
                Init(baseName);
                odb = Open(baseName);
                var query = odb.Query <User>();
                query.Descend("profile.functions").Constrain(4).SizeEq();
                var l = query.Execute <User>();
                AssertEquals(1, l.Count());
                var u = l.GetFirst();
                AssertEquals("big profile", u.GetProfile().GetName());
                AssertEquals(4, u.GetProfile().GetFunctions().Count);
            }
            finally
            {
                if (odb != null)
                {
                    odb.Close();
                }
            }
        }
        public virtual void Test10()
        {
            IOdb odb = null;

            try
            {
                var baseName = GetBaseName();
                DeleteBase(baseName);
                odb = Open(baseName);
                var ca = new ClassA();
                var cb = new ClassB(ca, "b");
                ca.SetClassb(cb);
                ca.SetName("a");
                odb.Store(ca);
                var ci = ((global::NDatabase.Odb)odb).GetStorageEngine().GetSession().GetMetaModel().GetClassInfo(typeof(ClassA), true);
                AssertTrue(ci.HasCyclicReference());
            }
            finally
            {
                if (odb != null)
                {
                    odb.Close();
                }
            }
        }
Example #31
0
        public void Terminate(IOdb odb, NorthwindDataSet dataSet)
        {
            if (dataSet != null)
                dataSet.Dispose();

            if (odb == null)
                return;

            odb.Close();
        }