Refactor dblib
[ccsdk/sli/core.git] / dblib / provider / src / main / java / org / onap / ccsdk / sli / core / dblib / config / BaseDBConfiguration.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * onap
4  * ================================================================================
5  * Copyright (C) 2016 - 2017 ONAP
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.ccsdk.sli.core.dblib.config;
22
23 import java.util.Properties;
24
25 public abstract class BaseDBConfiguration {
26         public static final String DATABASE_TYPE        = "org.onap.ccsdk.sli.dbtype";
27         public static final String DATABASE_URL         = "org.onap.ccsdk.sli.jdbc.url";
28         public static final String DATABASE_NAME        = "org.onap.ccsdk.sli.jdbc.database";
29         public static final String CONNECTION_NAME      = "org.onap.ccsdk.sli.jdbc.connection.name";
30         public static final String DATABASE_USER        = "org.onap.ccsdk.sli.jdbc.user";
31         public static final String DATABASE_PSSWD       = "org.onap.ccsdk.sli.jdbc.password";
32         public static final String CONNECTION_TIMEOUT="org.onap.ccsdk.sli.jdbc.connection.timeout";
33         public static final String REQUEST_TIMEOUT      = "org.onap.ccsdk.sli.jdbc.request.timeout";
34         public static final String MIN_LIMIT            = "org.onap.ccsdk.sli.jdbc.limit.min";
35         public static final String MAX_LIMIT            = "org.onap.ccsdk.sli.jdbc.limit.max";
36         public static final String INIT_LIMIT           = "org.onap.ccsdk.sli.jdbc.limit.init";
37         public static final String DATABASE_HOSTS   = "org.onap.ccsdk.sli.jdbc.hosts";
38
39
40         protected final Properties props;
41
42         public BaseDBConfiguration(Properties properties) {
43                 this.props = properties;
44         }
45
46         public int getConnTimeout() {
47                 try {
48                         String value = props.getProperty(CONNECTION_TIMEOUT);
49                         return Integer.parseInt(value);
50                 } catch(Exception exc) {
51                         return -1;
52                 }
53         }
54
55         public int getRequestTimeout() {
56                 try {
57                         String value = props.getProperty(REQUEST_TIMEOUT);
58                         if(value == null)
59                                 return -1;
60                         return Integer.parseInt(value);
61                 } catch(Exception exc) {
62                         return -1;
63                 }
64         }
65
66         public String getDbConnectionName() {
67                 return props.getProperty(CONNECTION_NAME);
68         }
69
70         public String getDatabaseName() {
71                 return props.getProperty(DATABASE_NAME);
72         }
73
74         public String getDbUserId() {
75                 return props.getProperty(DATABASE_USER);
76         }
77
78         public String getDbPasswd() {
79                 return props.getProperty(DATABASE_PSSWD);
80         }
81
82         public int getDbMinLimit() {
83                 String value = props.getProperty(MIN_LIMIT);
84                 return Integer.parseInt(value);
85         }
86
87         public int getDbMaxLimit() {
88                 String value = props.getProperty(MAX_LIMIT);
89                 return Integer.parseInt(value);
90         }
91
92         public int getDbInitialLimit() {
93                 String value = props.getProperty(INIT_LIMIT);
94                 return Integer.parseInt(value);
95         }
96
97         public String getDbUrl() {
98                 return props.getProperty(DATABASE_URL);
99         }
100
101         public String getServerGroup() {
102                 return null;
103         }
104 }