Package org.hibernate.search.util

Source Code of org.hibernate.search.util.ContextHelper

//$Id: ContextHelper.java 20106 2010-08-04 06:31:38Z stliu $
package org.hibernate.search.util;

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

/**
* @author Emmanuel Bernard
* @deprecated Use {@link org.hibernate.search.FullTextSession#getSearchFactory()} instead.
*/
public abstract class ContextHelper {

  public static SearchFactoryImplementor getSearchFactory(Session session) {
    return getSearchFactoryBySFI( (SessionImplementor) session );
  }

 
  public static SearchFactoryImplementor getSearchFactoryBySFI(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(
        "Hibernate Search Event listeners not configured, please check the reference documentation and the " +
            "application's hibernate.cfg.xml" );
    return listener.getSearchFactoryImplementor();
  }
}
TOP

Related Classes of org.hibernate.search.util.ContextHelper

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.