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 com.db4o.config package/namespace.

Some hints around using configuration calls:


    13.1. Scope

    Configuration calls can be issued to a global VM-wide configuration context with
    Db4o.configure()

    and to an open ObjectContainer/ObjectServer with
    objectContainer.ext().configure()
    objectServer.ext().configure()


    When an ObjectContainer/ObjectServer is opened, the global configuration context is cloned and copied into the newly opened ObjectContainer/ObjectServer. Subsequent calls against the global context with Db4o.configure() have no effect on open ObjectContainers/ObjectServers.


    13.2. Calling Methods

    Many configuration methods have to be called before an ObjectContainer/ObjectServer is opened and will be ignored if they are called against open ObjectContainers/ObjectServers. Some examples:
    Configuration conf = Db4o.configure();
    conf.objectClass(Foo.class).objectField("bar").indexed(true);
    conf.objectClass(Foo.class).cascadeOnUpdate();
    conf.objectClass(Foo.class).cascadeOnDelete();
    conf.objectClass(typeof(System.Drawing.Image))
      .translate(new TSerializable());
    conf.generateUUIDs(Integer.MAX_VALUE);
    conf.generateVersionNumbers(Integer.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 = Db4o.configure();
    conf.blockSize(8);
    conf.encrypt(true);
    conf.password("yourEncryptionPasswordHere");
    conf.unicode(false);


    Configuration settings are not stored in db4o database files. Accordingly all configuration methods have to be called every time before an ObjectContainer/ObjectServer is opened. For using db4o in client/server mode it is recommended to use the same global 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 does all the db4o configuration and to deploy this class both to the server and to all clients.

    Further reading
    Some configuration switches are discussed in more detail in the following chapters:
    -Tuning
    -Indexes
    -Encryption



    --
    generated by
    Doctor courtesy of db4objects Inc.