The OJB Gps Device provides support for database indexing through the use of Apache OJB ORM mappings. If your application uses OJB, it couldn't be easier to integrate Compass into your application (Sometimes with no code attached - see the petclinic sample).
OJB Device uses Compass::Core OSEM feature (Object to Search Engine Mappings) and OJB ORM feature (Object to Relational Mappings) to provide simple database indexing. The device also utilizes OJB lifecycle events to provide real time mirroring of data changes done through OJB. The path data travels through the system is: Database -- OJB -- Objects -- Compass::Gps -- Compass::Core (Search Engine).
OJB device provides the ability to index the database. The objects that will be indexed (or their matching database tables in the OJB mappings) are ones that have both OJB mappings and Compass::Core mappings (OSEM).
Indexing the data (using the <code>index()</code> operation) requires the indexPersistentBroker property to be set, before the index() operation is called. You can use the OjbGpsDevice#attachPersistenceBrokerForIndex(CompassGpsDevice, PersistenceBroker) as a helper method.
Real-time mirroring of data changes requires using the OjbGpsDevice#attachLifecycleListeners(PersistenceBroker) to let the device listen for any data changes, and OjbGpsDevice#removeLifecycleListeners(PersistenceBroker) to remove the listener. Since the lifecycle listener can only be set on the instance level and not the factory level, attach and remove must be called every time a PersistentBroker is instantiated. You can use the OjbGpsDeviceUtils#attachPersistentBrokerForMirror(CompassGpsDevice, PersistenceBroker) and OjbGpsDeviceUtils#removePersistentBrokerForMirror(CompassGpsDevice, PersistenceBroker) as helper methods if attachment/removal is required for a generic device (i.e. OjbGpsDevice).
Since the real time mirroring and the event listener registration sounds like an aspect for Ojb aware classes/methods, Compass::Spring utilizes spring support for OJB and aspects for a much simpler event registration, please see Compass::Spring for more documentation.
Here is a code sample of how to configure the ojb device:
Compass compass = ... // set compass instance CompassGps gps = new SingleCompassGps(compass); CompassGpsDevice ojbDevice = new OjbGpsDevice(); ojbDevice.setName("ojb"); gps.addDevice(ojbDevice); .... // configure other devices gps.start(); .... // just before calling the index method PersistenceBroker pb = // create Persistence Broker OjbGpsDeviceUtils.attachPersistenceBrokerForIndex(ojbDevice, pb); gps.index(); .... // a Persistence Broker operation level PersistenceBroker pb = // create Persistence Broker OjbGpsDeviceUtils.attachPersistenceBrokerForMirror(ojbDevice, pb); .... // Persistence Broker operations OjbGpsDeviceUtils.removePersistenceBrokerForMirror(ojbDevice, pb);