package javango.contrib.hibernate;
import javango.db.Manager;
import javango.db.Managers;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration;
import com.google.inject.assistedinject.FactoryProvider;
import com.google.inject.Binder;
import com.google.inject.Module;
import com.google.inject.ProvidedBy;
import com.google.inject.Provider;
import com.google.inject.TypeLiteral;
/**
* @author johns
*
*/
public class HibernateModule implements Module {
Log log = LogFactory.getLog(HibernateModule.class);
public void configure(Binder binder) {
AnnotationConfiguration configuration = new AnnotationConfiguration();
if (!configuration.getProperties().contains("hibernate.current_session_context_class")) {
log.info("Defaulting hibernate.current_session_context_class to managed");
configuration.setProperty("hibernate.current_session_context_class", "managed");
}
binder.bind(AnnotationConfiguration.class).toInstance(configuration);
SessionFactory sessionFactory = configuration.configure().buildSessionFactory();
binder.bind(SessionFactory.class).toInstance(sessionFactory);
// Guice/AssistedInject seems to need an explicit binding.
// this may be able to go away in fiture version of guice
binder.bind(HibernateUtil.class).to(HibernateUtilImpl.class);
binder.bind(Managers.class).to(HibernateManagersImpl.class);
}
}