2 * Copyright 2021 ZTE Corporation.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 package org.onap.holmes.common.database;
18 import org.jdbi.v3.core.Jdbi;
19 import org.jdbi.v3.core.mapper.RowMapper;
20 import org.jdbi.v3.core.spi.JdbiPlugin;
21 import org.jdbi.v3.postgres.PostgresPlugin;
22 import org.jdbi.v3.sqlobject.SqlObjectPlugin;
23 import org.springframework.context.annotation.Bean;
24 import org.springframework.context.annotation.Configuration;
25 import org.springframework.jdbc.datasource.TransactionAwareDataSourceProxy;
27 import javax.sql.DataSource;
28 import java.util.List;
31 public class DatabaseConfiguration {
33 // @Value("${spring.datasource.url}")
34 // private String url;
36 // @Value("${spring.datasource.username}")
37 // private String username;
39 // @Value("${spring.datasource.password}")
40 // private String pwd;
42 // @Value("${spring.datasource.dirver-class-name}")
43 // private String driverClass;
46 // public DataSource driverManagerDataSource() {
47 // System.out.println("======================================: " + driverClass);
48 // DriverManagerDataSource ds = new DriverManagerDataSource();
49 // ds.setDriverClassName(driverClass);
51 // ds.setUsername(username);
52 // ds.setPassword(pwd);
57 // public DataSourceTransactionManager dataSourceTransactionManager(DataSource dataSource) {
58 // DataSourceTransactionManager dataSourceTransactionManager = new DataSourceTransactionManager();
59 // dataSourceTransactionManager.setDataSource(dataSource);
60 // return dataSourceTransactionManager;
64 public Jdbi jdbi(DataSource dataSource) {
65 return Jdbi.create(dataSource)
66 .installPlugin(new SqlObjectPlugin())
67 .installPlugin(new PostgresPlugin());
71 // public Jdbi jdbi(DataSource ds, List<JdbiPlugin> jdbiPlugins, List<RowMapper<?>> rowMappers) {
72 // TransactionAwareDataSourceProxy proxy = new TransactionAwareDataSourceProxy(ds);
73 // Jdbi jdbi = Jdbi.create(proxy);
74 // jdbiPlugins.forEach(plugin -> jdbi.installPlugin(plugin));
75 // rowMappers.forEach(mapper -> jdbi.registerRowMapper(mapper));