Search in sources :

Example 21 with LocalContainerEntityManagerFactoryBean

use of org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean in project cloudbreak by hortonworks.

the class DatabaseConfig method entityManagerFactory.

@Bean
@DependsOn("databaseUpMigration")
public LocalContainerEntityManagerFactoryBean entityManagerFactory() throws SQLException {
    LocalContainerEntityManagerFactoryBean entityManagerFactory = new LocalContainerEntityManagerFactoryBean();
    entityManagerFactory.setPackagesToScan("com.sequenceiq.cloudbreak.domain");
    entityManagerFactory.setDataSource(dataSource());
    entityManagerFactory.setJpaVendorAdapter(jpaVendorAdapter());
    entityManagerFactory.setJpaProperties(jpaProperties());
    entityManagerFactory.afterPropertiesSet();
    return entityManagerFactory;
}
Also used : LocalContainerEntityManagerFactoryBean(org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean) DependsOn(org.springframework.context.annotation.DependsOn) Bean(org.springframework.context.annotation.Bean) LocalContainerEntityManagerFactoryBean(org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean)

Example 22 with LocalContainerEntityManagerFactoryBean

use of org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean in project spring-security by spring-projects.

the class ApplicationConfig method entityManagerFactory.

@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
    HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
    vendorAdapter.setDatabase(Database.HSQL);
    vendorAdapter.setGenerateDdl(true);
    vendorAdapter.setShowSql(true);
    LocalContainerEntityManagerFactoryBean factory = new LocalContainerEntityManagerFactoryBean();
    factory.setJpaVendorAdapter(vendorAdapter);
    factory.setPackagesToScan(User.class.getPackage().getName());
    factory.setDataSource(dataSource());
    return factory;
}
Also used : HibernateJpaVendorAdapter(org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter) LocalContainerEntityManagerFactoryBean(org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean) Bean(org.springframework.context.annotation.Bean) LocalContainerEntityManagerFactoryBean(org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean)

Example 23 with LocalContainerEntityManagerFactoryBean

use of org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean in project Asqatasun by Asqatasun.

the class PersistenceCommonConfig method entityManagerFactory.

/**
 * @param dataSource
 * @param url
 * @param packagesToScan
 * @return
 */
public LocalContainerEntityManagerFactoryBean entityManagerFactory(DataSource dataSource, String url, String... packagesToScan) {
    LocalContainerEntityManagerFactoryBean emf = new LocalContainerEntityManagerFactoryBean();
    emf.setDataSource(dataSource);
    emf.setPackagesToScan(packagesToScan);
    HibernateJpaVendorAdapter hibernateAdapter = new HibernateJpaVendorAdapter();
    hibernateAdapter.setShowSql(hibernateShowSql);
    final Properties jpaProperties = new Properties();
    jpaProperties.put(HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE, hibernateUse2ndLevelQueryCache);
    jpaProperties.put(HIBERNATE_CACHE_USE_QUERY_CACHE, hibernateUseQueryCache);
    jpaProperties.put(HIBERNATE_CACHE_REGION_FACTORY_CLASS, hibernateRegionFactory);
    jpaProperties.put(HIBERNATE_GENERATE_STATISTICS, false);
    jpaProperties.put(HIBERNATE_JDBC_BATCH_SIZE, hibernateJdbcBatchSize);
    jpaProperties.put(HIBERNATE_MAX_FETCH_DEPTH, hibernateMaxFetchDepth);
    jpaProperties.put(HIBERNATE_USE_OUTER_JOIN, hibernateUseOuterJoin);
    jpaProperties.put(HIBERNATE_DEFAULT_BATCH_FETCH_SIZE, hibernateDefaultBatchFetchSize);
    jpaProperties.put(HIBERNATE_DIALECT, getHibernateDialedFromUrl(url));
    if (PersistenceCommonConfig.isHsqlDb(url)) {
        jpaProperties.put("javax.persistence.schema-generation.database.action", "drop-and-create");
    }
    emf.setJpaProperties(jpaProperties);
    emf.setJpaVendorAdapter(hibernateAdapter);
    return emf;
}
Also used : HibernateJpaVendorAdapter(org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter) Properties(java.util.Properties) LocalContainerEntityManagerFactoryBean(org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean)

Example 24 with LocalContainerEntityManagerFactoryBean

use of org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean in project spring-boot by spring-projects.

the class AbstractJpaAutoConfigurationTests method usesManuallyDefinedLocalContainerEntityManagerFactoryBeanIfAvailable.

@Test
void usesManuallyDefinedLocalContainerEntityManagerFactoryBeanIfAvailable() {
    this.contextRunner.withUserConfiguration(TestConfigurationWithLocalContainerEntityManagerFactoryBean.class).run((context) -> {
        LocalContainerEntityManagerFactoryBean factoryBean = context.getBean(LocalContainerEntityManagerFactoryBean.class);
        Map<String, Object> map = factoryBean.getJpaPropertyMap();
        assertThat(map.get("configured")).isEqualTo("manually");
    });
}
Also used : LocalContainerEntityManagerFactoryBean(org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean) Test(org.junit.jupiter.api.Test)

Example 25 with LocalContainerEntityManagerFactoryBean

use of org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean in project kylo by Teradata.

the class OperationalMetadataConfig method entityManagerFactory.

/**
 * Return the entity manager factory for Hibernate
 *
 * @return the Hibernate entity manager factory
 */
@Bean(name = "operationalMetadataEntityManagerFactory")
public EntityManagerFactory entityManagerFactory(@Qualifier("dataSource") DataSource dataSource) {
    LocalContainerEntityManagerFactoryBean emfBean = new LocalContainerEntityManagerFactoryBean();
    emfBean.setDataSource(dataSource);
    emfBean.setPackagesToScan("com.thinkbiganalytics.jobrepo.jpa", "com.thinkbiganalytics.metadata.jpa");
    emfBean.setJpaVendorAdapter(jpaVendorAdapter());
    emfBean.afterPropertiesSet();
    return emfBean.getObject();
}
Also used : LocalContainerEntityManagerFactoryBean(org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean) AugmentableQueryRepositoryFactoryBean(com.thinkbiganalytics.metadata.jpa.feed.AugmentableQueryRepositoryFactoryBean) Bean(org.springframework.context.annotation.Bean) LocalContainerEntityManagerFactoryBean(org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean)

Aggregations

LocalContainerEntityManagerFactoryBean (org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean)75 Bean (org.springframework.context.annotation.Bean)63 HibernateJpaVendorAdapter (org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter)42 Properties (java.util.Properties)14 JpaVendorAdapter (org.springframework.orm.jpa.JpaVendorAdapter)7 HashMap (java.util.HashMap)4 JpaConfigDataHolder (org.apereo.cas.configuration.model.support.jpa.JpaConfigDataHolder)4 Test (org.junit.jupiter.api.Test)4 DependsOn (org.springframework.context.annotation.DependsOn)4 Lazy (org.springframework.context.annotation.Lazy)4 AbstractJpaProperties (org.apereo.cas.configuration.model.support.jpa.AbstractJpaProperties)2 DatabaseProperties (org.apereo.cas.configuration.model.support.jpa.DatabaseProperties)2 Autowired (org.springframework.beans.factory.annotation.Autowired)2 Primary (org.springframework.context.annotation.Primary)2 DefaultPersistenceUnitManager (org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager)2 DatabaseManager (com.fredboat.backend.quarterdeck.db.DatabaseManager)1 AugmentableQueryRepositoryFactoryBean (com.thinkbiganalytics.metadata.jpa.feed.AugmentableQueryRepositoryFactoryBean)1 DataSourceBean (de.alpharogroup.springconfig.DataSourceBean)1 JdbcUrlBean (de.alpharogroup.springconfig.JdbcUrlBean)1 PersistenceUnitInfo (jakarta.persistence.spi.PersistenceUnitInfo)1