Instrumenting Class Files

This topic applies to Java version only

Note: Instrumented optimized classes will work with JDK1.1, but the optimization process itself requires at least JDK 1.2.

File instrumentation can be done either programmatically or during an Ant build.

Programmatic Instrumentation

To instrument all predicate classes in directory 'bin', whose package name starts with 'my.package' and store the modified files below directory 'instrumented', ensure that db4o-x.x-nqopt.jar and bloat-1.0.jar are in your CLASSPATH and use code like the following:

NQExample.java: enhance
01public static void enhance(){ 02 try { 03 new com.db4o.nativequery.main.Db4oFileEnhancer().enhance( 04 "bin", // source directory 05 "instrumented", // target directory 06 new String[]{ // class path if needed 07 "lib/my_application.jar", 08 "lib/db4o-5.7-java1.x.jar" 09 }, 10 "my.package" // optional package prefix 11 ); 12 }catch (Exception ex){ 13 System.out.println(ex.getMessage()); 14 } 15 }

Ant Instrumentation

An equivalent Ant target might look like this:

nqopt.xml
01<taskdef name="db4ooptimize" 02 classname="com.db4o.nativequery.main.Db4oFileEnhancerAntTask"> 03 <classpath> 04 <path path="lib/db4o-5.0-java1.x.jar" /> 05 <path path="lib/db4o-5.0-nqopt.jar" /> 06 <path path="lib/bloat-1.0.jar" /> 07 <path path="lib/db4o-5.0-java1.x.jar" /> 08 </classpath> 09</taskdef> 10 11<target name="optimize"> 12 <db4ooptimize 13 srcdir="bin" 14 targetdir="instrumented" 15 packagefilter="my.package"> 16 <classpath> 17 <path location="lib/my_application.jar" /> 18 <path path="lib/db4o-5.0-java1.x.jar" /> 19 </classpath> 20 </db4oenhance> 21</target>

All non-Predicate classes will just be copied to the target directory without modification.