Dashboard > db4o OpenDoc > ... > db4o7.0指南 > 12. Configuration
db4o OpenDoc Log In   View a printable version of the current page.
12. Configuration
Added by jeff jie, last edited by cleverpig on Dec 28, 2007  (view change)
Labels: 
(None)

12. 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. A more complete description of Configuration usage and scope can also be obtained from the Reference  documentation.

db4o提供了大量的配置方法来实现特定的行为。如果希望获取全部方法的完整列表,请参考com.db4o.config包的API文档。当然,也可以从参考文档获得对配置的使用和范围的详尽解释。

Some hints around using configuration calls:

下面是使用配置调用的一些提示:

12.1. Scope范围

Configuration calls can be issued to a global VM-wide configuration context with

通过如下方法, 配置调用可以被用作一个VM范围的全局配置上下文:

Db4o.configure()

 

and to an open ObjectContainer/ObjectServer with

使用如下方法打开ObjectContainer/ObjectServer:

objectContainer.ext().configure()
objectServer.ext().configure()

 

A separate configuration instance can be obtained with

要获得一个单独的配置实例的话,可以通过下面方法:

Configuration config = Db4o.newConfiguration()

 

or cloned from the global configuration with

或者把全局配置克隆过来:

Configuration config = Db4o.cloneConfiguration()

 

Configuration can be submitted when an ObjectContainer/ObjectServer is opened:

在ObjectContainer/ObjectServer被打开时,我们也可以提交 配置:

Db4o.openFile(config, filename)

 

Otherwise the global configuration context will be 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.

否则,全局配置上下文将会被克隆,并复制到最新打开的ObjectContainer/ObjectServer中。如果使用Db4o.configure()对全局上下文进行后继调用,则这些后继调用将不会对已经打开的ObjectContainer/ObjectServers产生影响。

12.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:

一些配置方法不得不在ObjectContainer/ObjectServer被打开之前被调用,在ObjectContainer/ObjectServers已经打开后的调用将被忽略。下面是一些例子:

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:

影响数据库文件格式的配置必须在数据库创建之前进行配置并使之生效(在第一个#openXXX()调用之前)。下面是一些例子:

Configuration conf = Db4o.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.

由于配置的设置不会存储在db4o数据库文件中,因此在每次打开ObjectContainer/ObjectServer时都必须提交相同的配置。如果将db4o用在C/S模式下,我们推荐在服务端和客户端使用同一个配置。为了更好地进行配置,这里有一个十分有效的方法:创建一个应用程序类,用这个类的一个方法来创建适当的配置,然后把这个类同时部署到服务器端和所有的客户端上。

Powered by Atlassian Confluence, the Enterprise Wiki. (Version: 2.1.3 Build:#408 Jan 23, 2006) - Bug/feature request - Contact Administrators