A Java Persistence API Gps Device (EJB3 Persistence).
The jpa device provides support for using jpa to index a database. The path can
be viewed as: Database <-> EntityManager(JPA) <-> Objects <-> Compass::Gps
<-> Compass::Core (Search Engine). What it means is that for every object that has both
jpa and compass mappings, you will be able to index it's data, as well as real time mirroring of
data changes.
When creating the object, an EntityManagerFactory must be provided to the Device.
Indexing uses
JpaEntitiesLocator to locate all the entities that can be
indexed (i.e. entities that have both Compass and JPA mappings). Most of the time
the
org.compass.gps.device.jpa.entities.DefaultJpaEntitiesLocator is enough, but
special JPA implementation one can be provided. If none is provided, the device will use the
JpaEntitiesLocatorDetector to auto detect the correct locator (which defaults to the (
org.compass.gps.device.jpa.entities.DefaultJpaEntitiesLocator ).
The indexing process itself is done through an implementation of
org.compass.gps.device.jpa.indexer.JpaIndexEntitiesIndexer . There are several implemenations
for it including a default one that uses plain JPA APIs. Specific implementations (such as Hibernate
and OpenJPA) are used for better performance.
Mirroring can be done in two ways. The first one is using JPA official API, implemeting
an Entity Lifecycle listener and specifing it for each entity class via annotations. Compass
comes with helper base clases for it,
AbstractCompassJpaEntityListener and
AbstractDeviceJpaEntityListener . As far as integrating Compass with JPA for mirroring,
this is the less preferable way. The second option for mirroring is to use the
JpaEntityLifecycleInjector , which will use the internal JPA implementation to
inject global lifecycle event listerens (sadly, there is no option to do that with the
EntityManagerFactory API). If the
JpaGpsDevice.setInjectEntityLifecycleListener(boolean) is
set to true (defaults to false ), the device will try to use the injector to
inject global event listeners. If no
JpaEntityLifecycleInjector is defined, the device will
try to autodetect the injector based on the current support for specific JPA implementations using
the
JpaEntityLifecycleInjectorDetector . See its javadoc for a list of the current JPA
implementations supported.
Mirroring can be turned off using the
JpaGpsDevice.setMirrorDataChanges(boolean) to false .
It defaults to true.
The device allows for
NativeJpaExtractor to be set, for applications
that use a framework or by themself wrap the actual EntityManagerFactory implementation.
For advance usage, the device allows for
EntityManagerWrapper to be set,
allowing to control the creation of EntityManager s, and transactions.
The
DefaultEntityManagerWrapper should suffice for most cases.
The device extends the parallel device provinding supprot for parallel indexing.
author: kimchy |