Search in sources :

Example 1 with AbstractJpaProperties

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;
}
Also used : PasswordEncoderProperties(org.apereo.cas.configuration.model.core.authentication.PasswordEncoderProperties) AbstractLdapAuthenticationProperties(org.apereo.cas.configuration.model.support.ldap.AbstractLdapAuthenticationProperties) PrincipalAttributesProperties(org.apereo.cas.configuration.model.core.authentication.PrincipalAttributesProperties) DatabaseProperties(org.apereo.cas.configuration.model.support.jpa.DatabaseProperties) Properties(java.util.Properties) ConnectionPoolingProperties(org.apereo.cas.configuration.model.support.ConnectionPoolingProperties) AbstractMongoInstanceProperties(org.apereo.cas.configuration.model.support.mongo.AbstractMongoInstanceProperties) CryptographyProperties(org.apereo.cas.configuration.model.core.util.CryptographyProperties) AbstractJpaProperties(org.apereo.cas.configuration.model.support.jpa.AbstractJpaProperties) AbstractLdapProperties(org.apereo.cas.configuration.model.support.ldap.AbstractLdapProperties) PrincipalTransformationProperties(org.apereo.cas.configuration.model.core.authentication.PrincipalTransformationProperties) LocalContainerEntityManagerFactoryBean(org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean)

Example 2 with AbstractJpaProperties

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;
}
Also used : Properties(java.util.Properties) AbstractJpaProperties(org.apereo.cas.configuration.model.support.jpa.AbstractJpaProperties) DatabaseProperties(org.apereo.cas.configuration.model.support.jpa.DatabaseProperties) LocalContainerEntityManagerFactoryBean(org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean)

Example 3 with AbstractJpaProperties

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;
}
Also used : lombok.val(lombok.val) JpaBeans(org.apereo.cas.configuration.support.JpaBeans) ApplicationContextAware(org.springframework.context.ApplicationContextAware) Properties(java.util.Properties) AbstractJpaProperties(org.apereo.cas.configuration.model.support.jpa.AbstractJpaProperties) DatabaseProperties(org.apereo.cas.configuration.model.support.jpa.DatabaseProperties)

Aggregations

Properties (java.util.Properties)3 AbstractJpaProperties (org.apereo.cas.configuration.model.support.jpa.AbstractJpaProperties)3 DatabaseProperties (org.apereo.cas.configuration.model.support.jpa.DatabaseProperties)3 LocalContainerEntityManagerFactoryBean (org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean)2 lombok.val (lombok.val)1 PasswordEncoderProperties (org.apereo.cas.configuration.model.core.authentication.PasswordEncoderProperties)1 PrincipalAttributesProperties (org.apereo.cas.configuration.model.core.authentication.PrincipalAttributesProperties)1 PrincipalTransformationProperties (org.apereo.cas.configuration.model.core.authentication.PrincipalTransformationProperties)1 CryptographyProperties (org.apereo.cas.configuration.model.core.util.CryptographyProperties)1 ConnectionPoolingProperties (org.apereo.cas.configuration.model.support.ConnectionPoolingProperties)1 AbstractLdapAuthenticationProperties (org.apereo.cas.configuration.model.support.ldap.AbstractLdapAuthenticationProperties)1 AbstractLdapProperties (org.apereo.cas.configuration.model.support.ldap.AbstractLdapProperties)1 AbstractMongoInstanceProperties (org.apereo.cas.configuration.model.support.mongo.AbstractMongoInstanceProperties)1 JpaBeans (org.apereo.cas.configuration.support.JpaBeans)1 ApplicationContextAware (org.springframework.context.ApplicationContextAware)1