Open topic with navigation
Pluggable Typehandler Benefits
As the name suggests Pluggable allows anybody to
write custom typehandlers, and thus control the way the class objects are
stored to the database and retrieved in a query. Why would you do this? There
can be various reasons:
- You know a more performant way to convert
objects to byte array or to compare them.
- You need to store only part of the object's
information and want to skip unneeded fields to keep the database smaller. You
can also do the same using Transientmarker, but this is only possible for classes with available code. Using custom
typehandler you can configure partial storage for any third-party class.
- You need to keep information that will allow you
to restore fields that cannot be stored as is, for example: references to
environmental variables (like time zone), proxy objects or variables of
temporary state (like current memory usage). Previously, this job was done by
Translators, but certainly custom Typehandler gives you more control
and unifies the approach.
- You need to perform a complex refactoring
on-the-fly (use typehandler versioning)
- You want to cipher each object before putting it
into the database
Other not so common and more
difficult in realization behaviours that can be realized with the new
Typehandler:
- Customary indexes
- Versioning of typehandlers (can be used for
refactoring and db4o version upgrades)
Of course, writing typehandlers
is not totally simple, but once you understand how to do that - you will also
gain a much deeper understanding of db4o itself. You can start with a simple
example provided in this documentation and continue by looking into existing
db4o typehandler implementations: StringHandler, VariableLengthTypeHandler,
IndexableTypeHandler etc.