Enhancement tools provide a convenient framework for application (jar, dll, exe) or classes modification to support db4o-specific functionality. Enhancement tools can work on a ready application or library and apply the improvements at load or build time.
The tools functionality is provided through bytecode instrumentation. This process inserts special, usually short, sequences of bytecode at designated points in your code. It is typically used for profiling or monitoring, however the range of use of bytecode instrumentation is not limited by this tasks: it can be applied anywhere where a specific functionality should be plugged into the ready built classes.
db4o Enhancement Tools currently have these cases for bytecodeinstrumentation:
In transparent activation/persistence case, classes are required to implement IActivatable interface to support transparent activation. In many cases you don't want to pollute your classes with some additional interface, or even won't be able to do so if you use a third party classes library. That's where bytecode instrumentation comes handy: IActivatableinterface will be implemented on your existing classes by applying bytecode instrumentation. Another advantage of this approach - you can still work on your "clean" classes, just do not forget to run the instrumentation afterwards.
In the native query optimization case bytecode
instrumentation is used as a more performant alternative to a run-time
optimization. When an native query is optimized the user and compiler-friendly syntax of
NQ predicate is replaced with a query-processor-friendly code. Obviously, optimization process can take some time, therefore it
can be a good choice to use pre-instrumented classes, then to let the
optimization be executed each time it is required by application.
The instrumentation can be run at build time, also known as static instrumentation. In this case a special build script calls runs the instrumentation on the classes before packaging them to assembly, or on the assembly itself. This is the fastest solution as no time is spent on bytecode instrumentation at runtime.
There are different possibilities to integrate the enhancement tools into a project.