summaryrefslogtreecommitdiffstats
path: root/dblib/provider/src
diff options
context:
space:
mode:
authorRich Tabedzki <richard.tabedzki@att.com>2019-01-07 15:10:11 -0500
committerRich Tabedzki <richard.tabedzki@att.com>2019-01-07 15:31:41 -0500
commitc62fdd3be263bdb4543aba980780df642af67313 (patch)
tree977f90e2f4f8c5e94aa679574555a8e9ec1adb96 /dblib/provider/src
parent62734cb1e278b32b3ade040eb97491ffc0b04dcc (diff)
fixed sonar issue in JdbcCachedDataSource
Changes made: * updated cleanup code * added TerminatingConfiguration class Change-Id: Iee16116a5fc419065915b9f84488874dd192af7c Issue-ID: CCSDK-913 Signed-off-by: Rich Tabedzki <richard.tabedzki@att.com>
Diffstat (limited to 'dblib/provider/src')
-rwxr-xr-xdblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/CachedDataSource.java5
-rwxr-xr-xdblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/TerminatingCachedDataSource.java10
-rwxr-xr-xdblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/config/BaseDBConfiguration.java14
-rwxr-xr-xdblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/config/TerminatingConfiguration.java33
-rwxr-xr-xdblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/jdbc/JdbcDBCachedDataSource.java5
5 files changed, 60 insertions, 7 deletions
diff --git a/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/CachedDataSource.java b/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/CachedDataSource.java
index f3ecfa27..0f1674f9 100755
--- a/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/CachedDataSource.java
+++ b/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/CachedDataSource.java
@@ -94,6 +94,7 @@ public abstract class CachedDataSource implements DataSource, SQLExecutionMonito
}
protected abstract DataSource configure(BaseDBConfiguration jdbcElem) throws DBConfigException;
+ protected abstract int getAvailableConnections();
/*
* (non-Javadoc)
@@ -488,9 +489,9 @@ public abstract class CachedDataSource implements DataSource, SQLExecutionMonito
isSlave = true;
}
if (isSlave) {
- LOGGER.debug("SQL SLAVE : {} on server {}", connectionName, hostname);
+ LOGGER.debug("SQL SLAVE : {} on server {}, pool {}", connectionName, getDbConnectionName(), getAvailableConnections());
} else {
- LOGGER.debug("SQL MASTER : {} on server {}", connectionName, hostname);
+ LOGGER.debug("SQL MASTER : {} on server {}, pool {}", connectionName, getDbConnectionName(), getAvailableConnections());
}
return isSlave;
}
diff --git a/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/TerminatingCachedDataSource.java b/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/TerminatingCachedDataSource.java
index e1afcc22..884f8882 100755
--- a/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/TerminatingCachedDataSource.java
+++ b/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/TerminatingCachedDataSource.java
@@ -7,9 +7,9 @@
* 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.
@@ -29,6 +29,8 @@ import org.onap.ccsdk.sli.core.dblib.pm.SQLExecutionMonitorObserver;
public class TerminatingCachedDataSource extends CachedDataSource implements SQLExecutionMonitorObserver {
+ private static final int DEFAULT_AVAILABLE_CONNECTIONS = 0;
+
public TerminatingCachedDataSource(BaseDBConfiguration jdbcElem) throws DBConfigException {
super(jdbcElem);
}
@@ -43,4 +45,8 @@ public class TerminatingCachedDataSource extends CachedDataSource implements SQL
return null;
}
+ @Override
+ protected int getAvailableConnections() {
+ return DEFAULT_AVAILABLE_CONNECTIONS;
+ }
}
diff --git a/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/config/BaseDBConfiguration.java b/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/config/BaseDBConfiguration.java
index 967059a3..ea6bc450 100755
--- a/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/config/BaseDBConfiguration.java
+++ b/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/config/BaseDBConfiguration.java
@@ -29,7 +29,7 @@ import org.slf4j.LoggerFactory;
*/
public abstract class BaseDBConfiguration {
- private Logger logger = LoggerFactory.getLogger(BaseDBConfiguration.class);
+ private static final Logger LOGGER = LoggerFactory.getLogger(BaseDBConfiguration.class);
/**
* Property key within a properties configuration File for db type
*/
@@ -134,7 +134,7 @@ public abstract class BaseDBConfiguration {
String value = properties.getProperty(CONNECTION_TIMEOUT, DEFAULT_REJECT_CHANGE_VALUE);
return Integer.parseInt(value);
} catch (Exception exc) {
- logger.error("Exception",exc);
+ LOGGER.error("Exception",exc);
return Integer.parseInt(DEFAULT_REJECT_CHANGE_VALUE);
}
}
@@ -150,7 +150,7 @@ public abstract class BaseDBConfiguration {
String value = properties.getProperty(REQUEST_TIMEOUT, DEFAULT_REJECT_CHANGE_VALUE);
return Integer.parseInt(value);
} catch (Exception exc) {
- logger.error("Exception",exc);
+ LOGGER.error("Exception",exc);
return Integer.parseInt(DEFAULT_REJECT_CHANGE_VALUE);
}
}
@@ -247,4 +247,12 @@ public abstract class BaseDBConfiguration {
public String getDbUrl() {
return properties.getProperty(DATABASE_URL);
}
+
+ public boolean containsKey(String propertyname) {
+ return properties.containsKey(propertyname);
+ }
+
+ public String getProperty(String propertyname) {
+ return properties.getProperty(propertyname);
+ }
}
diff --git a/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/config/TerminatingConfiguration.java b/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/config/TerminatingConfiguration.java
new file mode 100755
index 00000000..1ebd1441
--- /dev/null
+++ b/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/config/TerminatingConfiguration.java
@@ -0,0 +1,33 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * onap
+ * ================================================================================
+ * Copyright (C) 2016 - 2017 ONAP
+ * ================================================================================
+ * Modifications Copyright (C) 2018 IBM.
+ * ================================================================================
+ * 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.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.ccsdk.sli.core.dblib.config;
+
+import java.util.Properties;
+
+public class TerminatingConfiguration extends BaseDBConfiguration {
+
+ public TerminatingConfiguration() {
+ super(new Properties());
+ }
+
+}
diff --git a/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/jdbc/JdbcDBCachedDataSource.java b/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/jdbc/JdbcDBCachedDataSource.java
index 09c1c202..a53d1863 100755
--- a/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/jdbc/JdbcDBCachedDataSource.java
+++ b/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/jdbc/JdbcDBCachedDataSource.java
@@ -193,4 +193,9 @@ public class JdbcDBCachedDataSource extends CachedDataSource {
dataSource.close(true);
super.cleanUp();
}
+
+ @Override
+ protected int getAvailableConnections() {
+ return org.apache.tomcat.jdbc.pool.DataSource.class.cast(ds).getSize();
+ }
}