13. Configuration


db4o provides a wide range of configuration methods to request special behaviour. For a complete list of all available methods see the API documentation for the Db4objects.Db4o.Config namespace. A more complete description of Configuration usage and scope can also be obtained from the Reference  documentation.


Some hints around using configuration calls:


    13.1. Scope

    Configuration calls can be issued to a global configuration context with
    Db4oFactory.Configure()

    and to an open IObjectContainer/IObjectServer with
    objectContainer.Ext().Configure()
    objectServer.Ext().Configure()

    A separate configuration instance can be obtained with
    IConfiguration config = Db4oFactory.NewConfiguration()

    or cloned from the global configuration with
    IConfiguration config = Db4oFactory.CloneConfiguration()

    Configuration can be submitted when an IObjectContainer/IObjectServer is opened:
    Db4oFactory.OpenFile(config, filename)

    Otherwise  the global configuration context will be cloned and copied into the newly opened IObjectContainer/IObjectServer. Subsequent calls against the global context with Db4oFactory.Configure() have no effect on open IObjectContainers/IObjectServers.


    13.2. Calling Methods

    Many configuration methods have to be called before an IObjectContainer/IObjectServer is opened and will be ignored if they are called against open IObjectContainers/IObjectServers. Some examples:
    Configuration conf = Db4oFactory.Configure();
    conf.ObjectClass(typeof(Foo)).ObjectField("bar").Indexed(true);
    conf.ObjectClass(typeof(Foo)).CascadeOnUpdate();
    conf.ObjectClass(typeof(Foo)).CascadeOnDelete();
    conf.ObjectClass(typeof(System.Drawing.Image))
      .translate(new TSerializable());
    conf.GenerateUUIDs(int.MAX_VALUE);
    conf.GenerateVersionNumbers(int.MAX_VALUE);
    conf.AutomaticShutDown(false);
    conf.LockDatabaseFile(false);
    conf.SingleThreadedClient(true);
    conf.WeakReferences(false);


    Configurations that influence the database file format will have to take place, before a database is created, before the first #OpenXXX() call. Some examples:
    Configuration conf = Db4oFactory.Configure();
    conf.BlockSize(8);
    conf.Unicode(false);


    Configuration settings are not stored in db4o database files. Accordingly the same configuration has to be submitted  every time an ObjectContainer/ObjectServer is opened. For using db4o in client/server mode it is recommended to use the same configuration on the server and on the client. To set this up nicely it makes sense to create one application class with one method that creates an appropriate configuration and to deploy this class both to the server and to all clients.



    www.db4o.com