use of org.apereo.cas.configuration.model.support.jpa.AbstractJpaProperties in project cas by apereo.
the class Beans method newHibernateEntityManagerFactoryBean.
/**
* New entity manager factory bean.
*
* @param config the config
* @param jpaProperties the jpa properties
* @return the local container entity manager factory bean
*/
public static LocalContainerEntityManagerFactoryBean newHibernateEntityManagerFactoryBean(final JpaConfigDataHolder config, final AbstractJpaProperties jpaProperties) {
final LocalContainerEntityManagerFactoryBean bean = new LocalContainerEntityManagerFactoryBean();
bean.setJpaVendorAdapter(config.getJpaVendorAdapter());
if (StringUtils.isNotBlank(config.getPersistenceUnitName())) {
bean.setPersistenceUnitName(config.getPersistenceUnitName());
}
bean.setPackagesToScan(config.getPackagesToScan());
bean.setDataSource(config.getDataSource());
final Properties properties = new Properties();
properties.put("hibernate.dialect", jpaProperties.getDialect());
properties.put("hibernate.hbm2ddl.auto", jpaProperties.getDdlAuto());
properties.put("hibernate.jdbc.batch_size", jpaProperties.getBatchSize());
if (StringUtils.isNotBlank(jpaProperties.getDefaultCatalog())) {
properties.put("hibernate.default_catalog", jpaProperties.getDefaultCatalog());
}
if (StringUtils.isNotBlank(jpaProperties.getDefaultSchema())) {
properties.put("hibernate.default_schema", jpaProperties.getDefaultSchema());
}
bean.setJpaProperties(properties);
return bean;
}
use of org.apereo.cas.configuration.model.support.jpa.AbstractJpaProperties in project cas by apereo.
the class JpaBeans method newHibernateEntityManagerFactoryBean.
/**
* New entity manager factory bean.
*
* @param config the config
* @param jpaProperties the jpa properties
* @return the local container entity manager factory bean
*/
public static LocalContainerEntityManagerFactoryBean newHibernateEntityManagerFactoryBean(final JpaConfigDataHolder config, final AbstractJpaProperties jpaProperties) {
final LocalContainerEntityManagerFactoryBean bean = new LocalContainerEntityManagerFactoryBean();
bean.setJpaVendorAdapter(config.getJpaVendorAdapter());
if (StringUtils.isNotBlank(config.getPersistenceUnitName())) {
bean.setPersistenceUnitName(config.getPersistenceUnitName());
}
bean.setPackagesToScan(config.getPackagesToScan().toArray(new String[] {}));
if (config.getDataSource() != null) {
bean.setDataSource(config.getDataSource());
}
final Properties properties = new Properties();
properties.put(Environment.DIALECT, jpaProperties.getDialect());
properties.put(Environment.HBM2DDL_AUTO, jpaProperties.getDdlAuto());
properties.put(Environment.STATEMENT_BATCH_SIZE, jpaProperties.getBatchSize());
if (StringUtils.isNotBlank(jpaProperties.getDefaultCatalog())) {
properties.put(Environment.DEFAULT_CATALOG, jpaProperties.getDefaultCatalog());
}
if (StringUtils.isNotBlank(jpaProperties.getDefaultSchema())) {
properties.put(Environment.DEFAULT_SCHEMA, jpaProperties.getDefaultSchema());
}
properties.put(Environment.ENABLE_LAZY_LOAD_NO_TRANS, Boolean.TRUE);
properties.put(Environment.FORMAT_SQL, Boolean.TRUE);
properties.putAll(jpaProperties.getProperties());
bean.setJpaProperties(properties);
return bean;
}
use of org.apereo.cas.configuration.model.support.jpa.AbstractJpaProperties in project cas by apereo.
the class CasHibernateJpaBeanFactory method newEntityManagerFactoryBean.
@Override
public FactoryBean<EntityManagerFactory> newEntityManagerFactoryBean(final JpaConfigurationContext config, final AbstractJpaProperties jpaProperties) {
val properties = new Properties();
properties.put(Environment.DIALECT, jpaProperties.getDialect());
properties.put(Environment.HBM2DDL_AUTO, jpaProperties.getDdlAuto());
properties.put(Environment.STATEMENT_BATCH_SIZE, jpaProperties.getBatchSize());
properties.put(Environment.GENERATE_STATISTICS, jpaProperties.isGenerateStatistics());
if (StringUtils.isNotBlank(jpaProperties.getDefaultCatalog())) {
properties.put(Environment.DEFAULT_CATALOG, jpaProperties.getDefaultCatalog());
}
if (StringUtils.isNotBlank(jpaProperties.getDefaultSchema())) {
properties.put(Environment.DEFAULT_SCHEMA, jpaProperties.getDefaultSchema());
}
properties.put(Environment.ENABLE_LAZY_LOAD_NO_TRANS, Boolean.TRUE);
properties.put(Environment.FORMAT_SQL, Boolean.TRUE);
properties.put("hibernate.connection.useUnicode", Boolean.TRUE);
properties.put("hibernate.connection.characterEncoding", StandardCharsets.UTF_8.name());
properties.put("hibernate.connection.charSet", StandardCharsets.UTF_8.name());
properties.put(Environment.AUTOCOMMIT, jpaProperties.isAutocommit());
properties.put("hibernate.jdbc.time_zone", "UTC");
properties.put("hibernate.jdbc.fetch_size", jpaProperties.getFetchSize());
FunctionUtils.doIfNotNull(jpaProperties.getPhysicalNamingStrategyClassName(), s -> {
val clazz = ClassUtils.getClass(JpaBeans.class.getClassLoader(), jpaProperties.getPhysicalNamingStrategyClassName());
val namingStrategy = PhysicalNamingStrategy.class.cast(clazz.getDeclaredConstructor().newInstance());
if (namingStrategy instanceof ApplicationContextAware) {
((ApplicationContextAware) namingStrategy).setApplicationContext(applicationContext);
}
properties.put(Environment.PHYSICAL_NAMING_STRATEGY, namingStrategy);
});
properties.putAll(jpaProperties.getProperties());
val bean = JpaBeans.newEntityManagerFactoryBean(config);
bean.setJpaProperties(properties);
bean.afterPropertiesSet();
return bean;
}
Aggregations