You are here: Configuration > Adding a Field Index

Field Specific Configuration

Some settings are field-specific. It's part of the object-configuration, which is available on the client, server and embedded-mode of db4o.

Its recommended that you use the same configuration for the client and the server.

Access the Field Configuration

The configuration for a field follows the same pattern. First you specify for which type this configuration applies. You pass the type or the name as string. Then you navigate to the specific field by passing the field name as string.

Adding a Field Index

Index dramatically speed up queries. You should index all fields which you run queries on. See "Indexing"

@Indexed
private String zipCode;
City.java: Index a field

As alternative you can externally configure a field index:

EmbeddedConfiguration configuration = Db4oEmbedded.newConfiguration();
configuration.common().objectClass(Person.class).objectField("name").indexed(true);
ObjectFieldConfigurations.java: Index a certain field

As an alternative you also can use the appropriate Annotation on the field which you want to index.

Cascade On Activate

db4o uses the concept of activation to avoid loading to much data into memory. When this setting is turned on, the object referenced by this field is activated, when the object is activated.

Note: As soon as you use transparent activation/persistence this configuration option has no effect.
EmbeddedConfiguration configuration = Db4oEmbedded.newConfiguration();
configuration.common().objectClass(Person.class).objectField("father").cascadeOnActivate(true);
ObjectFieldConfigurations.java: When activated, activate also the object referenced by this field

Cascade On Update

When the object is updated, the object referenced by this field is also updated.

Note: As soon as you use transparent persistence this configuration option has no effect and isn't needed.
EmbeddedConfiguration configuration = Db4oEmbedded.newConfiguration();
configuration.common().objectClass(Person.class).objectField("father").cascadeOnUpdate(true);
ObjectFieldConfigurations.java: When updated, update also the object referenced by this field

Cascade On Delete

When the object is deleted, the object referenced by this field is also deleted

EmbeddedConfiguration configuration = Db4oEmbedded.newConfiguration();
configuration.common().objectClass(Person.class).objectField("father").cascadeOnDelete(true);
ObjectFieldConfigurations.java: When deleted, delete also the object referenced by this field

Rename Field

Allows you to rename this field. . See "Refactoring and Schema Evolution"

EmbeddedConfiguration configuration = Db4oEmbedded.newConfiguration();
configuration.common().objectClass(Person.class).objectField("name").rename("sirname");
ObjectFieldConfigurations.java: Rename this field