logger.info("Configuring persistence extension.");
}
public void configure(Map<Class, Provider> bindings, Map<String, Provider> resourceProviders) {
final AnnotationConfiguration cfg = new AnnotationConfiguration();
if (!config.hasProperty("errai.prototyping.persistence.connection.driver_class")) {
return;
}
cfg.setProperty("hibernate.connection.driver_class", config.getProperty("errai.prototyping.persistence.connection.driver_class"));
cfg.setProperty("hibernate.connection.url", config.getProperty("errai.prototyping.persistence.connection.url"));
cfg.setProperty("hibernate.connection.username", config.getProperty("errai.prototyping.persistence.connection.username"));
cfg.setProperty("hibernate.connection.password", config.getProperty("errai.prototyping.persistence.connection.password"));
cfg.setProperty("hibernate.connection.pool_size", config.getProperty("errai.prototyping.persistence.connection.pool_size"));
cfg.setProperty("hibernate.dialect", config.getProperty("errai.prototyping.persistence.dialect"));
cfg.setProperty("hibernate.current_session_context_class", "thread");
cfg.setProperty("hibernate.cache.use_second_level_cache", "false");
cfg.setProperty("hibernate.cache.provider_class", "org.hibernate.cache.NoCacheProvider");
cfg.setProperty("hibernate.show_sql", "true");
cfg.setProperty("hibernate.hbm2ddl.auto", "update");
List<File> roots = config.getConfigurationRoots();
logger.info("Begin scan for annotated classes.");
ConfigUtil.visitAllTargets(roots, new ConfigVisitor() {
public void visit(Class<?> clazz) {
if (clazz.isAnnotationPresent(Entity.class)) {
cfg.addAnnotatedClass(clazz);
}
}
});
final SessionFactory sessionFactory = cfg.buildSessionFactory();
Provider<Session> sessionProvider = new Provider<Session>() {
public Session get() {
return sessionFactory.openSession();
}