Java Code Examples for org.springframework.jdbc.datasource.init.DataSourceInitializer#setEnabled()
The following examples show how to use
org.springframework.jdbc.datasource.init.DataSourceInitializer#setEnabled() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MasterDomain.java From syncope with Apache License 2.0 | 5 votes |
@Bean(name = "MasterDataSourceInitializer") @ConditionalOnMissingBean(name = "MasterDataSourceInitializer") public DataSourceInitializer masterDataSourceInitializer() { DataSourceInitializer dataSourceInitializer = new DataSourceInitializer(); dataSourceInitializer.setDataSource((DataSource) Objects.requireNonNull(masterDataSource().getObject())); dataSourceInitializer.setEnabled(true); dataSourceInitializer.setDatabasePopulator(masterResourceDatabasePopulator()); return dataSourceInitializer; }
Example 2
Source File: DomainConfFactory.java From syncope with Apache License 2.0 | 4 votes |
@Override public void register(final Domain domain) { HikariConfig hikariConfig = new HikariConfig(); hikariConfig.setDriverClassName(domain.getJdbcDriver()); hikariConfig.setJdbcUrl(domain.getJdbcURL()); hikariConfig.setUsername(domain.getDbUsername()); hikariConfig.setPassword(domain.getDbPassword()); hikariConfig.setSchema(domain.getDbSchema()); hikariConfig.setTransactionIsolation(domain.getTransactionIsolation().name()); hikariConfig.setMaximumPoolSize(domain.getPoolMaxActive()); hikariConfig.setMinimumIdle(domain.getPoolMinIdle()); // domainDataSource registerBeanDefinition( domain.getKey() + "DataSource", BeanDefinitionBuilder.rootBeanDefinition(JndiObjectFactoryBean.class). addPropertyValue("jndiName", "java:comp/env/jdbc/syncope" + domain.getKey() + "DataSource"). addPropertyValue("defaultObject", new HikariDataSource(hikariConfig)). getBeanDefinition()); DataSource initedDataSource = ApplicationContextProvider.getBeanFactory(). getBean(domain.getKey() + "DataSource", DataSource.class); // domainResourceDatabasePopulator ResourceDatabasePopulator databasePopulator = new ResourceDatabasePopulator(); databasePopulator.setContinueOnError(true); databasePopulator.setIgnoreFailedDrops(true); databasePopulator.setSqlScriptEncoding(StandardCharsets.UTF_8.name()); databasePopulator.addScript(new ClassPathResource("/audit/" + domain.getAuditSql())); registerSingleton(domain.getKey().toLowerCase() + "ResourceDatabasePopulator", databasePopulator); // domainDataSourceInitializer DataSourceInitializer dataSourceInitializer = new DataSourceInitializer(); dataSourceInitializer.setDataSource(initedDataSource); dataSourceInitializer.setEnabled(true); dataSourceInitializer.setDatabasePopulator(databasePopulator); registerSingleton(domain.getKey().toLowerCase() + "DataSourceInitializer", dataSourceInitializer); // domainEntityManagerFactory OpenJpaVendorAdapter vendorAdapter = new OpenJpaVendorAdapter(); vendorAdapter.setShowSql(false); vendorAdapter.setGenerateDdl(true); vendorAdapter.setDatabasePlatform(domain.getDatabasePlatform()); BeanDefinitionBuilder emf = BeanDefinitionBuilder.rootBeanDefinition(DomainEntityManagerFactoryBean.class). addPropertyValue("mappingResources", domain.getOrm()). addPropertyValue("persistenceUnitName", domain.getKey()). addPropertyReference("dataSource", domain.getKey() + "DataSource"). addPropertyValue("jpaVendorAdapter", vendorAdapter). addPropertyReference("commonEntityManagerFactoryConf", "commonEMFConf"); if (env.containsProperty("openjpaMetaDataFactory")) { emf.addPropertyValue("jpaPropertyMap", Map.of( "openjpa.MetaDataFactory", Objects.requireNonNull(env.getProperty("openjpaMetaDataFactory")). replace("##orm##", domain.getOrm()))); } registerBeanDefinition(domain.getKey() + "EntityManagerFactory", emf.getBeanDefinition()); ApplicationContextProvider.getBeanFactory().getBean(domain.getKey() + "EntityManagerFactory"); // domainTransactionManager AbstractBeanDefinition domainTransactionManager = BeanDefinitionBuilder.rootBeanDefinition(JpaTransactionManager.class). addPropertyReference("entityManagerFactory", domain.getKey() + "EntityManagerFactory"). getBeanDefinition(); domainTransactionManager.addQualifier(new AutowireCandidateQualifier(Qualifier.class, domain.getKey())); registerBeanDefinition(domain.getKey() + "TransactionManager", domainTransactionManager); // domainContentXML registerBeanDefinition(domain.getKey() + "ContentXML", BeanDefinitionBuilder.rootBeanDefinition(ByteArrayInputStream.class). addConstructorArgValue(domain.getContent().getBytes()). getBeanDefinition()); // domainKeymasterConfParamsJSON registerBeanDefinition(domain.getKey() + "KeymasterConfParamsJSON", BeanDefinitionBuilder.rootBeanDefinition(ByteArrayInputStream.class). addConstructorArgValue(domain.getKeymasterConfParams().getBytes()). getBeanDefinition()); }