Revert "Renaming Files having BluePrint to have Blueprint"
[ccsdk/cds.git] / ms / blueprintsprocessor / modules / commons / db-lib / src / main / kotlin / org / onap / ccsdk / cds / blueprintsprocessor / db / BluePrintDBLibConfiguration.kt
1 /*
2  * Copyright © 2017-2018 AT&T Intellectual Property.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 package org.onap.ccsdk.cds.blueprintsprocessor.db
18
19 import org.onap.ccsdk.cds.blueprintsprocessor.core.BluePrintCoreConfiguration
20 import org.onap.ccsdk.cds.blueprintsprocessor.core.BluePrintPropertiesService
21 import org.onap.ccsdk.cds.blueprintsprocessor.core.BluePrintPropertyConfiguration
22 import org.onap.ccsdk.cds.blueprintsprocessor.db.primary.BluePrintDBLibPropertyService
23 import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintDependencyService
24 import org.springframework.boot.context.properties.EnableConfigurationProperties
25 import org.springframework.context.annotation.Bean
26 import org.springframework.context.annotation.Configuration
27 import org.springframework.context.annotation.Import
28 import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate
29 import javax.sql.DataSource
30
31 @Configuration
32 @Import(
33     BluePrintPropertyConfiguration::class,
34     BluePrintPropertiesService::class,
35     BluePrintCoreConfiguration::class
36 )
37 @EnableConfigurationProperties
38 open class BluePrintDBLibConfiguration(private var bluePrintPropertiesService: BluePrintPropertiesService) {
39
40     @Bean("primary-database-properties")
41     open fun getPrimaryProperties(): PrimaryDataSourceProperties {
42         return bluePrintPropertiesService.propertyBeanType(
43             DBLibConstants.PREFIX_DB,
44             PrimaryDataSourceProperties::class.java
45         )
46     }
47
48     @Bean("primaryNamedParameterJdbcTemplate")
49     open fun primaryNamedParameterJdbcTemplate(primaryDataSource: DataSource): NamedParameterJdbcTemplate {
50         return NamedParameterJdbcTemplate(primaryDataSource)
51     }
52 }
53
54 /**
55  * Exposed Dependency Service by this SSH Lib Module
56  */
57 fun BluePrintDependencyService.dbLibPropertyService(): BluePrintDBLibPropertyService =
58     instance(BluePrintDBLibPropertyService::class)
59
60 fun BluePrintDependencyService.primaryDBLibGenericService(): BluePrintDBLibGenericService =
61     instance(PrimaryDBLibGenericService::class)
62
63 class DBLibConstants {
64     companion object {
65
66         const val PREFIX_DB: String = "blueprintsprocessor.db"
67
68         // list of database
69         const val MARIA_DB: String = "maria-db"
70         const val PROCESSOR_DB: String = "processor-db"
71         const val MYSQL_DB: String = "mysql-db"
72         const val ORACLE_DB: String = "oracle-db"
73         const val POSTGRES_DB: String = "postgres-db"
74         const val MSSQL_DB: String = "mssql"
75
76         // List of database drivers
77         const val DRIVER_MARIA_DB = "org.mariadb.jdbc.Driver"
78         const val DRIVER_MYSQL_DB = "com.mysql.jdbc.Driver"
79         const val DRIVER_ORACLE_DB = "oracle.jdbc.driver.OracleDriver"
80         const val DRIVER_POSTGRES_DB = "org.postgresql.Driver"
81         const val DRIVER_MSSQL_DB = "com.microsoft.sqlserver.jdbc.SQLServerDriver"
82     }
83 }