You are here: Advanced Features > Enhancement Tools > Load Time Enhancement

Load Time Enhancement

Its possible to enhance you classes at runtime. This mechanism uses the Java class loading mechanism. Instead of using the regular class-loader, the application needs to use a db4o-classloader which enhanced the classes when loaded.

The enable load time enhancement, you need to create a special launcher for your application. This launcher sets up the class-loader and then starts the application.

The db4o instrumenting classloader has following configuration options available:

A start of your application might look like this:

EnhancerStarter.java: main
public static void main(String[] args) throws Exception  { 
    // use a class-filter to only enhance certain classes
    ClassFilter filter = new ByNameClassFilter("yourpackages.datamodel.", true);
    // specify which enhancements you need. Typically the native-query
    // optimisation and tranparent activation support
    BloatClassEdit[] edits =  { new TranslateNQToSODAEdit() , new InjectTransparentActivationEdit(filter) };
    // specify the where the jars & classes of your project are
    URL[] urls =  { new File("/work/workspaces/db4o/tatest/bin").toURI().toURL() };
    // the launch the application
    Db4oInstrumentationLauncher.launch(edits, urls, EnhancerMain.class.getName(), args);
  }

Try this code now - if everything is correct you will see that the objects are getting activated as they are requested. NQ info also should say that the queries are preoptimized.

Note that for load time instrumentation to work, the application code has to make sure db4o operates on the appropriate classloader for the persistent model classes.

This means that you need to set explicitly the class-loader for the reflection. Set the thread-context class loader in the db4o configuration.

Don't forget that you still need to enable transparent activationpersistence in order to use it.