NeoDatis & OSGI

Here is a simple example on how to use NeoDatis ODB on OSGi:

  • For this example we used Equinox as OSGi container, but it is up to you.

An example using ODB as an OSGi service. Basically we created 3 projects:

  1. ODB wrapper as a OSGi bundle
    • Extracted Jar
    • P.S: We are trying to keep it up to date, using the latest ODB release. So, you can just use this our example bundle, or if you prefer, create a new one wrapping the ODB jar file. It is up to you.
  2. An OSGi service for ODB (a simple and basic service)
  3. A plug-in just for tests.

Different approaches can be applied for OSGi services. For this basic example we just created a service that exposes some methods like open, store and retrieve. But as we said, it was just a simple example to use ODB as a OSGi service, and of course you can create more things on top of that, or just use ODB in a different way through OSGi. In the future we'd like to implement a complete OSGi service for ODB, especially taking advantage of RFC119(Distributed Services for OSGi), but right now it is not possible yet(time constraints).

Anyway, take a look at the code and we hope that it can help you. There is just a "trick" there, because ODB needs to deal with the "current" classloader, so on the service we get the current classloader for the class and put it on ODB. The idea was use the context class loader for OSGi services, a context class loader is associated with a Thread. This class loader is provided by the thread creator to code running in the thread for the purpose loading classes and resources, then with it ODB can deal correctly with the file.

As you can see on the example bundles, basically what we did:

org.neodatis.odb.Configuration.setClassLoader(this.getClass().getClassLoader());

The code is available here

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License