diff options
Diffstat (limited to 'ms/blueprintsprocessor/modules/commons/db-lib/src/main')
-rw-r--r-- | ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/BluePrintDBLibConfiguration.kt | 16 | ||||
-rw-r--r-- | ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/PrimaryDBLibGenericService.kt (renamed from ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/PrimaryDBLibGenericService.kt) | 5 | ||||
-rw-r--r-- | ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/MariaDatabaseConfiguration.kt | 4 | ||||
-rw-r--r-- | ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/PrimaryDatabaseConfiguration.kt | 38 |
4 files changed, 24 insertions, 39 deletions
diff --git a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/BluePrintDBLibConfiguration.kt b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/BluePrintDBLibConfiguration.kt index d990f397d..0d737f4ca 100644 --- a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/BluePrintDBLibConfiguration.kt +++ b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/BluePrintDBLibConfiguration.kt @@ -16,15 +16,24 @@ package org.onap.ccsdk.cds.blueprintsprocessor.db +import org.onap.ccsdk.cds.blueprintsprocessor.core.BluePrintCoreConfiguration import org.onap.ccsdk.cds.blueprintsprocessor.core.BluePrintPropertiesService +import org.onap.ccsdk.cds.blueprintsprocessor.core.BluePrintPropertyConfiguration import org.onap.ccsdk.cds.blueprintsprocessor.db.primary.BluePrintDBLibPropertyService -import org.onap.ccsdk.cds.blueprintsprocessor.db.primary.PrimaryDBLibGenericService import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintDependencyService import org.springframework.boot.context.properties.EnableConfigurationProperties import org.springframework.context.annotation.Bean import org.springframework.context.annotation.Configuration +import org.springframework.context.annotation.Import +import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate +import javax.sql.DataSource @Configuration +@Import( + BluePrintPropertyConfiguration::class, + BluePrintPropertiesService::class, + BluePrintCoreConfiguration::class +) @EnableConfigurationProperties open class BluePrintDBLibConfiguration(private var bluePrintPropertiesService: BluePrintPropertiesService) { @@ -35,6 +44,11 @@ open class BluePrintDBLibConfiguration(private var bluePrintPropertiesService: B PrimaryDataSourceProperties::class.java ) } + + @Bean("primaryNamedParameterJdbcTemplate") + open fun primaryNamedParameterJdbcTemplate(primaryDataSource: DataSource): NamedParameterJdbcTemplate { + return NamedParameterJdbcTemplate(primaryDataSource) + } } /** diff --git a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/PrimaryDBLibGenericService.kt b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/PrimaryDBLibGenericService.kt index 4363feb2b..006b7ca45 100644 --- a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/PrimaryDBLibGenericService.kt +++ b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/PrimaryDBLibGenericService.kt @@ -1,5 +1,5 @@ /* - * Copyright © 2017-2018 AT&T Intellectual Property. + * Copyright © 2018-2019 AT&T Intellectual Property. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,9 +14,8 @@ * limitations under the License. */ -package org.onap.ccsdk.cds.blueprintsprocessor.db.primary +package org.onap.ccsdk.cds.blueprintsprocessor.db -import org.onap.ccsdk.cds.blueprintsprocessor.db.AbstractDBLibGenericService import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate import org.springframework.stereotype.Service diff --git a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/MariaDatabaseConfiguration.kt b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/MariaDatabaseConfiguration.kt index 4faaa2eef..82895257a 100644 --- a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/MariaDatabaseConfiguration.kt +++ b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/MariaDatabaseConfiguration.kt @@ -25,6 +25,8 @@ import javax.sql.DataSource class MariaDatabaseConfiguration(private val mariaDataSourceProperties: MariaDataSourceProperties) : BluePrintDBLibGenericService { + val log = LoggerFactory.getLogger(MariaDatabaseConfiguration::class.java)!! + override fun namedParameterJdbcTemplate(): NamedParameterJdbcTemplate { return mariaNamedParameterJdbcTemplate(mariaDataSource()) } @@ -37,8 +39,6 @@ class MariaDatabaseConfiguration(private val mariaDataSourceProperties: MariaDat return mariaNamedParameterJdbcTemplate(mariaDataSource()).update(sql, params) } - val log = LoggerFactory.getLogger(PrimaryDatabaseConfiguration::class.java)!! - fun mariaDataSource(): DataSource { val dataSource = DriverManagerDataSource() dataSource.setDriverClassName(mariaDataSourceProperties.driverClassName) diff --git a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/PrimaryDatabaseConfiguration.kt b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/PrimaryDatabaseConfiguration.kt index 4223ed31c..0913a0a58 100644 --- a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/PrimaryDatabaseConfiguration.kt +++ b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/PrimaryDatabaseConfiguration.kt @@ -18,13 +18,6 @@ package org.onap.ccsdk.cds.blueprintsprocessor.db.primary import org.onap.ccsdk.cds.blueprintsprocessor.db.PrimaryDataSourceProperties import org.slf4j.LoggerFactory -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty -import org.springframework.context.annotation.Bean -import org.springframework.context.annotation.ComponentScan -import org.springframework.context.annotation.Configuration -import org.springframework.data.jpa.repository.config.EnableJpaAuditing -import org.springframework.data.jpa.repository.config.EnableJpaRepositories -import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate import org.springframework.jdbc.datasource.DriverManagerDataSource import org.springframework.orm.jpa.JpaTransactionManager import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean @@ -33,31 +26,15 @@ import org.springframework.transaction.PlatformTransactionManager import java.util.HashMap import javax.sql.DataSource -@Configuration -@ConditionalOnProperty( - name = ["blueprintsprocessor.db.primary.defaultConfig"], havingValue = "true", - matchIfMissing = true -) -@ComponentScan -@EnableJpaRepositories( - basePackages = ["org.onap.ccsdk.cds.blueprintsprocessor.*", - "org.onap.ccsdk.cds.controllerblueprints.*"], - entityManagerFactoryRef = "primaryEntityManager", - transactionManagerRef = "primaryTransactionManager" -) -@EnableJpaAuditing open class PrimaryDatabaseConfiguration(private val primaryDataSourceProperties: PrimaryDataSourceProperties) { private val log = LoggerFactory.getLogger(PrimaryDatabaseConfiguration::class.java)!! - @Bean("primaryEntityManager") - open fun primaryEntityManager(): LocalContainerEntityManagerFactoryBean { + /** Child class will override with spring bean annotation 'primaryEntityManager' and passing entity [packagesToScan]*/ + open fun primaryEntityManager(vararg packagesToScan: String): LocalContainerEntityManagerFactoryBean { val em = LocalContainerEntityManagerFactoryBean() em.dataSource = primaryDataSource() - em.setPackagesToScan( - "org.onap.ccsdk.cds.blueprintsprocessor.*", - "org.onap.ccsdk.cds.controllerblueprints.*" - ) + em.setPackagesToScan(*packagesToScan) em.jpaVendorAdapter = HibernateJpaVendorAdapter() val properties = HashMap<String, Any>() properties["hibernate.hbm2ddl.auto"] = primaryDataSourceProperties.hibernateHbm2ddlAuto @@ -66,7 +43,7 @@ open class PrimaryDatabaseConfiguration(private val primaryDataSourceProperties: return em } - @Bean("primaryDataSource") + /** Child class will override with spring bean annotation 'primaryDataSource' */ open fun primaryDataSource(): DataSource { val dataSource = DriverManagerDataSource() dataSource.setDriverClassName(primaryDataSourceProperties.driverClassName) @@ -76,16 +53,11 @@ open class PrimaryDatabaseConfiguration(private val primaryDataSourceProperties: return dataSource } - @Bean("primaryTransactionManager") + /** Child class will override with spring bean annotation 'primaryTransactionManager' */ open fun primaryTransactionManager(): PlatformTransactionManager { val transactionManager = JpaTransactionManager() transactionManager.entityManagerFactory = primaryEntityManager().getObject() log.info("Initialised Primary Transaction Manager for url ${primaryDataSourceProperties.url}") return transactionManager } - - @Bean("primaryNamedParameterJdbcTemplate") - open fun primaryNamedParameterJdbcTemplate(primaryDataSource: DataSource): NamedParameterJdbcTemplate { - return NamedParameterJdbcTemplate(primaryDataSource) - } } |