Class CompassEventListener

  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:


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


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.

See Also:
Serialized Form

Field Summary
Constructor Summary
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


public static final String COMPASS_CONFIG_LOCATION
See Also:
Constant Field Values


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


public CompassEventListener()
Method Detail


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


public Compass getCompass()


public Properties getIndexSettings()


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


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


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


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


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


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

Copyright (c) 2004-2008 The Compass Project.