summaryrefslogtreecommitdiffstats
path: root/dblib/provider
diff options
context:
space:
mode:
authorMarcus Williams <marcus.williams@intel.com>2017-09-14 16:28:52 +0000
committerGerrit Code Review <gerrit@onap.org>2017-09-14 16:28:52 +0000
commitbd920facad4f9ce5e8651acb6c477446106e892f (patch)
tree3b8798efce7580afcf56ad802e00f7d6b97c92c5 /dblib/provider
parent39975ca97ae77b06f0aab34396f7bceda7e6e8e3 (diff)
parent222513c30f3c0c0e7bfce48b6c96d9ddfba75dba (diff)
Merge "Clean up BaseDBConfiguration class"
Diffstat (limited to 'dblib/provider')
-rw-r--r--dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/config/BaseDBConfiguration.java289
1 files changed, 211 insertions, 78 deletions
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 4b738d42..d53be0e7 100644
--- 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
@@ -22,83 +22,216 @@ package org.onap.ccsdk.sli.core.dblib.config;
import java.util.Properties;
+/**
+ * Base class responsible for parsing business logic for database configuration from given <code>Properties</code>.
+ */
public abstract class BaseDBConfiguration {
- public static final String DATABASE_TYPE = "org.onap.ccsdk.sli.dbtype";
- public static final String DATABASE_URL = "org.onap.ccsdk.sli.jdbc.url";
- public static final String DATABASE_NAME = "org.onap.ccsdk.sli.jdbc.database";
- public static final String CONNECTION_NAME = "org.onap.ccsdk.sli.jdbc.connection.name";
- public static final String DATABASE_USER = "org.onap.ccsdk.sli.jdbc.user";
- public static final String DATABASE_PSSWD = "org.onap.ccsdk.sli.jdbc.password";
- public static final String CONNECTION_TIMEOUT="org.onap.ccsdk.sli.jdbc.connection.timeout";
- public static final String REQUEST_TIMEOUT = "org.onap.ccsdk.sli.jdbc.request.timeout";
- public static final String MIN_LIMIT = "org.onap.ccsdk.sli.jdbc.limit.min";
- public static final String MAX_LIMIT = "org.onap.ccsdk.sli.jdbc.limit.max";
- public static final String INIT_LIMIT = "org.onap.ccsdk.sli.jdbc.limit.init";
- public static final String DATABASE_HOSTS = "org.onap.ccsdk.sli.jdbc.hosts";
-
-
- protected final Properties props;
-
- public BaseDBConfiguration(Properties properties) {
- this.props = properties;
- }
-
- public int getConnTimeout() {
- try {
- String value = props.getProperty(CONNECTION_TIMEOUT);
- return Integer.parseInt(value);
- } catch(Exception exc) {
- return -1;
- }
- }
-
- public int getRequestTimeout() {
- try {
- String value = props.getProperty(REQUEST_TIMEOUT);
- if(value == null)
- return -1;
- return Integer.parseInt(value);
- } catch(Exception exc) {
- return -1;
- }
- }
-
- public String getDbConnectionName() {
- return props.getProperty(CONNECTION_NAME);
- }
-
- public String getDatabaseName() {
- return props.getProperty(DATABASE_NAME);
- }
-
- public String getDbUserId() {
- return props.getProperty(DATABASE_USER);
- }
-
- public String getDbPasswd() {
- return props.getProperty(DATABASE_PSSWD);
- }
-
- public int getDbMinLimit() {
- String value = props.getProperty(MIN_LIMIT);
- return Integer.parseInt(value);
- }
-
- public int getDbMaxLimit() {
- String value = props.getProperty(MAX_LIMIT);
- return Integer.parseInt(value);
- }
-
- public int getDbInitialLimit() {
- String value = props.getProperty(INIT_LIMIT);
- return Integer.parseInt(value);
- }
-
- public String getDbUrl() {
- return props.getProperty(DATABASE_URL);
- }
-
- public String getServerGroup() {
- return null;
- }
+
+ /**
+ * Property key within a properties configuration File for db type
+ */
+ public static final String DATABASE_TYPE = "org.onap.ccsdk.sli.dbtype";
+
+ /**
+ * Property key with a properties configuration File for db url
+ */
+ public static final String DATABASE_URL = "org.onap.ccsdk.sli.jdbc.url";
+
+ /**
+ * Property key with a properties configuration File for database name
+ */
+ public static final String DATABASE_NAME = "org.onap.ccsdk.sli.jdbc.database";
+
+ /**
+ * Property key with a properties configuration File for db database connection name
+ */
+ public static final String CONNECTION_NAME = "org.onap.ccsdk.sli.jdbc.connection.name";
+
+ /**
+ * Property key with a properties configuration File for database user
+ */
+ public static final String DATABASE_USER = "org.onap.ccsdk.sli.jdbc.user";
+
+ /**
+ * Property key with a properties configuration File for database password for associated with
+ * <code>org.onap.ccsdk.sli.jdbc.user</code>.
+ */
+ public static final String DATABASE_PSSWD = "org.onap.ccsdk.sli.jdbc.password";
+
+ /**
+ * Property key with a properties configuration File for database connection timeout
+ */
+ public static final String CONNECTION_TIMEOUT="org.onap.ccsdk.sli.jdbc.connection.timeout";
+
+ /**
+ * Property key with a properties configuration File for database request timeout
+ */
+ public static final String REQUEST_TIMEOUT = "org.onap.ccsdk.sli.jdbc.request.timeout";
+
+ /**
+ * Property key with a properties configuration File for database minimum limit
+ */
+ public static final String MIN_LIMIT = "org.onap.ccsdk.sli.jdbc.limit.min";
+
+ /**
+ * Property key with a properties configuration File for database maximum limit
+ */
+ public static final String MAX_LIMIT = "org.onap.ccsdk.sli.jdbc.limit.max";
+
+ /**
+ * Property key with a properties configuration File for database initial limit
+ */
+ public static final String INIT_LIMIT = "org.onap.ccsdk.sli.jdbc.limit.init";
+
+ /**
+ * Property key with a properties configuration File for database hosts
+ */
+ public static final String DATABASE_HOSTS = "org.onap.ccsdk.sli.jdbc.hosts";
+
+ /**
+ * default value when the connection timeout is not present or cannot be parsed
+ */
+ private static final int DEFAULT_CONNECTION_TIMEOUT = -1;
+
+ /**
+ * default value when the request timeout is not present or cannot be parsed
+ */
+ private static final int DEFAULT_REQUEST_TIMEOUT = -1;
+
+ /**
+ * A set of properties with database configuration information.
+ */
+ protected final Properties properties;
+
+ /**
+ * Builds a configuration based on given properties
+ *
+ * @param properties properties represented by the public constant keys defined by this class
+ */
+ public BaseDBConfiguration(final Properties properties) {
+ this.properties = properties;
+ }
+
+ /**
+ * Extracts the connection timeout.
+ *
+ * @return the connection timeout, or <code>DEFAULT_CONNECTION_TIMEOUT</code> if not present
+ */
+ public int getConnTimeout() {
+ return extractProperty(properties, CONNECTION_TIMEOUT, DEFAULT_CONNECTION_TIMEOUT);
+ }
+
+ /**
+ * Extracts the request timeout.
+ *
+ * @return the request timeout, or <code>DEFAULT_REQUEST_TIMEOUT</code> if not present
+ */
+ public int getRequestTimeout() {
+ return extractProperty(properties, REQUEST_TIMEOUT, DEFAULT_REQUEST_TIMEOUT);
+ }
+
+ /**
+ * A utility method to extract int property from Properties.
+ *
+ * @param properties a set of <code>Properties</code>
+ * @param propertyKey the key in question
+ * @param defaultValue the value to return if the key does not exist
+ * @return Either the property value for <code>propertyKey</code> or <code>defaultValue</code> if not present
+ */
+ private static int extractProperty(final Properties properties, final String propertyKey, final int defaultValue) {
+ try {
+ final String valueString = properties.getProperty(propertyKey, Integer.toString(defaultValue));
+ return Integer.parseInt(valueString);
+ } catch(final NumberFormatException e) {
+ return defaultValue;
+ }
+ }
+
+ /**
+ * Extracts the db connection name.
+ *
+ * @return the db connection name, or <code>null</code> if not present
+ */
+ public String getDbConnectionName() {
+ return properties.getProperty(CONNECTION_NAME);
+ }
+
+ /**
+ * Extracts the db name.
+ *
+ * @return the db name, or <code>null</code> if not present
+ */
+ public String getDatabaseName() {
+ return properties.getProperty(DATABASE_NAME);
+ }
+
+ /**
+ * Extracts the db user id.
+ *
+ * @return the db user id, or <code>null</code> if not present
+ */
+ public String getDbUserId() {
+ return properties.getProperty(DATABASE_USER);
+ }
+
+ /**
+ * Extracts the db password.
+ *
+ * @return the db password, or <code>null</code> if not present
+ */
+ public String getDbPasswd() {
+ return properties.getProperty(DATABASE_PSSWD);
+ }
+
+ /**
+ * Extracts the db min limit.
+ *
+ * @return the db min limit
+ * @throws NumberFormatException if the property is not specified, or cannot be parsed as an <code>Integer</code>.
+ */
+ public int getDbMinLimit() throws NumberFormatException {
+ String value = properties.getProperty(MIN_LIMIT);
+ return Integer.parseInt(value);
+ }
+
+ /**
+ * Extracts the db max limit.
+ *
+ * @return the db max limit
+ * @throws NumberFormatException if the property is not specified, or cannot be parsed as an <code>Integer</code>.
+ */
+ public int getDbMaxLimit() throws NumberFormatException {
+ String value = properties.getProperty(MAX_LIMIT);
+ return Integer.parseInt(value);
+ }
+
+ /**
+ * Extracts the db initial limit.
+ *
+ * @return the db initial limit
+ * @throws NumberFormatException if the property is not specified, or cannot be parsed as an <code>Integer</code>.
+ */
+ public int getDbInitialLimit() throws NumberFormatException {
+ String value = properties.getProperty(INIT_LIMIT);
+ return Integer.parseInt(value);
+ }
+
+ /**
+ * Extracts the db url.
+ *
+ * @return the db url, or <code>null</code> if not present
+ */
+ public String getDbUrl() {
+ return properties.getProperty(DATABASE_URL);
+ }
+
+ /**
+ * Extracts the db server group.
+ *
+ * @return <code>null</code>
+ */
+ @Deprecated
+ public String getServerGroup() {
+ return null;
+ }
}