added svcapi ui and camunda code
[it/otf.git] / otf-camunda / src / main / java / org / oran / otf / camunda / configuration / OTFDataSourceConfiguration.java
1 /*  Copyright (c) 2019 AT&T Intellectual Property.                             #\r
2 #                                                                              #\r
3 #   Licensed under the Apache License, Version 2.0 (the "License");            #\r
4 #   you may not use this file except in compliance with the License.           #\r
5 #   You may obtain a copy of the License at                                    #\r
6 #                                                                              #\r
7 #       http://www.apache.org/licenses/LICENSE-2.0                             #\r
8 #                                                                              #\r
9 #   Unless required by applicable law or agreed to in writing, software        #\r
10 #   distributed under the License is distributed on an "AS IS" BASIS,          #\r
11 #   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   #\r
12 #   See the License for the specific language governing permissions and        #\r
13 #   limitations under the License.                                             #\r
14 ##############################################################################*/\r
15 \r
16 \r
17 package org.oran.otf.camunda.configuration;\r
18 \r
19 import javax.sql.DataSource;\r
20 \r
21 import com.zaxxer.hikari.HikariDataSource;\r
22 import org.springframework.beans.factory.annotation.Value;\r
23 import org.springframework.boot.jdbc.DataSourceBuilder;\r
24 import org.springframework.context.annotation.Bean;\r
25 import org.springframework.context.annotation.Configuration;\r
26 import org.springframework.context.annotation.Primary;\r
27 import org.springframework.jdbc.datasource.DataSourceTransactionManager;\r
28 import org.springframework.transaction.PlatformTransactionManager;\r
29 \r
30 @Configuration\r
31 public class OTFDataSourceConfiguration {\r
32   @Value("${otf.camunda.mysql.url}")\r
33   private String url;\r
34 \r
35   @Value("${otf.camunda.mysql.username}")\r
36   private String username;\r
37 \r
38   @Value("${otf.camunda.mysql.password}")\r
39   private String password;\r
40 \r
41   @Bean\r
42   @Primary\r
43   public DataSource dataSource() {\r
44     DataSource dataSource = DataSourceBuilder.create()\r
45             .url(url)\r
46             .username(username)\r
47             .password(password)\r
48             .driverClassName("com.mysql.cj.jdbc.Driver")\r
49             .build();\r
50     if (dataSource instanceof HikariDataSource){\r
51 //      ((HikariDataSource) dataSource).setLeakDetectionThreshold(10000);\r
52 \r
53       ((HikariDataSource) dataSource).setMaximumPoolSize(75);\r
54       ((HikariDataSource) dataSource).setMinimumIdle(15);\r
55     }\r
56     return dataSource;\r
57   }\r
58 \r
59   @Bean\r
60   public PlatformTransactionManager transactionManager() {\r
61     return new DataSourceTransactionManager(dataSource());\r
62   }\r
63 }\r