Switched from Dropwizard to Springboot
[holmes/common.git] / holmes-actions / src / main / java / org / onap / holmes / common / database / DatabaseConfiguration.java
1 /**
2  * Copyright 2021 ZTE Corporation.
3  * <p>
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  * <p>
8  * http://www.apache.org/licenses/LICENSE-2.0
9  * <p>
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 package org.onap.holmes.common.database;
17
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;
26
27 import javax.sql.DataSource;
28 import java.util.List;
29
30 @Configuration
31 public class DatabaseConfiguration {
32 //
33 //    @Value("${spring.datasource.url}")
34 //    private String url;
35 //
36 //    @Value("${spring.datasource.username}")
37 //    private String username;
38 //
39 //    @Value("${spring.datasource.password}")
40 //    private String pwd;
41 //
42 //    @Value("${spring.datasource.dirver-class-name}")
43 //    private String driverClass;
44 //
45 //    @Bean
46 //    public DataSource driverManagerDataSource() {
47 //        System.out.println("======================================: " + driverClass);
48 //        DriverManagerDataSource ds = new DriverManagerDataSource();
49 //        ds.setDriverClassName(driverClass);
50 //        ds.setUrl(url);
51 //        ds.setUsername(username);
52 //        ds.setPassword(pwd);
53 //        return ds;
54 //    }
55
56 //    @Bean
57 //    public DataSourceTransactionManager dataSourceTransactionManager(DataSource dataSource) {
58 //        DataSourceTransactionManager dataSourceTransactionManager = new DataSourceTransactionManager();
59 //        dataSourceTransactionManager.setDataSource(dataSource);
60 //        return dataSourceTransactionManager;
61 //    }
62
63     @Bean
64     public Jdbi jdbi(DataSource dataSource) {
65         return Jdbi.create(dataSource)
66                 .installPlugin(new SqlObjectPlugin())
67                 .installPlugin(new PostgresPlugin());
68     }
69
70 //    @Bean
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));
76 //        return jdbi;
77 //    }
78 }