You are here: Basics Operations & Concepts > Querying > Native Queries > Native Query Optimization At Build Time

Native Query Optimization At Build Time

If the platform you're running doesn't support optimization at runtime you can use the compile-time optimization. See "Enhancement Tools"

Create the Enhancement Task

First we define the enhancement-task. This task will process the jar and enhance it.

If you haven't used Ant yet, read more on the official Ant website.

<target name="enhance">
    <db4o-enhance classtargetdir="${basedir}/bin"
                  jartargetdir="${basedir}/lib"
                  nq="true" ta="true"
                  collections="true">
        <classpath refid="project.classpath"/>
        <sources dir="${basedir}/bin">
            <include name="**/*.class"/>
        </sources>
    </db4o-enhance>
</target>
simple-enhance-example.xml: Define a target which runs the task

And the execute the task after the compilation.

<target name="enhance-nq">
    <db4o-enhance classtargetdir="${basedir}/bin"
                  jartargetdir="${basedir}/lib"
                  nq="true" ta="false"
                  collections="false">
        <classpath refid="project.classpath"/>
        <sources dir="${basedir}/bin">
            <include name="**/*.class"/>
        </sources>
    </db4o-enhance>
</target>
simple-enhance-example.xml: Only enhance native queries

You can configure Eclipse to run the Ant build with each compile step. Right click on your project and choose 'Properties'. Then switch to 'Builders' and add a new one. Choose the 'Ant Builder'. On the new window choose the build-file which contains the example-code. Switch to the 'Targets'-Tab. There choose the enhance-target for the 'Auto-Build'. Now the enhancer-task will be run by Eclipse automatically. The example project above is configured this way.

Often it's practical to have all persistent classes in a separate project or compile unit. Then the enhancement script runs only for this project. This makes it easy to enhance only the classes for the persistent objects.

There are lot of possibilities to tweak and configure the build-time enhancement so that it fits your requirements.