Do you have much more money than you can fit into a long? Or do you like splitting hairs to fractions that cannot be accurately measured with double values? Then chances are that you are not happy with the primitive numeric types Java provides, and you'll have to resort to BigInteger/BigDecimal. Now you can rely on dedicated db4o support for applications requiring this level of magnitude and/or accuracy.

Well, actually db4o has supported BI/BD instances already in a way - they are objects, so db4o could store and retrieve them. But there were quite some show stoppers:
  • These classes rely on transient field setup in the constructor. Worse, the internal representation has changed over time: db4o would require (sometimes JDK version specific) configuration to be able to reinstantiate these objects to a consistent state.
  • db4o would store instances of these classes as full object graphs: A BigDecimal contains a BigInteger which contains a byte array, plus some more white noise at all object graph levels. This graph would faithfully be persisted into the database file and it would have to be read and reconstructed on access.
  • Querying would not be reasonably applicable to instances of these classes: The best you could hope for was "query by example" semantics - which are bound to fail in the presence of "state relevant" transient fields.

Enter a type handler that makes BI/BD almost look like primitive types from a db4o point of view: You lose "object identity" for those values (they are effectively handled as value types like int/float), in turn you gain much faster marshall/unmarshall times and query capabilities, including indexing. Instead of persisting full object graphs, the primitive representations provided by BigInteger#toByteArray() and BigDecimal#toString() are used for the marshalling process. In an artificial benchmark, this type handler shows 2-3x better marshall/unmarshall performance for BI, 3-4x for BD. Queries into BI/BD now just work like queries into int/float, and they can take advantage of field indices (potentially speeding up queries by multiple orders of magnitude).

BI/BD support is packaged with the db4o-optional module/jar, enabling it is as simple as typing

config.add(new BigMathSupport());

Please take a look and report any issues or suggestions for improvement you may encounter. This code (with the abstract class com.db4o.internal.handlers.BigNumberTypeHandler containing the bulk of the implementation) may also serve as a blueprint for custom type handler implementations for "primitive-like" objects. Please note that work on the type handler API is still in progress - we still discourage custom use of the current API in production environments, but we wholeheartedly encourage all feedback from experimental use that may help us to further improve it.