org.compass.gps.device.hibernate
Class HibernateGpsDevice

java.lang.Object
  extended by org.compass.gps.device.AbstractGpsDevice
      extended by org.compass.gps.device.support.parallel.AbstractParallelGpsDevice
          extended by org.compass.gps.device.hibernate.HibernateGpsDevice
All Implemented Interfaces:
CompassGpsDevice, MirrorDataChangesGpsDevice, PassiveMirrorGpsDevice

public class HibernateGpsDevice
extends AbstractParallelGpsDevice
implements PassiveMirrorGpsDevice

A Hibernate Gps Device.

The hibernate device provides support for using jpa to index a database. The path can be viewed as: Database <-> Hibernate <-> Objects <-> Compass::Gps <-> Compass::Core (Search Engine). What it means is that for every object that has both Hibernate 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, a SessionFactory must be provided to the Device.

Indexing uses HibernateEntitiesLocator to locate all the entities that can be indexed (i.e. entities that have both Compass and Hibernate mappings). The default implementaion used it the DefaultHibernateEntitiesLocator.

The indexing process itself is done through an implementation of HibernateIndexEntitiesIndexer. It has two different implementation, the PaginationHibernateIndexEntitiesIndexer and the ScrollableHibernateIndexEntitiesIndexer. The default used is the scrollable indexer.

Mirroring is done by injecting lifecycle listeners into Hibernate. It is done using HibernateEntityLifecycleInjector with a default implementation of DefaultHibernateEntityLifecycleInjector when using Hibernate version < 3.2.6 and DefaultHibernateEntityCollectionLifecycleInjector when using Hibernate version >= 3.2.6.

Mirroring can be turned off using the setMirrorDataChanges(boolean) to false. It defaults to true.

The device allows for NativeHibernateExtractor to be set, for applications that use a framework or by themself wrap the actual SessionFactory implementation.

The device extends the parallel device provinding supprot for parallel indexing.

Author:
kimchy

Field Summary
 
Fields inherited from class org.compass.gps.device.AbstractGpsDevice
compassGps, log
 
Constructor Summary
HibernateGpsDevice()
           
HibernateGpsDevice(String name, SessionFactory sessionFactory)
           
 
Method Summary
protected  IndexEntity[] doGetIndexEntities()
          Returns all the indexed entities for this device.
protected  IndexEntitiesIndexer doGetIndexEntitiesIndexer()
          Returns an index entities indexer that knows how to index indexable entities.
protected  void doStart()
          Derived devices can implement it in case of start event notification.
protected  void doStop()
          Derived devices can implement it in case of stop event notification.
 int getFetchCount()
          Returns the fetch count for the indexing process.
 HibernateMirrorFilter getMirrorFilter()
          Returns mirroring filter that can filter hibernate mirror events.
 SessionFactory getSessionFactory()
          Returns a native Hibernate extractor to work with frameworks that wrap the actual SessionFactory.
 boolean isIgnoreMirrorExceptions()
          Should exceptions be ignored during the mirroring operations (the Hibernate event listeners).
 boolean isMirrorDataChanges()
          Should the device perform real time data mirroring.
 void setEntitiesIndexer(HibernateIndexEntitiesIndexer entitiesIndexer)
          Sets a custom entities indexer allowing to control the indexing process.
 void setEntitiesLocator(HibernateEntitiesLocator entitiesLocator)
          Sets a pluggable index entities locator allowing to control the indexes entties that will be used.
 void setFetchCount(int fetchCount)
          Sets the fetch count for the indexing process.
 void setIgnoreMirrorExceptions(boolean ignoreMirrorExceptions)
          Should exceptions be ignored during the mirroring operations (the Hibernate event listeners).
 void setIndexQueryProvider(Class entityClass, HibernateQueryProvider queryProvider)
          Sets a specific query provider for the index process of the given entity class.
 void setIndexQueryProvider(String entityName, HibernateQueryProvider queryProvider)
          Sets a specific query provider for the index process of the given entity name.
 void setIndexSelectQuery(Class entityClass, String selectQuery)
          Sets a specific select statement for the index process of the given entity class.
 void setIndexSelectQuery(String entityName, String selectQuery)
          Sets a specific select statement for the index process of the given entity name.
 void setLifecycleInjector(HibernateEntityLifecycleInjector lifecycleInjector)
          Sets a custom lifecycle injector controlling the injection of Hibernate lifecycle listeners for mirroring operations.
 void setMirrorDataChanges(boolean mirrorDataChanges)
          Sets if the device will perform real time data changes mirroring.
 void setMirrorFilter(HibernateMirrorFilter mirrorFilter)
          Sets a mirroring filter that can filter hibernate mirror events.
 void setNativeExtractor(NativeHibernateExtractor nativeExtractor)
          Sets a native Hibernate extractor to work with frameworks that wrap the actual SessionFactory.
 void setSessionFactory(SessionFactory sessionFactory)
          Sets the Hibernate SessionFactory to be used before the start operation.
 
Methods inherited from class org.compass.gps.device.support.parallel.AbstractParallelGpsDevice
doIndex, index, setIndexEntitiesPartitioner, setParallelIndexExecutor, start
 
Methods inherited from class org.compass.gps.device.AbstractGpsDevice
buildMessage, getGps, getName, injectGps, isFilteredForIndex, isPerformingIndexOperation, isRunning, setFilteredEntitiesForIndex, setName, shouldMirrorDataChanges, stop
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.compass.gps.CompassGpsDevice
getGps, getName, index, injectGps, isPerformingIndexOperation, isRunning, setName, shouldMirrorDataChanges, start, stop
 

Constructor Detail

HibernateGpsDevice

public HibernateGpsDevice()

HibernateGpsDevice

public HibernateGpsDevice(String name,
                          SessionFactory sessionFactory)
Method Detail

doStart

protected void doStart()
                throws CompassGpsException
Description copied from class: AbstractGpsDevice
Derived devices can implement it in case of start event notification.

Overrides:
doStart in class AbstractGpsDevice
Throws:
CompassGpsException

doStop

protected void doStop()
               throws CompassGpsException
Description copied from class: AbstractGpsDevice
Derived devices can implement it in case of stop event notification.

Overrides:
doStop in class AbstractGpsDevice
Throws:
CompassGpsException

doGetIndexEntities

protected IndexEntity[] doGetIndexEntities()
                                    throws CompassGpsException
Description copied from class: AbstractParallelGpsDevice
Returns all the indexed entities for this device.

Specified by:
doGetIndexEntities in class AbstractParallelGpsDevice
Throws:
CompassGpsException

doGetIndexEntitiesIndexer

protected IndexEntitiesIndexer doGetIndexEntitiesIndexer()
Description copied from class: AbstractParallelGpsDevice
Returns an index entities indexer that knows how to index indexable entities.

Specified by:
doGetIndexEntitiesIndexer in class AbstractParallelGpsDevice

setSessionFactory

public void setSessionFactory(SessionFactory sessionFactory)
Sets the Hibernate SessionFactory to be used before the start operation.


setFetchCount

public void setFetchCount(int fetchCount)
Sets the fetch count for the indexing process. A large number will perform the indexing faster, but will consume more memory. Defaults to 200.


getFetchCount

public int getFetchCount()
Returns the fetch count for the indexing process. A large number will perform the indexing faster, but will consume more memory. Default to 200.


isMirrorDataChanges

public boolean isMirrorDataChanges()
Description copied from interface: MirrorDataChangesGpsDevice
Should the device perform real time data mirroring.

Specified by:
isMirrorDataChanges in interface MirrorDataChangesGpsDevice
Returns:
true if the device mirror data changes
See Also:
MirrorDataChangesGpsDevice.isMirrorDataChanges()

isIgnoreMirrorExceptions

public boolean isIgnoreMirrorExceptions()
Should exceptions be ignored during the mirroring operations (the Hibernate event listeners). Defaults to false.


setIgnoreMirrorExceptions

public void setIgnoreMirrorExceptions(boolean ignoreMirrorExceptions)
Should exceptions be ignored during the mirroring operations (the Hibernate event listeners). Defaults to false.


setMirrorDataChanges

public void setMirrorDataChanges(boolean mirrorDataChanges)
Description copied from interface: MirrorDataChangesGpsDevice
Sets if the device will perform real time data changes mirroring.

Specified by:
setMirrorDataChanges in interface MirrorDataChangesGpsDevice
Parameters:
mirrorDataChanges - Should the device mirror data changes
See Also:
MirrorDataChangesGpsDevice.setMirrorDataChanges(boolean)

setEntitiesLocator

public void setEntitiesLocator(HibernateEntitiesLocator entitiesLocator)
Sets a pluggable index entities locator allowing to control the indexes entties that will be used. Defaults to DefaultHibernateEntitiesLocator.


getMirrorFilter

public HibernateMirrorFilter getMirrorFilter()
Returns mirroring filter that can filter hibernate mirror events. If no mirror filter is set no filtering will happen.


setMirrorFilter

public void setMirrorFilter(HibernateMirrorFilter mirrorFilter)
Sets a mirroring filter that can filter hibernate mirror events. If no mirror filter is set no filtering will happen.

Parameters:
mirrorFilter - The mirror filter handler

setNativeExtractor

public void setNativeExtractor(NativeHibernateExtractor nativeExtractor)
Sets a native Hibernate extractor to work with frameworks that wrap the actual SessionFactory.


setEntitiesIndexer

public void setEntitiesIndexer(HibernateIndexEntitiesIndexer entitiesIndexer)
Sets a custom entities indexer allowing to control the indexing process. Defaults to PaginationHibernateIndexEntitiesIndexer.


setLifecycleInjector

public void setLifecycleInjector(HibernateEntityLifecycleInjector lifecycleInjector)
Sets a custom lifecycle injector controlling the injection of Hibernate lifecycle listeners for mirroring operations. Defaults to DefaultHibernateEntityLifecycleInjector.


setIndexSelectQuery

public void setIndexSelectQuery(Class entityClass,
                                String selectQuery)

Sets a specific select statement for the index process of the given entity class.

Note, when using ScrollableHibernateIndexEntitiesIndexer it is preferable not to use this mehotd, instead use setIndexQueryProvider(Class, HibernateQueryProvider) and return a Hibernate Criteria object instead.

Note, this information is used when the device starts.

Parameters:
entityClass - The Entity class to associate the select query with
selectQuery - The select query to execute when indexing the given entity

setIndexSelectQuery

public void setIndexSelectQuery(String entityName,
                                String selectQuery)
Sets a specific select statement for the index process of the given entity name.

Note, when using ScrollableHibernateIndexEntitiesIndexer it is preferable not to use this mehotd, instead use setIndexQueryProvider(String, HibernateQueryProvider) and return a Hibernate Criteria object instead.

Note, this information is used when the device starts.

Parameters:
entityName - The entity name to associate the select query with
selectQuery - The select query to execute when indexing the given entity

setIndexQueryProvider

public void setIndexQueryProvider(Class entityClass,
                                  HibernateQueryProvider queryProvider)
Sets a specific query provider for the index process of the given entity class.

Note, this information is used when the device starts.

Parameters:
entityClass - The Entity class to associate the query provider with
queryProvider - The query provider to execute when indexing the given entity

setIndexQueryProvider

public void setIndexQueryProvider(String entityName,
                                  HibernateQueryProvider queryProvider)
Sets a specific query provider for the index process of the given entity name.

Note, this information is used when the device starts.

Parameters:
entityName - The Entity name to associate the query provider with
queryProvider - The query provider to execute when indexing the given entity

getSessionFactory

public SessionFactory getSessionFactory()
Returns a native Hibernate extractor to work with frameworks that wrap the actual SessionFactory.



Copyright (c) 2004-2008 The Compass Project.