All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.hibernate.search.util.ContextHelper Maven / Gradle / Ivy

There is a newer version: 3.5.6-Final
Show newest version
//$Id: $
package org.hibernate.search.util;

import org.hibernate.HibernateException;
import org.hibernate.engine.SessionImplementor;
import org.hibernate.event.PostInsertEventListener;
import org.hibernate.search.event.FullTextIndexEventListener;

/**
 * @author Emmanuel Bernard
 */
public abstract class ContextHelper {

	public static FullTextIndexEventListener getLuceneEventListener(SessionImplementor session) {
		PostInsertEventListener[] listeners = session.getListeners().getPostInsertEventListeners();
		FullTextIndexEventListener listener = null;
		//FIXME this sucks since we mandante the event listener use
		for ( PostInsertEventListener candidate : listeners ) {
			if ( candidate instanceof FullTextIndexEventListener ) {
				listener = (FullTextIndexEventListener) candidate;
				break;
			}
		}
		if ( listener == null ) throw new HibernateException( "Lucene event listener not initialized" );
		return listener;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy