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); }
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); }
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); }