1

I'm currently evaluating the Spring-db4o integration. I was impressed by the declarative transaction support as well as the ease to provide declarative configuration.

Unfortunately, I'm struggling to figure how to create an index on specific fields. Spring is preparing the db during the tomcat server startup. Here's my spring entry :

<bean id="objectContainer" class="org.springmodules.db4o.ObjectContainerFactoryBean">
  <property name="configuration" ref="db4oConfiguration" />
  <property name="databaseFile" value="/WEB-INF/repo/taxonomy.db4o" />
</bean>
<bean id="db4oConfiguration" class="org.springmodules.db4o.ConfigurationFactoryBean">
  <property name="updateDepth" value="5" />
  <property name="configurationCreationMode" value="NEW" />
</bean>
<bean id="db4otemplate" class="org.springmodules.db4o.Db4oTemplate">
  <constructor-arg ref="objectContainer" />
</bean>

db4oConfiguration doesn't provide any means to specify the index. I wrote a simple ServiceServletListener to set the index. Here's the relevant code:

Db4o.configure().objectClass(com.test.Metadata.class).objectField("id").indexed(true); 
Db4o.configure().objectClass(com.test.Metadata.class).objectField("value").indexed(true);

I inserted around 6000 rows in this table and then used a SODA query to retrieve a row based on the key. But the performance was pretty poor. To verify that indexes have been applied properly, I ran the following program:

private static void indexTest(ObjectContainer db){
   for (StoredClass storedClass : db.ext().storedClasses()) {
       for (StoredField field : storedClass.getStoredFields()) {
          if(field.hasIndex()){
              System.out.println("Field "+field.getName()+" is indexed! ");
          }else{
              System.out.println("Field "+field.getName()+" isn't indexed! ");
          }
       }
   }
}

Unfortunately, the results show that no field is indexed.

On a similar context, in OME browser, I saw there's an option to create index on fields of each class. If I turn the index to true and save, it appears to be applying the change to db4o. But again, if run this sample test on the db4o file, it doesn't reveal any index.

Any pointers on this will be highly appreciated.

Paŭlo Ebermann
  • 73,284
  • 20
  • 146
  • 210
Shamik
  • 1,671
  • 11
  • 36
  • 64

1 Answers1

1

Unfortunately I don't know the spring extension for db4o that well.

However the Db4o.configure() stuff is deprecated and works differently than in earlier versions. In earlier versions there was a global db4o configuration. Not this configuration doesn't exist anymore. The Db4o.configure() call doesn't change the configuration for running object containers.

Now you could try to do this work around and a running container:

container.ext().configure().objectClass(com.test.Metadata.class).objectField("id").indexed(true); 

This way you change the configuration of the running object container. Note that changing the configuration of a running object container can lead to dangerous side effect and should be only used as last resort.

Gamlor
  • 12,978
  • 7
  • 43
  • 70