diff options
Diffstat (limited to 'ms/blueprintsprocessor/modules/commons/db-lib')
3 files changed, 86 insertions, 28 deletions
diff --git a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/BluePrintDBLibConfiguration.kt b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/BluePrintDBLibConfiguration.kt index 0bdee9be5..276ece139 100644 --- a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/BluePrintDBLibConfiguration.kt +++ b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/BluePrintDBLibConfiguration.kt @@ -37,5 +37,19 @@ open class BluePrintDBLibConfiguration(private var bluePrintProperties: BluePrin class DBLibConstants { companion object { const val PREFIX_DB_PRIMARY: String = "blueprintsprocessor.db.primary" + + //list of database + const val MARIA_DB: String = "maria-db" + const val MYSQL_DB: String = "mysql-db" + const val ORACLE_DB: String = "oracle-db" + const val POSTGRES_DB: String = "postgres-db" + + //List of database drivers + const val DRIVER_MARIA_DB = "org.mariadb.jdbc.Driver" + const val DRIVER_MYSQL_DB = "com.mysql.jdbc.Driver" + const val DRIVER_ORACLE_DB = "oracle.jdbc.driver.OracleDriver" + const val DRIVER_POSTGRES_DB = "org.postgresql.Driver" + + } }
\ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/primary/DBLibGenericService.kt b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/primary/DBLibGenericService.kt new file mode 100644 index 000000000..af7ab0547 --- /dev/null +++ b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/primary/DBLibGenericService.kt @@ -0,0 +1,72 @@ +/* + * Copyright © 2017-2018 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.apps.blueprintsprocessor.db.primary + +import com.fasterxml.jackson.databind.JsonNode +import org.onap.ccsdk.apps.blueprintsprocessor.db.AbstractDBLibGenericService +import org.onap.ccsdk.apps.blueprintsprocessor.db.DBLibConstants +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintProcessorException +import org.springframework.boot.jdbc.DataSourceBuilder +import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate +import org.springframework.stereotype.Service + +@Service +open class DBLibGenericService(primaryNamedParameterJdbcTemplate: NamedParameterJdbcTemplate) + : AbstractDBLibGenericService(primaryNamedParameterJdbcTemplate) { + + fun primaryJdbcTemplate():NamedParameterJdbcTemplate{ + return namedParameterJdbcTemplate() + } + + fun remoteJdbcTemplate(jsonNode: JsonNode): NamedParameterJdbcTemplate { + val type = jsonNode.get("type").textValue() + val driverDB: String + + return when (type) { + DBLibConstants.MARIA_DB -> { + driverDB = DBLibConstants.DRIVER_MARIA_DB + jdbcTemplate(jsonNode, driverDB) + } + DBLibConstants.MYSQL_DB -> { + driverDB = DBLibConstants.DRIVER_MYSQL_DB + jdbcTemplate(jsonNode, driverDB) + } + DBLibConstants.ORACLE_DB -> { + driverDB = DBLibConstants.DRIVER_ORACLE_DB + jdbcTemplate(jsonNode, driverDB) + } + DBLibConstants.POSTGRES_DB -> { + driverDB = DBLibConstants.DRIVER_POSTGRES_DB + jdbcTemplate(jsonNode, driverDB) + } + else -> { + throw BluePrintProcessorException("Rest adaptor($type) is not supported") + } + } + } + + fun jdbcTemplate(jsonNode: JsonNode, driver: String): NamedParameterJdbcTemplate { + val dataSourceBuilder = DataSourceBuilder + .create() + .username(jsonNode.get("username").textValue()) + .password(jsonNode.get("password").textValue()) + .url(jsonNode.get("url").textValue()) + .driverClassName(driver) + .build() + return NamedParameterJdbcTemplate(dataSourceBuilder) + } +}
\ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/primary/PrimaryDBLibGenericService.kt b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/primary/PrimaryDBLibGenericService.kt deleted file mode 100644 index 0e0f1e9c1..000000000 --- a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/primary/PrimaryDBLibGenericService.kt +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright © 2017-2018 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.apps.blueprintsprocessor.db.primary - -import org.onap.ccsdk.apps.blueprintsprocessor.db.AbstractDBLibGenericService -import org.onap.ccsdk.apps.blueprintsprocessor.db.BluePrintDBLibGenericService -import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate -import org.springframework.stereotype.Service - -@Service -open class PrimaryDBLibGenericService(private val primaryNamedParameterJdbcTemplate: NamedParameterJdbcTemplate) - : AbstractDBLibGenericService(primaryNamedParameterJdbcTemplate) { - -}
\ No newline at end of file |