Exemple #1
0
        public void TestStoreSimpleJagged()
        {
            Siaqodb s_db = new Siaqodb(objPath);


            s_db.DropType <JaggedTy>();
            for (int i = 0; i < 10; i++)
            {
                JaggedTy jg = new JaggedTy();
                jg.jaggedByte       = new byte[2][];
                jg.jaggedByte[0]    = new byte[2];
                jg.jaggedByte[0][0] = (byte)i;
                jg.jaggedByte[0][1] = (byte)(i + 1);
                jg.jaggedByte[1]    = new byte[2];
                jg.jaggedByte[1][0] = (byte)(i + 2);
                jg.jaggedByte[1][1] = (byte)(i + 3);

                jg.jaggedInt       = new int[2][];
                jg.jaggedInt[0]    = new int[2];
                jg.jaggedInt[0][0] = i;
                jg.jaggedInt[0][1] = (i + 1);
                jg.jaggedInt[1]    = new int[2];
                jg.jaggedInt[1][0] = (i + 2);
                jg.jaggedInt[1][1] = (i + 3);

                jg.jaggedList = new List <List <int> >();
                List <int> myList = new List <int>();
                myList.Add(i);
                myList.Add(i + 1);
                List <int> myList2 = new List <int>();
                myList2.Add(i * 10);
                myList2.Add(i * 100);
                jg.jaggedList.Add(myList);
                jg.jaggedList.Add(myList2);

                jg.jaggedListStr = new List <List <string> >();
                List <string> myListStr = new List <string>();
                myListStr.Add("ws" + i.ToString());
                myListStr.Add("second" + i.ToString());
                jg.jaggedListStr.Add(myListStr);

                SimpleClass simple = new SimpleClass();
                simple.Name          = "ssss";
                jg.complexJaggedList = new List <List <SimpleClass> >();
                List <SimpleClass> listSimple = new List <SimpleClass>();
                listSimple.Add(simple);

                jg.complexJaggedList.Add(listSimple);
                jg.complexJaggedList.Add(listSimple);
                s_db.StoreObject(jg);
            }
            IList <JaggedTy> all = s_db.LoadAll <JaggedTy>();

            Assert.AreEqual(10, all.Count);
            for (int i = 0; i < 10; i++)
            {
                Assert.AreEqual((byte)i, all[i].jaggedByte[0][0]);
                Assert.AreEqual((byte)(i + 1), all[i].jaggedByte[0][1]);
                Assert.AreEqual((byte)(i + 2), all[i].jaggedByte[1][0]);
                Assert.AreEqual((byte)(i + 3), all[i].jaggedByte[1][1]);

                Assert.AreEqual(i, all[i].jaggedInt[0][0]);
                Assert.AreEqual((i + 1), all[i].jaggedInt[0][1]);
                Assert.AreEqual((i + 2), all[i].jaggedInt[1][0]);
                Assert.AreEqual((i + 3), all[i].jaggedInt[1][1]);

                Assert.AreEqual(2, all[i].jaggedList[0].Count);
                Assert.AreEqual(2, all[i].jaggedList.Count);
                Assert.AreEqual(i, all[i].jaggedList[0][0]);
                Assert.AreEqual(i + 1, all[i].jaggedList[0][1]);
                Assert.AreEqual(i * 10, all[i].jaggedList[1][0]);
                Assert.AreEqual(i * 100, all[i].jaggedList[1][1]);

                Assert.AreEqual(1, all[i].jaggedListStr.Count);
                Assert.AreEqual(2, all[i].jaggedListStr[0].Count);
                Assert.AreEqual("ws" + i, all[i].jaggedListStr[0][0]);
                Assert.AreEqual("second" + i, all[i].jaggedListStr[0][1]);
                Assert.AreEqual(2, all[i].complexJaggedList.Count);
                Assert.IsNotNull(all[i].complexJaggedList[0][0]);
            }
            s_db.Close();
            s_db = new Siaqodb(objPath);
            all  = s_db.LoadAll <JaggedTy>();
            Assert.AreEqual(10, all.Count);
            for (int i = 0; i < 10; i++)
            {
                Assert.AreEqual((byte)i, all[i].jaggedByte[0][0]);
                Assert.AreEqual((byte)(i + 1), all[i].jaggedByte[0][1]);
                Assert.AreEqual((byte)(i + 2), all[i].jaggedByte[1][0]);
                Assert.AreEqual((byte)(i + 3), all[i].jaggedByte[1][1]);

                Assert.AreEqual(i, all[i].jaggedInt[0][0]);
                Assert.AreEqual((i + 1), all[i].jaggedInt[0][1]);
                Assert.AreEqual((i + 2), all[i].jaggedInt[1][0]);
                Assert.AreEqual((i + 3), all[i].jaggedInt[1][1]);

                Assert.AreEqual(2, all[i].jaggedList[0].Count);
                Assert.AreEqual(2, all[i].jaggedList.Count);
                Assert.AreEqual(i, all[i].jaggedList[0][0]);
                Assert.AreEqual(i + 1, all[i].jaggedList[0][1]);
                Assert.AreEqual(i * 10, all[i].jaggedList[1][0]);
                Assert.AreEqual(i * 100, all[i].jaggedList[1][1]);

                Assert.AreEqual(1, all[i].jaggedListStr.Count);
                Assert.AreEqual(2, all[i].jaggedListStr[0].Count);
                Assert.AreEqual("ws" + i, all[i].jaggedListStr[0][0]);
                Assert.AreEqual("second" + i, all[i].jaggedListStr[0][1]);
                Assert.AreEqual(2, all[i].complexJaggedList.Count);
                Assert.IsNotNull(all[i].complexJaggedList[0][0]);
            }
            var q = from JaggedTy jgd in s_db
                    where jgd.jaggedInt.Length == 2
                    select jgd;

            Assert.AreEqual(10, q.ToList().Count);

            List <int> myInList = new List <int>();

            myInList.Add(0);
            myInList.Add(1);

            var q2 = from JaggedTy jgd in s_db
                     where jgd.jaggedList.Contains(myInList)
                     select jgd;

            Assert.AreEqual(1, q2.ToList().Count);
        }
Exemple #2
0
        public void TestStoreDictionaryTransactional()
        {
            Siaqodb s_db = new Siaqodb(objPath);


            s_db.DropType <WithDict>();
            s_db.DropType <JaggedTy>();
            s_db.DropType <NMatrixTy>();
            ITransaction transaction = s_db.BeginTransaction();

            for (int i = 0; i < 10; i++)
            {
                WithDict dict = new WithDict();
                dict.DictInt     = new Dictionary <int, int>();
                dict.DictStr     = new Dictionary <byte, string>();
                dict.DictComplex = new Dictionary <JaggedTy, int>();
                dict.ZuperDict   = new Dictionary <uint, NMatrixTy>();

                for (int j = 0; j < 5; j++)
                {
                    dict.DictInt[j]         = i + j;
                    dict.ZuperDict[(uint)j] = new NMatrixTy();
                    dict.DictStr[(byte)j]   = "sss" + i.ToString();
                    JaggedTy jt = new JaggedTy();
                    dict.DictComplex[jt] = j + i;
                }

                s_db.StoreObject(dict, transaction);
            }
            transaction.Commit();
            try {
                transaction = s_db.BeginTransaction();
                for (int i = 0; i < 10; i++)
                {
                    WithDict dict = new WithDict();
                    dict.DictInt     = new Dictionary <int, int>();
                    dict.DictStr     = new Dictionary <byte, string>();
                    dict.DictComplex = new Dictionary <JaggedTy, int>();
                    dict.ZuperDict   = new Dictionary <uint, NMatrixTy>();

                    for (int j = 0; j < 5; j++)
                    {
                        dict.DictInt[j]         = i + j;
                        dict.ZuperDict[(uint)j] = new NMatrixTy();
                        dict.DictStr[(byte)j]   = "sss" + i.ToString();
                        JaggedTy jt = new JaggedTy();
                        dict.DictComplex[jt] = j + i;
                    }

                    s_db.StoreObject(dict, transaction);
                    if (i == 5)
                    {
                        throw new Exception("need some rollback");
                    }
                }
                transaction.Commit();
            }
            catch (Exception ex)
            {
                transaction.Rollback();
                if (ex.Message == "need some rollback")
                {
                }
                else
                {
                    throw ex;
                }
            }
            IList <WithDict> all = s_db.LoadAll <WithDict>();

            Assert.AreEqual(10, all.Count);
            for (int i = 0; i < 10; i++)
            {
                Assert.AreEqual(5, all[i].DictInt.Keys.Count);
                Assert.AreEqual(5, all[i].DictStr.Keys.Count);
                Assert.AreEqual(5, all[i].DictComplex.Keys.Count);
                Assert.AreEqual(5, all[i].ZuperDict.Keys.Count);
                for (int j = 0; j < 5; j++)
                {
                    Assert.AreEqual(i + j, all[i].DictInt[j]);
                    Assert.AreEqual("sss" + i, all[i].DictStr[(byte)j]);
                    Assert.IsNotNull(all[i].ZuperDict[(uint)j]);
                }
            }
            s_db.Close();
            s_db = new Siaqodb(objPath);
            all  = s_db.LoadAll <WithDict>();
            Assert.AreEqual(10, all.Count);
            for (int i = 0; i < 10; i++)
            {
                Assert.AreEqual(5, all[i].DictInt.Keys.Count);
                Assert.AreEqual(5, all[i].DictStr.Keys.Count);
                Assert.AreEqual(5, all[i].DictComplex.Keys.Count);
                Assert.AreEqual(5, all[i].ZuperDict.Keys.Count);
                for (int j = 0; j < 5; j++)
                {
                    Assert.AreEqual(i + j, all[i].DictInt[j]);
                    Assert.AreEqual("sss" + i, all[i].DictStr[(byte)j]);
                    Assert.IsTrue(all[i].ZuperDict[(uint)j].OID > 0);
                }
            }
            var q = from WithDict d in s_db
                    where d.DictInt.ContainsKey(1)
                    select d;

            Assert.AreEqual(10, q.ToList().Count);
            q = from WithDict d in s_db
                where d.DictInt.ContainsValue(1)
                select d;

            Assert.AreEqual(2, q.ToList().Count);

            q = from WithDict d in s_db
                where d.DictInt.ContainsKey(-1)
                select d;

            Assert.AreEqual(0, q.ToList().Count);
        }
Exemple #3
0
        public void TestStoreDictionaryAndShrink()
        {
            Siaqodb s_db = new Siaqodb(objPath);

            s_db.DropType <WithDict>();
            s_db.DropType <JaggedTy>();
            s_db.DropType <NMatrixTy>();
            for (int i = 0; i < 20; i++)
            {
                WithDict dict = new WithDict();
                dict.DictInt     = new Dictionary <int, int>();
                dict.DictStr     = new Dictionary <byte, string>();
                dict.DictComplex = new Dictionary <JaggedTy, int>();
                dict.ZuperDict   = new Dictionary <uint, NMatrixTy>();

                for (int j = 0; j < 5; j++)
                {
                    dict.DictInt[j]         = i + j;
                    dict.ZuperDict[(uint)j] = new NMatrixTy();
                    dict.DictStr[(byte)j]   = "sss" + i.ToString();
                    JaggedTy jt = new JaggedTy();
                    dict.DictComplex[jt] = j + i;
                }

                s_db.StoreObject(dict);
            }

            IList <WithDict> all = s_db.LoadAll <WithDict>();

            for (int i = 0; i < 10; i++)
            {
                s_db.Delete(all[i]);
            }
            s_db.Close();

            SiaqodbUtil.Shrink(objPath, ShrinkType.Normal);
            SiaqodbUtil.Shrink(objPath, ShrinkType.ForceClaimSpace);

            s_db = new Siaqodb(objPath);
            all  = s_db.LoadAll <WithDict>();

            for (int i = 10; i < 20; i++)
            {
                int j = i - 10;
                Assert.AreEqual(5, all[j].DictInt.Keys.Count);
                Assert.AreEqual(5, all[j].DictStr.Keys.Count);
                Assert.AreEqual(5, all[j].DictComplex.Keys.Count);
                Assert.AreEqual(5, all[j].ZuperDict.Keys.Count);
                for (int k = 0; k < 5; k++)
                {
                    Assert.AreEqual(i + k, all[j].DictInt[k]);
                    Assert.AreEqual("sss" + i, all[j].DictStr[(byte)k]);
                    Assert.IsNotNull(all[j].ZuperDict[(uint)k]);
                }
            }


            var q = from WithDict d in s_db
                    where d.DictInt.ContainsKey(1)
                    select d;

            Assert.AreEqual(10, q.ToList().Count);
            q = from WithDict d in s_db
                where d.DictInt.ContainsValue(11)
                select d;

            Assert.AreEqual(2, q.ToList().Count);

            q = from WithDict d in s_db
                where d.DictInt.ContainsKey(-1)
                select d;

            Assert.AreEqual(0, q.ToList().Count);
        }
Exemple #4
0
        public void TestUpdateDictionary()
        {
            Siaqodb s_db = new Siaqodb(objPath);

            s_db.DropType <WithDict>();
            s_db.DropType <JaggedTy>();
            s_db.DropType <NMatrixTy>();
            for (int i = 0; i < 10; i++)
            {
                WithDict dict = new WithDict();
                dict.DictInt     = new Dictionary <int, int>();
                dict.DictStr     = new Dictionary <byte, string>();
                dict.DictComplex = new Dictionary <JaggedTy, int>();
                dict.ZuperDict   = new Dictionary <uint, NMatrixTy>();

                for (int j = 0; j < 5; j++)
                {
                    dict.DictInt[j]         = i + j;
                    dict.ZuperDict[(uint)j] = new NMatrixTy();
                    dict.DictStr[(byte)j]   = "sss" + i.ToString();
                    JaggedTy jt = new JaggedTy();
                    dict.DictComplex[jt] = j + i;
                }

                s_db.StoreObject(dict);
            }
            IList <WithDict> all = s_db.LoadAll <WithDict>();

            for (int i = 0; i < 10; i++)
            {
                for (int j = 0; j < 5; j++)
                {
                    all[i].DictInt[j]         = i + j + 10;
                    all[i].DictStr[(byte)j]   = "updated test";
                    all[i].ZuperDict[(uint)j] = new NMatrixTy();
                }
                s_db.StoreObject(all[i]);
            }
            all = s_db.LoadAll <WithDict>();

            Assert.AreEqual(10, all.Count);
            for (int i = 0; i < 10; i++)
            {
                Assert.AreEqual(5, all[i].DictInt.Keys.Count);
                Assert.AreEqual(5, all[i].DictStr.Keys.Count);
                Assert.AreEqual(5, all[i].DictComplex.Keys.Count);
                Assert.AreEqual(5, all[i].ZuperDict.Keys.Count);
                for (int j = 0; j < 5; j++)
                {
                    Assert.AreEqual(i + j + 10, all[i].DictInt[j]);
                    Assert.AreEqual("updated test", all[i].DictStr[(byte)j]);
                    Assert.IsNotNull(all[i].ZuperDict[(uint)j]);
                }
            }
            s_db.Close();
            s_db = new Siaqodb(objPath);
            all  = s_db.LoadAll <WithDict>();
            Assert.AreEqual(10, all.Count);
            for (int i = 0; i < 10; i++)
            {
                Assert.AreEqual(5, all[i].DictInt.Keys.Count);
                Assert.AreEqual(5, all[i].DictStr.Keys.Count);
                Assert.AreEqual(5, all[i].DictComplex.Keys.Count);
                Assert.AreEqual(5, all[i].ZuperDict.Keys.Count);
                for (int j = 0; j < 5; j++)
                {
                    Assert.AreEqual(i + j + 10, all[i].DictInt[j]);
                    Assert.AreEqual("updated test", all[i].DictStr[(byte)j]);
                    Assert.IsNotNull(all[i].ZuperDict[(uint)j]);
                }
            }
            var q = from WithDict d in s_db
                    where d.DictInt.ContainsKey(1)
                    select d;

            Assert.AreEqual(10, q.ToList().Count);
            q = from WithDict d in s_db
                where d.DictInt.ContainsValue(11)
                select d;

            Assert.AreEqual(2, q.ToList().Count);

            q = from WithDict d in s_db
                where d.DictInt.ContainsKey(-1)
                select d;

            Assert.AreEqual(0, q.ToList().Count);
        }
Exemple #5
0
        public void TestStoreSimpleJaggedAndShrink()
        {
            Siaqodb s_db = new Siaqodb(objPath);


            s_db.DropType <JaggedTy>();
            for (int i = 0; i < 20; i++)
            {
                JaggedTy jg = new JaggedTy();
                jg.jaggedByte       = new byte[2][];
                jg.jaggedByte[0]    = new byte[2];
                jg.jaggedByte[0][0] = (byte)i;
                jg.jaggedByte[0][1] = (byte)(i + 1);
                jg.jaggedByte[1]    = new byte[2];
                jg.jaggedByte[1][0] = (byte)(i + 2);
                jg.jaggedByte[1][1] = (byte)(i + 3);

                jg.jaggedInt       = new int[2][];
                jg.jaggedInt[0]    = new int[2];
                jg.jaggedInt[0][0] = i;
                jg.jaggedInt[0][1] = (i + 1);
                jg.jaggedInt[1]    = new int[2];
                jg.jaggedInt[1][0] = (i + 2);
                jg.jaggedInt[1][1] = (i + 3);

                jg.jaggedList = new List <List <int> >();
                List <int> myList = new List <int>();
                myList.Add(i);
                myList.Add(i + 1);
                List <int> myList2 = new List <int>();
                myList2.Add(i * 10);
                myList2.Add(i * 100);
                jg.jaggedList.Add(myList);
                jg.jaggedList.Add(myList2);

                jg.jaggedListStr = new List <List <string> >();
                List <string> myListStr = new List <string>();
                myListStr.Add("ws" + i.ToString());
                myListStr.Add("second" + i.ToString());
                jg.jaggedListStr.Add(myListStr);


                s_db.StoreObject(jg);
            }
            IList <JaggedTy> all = s_db.LoadAll <JaggedTy>();

            for (int i = 0; i < 10; i++)
            {
                s_db.Delete(all[i]);
            }
            s_db.Close();

            SiaqodbUtil.Shrink(objPath, ShrinkType.Normal);
            SiaqodbUtil.Shrink(objPath, ShrinkType.ForceClaimSpace);

            s_db = new Siaqodb(objPath);
            all  = s_db.LoadAll <JaggedTy>();

            for (int i = 10; i < 20; i++)
            {
                int j = i - 10;
                Assert.AreEqual((byte)i, all[j].jaggedByte[0][0]);
                Assert.AreEqual((byte)(i + 1), all[j].jaggedByte[0][1]);
                Assert.AreEqual((byte)(i + 2), all[j].jaggedByte[1][0]);
                Assert.AreEqual((byte)(i + 3), all[j].jaggedByte[1][1]);

                Assert.AreEqual(i, all[j].jaggedInt[0][0]);
                Assert.AreEqual((i + 1), all[j].jaggedInt[0][1]);
                Assert.AreEqual((i + 2), all[j].jaggedInt[1][0]);
                Assert.AreEqual((i + 3), all[j].jaggedInt[1][1]);

                Assert.AreEqual(2, all[j].jaggedList[0].Count);
                Assert.AreEqual(2, all[j].jaggedList.Count);
                Assert.AreEqual(i, all[j].jaggedList[0][0]);
                Assert.AreEqual(i + 1, all[j].jaggedList[0][1]);
                Assert.AreEqual(i * 10, all[j].jaggedList[1][0]);
                Assert.AreEqual(i * 100, all[j].jaggedList[1][1]);

                Assert.AreEqual(1, all[j].jaggedListStr.Count);
                Assert.AreEqual(2, all[j].jaggedListStr[0].Count);
                Assert.AreEqual("ws" + i, all[j].jaggedListStr[0][0]);
                Assert.AreEqual("second" + i, all[j].jaggedListStr[0][1]);
            }

            var q = from JaggedTy jgd in s_db
                    where jgd.jaggedInt.Length == 2
                    select jgd;

            Assert.AreEqual(10, q.ToList().Count);

            List <int> myInList = new List <int>();

            myInList.Add(10);
            myInList.Add(11);

            var q2 = from JaggedTy jgd in s_db
                     where jgd.jaggedList.Contains(myInList)
                     select jgd;

            Assert.AreEqual(1, q2.ToList().Count);
        }