Example usage for org.springframework.orm.jpa LocalContainerEntityManagerFactoryBean getObject

List of usage examples for org.springframework.orm.jpa LocalContainerEntityManagerFactoryBean getObject

Introduction

In this page you can find the example usage for org.springframework.orm.jpa LocalContainerEntityManagerFactoryBean getObject.

Prototype

@Override
@Nullable
public EntityManagerFactory getObject() 

Source Link

Document

Return the singleton EntityManagerFactory.

Usage

From source file:org.surfnet.oaaas.repository.AbstractTestRepository.java

@SuppressWarnings({ "rawtypes", "unchecked" })
private static EntityManager entityManager(DataSource dataSource) {
    LocalContainerEntityManagerFactoryBean emfBean = new LocalContainerEntityManagerFactoryBean();
    emfBean.setDataSource(dataSource);//from  w w  w.  j  a va  2 s  .co  m
    emfBean.setPersistenceUnitName(PERSISTENCE_UNIT_NAME);
    emfBean.setPersistenceProviderClass(PERSISTENCE_PROVIDER_CLASS);
    emfBean.afterPropertiesSet();
    Map map = new HashMap<String, String>();
    map.put("openjpa.ConnectionFactoryProperties", "PrintParameters=true");
    return emfBean.getObject().createEntityManager(map);
}

From source file:fredboat.db.DatabaseManager.java

/**
 * @param jdbcUrl connection to the database
 * @param dialect set to null or empty String to have it autodetected by Hibernate, chosen jdbc driver must support that
 *//* w ww  .j a v a2s . co m*/
public static void startup(String jdbcUrl, String dialect, int poolSize) {
    state = DatabaseState.INITIALIZING;

    try {

        if (Config.CONFIG.isUseSshTunnel()) {
            connectSSH();
        }

        //These are now located in the resources directory as XML
        Properties properties = new Properties();
        properties.put("configLocation", "hibernate.cfg.xml");

        properties.put("hibernate.connection.provider_class",
                "org.hibernate.hikaricp.internal.HikariCPConnectionProvider");
        properties.put("hibernate.connection.url", jdbcUrl);
        if (dialect != null && !"".equals(dialect))
            properties.put("hibernate.dialect", dialect);
        properties.put("hibernate.cache.region.factory_class",
                "org.hibernate.cache.ehcache.EhCacheRegionFactory");

        //properties.put("hibernate.show_sql", "true");

        //automatically update the tables we need
        //caution: only add new columns, don't remove or alter old ones, otherwise manual db table migration needed
        properties.put("hibernate.hbm2ddl.auto", "update");

        properties.put("hibernate.hikari.maximumPoolSize", Integer.toString(poolSize));
        properties.put("hibernate.hikari.idleTimeout", Integer.toString(Config.HIKARI_TIMEOUT_MILLISECONDS));

        LocalContainerEntityManagerFactoryBean emfb = new LocalContainerEntityManagerFactoryBean();
        emfb.setPackagesToScan("fredboat.db.entity");
        emfb.setJpaVendorAdapter(new HibernateJpaVendorAdapter());
        emfb.setJpaProperties(properties);
        emfb.setPersistenceUnitName("fredboat.test");
        emfb.setPersistenceProviderClass(HibernatePersistenceProvider.class);
        emfb.afterPropertiesSet();
        emf = emfb.getObject();

        log.info("Started Hibernate");
        state = DatabaseState.READY;
    } catch (Exception ex) {
        state = DatabaseState.FAILED;
        throw new RuntimeException("Failed starting database connection", ex);
    }
}

From source file:corner.orm.gae.GaeModule.java

public static EntityManagerFactory buildEntityManagerFactory(
        @Autobuild DatastorePersistenceProvider persistenceProvider) {
    LocalContainerEntityManagerFactoryBean entityManagerFactoryBean = new LocalContainerEntityManagerFactoryBean();
    entityManagerFactoryBean.setPersistenceProvider(persistenceProvider);
    Properties jpaProperties = new Properties();
    jpaProperties.put("datanucleus.NontransactionalRead", "true");
    jpaProperties.put("datanucleus.NontransactionalWrite", "true");
    jpaProperties.put("datanucleus.ConnectionURL", "appengine");
    jpaProperties.put("datanucleus.jpa.addClassTransformer", "false");
    entityManagerFactoryBean.setJpaProperties(jpaProperties);
    LoadTimeWeaver loadTimeWeaver = new SimpleLoadTimeWeaver();
    entityManagerFactoryBean.setLoadTimeWeaver(loadTimeWeaver);
    entityManagerFactoryBean.afterPropertiesSet();
    return entityManagerFactoryBean.getObject();
}

From source file:org.statefulj.demo.ddd.config.DBConfig.java

@Bean
public PlatformTransactionManager transactionManager(
        LocalContainerEntityManagerFactoryBean entityManagerFactory, List<TransactionObserver> observers) {
    EntityManagerFactory factory = entityManagerFactory.getObject();
    return new ObservableTransactionManager(factory, observers);
}

From source file:org.jbr.taskmgr.config.TaskManagerDatabaseConfig.java

@Bean
@Primary/*from w w w.j a  v a  2  s .co m*/
public PlatformTransactionManager transactionManager(
        final LocalContainerEntityManagerFactoryBean entityManagerFactory) {
    final JpaTransactionManager txManager = new JpaTransactionManager();
    txManager.setEntityManagerFactory(entityManagerFactory.getObject());
    return txManager;
}

From source file:io.gravitee.repository.jdbc.config.JdbcRepositoryConfiguration.java

@Bean
public AbstractPlatformTransactionManager graviteeTransactionManager(
        LocalContainerEntityManagerFactoryBean localContainerEntityManagerFactoryBean) {
    final JpaTransactionManager transactionManager = new JpaTransactionManager();
    transactionManager.setEntityManagerFactory(localContainerEntityManagerFactoryBean.getObject());
    return transactionManager;
}

From source file:org.ops4j.pax.exam.regression.web.spring.TestSpringConfig.java

@Bean
public EntityManagerFactory entityManagerFactory() {
    LocalContainerEntityManagerFactoryBean bean = new LocalContainerEntityManagerFactoryBean();
    bean.setDataSource(dataSource());//from   ww w. j  ava2  s  .  c  om
    bean.setPersistenceXmlLocation("classpath:META-INF/persistence.xml");
    bean.afterPropertiesSet();
    return bean.getObject();
}

From source file:com.gopivotal.cla.repository.RepositoryConfiguration.java

@Bean
EntityManagerFactory entityManagerFactory() {
    HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();

    LocalContainerEntityManagerFactoryBean factory = new LocalContainerEntityManagerFactoryBean();
    factory.setJpaVendorAdapter(vendorAdapter);
    factory.setDataSource(dataSource());
    factory.afterPropertiesSet();/*  w ww  .j  a  v a  2 s. co m*/

    return factory.getObject();
}

From source file:br.com.gumga.academia.aplicacao.Aplicacao.java

@Bean
public EntityManagerFactory entityManagerFactory() {

    HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
    vendorAdapter.setGenerateDdl(true);/*from w  w  w . j a v a2 s.  co m*/

    LocalContainerEntityManagerFactoryBean factory = new LocalContainerEntityManagerFactoryBean();
    factory.setJpaVendorAdapter(vendorAdapter);
    factory.setPackagesToScan("br.com.gumga.academia.entidades");
    factory.setDataSource(dataSource());
    factory.afterPropertiesSet();

    return factory.getObject();
}

From source file:br.com.gumga.academia.Aplicacao.java

@Bean
public EntityManagerFactory entityManagerFactory() {

    HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
    vendorAdapter.setGenerateDdl(true);/*from  w w  w. j  ava2s  .c  o  m*/

    LocalContainerEntityManagerFactoryBean factory = new LocalContainerEntityManagerFactoryBean();
    factory.setJpaVendorAdapter(vendorAdapter);
    factory.setPackagesToScan("br.com.gumga.academia.entidade");
    factory.setDataSource(dataSource());
    factory.afterPropertiesSet();

    return factory.getObject();
}