Example #1
0
        public void ItemCreatedByIocWorks()
        {
            using var tr = _db.StartTransaction();
            var items = tr.GetRelation <IItems>();

            items.Upsert(_container.Resolve <Item>());
            Assert.Equal("Hello", items.First().Param);
        }
Example #2
0
 public void StartRelationTransaction()
 {
     using (var tr = db.StartTransaction())
     {
         db.Open(kvDb, false);
         creator = tr.InitRelation <IPersonTable>("Person");
         var personTable = creator(tr);
         personTable.Insert(new Person {
             Id = 2, Name = "admin", Age = 100
         });
         tr.Commit();
     }
 }
Example #3
0
 public void Basics()
 {
     using (var tr = _db.StartTransaction())
     {
         var jobs = tr.Singleton <JobMap>();
         jobs.Jobs[1] = new Job {
             Duty = new Duty {
                 Name = "HardCore Code"
             }
         };
         tr.Commit();
     }
     IterateWithApprove();
 }
Example #4
0
        private TResult Benchmark <TResult>(Func <IPersonTable, TResult> test)
        {
            using var tr = _db.StartTransaction();
            var personTable = _creator(tr);

            return(test(personTable));
        }
Example #5
0
 public void StartTransaction()
 {
     if (!IsEnabled)
     {
         return;
     }
     _tr = _odb.StartTransaction();
 }
        public void FastRemoveCanBeUsed()
        {
            Func <IObjectDBTransaction, IResourcesTable> creator;

            using (var tr = _db.StartTransaction())
            {
                creator = tr.InitRelation <IResourcesTable>("FastRemoveCanBeUsed");
                var table = creator(tr);
                for (var i = 0; i < 100; i++)
                {
                    table.Insert(new Resource
                    {
                        CompanyId  = 1,
                        Location   = new RangeLocation(),
                        ResourceId = i.ToString()
                    });
                    table.Insert(new Resource
                    {
                        CompanyId  = 2,
                        Location   = new RangeLocation(),
                        ResourceId = i.ToString()
                    });
                }

                tr.Commit();
            }

            using (var tr = _db.StartTransaction())
            {
                var table = creator(tr);
                Assert.Equal(100, table.RemoveById(1));
                AssertCounts(tr, 1, 0);
                Assert.Equal(100, table.Count);
            }
        }
Example #7
0
        public void GlobalSetup()
        {
            _db = new ObjectDB();
            var directory = Path.Combine(Directory.GetCurrentDirectory(), "BTDBDist");

            Directory.CreateDirectory(directory);

            Console.WriteLine($"GlobalSetup, db: {directory}");
            _db.Open(new KeyValueDB(new OnDiskFileCollection(directory)), true);

            using var tr = _db.StartTransaction();
            _creator     = tr.InitRelation <IPersonTable>("Person");
            var personTable = _creator(tr);

            if (personTable.CountByCountry(Country.Czech) > 0)
            {
                return;
            }
            var nationality   = Country.Czech;
            var slovakiaCount = 0;
            var czechCount    = 0;

            for (ulong i = 0; i < TotalRecords; i++)
            {
                personTable.Insert(new Person(i, $"Name{i}", nationality, 0));

                if (i % 2 == 0 && slovakiaCount < SlovakiaTotal)
                {
                    nationality = Country.Slovakia;
                    slovakiaCount++;
                }
                else if (czechCount < CzechTotal)
                {
                    nationality = Country.Czech;
                    czechCount++;
                }
                else
                {
                    nationality = nationality switch
                    {
                        Country.Czech => Country.Poland,
                        Country.Poland => Country.Germany,
                        Country.Germany => Country.Poland,
                        Country.Slovakia => Country.Poland,
                        _ => nationality
                    };
                }
            }

            foreach (var countryType in Enum.GetValues(typeof(Country)))
            {
                var count = personTable.CountByCountry((Country)countryType);
                Console.WriteLine($"{(Country) countryType} Total: {count}");
            }

            tr.Commit();
        }
Example #8
0
 public void Test()
 {
     using (var tr = _db.StartTransaction())
     {
         _db.Open(_lowDb, false);
         var creator     = tr.InitRelation <IPersonTable>("Person");
         var personTable = creator(tr);
         personTable.Insert(new Person {
             Id = 2, Name = "admin", Age = 100
         });
         tr.Commit();
     }
     ReopenDb();
 }
Example #9
0
        public void ChangeOfPrimaryKeyDeleteAllData()
        {
            using (var tr = _db.StartTransaction())
            {
                var creator  = tr.InitRelation <IJobTable1>("Job");
                var jobTable = creator(tr);
                var job      = new JobV1 {
                    Id = 11, Name = "Code"
                };
                jobTable.Insert(job);
                tr.Commit();
            }

            ReopenDb();
            using (var tr = _db.StartTransaction())
            {
                var creator = tr.InitRelation <IJobTableIncompatible>("Job");
                Assert.NotEmpty(_logger.ReportedIncompatibleKeys);
                Assert.Equal("Job", _logger.ReportedIncompatibleKeys[0].Item1);
                Assert.Equal("Id", _logger.ReportedIncompatibleKeys[0].Item2);

                var jobTable = creator(tr);
                Assert.Empty(jobTable);

                var job = new JobIncompatible()
                {
                    Id = Guid.NewGuid(), Name = "Code"
                };
                jobTable.Insert(job);

                var en = jobTable.ListByName(new AdvancedEnumeratorParam <string>(EnumerationOrder.Ascending));
                Assert.True(en.MoveNext());
                Assert.Equal("Code", en.Current.Name);

                AssertNoLeaksInDb();
            }
        }
Example #10
0
 void StoreJob(ulong id, string name)
 {
     using (var tr = _db.StartTransaction())
     {
         var jobs = tr.Singleton <ODBIteratorTest.JobMap>();
         jobs.Jobs[id] = new ODBIteratorTest.Job {
             Duty = new ODBIteratorTest.Duty {
                 Name = name
             }
         };
         tr.Commit();
     }
 }
Example #11
0
        public void MaterializesInlineObjectProperty()
        {
            ulong oid;

            using (var tr = _db.StartTransaction())
            {
                oid = tr.Store(new Parent {
                    Child = new DerivedChild {
                        Id = 1
                    }
                });
                tr.Commit();
            }
            ReopenDb();
            _db.RegisterType(typeof(ParentNewVersion), "Parent");
            _db.RegisterType(typeof(DerivedChild));
            _db.RegisterType(typeof(Child));
            using (var tr = _db.StartReadOnlyTransaction())
            {
                var parent = (ParentNewVersion)tr.Get(oid);
                Assert.NotNull(parent.Child);
                Assert.Equal(1ul, parent.Child.Id);
            }
        }
Example #12
0
 public void ChangeOfPrimaryKeyIsNotSupported()
 {
     using (var tr = _db.StartTransaction())
     {
         var creator  = tr.InitRelation <IJobTable1>("Job");
         var jobTable = creator(tr);
         var job      = new JobV1 {
             Id = 11, Name = "Code"
         };
         jobTable.Insert(job);
         tr.Commit();
     }
     ReopenDb();
     using (var tr = _db.StartTransaction())
     {
         Assert.Throws <BTDBException>(() => tr.InitRelation <IJobTableIncompatible>("Job"));
     }
 }
Example #13
0
        public void GeneratesCreator()
        {
            Func <IObjectDBTransaction, IPersonSimpleTableWithJustInsert> creator;

            using (var tr = _db.StartTransaction())
            {
                creator = tr.InitRelation <IPersonSimpleTableWithJustInsert>("PersonSimple");
                tr.Commit();
            }
            using (var tr = _db.StartTransaction())
            {
                var personSimpleTable = creator(tr);
                personSimpleTable.Insert(new PersonSimple {
                    TenantId = 1, Email = "*****@*****.**", Name = "Boris"
                });
                tr.Commit();
            }
        }
        public void FreeIDictionary()
        {
            var creator = InitILinks();

            using (var tr = _db.StartTransaction())
            {
                var links = creator(tr);
                Assert.True(links.RemoveById(1));
                tr.Commit();
            }
            AssertNoLeaksInDb();
        }
Example #15
0
 public void StartTransaction()
 {
     _tr = _odb.StartTransaction();
 }
Example #16
0
 public void NewDatabaseIsEmpty()
 {
     using (var tr = _db.StartTransaction())
     {
         Assert.AreEqual(tr.Enumerate <IPerson>().Count(), 0);
     }
 }