示例#1
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);
        }
示例#2
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();
        }
示例#3
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);
            }
        }
示例#4
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);
        }
示例#5
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);
        }
示例#6
0
        public virtual void Test2UpdateTriggers()
        {
            if (!testNewFeature)
            {
                return;
            }
            IOdb odb      = null;
            var  baseName = GetBaseName();

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

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

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

            odb.Store(f);
            var id = odb.GetObjectId(f);

            odb.Commit();
            try
            {
                odb.Delete(f);
                odb.GetObjectFromId(id);
                Fail("The object has been deleted, the id should have been marked as deleted");
            }
            catch (OdbRuntimeException)
            {
                odb.Close();
                DeleteBase("t-delete1.ndb");
            }
        }