org.compass.gps.device.hibernate.embedded
Class CompassEventListener

java.lang.Object
  extended by org.compass.gps.device.hibernate.embedded.CompassEventListener
All Implemented Interfaces:
Serializable, Initializable, PostCollectionRecreateEventListener, PostCollectionRemoveEventListener, PostCollectionUpdateEventListener, PostDeleteEventListener, PostInsertEventListener, PostUpdateEventListener
Direct Known Subclasses:
FullTextIndexCollectionEventListener, FullTextIndexEventListener

public class CompassEventListener
extends Object
implements PostDeleteEventListener, PostInsertEventListener, PostUpdateEventListener, PostCollectionRecreateEventListener, PostCollectionRemoveEventListener, PostCollectionUpdateEventListener, Initializable

An Hibernate event listener allowing to run Compass embedded within Hibernate. The embedded mode will allow to automatically (with minimal configuration) get Compass configured to mirror changes done through Hibernate to the search engine, as well as simply indexing the whole database content.

Configuration of this listener is simple:

 <hibernate-configuration>
      <session-factory>

          <event type="post-update">
              <listener class="org.compass.gps.device.hibernate.embedded.CompassEventListener"/>
          </event>
          <event type="post-insert">
              <listener class="org.compass.gps.device.hibernate.embedded.CompassEventListener"/>
          </event>
          <event type="post-delete">
              <listener class="org.compass.gps.device.hibernate.embedded.CompassEventListener"/>
          </event>
          <event type="post-collection-recreate">
              <listener class="org.compass.gps.device.hibernate.embedded.CompassEventListener"/>
          </event>
          <event type="post-collection-remove">
              <listener class="org.compass.gps.device.hibernate.embedded.CompassEventListener"/>
          </event>
          <event type="post-collection-update">
              <listener class="org.compass.gps.device.hibernate.embedded.CompassEventListener"/>
          </event>

      </session-factory>
 </hibernate-configuration>
 

When using Hiberante annotations or entity manager Compass also contains Hibernate search event class so it will be automatically detected. In such a case, there is no need for the event listener configuration.

Once the above configuration is set, then Compass is "installed" within Hibernate. In order to enable Compass, the search engine connection url must be set using Hibernate properties configuration. For example: <property name="compass.engine.connection">testindex</property>.

Compass will automatically go over the mapped classes in Hibernate and will check if they have Compass mappings. If they do, they will be added to the searchable entities. If no such searchable classes are found, this listener will perform no operations.

Compass additional configuration can be set using typical Hiberante properties configuration using the compass. prefix. If using an external Compass configuration file is preferred, then the compass.hibernate.config can be configured and point to the location of a Compass configuration file.

Embedded Compass also allows to use CompassGps.index() in order to complely reindex the database. See HibernateHelper for more information. In order to configure the Compass instance that will be used to index the database, the gps.index. can be used.

Transaction management is automatically bounded to Hibernate by using Compass local transaction. If other transaction strategies are used (such as JTA Sync or XA) then the Compass transaction will be bounded to them and not the Hibernate transaction.

A user defined HibernateMirrorFilter can be used to filter out mirror operations. In order to configure one, the compass.hibernate.mirrorFilter can be used with the implementation class FQN.

In order to get the Compass instnace bounded to this Hibernate configuration, the HibernateHelper can be used. This is mainly used in order to perform search operations on the index and get a Compass Gps in order to reindex the database.

Author:
kimchy
See Also:
Serialized Form

Field Summary
static String COMPASS_CONFIG_LOCATION
           
static String COMPASS_GPS_INDEX_PREFIX
           
static String COMPASS_MIRROR_FILTER
           
static String COMPASS_PREFIX
           
static String COMPASS_PROCESS_COLLECTIONS
           
static org.apache.commons.logging.Log log
           
 
Constructor Summary
CompassEventListener()
           
 
Method Summary
 Compass getCompass()
           
 Properties getIndexSettings()
           
 void initialize(Configuration cfg)
           
 void onPostDelete(PostDeleteEvent event)
           
 void onPostInsert(PostInsertEvent event)
           
 void onPostRecreateCollection(PostCollectionRecreateEvent postCollectionRecreateEvent)
           
 void onPostRemoveCollection(PostCollectionRemoveEvent postCollectionRemoveEvent)
           
 void onPostUpdate(PostUpdateEvent event)
           
 void onPostUpdateCollection(PostCollectionUpdateEvent postCollectionUpdateEvent)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

public static final org.apache.commons.logging.Log log

COMPASS_PREFIX

public static final String COMPASS_PREFIX
See Also:
Constant Field Values

COMPASS_GPS_INDEX_PREFIX

public static final String COMPASS_GPS_INDEX_PREFIX
See Also:
Constant Field Values

COMPASS_CONFIG_LOCATION

public static final String COMPASS_CONFIG_LOCATION
See Also:
Constant Field Values

COMPASS_MIRROR_FILTER

public static final String COMPASS_MIRROR_FILTER
See Also:
Constant Field Values

COMPASS_PROCESS_COLLECTIONS

public static final String COMPASS_PROCESS_COLLECTIONS
See Also:
Constant Field Values
Constructor Detail

CompassEventListener

public CompassEventListener()
Method Detail

initialize

public void initialize(Configuration cfg)
Specified by:
initialize in interface Initializable

getCompass

public Compass getCompass()

getIndexSettings

public Properties getIndexSettings()

onPostDelete

public void onPostDelete(PostDeleteEvent event)
Specified by:
onPostDelete in interface PostDeleteEventListener

onPostInsert

public void onPostInsert(PostInsertEvent event)
Specified by:
onPostInsert in interface PostInsertEventListener

onPostUpdate

public void onPostUpdate(PostUpdateEvent event)
Specified by:
onPostUpdate in interface PostUpdateEventListener

onPostRecreateCollection

public void onPostRecreateCollection(PostCollectionRecreateEvent postCollectionRecreateEvent)
Specified by:
onPostRecreateCollection in interface PostCollectionRecreateEventListener

onPostRemoveCollection

public void onPostRemoveCollection(PostCollectionRemoveEvent postCollectionRemoveEvent)
Specified by:
onPostRemoveCollection in interface PostCollectionRemoveEventListener

onPostUpdateCollection

public void onPostUpdateCollection(PostCollectionUpdateEvent postCollectionUpdateEvent)
Specified by:
onPostUpdateCollection in interface PostCollectionUpdateEventListener


Copyright (c) 2004-2008 The Compass Project.