public virtual void Querydb(IEmbeddedConfiguration config, int[] count, Type class1
                                    , Type class2)
        {
            IEmbeddedObjectContainer database = Db4oEmbedded.OpenFile(config, TempFile());

            try
            {
                IList list = database.Query(class1);
                Assert.AreEqual(count[0], list.Count, "Unexpected result querying for " + class1.
                                Name);
                if (count[0] > 0)
                {
                }
                // System.out.println("Querying for " + class1.getSimpleName() + " getting " + list.get(0).getClass().getSimpleName());
                IList list1 = database.Query(class2);
                Assert.AreEqual(count[1], list1.Count, "Unexpected result querying for " + class2
                                .Name);
                if (count[1] > 0)
                {
                }
            }
            finally
            {
                // System.out.println("Querying for " + class2.getSimpleName() + " getting " + list1.get(0).getClass().getSimpleName());
                database.Close();
            }
        }
Esempio n. 2
0
        private void CloseDb4OContainer()
        {
            if (!UseClient && _emmbededServer == null)
            {
                return;
            }

            if (UseClient && _embeddedContainer == null)
            {
                return;
            }

            if (!UseClient)
            {
                _emmbededServer.Close();
                _emmbededServer.Dispose();
                _emmbededServer = null;
            }
            else
            {
                _embeddedContainer.Close();
                _embeddedContainer.Dispose();
                _embeddedContainer = null;
            }

            _isDb4OInitiated = false;
        }
Esempio n. 3
0
 public static void Close()
 {
     if (container != null)
     {
         container.Close();
     }
 }
Esempio n. 4
0
        /// <exception cref="System.Exception"></exception>
        public virtual void SetUp()
        {
            IEmbeddedObjectContainer db = Db4oEmbedded.OpenFile(Config(), DbPath);

            db.Store(new KnownClassesIndexTestCase.WithIndex(42));
            db.Close();
        }
        /// <exception cref="System.Exception"></exception>
        public virtual void Test()
        {
            Db4oLibraryEnvironment originalEnv = EnvironmentForVersion("6.0");

            originalEnv.InvokeInstanceMethod(typeof(MigrationHopsTestCase.Tester), "createDatabase"
                                             , new object[] { TempFile() });
            string[] hopArray = new string[] { "6.4", "7.4", CurrentVersion() };
            for (int hopIndex = 0; hopIndex < hopArray.Length; ++hopIndex)
            {
                string hop = hopArray[hopIndex];
                Db4oLibraryEnvironment hopEnvironment = EnvironmentForVersion(hop);
                Assert.AreEqual(originalEnv.Version(), InvokeTesterMethodOn(hopEnvironment, "currentVersion"
                                                                            ));
            }
            IEmbeddedConfiguration config = Db4oEmbedded.NewConfiguration();

            config.Common.ReflectWith(new ExcludingReflector(new Type[] { typeof(MigrationHopsTestCase.Item
                                                                                 ) }));
            IEmbeddedObjectContainer container = Db4oEmbedded.OpenFile(config, TempFile());

            try
            {
                IQuery query = container.Query();
                query.Constrain(typeof(MigrationHopsTestCase.Item));
                object item = query.Execute()[0];
                Assert.AreEqual(originalEnv.Version(), ((GenericObject)item).Get(0));
            }
            finally
            {
                container.Close();
            }
        }
        protected virtual void AssertReplicates(object holder)
        {
            IEmbeddedObjectContainer sourceDb = OpenContainer("source");

            sourceDb.Store(holder);
            sourceDb.Commit();
            IEmbeddedObjectContainer targetDb = OpenContainer("target");

            try
            {
                Db4oEmbeddedReplicationProvider providerA = new Db4oEmbeddedReplicationProvider(sourceDb
                                                                                                );
                Db4oEmbeddedReplicationProvider providerB = new Db4oEmbeddedReplicationProvider(targetDb
                                                                                                );
                IReplicationSession replication = Replication.Begin(providerA, providerB);
                IObjectSet          changed     = replication.ProviderA().ObjectsChangedSinceLastReplication();
                while (changed.HasNext())
                {
                    object o = changed.Next();
                    if (holder.GetType() == o.GetType())
                    {
                        replication.Replicate(o);
                        break;
                    }
                }
                replication.Commit();
            }
            finally
            {
                sourceDb.Close();
                targetDb.Close();
            }
        }
Esempio n. 7
0
        private void AssertItems(string fileName, int count)
        {
            IEmbeddedObjectContainer objectContainer = Db4oEmbedded.OpenFile(fileName);

            AssertItems(objectContainer, count);
            objectContainer.Close();
        }
        private void AssertName(IEmbeddedConfiguration config, string expected)
        {
            IEmbeddedObjectContainer db = Db4oEmbedded.OpenFile(config, FileName);

            Assert.AreEqual(expected, db.ToString());
            db.Close();
        }
        private void CreateData()
        {
            IEmbeddedObjectContainer database = Db4oEmbedded.OpenFile(TempFile());

            database.Store(new QueryingReadOnlyWithNewClassTestCase.A("Item1"));
            database.Commit();
            database.Close();
        }
        /// <exception cref="System.Exception"></exception>
        public virtual void SetUp()
        {
            IEmbeddedObjectContainer db = OpenDatabase();

            db.Store(new ConcurrentRenameTestCase.QueryItem());
            db.Store(new ConcurrentRenameTestCase.RenameItem());
            db.Close();
        }
Esempio n. 11
0
        private void CreateData()
        {
            IEmbeddedObjectContainer database = Db4oEmbedded.OpenFile(TempFile());

            database.Store(new RenamingClassAfterQueryingTestCase.A("Item1"));
            database.Commit();
            database.Close();
        }
Esempio n. 12
0
 public void Dispose()
 {
     if (db != null)
     {
         db.Close();
         db.Dispose();
     }
 }
Esempio n. 13
0
        /// <exception cref="System.Exception"></exception>
        public virtual void SetUp()
        {
            storage = new MemoryStorage();
            IEmbeddedObjectContainer db = Db4oEmbedded.OpenFile(Config(), DbPath);

            for (int i = 0; i < NumItems; i++)
            {
                db.Store(new ClassRenameByConfigExcludingOldClassTestCase.OldItem(i));
            }
            db.Close();
        }
        public virtual void TestQuery()
        {
            CreateData();
            IEmbeddedObjectContainer database = Db4oEmbedded.OpenFile(AliasConfig(), TempFile
                                                                          ());

            database.Query(typeof(AliasesQueryingTestCase.B));
            database.Query(typeof(AliasesQueryingTestCase.A));
            database.Close();
            Querydb(Db4oEmbedded.NewConfiguration(), new int[] { 1, 0 }, typeof(AliasesQueryingTestCase.A
                                                                                ), typeof(AliasesQueryingTestCase.B));
        }
        private void AssertVersionAfterDefrag(long version, IEmbeddedConfiguration afterDefragConfig
                                              )
        {
            IEmbeddedObjectContainer db = OpenContainer(afterDefragConfig);

            CommitTimestampDefragmentTestCase.Item retrievedItem = ((CommitTimestampDefragmentTestCase.Item
                                                                     )db.Query(typeof(CommitTimestampDefragmentTestCase.Item)).Next());
            long retrievedVersion = db.Ext().GetObjectInfo(retrievedItem).GetCommitTimestamp(
                );

            Assert.AreEqual(version, retrievedVersion);
            db.Close();
        }
        /// <exception cref="System.IO.IOException"></exception>
        private void CreateDatabase(IList gaps)
        {
            Delete(TempFile());
            IEmbeddedConfiguration   config = NewConfiguration();
            IEmbeddedObjectContainer db     = Db4oEmbedded.OpenFile(config, TempFile());
            IList list = new ArrayList();

            list.Add(new FileUsageStatsTestCase.Child());
            FileUsageStatsTestCase.Item item = new FileUsageStatsTestCase.Item(0, "#0", list);
            db.Store(item);
            db.Commit();
            db.Close();
        }
Esempio n. 17
0
        public static void Main(string[] args)
        {
            IEmbeddedObjectContainer db = Db4oEmbedded.OpenFile(args[0]);

            try
            {
                Sharpen.Runtime.Out.WriteLine(new ConsistencyChecker(db).CheckSlotConsistency());
            }
            finally
            {
                db.Close();
            }
        }
Esempio n. 18
0
        public virtual void Test()
        {
            IEmbeddedConfiguration config = Db4oEmbedded.NewConfiguration();

            config.File.Storage = new MemoryStorage();
            EmbeddedConfigurationItemIntegrationTestCase.DummyConfigurationItem item = new EmbeddedConfigurationItemIntegrationTestCase.DummyConfigurationItem
                                                                                           (this);
            config.AddConfigurationItem(item);
            IEmbeddedObjectContainer container = Db4oEmbedded.OpenFile(config, string.Empty);

            item.Verify(config, container);
            container.Close();
        }
        private long StoreItemAndGetCommitTimestamp(IEmbeddedConfiguration config)
        {
            IEmbeddedObjectContainer db = OpenContainer(config);

            CommitTimestampDefragmentTestCase.Item item = new CommitTimestampDefragmentTestCase.Item
                                                              ();
            db.Store(item);
            db.Commit();
            long commitTimestamp = db.Ext().GetObjectInfo(item).GetCommitTimestamp();

            db.Close();
            return(commitTimestamp);
        }
        public virtual void Test()
        {
            IEmbeddedConfiguration config = Db4oEmbedded.NewConfiguration();

            config.File.Storage = new MemoryStorage();
            config.Common.Add(new ObjectContainerOpenEventTestCase.OpenListenerConfigurationItem
                                  (this, eventReceived));
            Assert.IsFalse(eventReceived.value);
            IEmbeddedObjectContainer db = Db4oEmbedded.OpenFile(config, string.Empty);

            Assert.IsTrue(eventReceived.value);
            db.Close();
        }
Esempio n. 21
0
        public virtual void QueryDb(IEmbeddedConfiguration config, Type clazz, int count)
        {
            IEmbeddedObjectContainer database = Db4oEmbedded.OpenFile(config, TempFile());

            try
            {
                IList list = database.Query(clazz);
                Assert.AreEqual(count, list.Count);
            }
            finally
            {
                database.Close();
            }
        }
Esempio n. 22
0
        public static FileUsageStats RunStats(string dbPath, bool collectSlots, IEmbeddedConfiguration
                                              config)
        {
            IEmbeddedObjectContainer db = Db4oEmbedded.OpenFile(config, dbPath);

            try
            {
                return(new Db4objects.Db4o.Filestats.FileUsageStatsCollector(db, collectSlots).CollectStats
                           ());
            }
            finally
            {
                db.Close();
            }
        }
Esempio n. 23
0
        public virtual void Test()
        {
            IEmbeddedConfiguration config = Config();

            config.Common.ObjectClass(typeof(ClassRenameByConfigExcludingOldClassTestCase.OldItem
                                             )).Rename(typeof(ClassRenameByConfigExcludingOldClassTestCase.NewItem).FullName);
            config.Common.ReflectWith(new ExcludingReflector(new Type[] { typeof(ClassRenameByConfigExcludingOldClassTestCase.OldItem
                                                                                 ) }));
            IEmbeddedObjectContainer db = Db4oEmbedded.OpenFile(config, DbPath);

            AssertExtentSize(0, typeof(ClassRenameByConfigExcludingOldClassTestCase.OldItem),
                             db);
            AssertExtentSize(NumItems, typeof(ClassRenameByConfigExcludingOldClassTestCase.NewItem
                                              ), db);
            db.Close();
        }
 private static void ApplyProcedure(PagingMemoryStorage storage, IProcedure4 procedure4
     )
 {
     IEmbeddedConfiguration config = Db4oEmbedded.NewConfiguration();
     config.File.Storage = storage;
     IEmbeddedObjectContainer container = Db4oEmbedded.OpenFile(config, "benchmark.db4o"
         );
     try
     {
         procedure4.Apply(container);
     }
     finally
     {
         container.Close();
     }
 }
Esempio n. 25
0
        public virtual void TestIndexInfoAvailableAfterInfoGathering()
        {
            IEmbeddedConfiguration config = Config();

            config.Common.ReflectWith(new ExcludingReflector(new Type[] { typeof(KnownClassesIndexTestCase.WithIndex
                                                                                 ) }));
            IEmbeddedObjectContainer db = Db4oEmbedded.OpenFile(config, DbPath);

            try
            {
                ScanThroughKnownClassesInfo(db);
                AssertHasIndexInfo(db);
            }
            finally
            {
                db.Close();
            }
        }
 private static void StoreItems(PagingMemoryStorage storage)
 {
     IEmbeddedConfiguration config = Db4oEmbedded.NewConfiguration();
     config.File.Storage = storage;
     IEmbeddedObjectContainer container = Db4oEmbedded.OpenFile(config, "benchmark.db4o"
         );
     try
     {
         for (int i = 0; i < ObjectCount; ++i)
         {
             container.Store(new SodaQueryComparatorBenchmark.Item(i, "Item " + i, new SodaQueryComparatorBenchmark.ItemChild
                 ("Child " + i)));
         }
     }
     finally
     {
         container.Close();
     }
 }
        /// <exception cref="System.Exception"></exception>
        public virtual void Test()
        {
            IEmbeddedObjectContainer db = OpenDatabase();
            IList exceptions            = new ArrayList();

            Thread[] threads = new Thread[] { new Thread(new ConcurrentRenameTestCase.QueryRunner
                                                             (db, exceptions), "ConcurrentRenameTestCase.test Thread[0]"), new Thread(new ConcurrentRenameTestCase.RenameRunner
                                                                                                                                          (db, exceptions), "ConcurrentRenameTestCase.test Thread[1]") };
            for (int threadIndex = 0; threadIndex < threads.Length; ++threadIndex)
            {
                Thread thread = threads[threadIndex];
                thread.Start();
            }
            for (int threadIndex = 0; threadIndex < threads.Length; ++threadIndex)
            {
                Thread thread = threads[threadIndex];
                thread.Join();
            }
            db.Close();
            Assert.AreEqual(0, exceptions.Count);
        }
        public virtual void TestEmbedded()
        {
            IList missingClasses = new ArrayList();
            IEmbeddedConfiguration excludingConfig = Db4oEmbedded.NewConfiguration();

            PrepareHost(excludingConfig.File, excludingConfig.Common, missingClasses);
            ExcludeClasses(excludingConfig.Common, new Type[] { typeof(MissingClassDiagnosticsTestCase.Pilot
                                                                       ), typeof(MissingClassDiagnosticsTestCase.Car) });
            IEmbeddedObjectContainer excludingContainer = Db4oEmbedded.OpenFile(excludingConfig
                                                                                , DbUri);

            try
            {
                excludingContainer.Query(new MissingClassDiagnosticsTestCase.AcceptAllPredicate()
                                         );
            }
            finally
            {
                excludingContainer.Close();
            }
            AssertPilotAndCarMissing(missingClasses);
        }
Esempio n. 29
0
 public void CommitTransaction()
 {
     _db.Commit();
     _db.Close();
 }
Esempio n. 30
0
 public virtual void Close()
 {
     _server.Close();
 }
        private static IEmbeddedObjectContainer GetContainer()
        {
            if (null == _container || _container.Ext().IsClosed())
            {
                var file = MapPath("northwind.db4o");

                _container = Db4oEmbedded.OpenFile(Db4oEmbedded.NewConfiguration(), file);

                HttpContext.Current.ApplicationInstance.Disposed += delegate
                {
                    _container.Close();
                };
            }
            return _container;
        }