diff options
Diffstat (limited to 'dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/config/BaseDBConfiguration.java')
-rwxr-xr-x[-rw-r--r--] | dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/config/BaseDBConfiguration.java | 126 |
1 files changed, 67 insertions, 59 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 d53be0e7..a8bc58b8 100644..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 @@ -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. @@ -30,58 +30,68 @@ public abstract class BaseDBConfiguration { /** * Property key within a properties configuration File for db type */ - public static final String DATABASE_TYPE = "org.onap.ccsdk.sli.dbtype"; + 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"; + 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"; + public static final String DATABASE_NAME = "org.onap.ccsdk.sli.jdbc.database"; + + /** + * Property key with a properties configuration File for jdbc driver + */ + public static final String DRIVER_NAME = "org.onap.ccsdk.sli.jdbc.driver"; /** * 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"; + 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"; + 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>. + * 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"; + public static final String DATABASE_PSSWD = "org.onap.ccsdk.sli.jdbc.password"; /** - * Property key with a properties configuration File for database connection timeout + * 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 + * Property key with a properties configuration File for database request + * timeout */ - public static final String REQUEST_TIMEOUT = "org.onap.ccsdk.sli.jdbc.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 + * Property key with a properties configuration File for database minimum + * limit */ - public static final String MIN_LIMIT = "org.onap.ccsdk.sli.jdbc.limit.min"; + public static final String MIN_LIMIT = "org.onap.ccsdk.sli.jdbc.limit.min"; /** - * Property key with a properties configuration File for database maximum limit + * Property key with a properties configuration File for database maximum + * limit */ - public static final String MAX_LIMIT = "org.onap.ccsdk.sli.jdbc.limit.max"; + public static final String MAX_LIMIT = "org.onap.ccsdk.sli.jdbc.limit.max"; /** - * Property key with a properties configuration File for database initial limit + * Property key with a properties configuration File for database initial + * limit */ - public static final String INIT_LIMIT = "org.onap.ccsdk.sli.jdbc.limit.init"; + public static final String INIT_LIMIT = "org.onap.ccsdk.sli.jdbc.limit.init"; /** * Property key with a properties configuration File for database hosts @@ -89,14 +99,10 @@ public abstract class BaseDBConfiguration { 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 + * default value when the connection timeout is not present or cannot be + * parsed. */ - private static final int DEFAULT_REQUEST_TIMEOUT = -1; + private static final String DEFAULT_REJECT_CHANGE_VALUE = "-1"; /** * A set of properties with database configuration information. @@ -106,7 +112,9 @@ public abstract class BaseDBConfiguration { /** * Builds a configuration based on given properties * - * @param properties properties represented by the public constant keys defined by this class + * @param properties + * properties represented by the public constant keys defined by + * this class */ public BaseDBConfiguration(final Properties properties) { this.properties = properties; @@ -115,35 +123,30 @@ public abstract class BaseDBConfiguration { /** * Extracts the connection timeout. * - * @return the connection timeout, or <code>DEFAULT_CONNECTION_TIMEOUT</code> if not present + * @return the connection timeout, or + * <code>DEFAULT_REJECT_CHANGE_VALUE</code> if not present */ public int getConnTimeout() { - return extractProperty(properties, CONNECTION_TIMEOUT, DEFAULT_CONNECTION_TIMEOUT); + try { + String value = properties.getProperty(CONNECTION_TIMEOUT, DEFAULT_REJECT_CHANGE_VALUE); + return Integer.parseInt(value); + } catch (Exception exc) { + return Integer.parseInt(DEFAULT_REJECT_CHANGE_VALUE); + } } /** * Extracts the request timeout. * - * @return the request timeout, or <code>DEFAULT_REQUEST_TIMEOUT</code> if not present + * @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; + String value = properties.getProperty(REQUEST_TIMEOUT, DEFAULT_REJECT_CHANGE_VALUE); + return Integer.parseInt(value); + } catch (Exception exc) { + return Integer.parseInt(DEFAULT_REJECT_CHANGE_VALUE); } } @@ -166,6 +169,15 @@ public abstract class BaseDBConfiguration { } /** + * Extracts the jdbc driver's name. + * + * @return the jdbc name, or <code>com.mysql.jdbc.Driver</code> if not present + */ + public String getDriverName() { + return properties.getProperty(DRIVER_NAME, "com.mysql.jdbc.Driver"); + } + + /** * Extracts the db user id. * * @return the db user id, or <code>null</code> if not present @@ -187,7 +199,9 @@ public abstract class BaseDBConfiguration { * 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>. + * @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); @@ -198,7 +212,9 @@ public abstract class BaseDBConfiguration { * 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>. + * @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); @@ -209,7 +225,9 @@ public abstract class BaseDBConfiguration { * 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>. + * @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); @@ -224,14 +242,4 @@ public abstract class BaseDBConfiguration { public String getDbUrl() { return properties.getProperty(DATABASE_URL); } - - /** - * Extracts the db server group. - * - * @return <code>null</code> - */ - @Deprecated - public String getServerGroup() { - return null; - } } |