// The cache may touch more bytes than the ones we modified.
            // We should be safe even if we don't get this test to pass.
            // The log file is not a public API yet anyway.
            // It's only needed for the PointerBasedIdSystem
            // With the new BTreeIdSystem it's not likely to become important
            // so we can safely ignore the failing write trash case.
            private IConfiguration BaseConfig(bool useLogFile)
            {
                Config4Impl config = (Config4Impl)Db4oFactory.NewConfiguration();

                config.ObjectClass(typeof(CrashSimulatingTestSuite.CrashData)).ObjectField("_name"
                                                                                           ).Indexed(true);
                config.ReflectWith(Platform4.ReflectorForType(typeof(CrashSimulatingTestSuite.CrashSimulatingTestCase
                                                                     )));
                config.BTreeNodeSize(4);
                config.LockDatabaseFile(false);
                config.FileBasedTransactionLog(useLogFile);
                ((CrashSimulatingTestSuite.LabeledConfig)IdSystem.Value).Configure(config);
                ((CrashSimulatingTestSuite.LabeledConfig)FreespaceManager.Value).Configure(config
                                                                                           );
                return(config);
            }
Ejemplo n.º 2
0
        public virtual void TestHandles()
        {
            IConfiguration config = Db4oFactory.NewConfiguration();

            config.Storage = new MemoryStorage();
            LocalObjectContainer db = (LocalObjectContainer)Db4oFactory.OpenFile(config, ClientTransactionTestUtil
                                                                                 .MainfileName);
            ClientTransactionPool pool = new ClientTransactionPool(db);

            try
            {
                ClientTransactionHandle handleA = new ClientTransactionHandle(pool);
                Assert.AreEqual(db, handleA.Transaction().Container());
                ClientTransactionHandle handleB = new ClientTransactionHandle(pool);
                Assert.AreNotEqual(handleA.Transaction(), handleB.Transaction());
                Assert.AreEqual(db, handleB.Transaction().Container());
                Assert.AreEqual(2, pool.OpenTransactionCount());
                Assert.AreEqual(1, pool.OpenFileCount());
                handleA.AcquireTransactionForFile(ClientTransactionTestUtil.FilenameA);
                Assert.AreEqual(3, pool.OpenTransactionCount());
                Assert.AreEqual(2, pool.OpenFileCount());
                Assert.AreNotEqual(db, handleA.Transaction().Container());
                handleB.AcquireTransactionForFile(ClientTransactionTestUtil.FilenameA);
                Assert.AreEqual(4, pool.OpenTransactionCount());
                Assert.AreEqual(2, pool.OpenFileCount());
                Assert.AreNotEqual(handleA.Transaction(), handleB.Transaction());
                Assert.AreEqual(handleA.Transaction().Container(), handleB.Transaction().Container
                                    ());
                handleA.ReleaseTransaction(ShutdownMode.Normal);
                Assert.AreEqual(db, handleA.Transaction().Container());
                Assert.AreNotEqual(db, handleB.Transaction().Container());
                Assert.AreEqual(3, pool.OpenTransactionCount());
                Assert.AreEqual(2, pool.OpenFileCount());
                handleB.ReleaseTransaction(ShutdownMode.Normal);
                Assert.AreEqual(db, handleB.Transaction().Container());
                Assert.AreEqual(2, pool.OpenTransactionCount());
                Assert.AreEqual(1, pool.OpenFileCount());
                handleB.Close(ShutdownMode.Normal);
                Assert.AreEqual(1, pool.OpenTransactionCount());
                handleA.Close(ShutdownMode.Normal);
                Assert.AreEqual(0, pool.OpenTransactionCount());
            }
            finally
            {
                pool.Close();
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Starts the server.
        /// </summary>
        /// <exception cref="InvalidOperationException">Thrown if the server has already been started.</exception>
        /// <exception cref="ObjectDisposedException">Thrown if the server has been disposed.</exception>
        /// <exception cref="AmbienceException">Thrown if the operation failed.</exception>
        public void Start()
        {
            ThrowIfDisposed();

            Directory.CreateDirectory(Path.GetDirectoryName(databasePath));

            try
            {
                IConfiguration db4oConfig = Db4oFactory.NewConfiguration();
                db4oServer = Db4oFactory.OpenServer(db4oConfig, databasePath, configuration.Port);
                db4oServer.GrantAccess(configuration.Credential.UserName, configuration.Credential.Password);
            }
            catch (Db4oException ex)
            {
                throw new AmbienceException("An error occurred while starting the server.", ex);
            }
        }
Ejemplo n.º 4
0
        private IConfiguration MetaConfiguration()
        {
            var config = Db4oFactory.NewConfiguration();

            config.ExceptionsOnNotStorable(true);
            // the following line is only necessary for the tests to run
            // in OSGi environment
            config.ReflectWith(Platform4.ReflectorForType(typeof(CustomClassRepository)));
            Cascade(config, typeof(CustomClassRepository));
            Cascade(config, typeof(Hashtable4));
            Cascade(config, typeof(CustomClass));
            // FIXME: [TA] this is necessary because the behavior
            // on .net differs with regards to cascade activation
            // remove the following two lines and run the test
            // on .net to see it fail
            Cascade(config, typeof(CustomField));
            Cascade(config, typeof(CustomUidField));
            return(config);
        }
Ejemplo n.º 5
0
        public void CreateDatabase(string path, bool indexed)
        {
            var config = Db4oFactory.NewConfiguration();

            config.ObjectClass(typeof(Item)).ObjectField("id").Indexed(indexed);

            using (var db = Db4oFactory.OpenFile(config, path))
            {
                db.Store(new Item {
                    id = Guid.NewGuid(), name = "Foo"
                });
                db.Store(new Item {
                    id = Guid.NewGuid(), name = "Bar"
                });
                db.Store(new Item {
                    id = Guid.NewGuid(), name = "Baz"
                });
            }
        }
Ejemplo n.º 6
0
        static void Main(string[] args)
        {
            DeleteDatabaseFile();
            InsertData();

            IConfiguration configuration = Db4oFactory.NewConfiguration();

            if (args.Length == 1 && args[0].ToUpper() == "-TA")
            {
                configuration.Add(new TransparentActivationSupport());
            }

            for (int i = 0; i < 5; i++)
            {
                Console.WriteLine("\r\nActivation Depth: {0}", i);
                ShowResultsAtActivationLevel(i, configuration);
                Console.WriteLine("{0}\r\n", new String('-', 80));
            }
        }
Ejemplo n.º 7
0
        public static IObjectContainer conectar()
        {
            if (servidor != null)
                servidor.Close();
            IConfiguration config = Db4oFactory.NewConfiguration();
            new TransparentActivationSupport().Prepare(config);
            config.LockDatabaseFile(false);
            config.DetectSchemaChanges(true);
            servidor = Db4oFactory.OpenServer(config, System.Web.HttpContext.Current.Server.MapPath("..\\bdoo\\financas.db4o"), 0);
            //servidor.Ext().Configure().ActivationDepth(2);
            db = servidor.OpenClient();
            db.Ext().Configure().ObjectClass(typeof(Usuario)).CascadeOnUpdate(true);
            db.Ext().Configure().ObjectClass(typeof(Conta)).CascadeOnUpdate(true);
            db.Ext().Configure().ObjectClass(typeof(Categoria)).CascadeOnUpdate(true);
            //db.Ext().Configure().ObjectClass(typeof(Lancamento)).ObjectField("Imagem").CascadeOnActivate(false);
            //db.Ext().Configure().ObjectClass(typeof(Lancamento)).ObjectField("Comprovante").CascadeOnActivate(false);

            return db;
        }
Ejemplo n.º 8
0
        public virtual void TestPool()
        {
            IConfiguration config = Db4oFactory.NewConfiguration();

            config.Storage = new MemoryStorage();
            LocalObjectContainer db = (LocalObjectContainer)Db4oFactory.OpenFile(config, ClientTransactionTestUtil
                                                                                 .MainfileName);
            ClientTransactionPool pool = new ClientTransactionPool(db);

            try
            {
                Assert.AreEqual(0, pool.OpenTransactionCount());
                Assert.AreEqual(1, pool.OpenFileCount());
                Transaction trans1 = pool.Acquire(ClientTransactionTestUtil.MainfileName);
                Assert.AreEqual(db, trans1.Container());
                Assert.AreEqual(1, pool.OpenTransactionCount());
                Assert.AreEqual(1, pool.OpenFileCount());
                Transaction trans2 = pool.Acquire(ClientTransactionTestUtil.FilenameA);
                Assert.AreNotEqual(db, trans2.Container());
                Assert.AreEqual(2, pool.OpenTransactionCount());
                Assert.AreEqual(2, pool.OpenFileCount());
                Transaction trans3 = pool.Acquire(ClientTransactionTestUtil.FilenameA);
                Assert.AreEqual(trans2.Container(), trans3.Container());
                Assert.AreEqual(3, pool.OpenTransactionCount());
                Assert.AreEqual(2, pool.OpenFileCount());
                pool.Release(ShutdownMode.Normal, trans3, true);
                Assert.AreEqual(2, pool.OpenTransactionCount());
                Assert.AreEqual(2, pool.OpenFileCount());
                pool.Release(ShutdownMode.Normal, trans2, true);
                Assert.AreEqual(1, pool.OpenTransactionCount());
                Assert.AreEqual(1, pool.OpenFileCount());
            }
            finally
            {
                Assert.IsFalse(db.IsClosed());
                Assert.IsFalse(pool.IsClosed());
                pool.Close();
                Assert.IsTrue(db.IsClosed());
                Assert.IsTrue(pool.IsClosed());
                Assert.AreEqual(0, pool.OpenFileCount());
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Connects the client to the remote server.
        /// </summary>
        /// <param name="configuration">The client configuration.</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="configuration"/> is null.</exception>
        /// <exception cref="AmbienceException">Thrown if the operation failed.</exception>
        public static AmbienceClient Connect(AmbienceClientConfiguration configuration)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException("configuration");
            }

            try
            {
                IConfiguration   db4oConfig    = Db4oFactory.NewConfiguration();
                IObjectContainer db4oContainer = Db4oFactory.OpenClient(db4oConfig,
                                                                        configuration.HostName, configuration.Port,
                                                                        configuration.Credential.UserName, configuration.Credential.Password);
                return(new AmbienceClient(new Db4oAmbientDataContainer(db4oContainer)));
            }
            catch (Db4oException ex)
            {
                throw new AmbienceException("An error occurred while connecting to the server.", ex);
            }
        }
Ejemplo n.º 10
0
        /// <summary>
        /// opens the IObjectServer, and waits forever until Close() is called
        /// or a StopServer message is being received.
        /// </summary>
        public void RunServer()
        {
            Console.WriteLine("Server starting");
            lock (this)
            {
                // Using the messaging functionality to redirect all
                // messages to this.processMessage
                IConfiguration configuration = Db4oFactory.NewConfiguration();
                configuration.ClientServer().SetMessageRecipient(this);


                configuration.Add(new TransparentActivationSupport());
                configuration.Add(new TransparentPersistenceSupport());


                server = Db4oFactory.OpenServer(configuration, FileName, Port);
                server.GrantAccess(User, Password);
                server.GrantAccess("server", "serverpass");

                Console.WriteLine("Server started");
                client = Db4oFactory.OpenClient(Host, Port, "server", "serverpass");
                try
                {
                    if (!stop)
                    {
                        // wait forever until Close will change stop variable
                        Console.WriteLine("Server waiting...");
                        Monitor.Wait(this);
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.ToString());
                }
                server.Close();
                Console.WriteLine("Server closed");
            }
        }
Ejemplo n.º 11
0
        public void Load(String filePath)
        {
            IConfiguration config = Db4oFactory.NewConfiguration();

            if (UseSpecificActivationDepth())
            {
                config.ActivationDepth(_activationDepth);
            }

            if (ActiveTransparently)
            {
                config.Add(new TransparentActivationSupport());
            }
            _db = Db4oFactory.OpenFile(config, filePath);

            IList <RootTask> tasks = _db.Query <RootTask>(typeof(RootTask));

            if (tasks.Count > 1)
            {
                throw new InvalidOperationException("Corrupted databse.");
            }

            _rootTask = tasks.Count == 1 ? tasks[0] : new RootTask();
        }
Ejemplo n.º 12
0
 protected override IConfiguration Config()
 {
     return(Db4oFactory.NewConfiguration());
 }
Ejemplo n.º 13
0
 protected virtual IConfiguration GetConfiguration()
 {
     return(Db4oFactory.NewConfiguration());
 }
 static public Db4oDataStore InitializeDataStore(string dataStoreName)
 {
     return(InitializeDataStore(dataStoreName, Db4oFactory.NewConfiguration()));
 }
Ejemplo n.º 15
0
 private static Config4Impl NewLegacyConfig()
 {
     return((Config4Impl)Db4oFactory.NewConfiguration());
 }
Ejemplo n.º 16
0
        protected IConfiguration Configure()
        {
            IConfiguration config = Db4oFactory.NewConfiguration();

            return(Configure(config));
        }