Search in sources :

Example 16 with HibernateJpaVendorAdapter

use of org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter in project main by JohnPeng739.

the class DalHibernateConfig method entityManagerFactoryBean.

/**
 * 创建实体管理器工厂Bean
 *
 * @return 实体管理器工厂Bean
 */
@Bean
@DependsOn({ "dataSource" })
public LocalContainerEntityManagerFactoryBean entityManagerFactoryBean() {
    String database = env.getProperty("jpa.database", String.class, "H2");
    String databasePlatform = env.getProperty("jpa.databasePlatform", String.class, "org.hibernate.dialect.H2Dialect");
    boolean generateDDL = env.getProperty("jpa.generateDDL", Boolean.class, true);
    boolean showSQL = env.getProperty("jpa.showSQL", Boolean.class, true);
    HibernateJpaVendorAdapter adapter = new HibernateJpaVendorAdapter();
    adapter.setDatabase(Database.valueOf(database));
    adapter.setDatabasePlatform(databasePlatform);
    adapter.setGenerateDdl(generateDDL);
    adapter.setShowSql(showSQL);
    adapter.setPrepareConnection(true);
    String[] jpaDefines = context.getBeanNamesForType(JpaEntityPackagesDefine.class);
    Set<String> jpaEntityPackages = new HashSet<>();
    for (String jpaDefine : jpaDefines) {
        JpaEntityPackagesDefine define = context.getBean(jpaDefine, JpaEntityPackagesDefine.class);
        jpaEntityPackages.addAll(define.getPackages());
    }
    LocalContainerEntityManagerFactoryBean emf = new LocalContainerEntityManagerFactoryBean();
    emf.setDataSource(context.getBean("dataSource", DataSource.class));
    emf.setPackagesToScan(jpaEntityPackages.toArray(new String[0]));
    emf.setJpaVendorAdapter(adapter);
    return emf;
}
Also used : HibernateJpaVendorAdapter(org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter) LocalContainerEntityManagerFactoryBean(org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean) HashSet(java.util.HashSet) DataSource(javax.sql.DataSource) LocalContainerEntityManagerFactoryBean(org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean)

Example 17 with HibernateJpaVendorAdapter

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

the class DatabaseConfig method jpaVendorAdapter.

@Bean
public JpaVendorAdapter jpaVendorAdapter() {
    HibernateJpaVendorAdapter hibernateJpaVendorAdapter = new HibernateJpaVendorAdapter();
    hibernateJpaVendorAdapter.setShowSql(true);
    hibernateJpaVendorAdapter.setDatabase(Database.POSTGRESQL);
    return hibernateJpaVendorAdapter;
}
Also used : HibernateJpaVendorAdapter(org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter) Bean(org.springframework.context.annotation.Bean) LocalContainerEntityManagerFactoryBean(org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean)

Example 18 with HibernateJpaVendorAdapter

use of org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter 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 19 with HibernateJpaVendorAdapter

use of org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter 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 20 with HibernateJpaVendorAdapter

use of org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter in project cas by apereo.

the class CasHibernateJpaBeanFactory method newJpaVendorAdapter.

@Override
public JpaVendorAdapter newJpaVendorAdapter(final DatabaseProperties databaseProperties) {
    val bean = new HibernateJpaVendorAdapter();
    bean.setGenerateDdl(databaseProperties.isGenDdl());
    bean.setShowSql(databaseProperties.isShowSql());
    return bean;
}
Also used : lombok.val(lombok.val) HibernateJpaVendorAdapter(org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter)

Aggregations

HibernateJpaVendorAdapter (org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter)55 LocalContainerEntityManagerFactoryBean (org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean)46 Bean (org.springframework.context.annotation.Bean)45 JpaVendorAdapter (org.springframework.orm.jpa.JpaVendorAdapter)6 Properties (java.util.Properties)5 Database (org.springframework.orm.jpa.vendor.Database)4 HashMap (java.util.HashMap)2 DatabaseManager (com.fredboat.backend.quarterdeck.db.DatabaseManager)1 DataSourceBean (de.alpharogroup.springconfig.DataSourceBean)1 JdbcUrlBean (de.alpharogroup.springconfig.JdbcUrlBean)1 Field (java.lang.reflect.Field)1 HashSet (java.util.HashSet)1 DataSource (javax.sql.DataSource)1 lombok.val (lombok.val)1 HSQLDialect (org.hibernate.dialect.HSQLDialect)1 Test (org.junit.Test)1 Test (org.junit.jupiter.api.Test)1 Autowired (org.springframework.beans.factory.annotation.Autowired)1 ConditionalOnMissingBean (org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean)1 Primary (org.springframework.context.annotation.Primary)1