Ejemplo n.º 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);
        }
Ejemplo n.º 2
0
        private void CheckCarRetrieval()
        {
            var query1 = odb.Query <Car>();
            var cars   = query1.Execute <Car>();

            AssertEquals(1, cars.Count);
            var car = cars.GetFirst();

            AssertEquals(car.GetModel(), "Ranger");
            AssertEquals(car.GetYear(), 2006);
            var query = odb.Query <Car>();

            query.Descend("model").Constrain((object)"Ranger").Equal();
            cars = query.Execute <Car>();
            car  = cars.GetFirst();
            AssertEquals(car.GetModel(), "Ranger");
        }
Ejemplo n.º 3
0
        public virtual void TestArray6UpdateIncreasingArraySize()
        {
            IOdb odb  = null;
            var  size = 50;

            try
            {
                DeleteBase("array10.ndb");
                odb = Open("array10.ndb");
                var array  = new Decimal[size];
                var array2 = new Decimal[size + 1];
                for (var i = 0; i < size; i++)
                {
                    array[i]  = new Decimal(((double)i) * 78954545 / 89);
                    array2[i] = new Decimal(((double)i) * 78954545 / 89);
                }
                array2[size] = new Decimal(100);
                var owna = new ObjectWithNativeArrayOfBigDecimal("t1", array);
                odb.Store(owna);
                odb.Close();
                odb = Open("array10.ndb");
                var query = odb.Query <ObjectWithNativeArrayOfBigDecimal>();
                var l     = query.Execute <ObjectWithNativeArrayOfBigDecimal>();
                var owna2 = l.GetFirst();
                owna2.SetNumbers(array2);
                odb.Store <ObjectWithNativeArrayOfBigDecimal>(owna2);
                odb.Close();
                odb = Open("array10.ndb");
                var query1 = odb.Query <ObjectWithNativeArrayOfBigDecimal>();
                l = query1.Execute <ObjectWithNativeArrayOfBigDecimal>();
                var o = l.GetFirst();
                AssertEquals(size + 1, (int)o.GetNumbers().Length);
                AssertEquals(new Decimal(100), o.GetNumber(size));
                AssertEquals((object)owna2.GetNumber(1), (object)o.GetNumber(1));
                odb.Close();
                DeleteBase("array10.ndb");
            }
            catch (Exception)
            {
                if (odb != null)
                {
                    odb.Rollback();
                }
                throw;
            }
        }
        public virtual void Test1000Objects()
        {
            var  OdbFileName = "index2.test1.odb";
            IOdb odb         = null;
            var  size        = 1000;
            var  start       = OdbTime.GetCurrentTimeInMs();

            try
            {
                DeleteBase(OdbFileName);
                odb = Open(OdbFileName);
                for (var i = 0; i < size; i++)
                {
                    var io = new IndexedObject("name" + i, i, new DateTime());
                    odb.Store(io);
                }
                odb.Close();
                Println("\n\n END OF INSERT \n\n");
                odb = Open(OdbFileName);
                var names = new[] { "name" };
                odb.IndexManagerFor <IndexedObject>().AddUniqueIndexOn("index1", names);
                Println("\n\n after create index\n\n");
                var query = odb.Query <IndexedObject>();
                query.Descend("name").Constrain((object)"name0").Equal();
                var objects =
                    query.Execute <IndexedObject>(true);

                Println("\n\nafter get Objects\n\n");
                AssertEquals(1, objects.Count);
                var query2 = odb.Query <IndexedObject>();
                query2.Descend("duration").Constrain((object)9).Equal();

                objects = query2.Execute <IndexedObject>(true);

                AssertEquals(1, objects.Count);
                objects = odb.Query <IndexedObject>().Execute <IndexedObject>(true);
                AssertEquals(size, objects.Count);
            }
            finally
            {
                var end = OdbTime.GetCurrentTimeInMs();
                Println((end - start) + "ms");

                odb.Close();
            }
        }
Ejemplo n.º 5
0
        public static TItem GetByNumericalID <TItem>(IOdb odb, string idField, long id)
        {
            var query = odb.Query <TItem>();

            query.Descend(idField).Constrain(id);
            var result = query.Execute <TItem>();

            return(result.FirstOrDefault());
        }
Ejemplo n.º 6
0
        public virtual void TestArray1()
        {
            IOdb odb = null;

            try
            {
                DeleteBase("array1.ndb");
                odb = Open("array1.ndb");
                decimal nb     = odb.Query <PlayerWithArray>().Count();
                var     player = new PlayerWithArray("kiko");
                player.AddGame("volley-ball");
                player.AddGame("squash");
                player.AddGame("tennis");
                player.AddGame("ping-pong");
                odb.Store(player);
                odb.Close();
                odb = Open("array1.ndb");
                var query = odb.Query <PlayerWithArray>();
                var l     = query.Execute <PlayerWithArray>(true);
                AssertEquals(nb + 1, l.Count);
                // gets first player
                var player2 = l.GetFirst();
                AssertEquals(player.ToString(), (string)player2.ToString());
            }
            catch (Exception e)
            {
                if (odb != null)
                {
                    odb.Rollback();
                    odb = null;
                }
                Console.WriteLine(e);
                throw e;
            }
            finally
            {
                if (odb != null)
                {
                    odb.Close();
                }
                DeleteBase("array1.ndb");
            }
        }
Ejemplo n.º 7
0
        public virtual void TestArray5()
        {
            IOdb odb  = null;
            var  size = 50;

            try
            {
                DeleteBase("array7.ndb");
                odb = Open("array7.ndb");
                var array = new Decimal[size];
                for (var i = 0; i < size; i++)
                {
                    array[i] = new Decimal(((double)i) * 78954545 / 89);
                }
                var owna = new ObjectWithNativeArrayOfBigDecimal("t1", array);
                odb.Store(owna);
                odb.Close();
                odb = Open("array7.ndb");
                var query = odb.Query <ObjectWithNativeArrayOfBigDecimal>();
                var l     = query.Execute <ObjectWithNativeArrayOfBigDecimal>();
                var owna2 = l.GetFirst();
                owna2.SetNumber(0, new Decimal(1));
                odb.Store <ObjectWithNativeArrayOfBigDecimal>(owna2);
                odb.Close();
                odb = Open("array7.ndb");
                var query1 = odb.Query <ObjectWithNativeArrayOfBigDecimal>();
                l = query1.Execute <ObjectWithNativeArrayOfBigDecimal>();
                var o = l.GetFirst();
                AssertEquals((object)owna2.GetNumber(0), (object)o.GetNumber(0));
                AssertEquals((object)owna2.GetNumber(1), (object)o.GetNumber(1));

                odb.Close();
                DeleteBase("array7.ndb");
            }
            catch (Exception)
            {
                if (odb != null)
                {
                    odb.Rollback();
                }
                throw;
            }
        }
Ejemplo n.º 8
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);
        }
Ejemplo n.º 9
0
        public virtual void TestCollectionWithContain()
        {
            IOdb odb      = null;
            var  baseName = GetBaseName();

            try
            {
                odb = Open(baseName);
                var nb     = odb.Query <PlayerWithList>().Count();
                var player = new PlayerWithList("kiko");
                player.AddGame("volley-ball");
                player.AddGame("squash");
                player.AddGame("tennis");
                player.AddGame("ping-pong");
                odb.Store(player);
                odb.Close();

                odb = Open(baseName);
                var query = odb.Query <PlayerWithList>();
                query.Descend("games").Constrain("tennis").Contains();
                var l = query.Execute <PlayerWithList>();
                AssertEquals(nb + 1, l.Count);
            }
            catch (Exception)
            {
                if (odb != null)
                {
                    odb.Rollback();
                    odb = null;
                }
                throw;
            }
            finally
            {
                if (odb != null)
                {
                    odb.Close();
                }
            }
        }
Ejemplo n.º 10
0
        public virtual void TestSelectUnCommitedObject2()
        {
            IOdb odb = null;

            try
            {
                DeleteBase(BaseName);
                odb = Open(BaseName);
                for (var i = 0; i < 4; i++)
                {
                    odb.Store(new User("user" + i, "email" + i,
                                       new Profile("profile" + i, new VO.Login.Function("function" + i))));
                }
                odb.Close();
                // reopen the database
                odb = Open(BaseName);
                // stores a new function
                odb.Store(new User("uncommited user", "uncommied email",
                                   new Profile("uncommiedt profile", new VO.Login.Function("uncommited function"))));
                var query = odb.Query <User>();
                var users = query.Execute <User>();
                AssertEquals(5, users.Count);
                var query1    = odb.Query <VO.Login.Function>();
                var functions = query1.Execute <VO.Login.Function>();
                AssertEquals(5, functions.Count);
                var query2   = odb.Query <Profile>();
                var profiles = query2.Execute <Profile>();
                AssertEquals(5, profiles.Count);
            }
            finally
            {
                if (odb != null)
                {
                    odb.Close();
                    DeleteBase(BaseName);
                }
            }
        }
        public void GetWarriorsByStartsOrEndsWith()
        {
            IOdb odb = OdbFactory.Open(DbName);

            try
            {
                IQuery query2 = odb.Query <Warrior>();
                query2.Descend("_name").Constrain("Warr").StartsWith(false);
                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 1").EndsWith(false);
                IObjectSet <Warrior> result2 = query3.Execute <Warrior>();
                Assert.That(result2.Count, Is.EqualTo(1));
                PrintResult(result2);
            }
            finally
            {
                odb.Close();
            }
        }
Ejemplo n.º 12
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);
        }
Ejemplo n.º 13
0
        public virtual void Test11()
        {
            var  baseName = GetBaseName();
            IOdb odb      = null;

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

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

            odb.Delete(f1bis);
            odb.Store(new VO.Login.Function("last function"));
            odb.Close();
            odb = Open(baseName);
            var query1 = odb.Query <VO.Login.Function>();

            AssertEquals(size + 1, query1.Execute <VO.Login.Function>().Count);
            odb.Close();
        }
        public List <T> GetAll <T>() where T : class, IDbObject
        {
            var resultList = new List <T>();

            IQuery query = _odb.Query <T>();

            resultList.AddRange(query.Execute <T>());

            return(resultList);
        }
        public void GetAllWarriors()
        {
            IOdb odb = OdbFactory.Open(DbName);

            try
            {
                IQuery query = odb.Query <Warrior>();
                IObjectSet <Warrior> result = query.Execute <Warrior>();
                Assert.That(result.Count, Is.EqualTo(2));
                PrintResult(result);
            }
            finally
            {
                odb.Close();
            }
        }
Ejemplo n.º 16
0
        public virtual void TestArray2()
        {
            IOdb odb  = null;
            var  size = 50;

            try
            {
                DeleteBase("array2.ndb");
                odb = Open("array2.ndb");
                var intArray = new int[size];
                for (var i = 0; i < size; i++)
                {
                    intArray[i] = i;
                }
                var owna = new ObjectWithNativeArrayOfInt("t1", intArray);
                odb.Store(owna);
                odb.Close();
                odb = Open("array2.ndb");
                var query = odb.Query <ObjectWithNativeArrayOfInt>();
                var l     = query.Execute <ObjectWithNativeArrayOfInt>();
                var owna2 = l.GetFirst();
                AssertEquals(owna.GetName(), (string)owna2.GetName());
                for (var i = 0; i < size; i++)
                {
                    AssertEquals(owna.GetNumbers()[i], (int)owna2.GetNumbers()[i]);
                }
                odb.Close();
                odb = null;
            }
            catch (Exception)
            {
                if (odb != null)
                {
                    odb.Rollback();
                    odb = null;
                }
                throw;
            }
            finally
            {
                if (odb != null)
                {
                    odb.Close();
                }
                DeleteBase("array2.ndb");
            }
        }
Ejemplo n.º 17
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);
        }
        public static void GetWarriorsByComparison()
        {
            IOdb odb = OdbFactory.Open(DbName);

            try
            {
                IQuery query = odb.Query <Warrior>();
                query.Descend("_attack").Constrain(2).Greater();
                IObjectSet <Warrior> result = query.Execute <Warrior>();
                Assert.That(result.Count, Is.EqualTo(2));
                PrintResult(result);
            }
            finally
            {
                odb.Close();
            }
        }
        public void GetWarriorByNegation()
        {
            IOdb odb = OdbFactory.Open(DbName);

            try
            {
                IQuery query = odb.Query <Warrior>();
                query.Descend("_name").Constrain("Warrior 1").Equal().Not();
                IObjectSet <Warrior> result = query.Execute <Warrior>();
                Assert.That(result.Count, Is.EqualTo(1));
                PrintResult(result);
            }
            finally
            {
                odb.Close();
            }
        }
Ejemplo n.º 20
0
        public virtual void Test13()
        {
            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("function3");

            odb.Store(f1);
            odb.Store(f2);
            odb.Store(f3);
            var idf1          = odb.GetObjectId(f1);
            var idf2          = odb.GetObjectId(f2);
            var idf3          = odb.GetObjectId(f3);
            var storageEngine = ((global::NDatabase.Odb)odb).GetStorageEngine();

            var p1 = storageEngine.GetObjectReader().GetObjectPositionFromItsOid(idf1, true, false);
            var p2 = storageEngine.GetObjectReader().GetObjectPositionFromItsOid(idf2, true, false);
            var p3 = storageEngine.GetObjectReader().GetObjectPositionFromItsOid(idf3, true, false);

            odb.Close();
            try
            {
                odb = Open(baseName);
                f1  = (VO.Login.Function)odb.GetObjectFromId(idf1);
                f2  = (VO.Login.Function)odb.GetObjectFromId(idf2);
                f3  = (VO.Login.Function)odb.GetObjectFromId(idf3);
                odb.Delete(f3);
                odb.Delete(f2);
                odb.Close();
                odb = Open(baseName);
                var query = odb.Query <VO.Login.Function>();
                var l     = query.Execute <VO.Login.Function>();
                odb.Close();
                AssertEquals(1, l.Count);
            }
            catch (OdbRuntimeException)
            {
                DeleteBase(baseName);
                throw;
            }
            DeleteBase(baseName);
        }
        public void GetWarriorByExactAttackValue()
        {
            IOdb odb = OdbFactory.Open(DbName);

            try
            {
                IQuery query = odb.Query <Warrior>();
                query.Descend("_attack").Constrain(3).Equal();
                IObjectSet <Warrior> result = query.Execute <Warrior>();
                Assert.That(result.Count, Is.EqualTo(2));
                PrintResult(result);
            }
            finally
            {
                odb.Close();
            }
        }
Ejemplo n.º 22
0
        public virtual void NewDownload(string name, string email, string downloadType, string fileName)
        {
            IOdb odb  = null;
            User user = null;

            try
            {
                odb = Open("download.ndb");
                var query = odb.Query <User>();
                query.Descend("email").Constrain((object)email).Equal();
                var users = query.Execute <User>();
                if (users.Count != 0)
                {
                    user = users.GetFirst();
                    user.SetLastDownload(new DateTime());
                    user.SetNbDownloads(user.GetNbDownloads() + 1);
                    odb.Store(user);
                }
                else
                {
                    user = new User();
                    user.SetName(name);
                    user.SetEmail(email);
                    user.SetLastDownload(new DateTime());
                    user.SetNbDownloads(1);
                    odb.Store(user);
                }
                var download = new Download();
                download.SetFileName(fileName);
                download.SetType(downloadType);
                download.SetUser(user);
                download.SetWhen(new DateTime());
                odb.Store(download);
            }
            finally
            {
                if (odb != null)
                {
                    odb.Close();
                }
            }
        }
Ejemplo n.º 23
0
        public virtual void TestIsNull()
        {
            IOdb odb = null;

            try
            {
                odb = Open(BaseName);
                var query = odb.Query <TestClass>();
                query.Descend("bigDecimal1").Constrain(null).Equal();
                var l = query.Execute <TestClass>();
                AssertEquals(0, l.Count);
            }
            finally
            {
                if (odb != null)
                {
                    odb.Close();
                }
            }
        }
Ejemplo n.º 24
0
        public virtual void TestArrayOfDate()
        {
            IOdb odb  = null;
            var  size = 50;

            try
            {
                DeleteBase("array6.ndb");
                odb = Open("array6.ndb");
                var array = new DateTime[size];
                var now   = new DateTime();
                for (var i = 0; i < size; i++)
                {
                    array[i] = new DateTime(now.Millisecond + i);
                }
                var owna = new ObjectWithNativeArrayOfDate("t1", array);
                odb.Store(owna);
                odb.Close();
                odb = Open("array6.ndb");
                var query = odb.Query <ObjectWithNativeArrayOfDate>();
                var l     = query.Execute <ObjectWithNativeArrayOfDate>();
                var owna2 = l.GetFirst();
                AssertEquals(owna.GetName(), (string)owna2.GetName());
                for (var i = 0; i < size; i++)
                {
                    AssertEquals(owna.GetNumbers()[i], owna2.GetNumbers()[i]);
                }
                odb.Close();
                odb = null;

                DeleteBase("array6.ndb");
            }
            catch (Exception)
            {
                if (odb != null)
                {
                    odb.Rollback();
                }
                throw;
            }
        }
        public virtual void Test3()
        {
            // LogUtil.objectReaderOn(true);
            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);
            var f1 = new VO.Login.Function("function1");

            o.GetMap().Add("a", c);
            var size = 1;

            for (var i = 0; i < size; i++)
            {
                o.GetMap().Add("A" + i, f1);
            }
            o.GetMap().Add("c", f1);
            Println("RealMap" + o.GetMap());
            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(size + 2, mmo.GetMap().Count);

            var enumerator = ((ICollection)mmo.GetMap()["a"]).GetEnumerator();

            enumerator.MoveNext();
            AssertEquals(mmo, enumerator.Current);
            AssertEquals("function1", mmo.GetMap()["c"].ToString());
        }
Ejemplo n.º 26
0
        public virtual void TestArray4()
        {
            DeleteBase("array5.ndb");
            IOdb odb  = null;
            var  size = 50;

            try
            {
                odb = Open("array5.ndb");
                var array = new Decimal[size];
                for (var i = 0; i < size; i++)
                {
                    array[i] = new Decimal(((double)i) * 78954545 / 89);
                }
                var owna = new ObjectWithNativeArrayOfBigDecimal("t1", array);
                odb.Store(owna);
                odb.Close();
                odb = Open("array5.ndb");
                var query = odb.Query <ObjectWithNativeArrayOfBigDecimal>();
                var l     = query.Execute <ObjectWithNativeArrayOfBigDecimal>();
                var owna2 = l.GetFirst();
                AssertEquals(owna.GetName(), (string)owna2.GetName());
                for (var i = 0; i < size; i++)
                {
                    AssertEquals(owna.GetNumbers()[i], owna2.GetNumbers()[i]);
                }
                odb.Close();
                odb = null;
                DeleteBase("array5.ndb");
            }
            catch (Exception)
            {
                if (odb != null)
                {
                    odb.Rollback();
                    odb = null;
                }
                throw;
            }
        }
Ejemplo n.º 27
0
        public virtual void TestListSizeNotEqulTo1()
        {
            IOdb odb = null;

            try
            {
                var baseName = GetBaseName();
                Init(baseName);
                odb = Open(baseName);
                var query = odb.Query <User>();
                query.Descend("profile.functions").Constrain(1).SizeNe();
                var l = query.Execute <User>();
                AssertEquals(2, l.Count());
            }
            finally
            {
                if (odb != null)
                {
                    odb.Close();
                }
            }
        }
Ejemplo n.º 28
0
        public virtual void Test8()
        {
            var baseName = GetBaseName();

            Println(baseName);
            IOdb odb       = null;
            var  utilDate  = new DateTime();
            var  sqlDate   = new DateTime(utilDate.Millisecond + 10000);
            var  timestamp = new DateTime(utilDate.Millisecond + 20000);

            try
            {
                odb = Open(baseName);
                var o = new ObjectWithDates("object1", utilDate, sqlDate, timestamp);
                odb.Store(o);
                odb.Close();
                odb = Open(baseName);
                var query = odb.Query <ObjectWithDates>();
                var dates = query.Execute <ObjectWithDates>();
                var o2    = dates.GetFirst();
                Println(o2.GetName());
                Println(o2.GetJavaUtilDate());
                Println(o2.GetJavaSqlDte());
                Println(o2.GetTimestamp());
                AssertEquals((string)"object1", (string)o2.GetName());
                AssertEquals(utilDate, o2.GetJavaUtilDate());
                AssertEquals(sqlDate, o2.GetJavaSqlDte());
                AssertEquals(timestamp, o2.GetTimestamp());
            }
            finally
            {
                if (odb != null)
                {
                    odb.Close();
                }
            }
        }
Ejemplo n.º 29
0
        public virtual void Test12()
        {
            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 idf1 = odb.GetObjectId(f1);
            var idf2 = odb.GetObjectId(f2);
            var idf3 = odb.GetObjectId(f3);

            odb.Close();
            try
            {
                odb = Open(baseName);
                odb.DeleteObjectWithId(idf3);
                odb.DeleteObjectWithId(idf2);
                odb.Close();
                odb = Open(baseName);
                var query = odb.Query <VO.Login.Function>();
                var l     = query.Execute <VO.Login.Function>();
                odb.Close();
                AssertEquals(1, l.Count);
            }
            catch (OdbRuntimeException)
            {
                DeleteBase(baseName);
                throw;
            }
        }
        public virtual void Test1()
        {
            DeleteBase("map-with-collections");
            IOdb odb = null;

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

            c.Add("ola");
            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);
            AssertEquals(o.GetMap()["c"], mmo.GetMap()["c"]);
        }