Modified: tomcat/trunk/java/org/apache/tomcat/dbcp/dbcp2/BasicDataSourceFactory.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/dbcp/dbcp2/BasicDataSourceFactory.java?rev=1833794&r1=1833793&r2=1833794&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/tomcat/dbcp/dbcp2/BasicDataSourceFactory.java (original) +++ tomcat/trunk/java/org/apache/tomcat/dbcp/dbcp2/BasicDataSourceFactory.java Tue Jun 19 09:04:08 2018 @@ -43,19 +43,16 @@ import org.apache.tomcat.dbcp.pool2.impl import org.apache.tomcat.dbcp.pool2.impl.GenericObjectPoolConfig; /** - * <p>JNDI object factory that creates an instance of - * <code>BasicDataSource</code> that has been configured based on the - * <code>RefAddr</code> values of the specified <code>Reference</code>, which - * must match the names and data types of the <code>BasicDataSource</code> bean - * properties with the following exceptions:</p> + * <p> + * JNDI object factory that creates an instance of <code>BasicDataSource</code> that has been configured based on the + * <code>RefAddr</code> values of the specified <code>Reference</code>, which must match the names and data types of the + * <code>BasicDataSource</code> bean properties with the following exceptions: + * </p> * <ul> - * <li><code>connectionInitSqls</code> must be passed to this factory as a - * single String using semi-colon to delimit the statements whereas - * <code>BasicDataSource</code> requires a collection of Strings.</li> + * <li><code>connectionInitSqls</code> must be passed to this factory as a single String using semi-colon to delimit the + * statements whereas <code>BasicDataSource</code> requires a collection of Strings.</li> * </ul> * - * @author Craig R. McClanahan - * @author Dirk Verbeeck * @since 2.0 */ public class BasicDataSourceFactory implements ObjectFactory { @@ -66,7 +63,7 @@ public class BasicDataSourceFactory impl private static final String PROP_DEFAULTREADONLY = "defaultReadOnly"; private static final String PROP_DEFAULTTRANSACTIONISOLATION = "defaultTransactionIsolation"; private static final String PROP_DEFAULTCATALOG = "defaultCatalog"; - private static final String PROP_CACHESTATE ="cacheState"; + private static final String PROP_CACHESTATE = "cacheState"; private static final String PROP_DRIVERCLASSNAME = "driverClassName"; private static final String PROP_LIFO = "lifo"; private static final String PROP_MAXTOTAL = "maxTotal"; @@ -91,8 +88,7 @@ public class BasicDataSourceFactory impl private static final String PROP_JMX_NAME = "jmxName"; /** - * The property name for connectionInitSqls. - * The associated value String must be of the form [query;]* + * The property name for connectionInitSqls. The associated value String must be of the form [query;]* */ private static final String PROP_CONNECTIONINITSQLS = "connectionInitSqls"; private static final String PROP_ACCESSTOUNDERLYINGCONNECTIONALLOWED = "accessToUnderlyingConnectionAllowed"; @@ -117,99 +113,58 @@ public class BasicDataSourceFactory impl private static final String PROP_DISCONNECTION_SQL_CODES = "disconnectionSqlCodes"; /* - * Block with obsolete properties from DBCP 1.x. - * Warn users that these are ignored and they should use the 2.x properties. + * Block with obsolete properties from DBCP 1.x. Warn users that these are ignored and they should use the 2.x + * properties. */ private static final String NUPROP_MAXACTIVE = "maxActive"; private static final String NUPROP_REMOVEABANDONED = "removeAbandoned"; private static final String NUPROP_MAXWAIT = "maxWait"; /* - * Block with properties expected in a DataSource - * This props will not be listed as ignored - we know that they may appear in Resource, - * and not listing them as ignored. + * Block with properties expected in a DataSource This props will not be listed as ignored - we know that they may + * appear in Resource, and not listing them as ignored. */ private static final String SILENTPROP_FACTORY = "factory"; private static final String SILENTPROP_SCOPE = "scope"; private static final String SILENTPROP_SINGLETON = "singleton"; private static final String SILENTPROP_AUTH = "auth"; - private static final String[] ALL_PROPERTIES = { - PROP_DEFAULTAUTOCOMMIT, - PROP_DEFAULTREADONLY, - PROP_DEFAULTTRANSACTIONISOLATION, - PROP_DEFAULTCATALOG, - PROP_CACHESTATE, - PROP_DRIVERCLASSNAME, - PROP_LIFO, - PROP_MAXTOTAL, - PROP_MAXIDLE, - PROP_MINIDLE, - PROP_INITIALSIZE, - PROP_MAXWAITMILLIS, - PROP_TESTONCREATE, - PROP_TESTONBORROW, - PROP_TESTONRETURN, - PROP_TIMEBETWEENEVICTIONRUNSMILLIS, - PROP_NUMTESTSPEREVICTIONRUN, - PROP_MINEVICTABLEIDLETIMEMILLIS, - PROP_SOFTMINEVICTABLEIDLETIMEMILLIS, - PROP_EVICTIONPOLICYCLASSNAME, - PROP_TESTWHILEIDLE, - PROP_PASSWORD, - PROP_URL, - PROP_USERNAME, - PROP_VALIDATIONQUERY, - PROP_VALIDATIONQUERY_TIMEOUT, - PROP_CONNECTIONINITSQLS, - PROP_ACCESSTOUNDERLYINGCONNECTIONALLOWED, - PROP_REMOVEABANDONEDONBORROW, - PROP_REMOVEABANDONEDONMAINTENANCE, - PROP_REMOVEABANDONEDTIMEOUT, - PROP_LOGABANDONED, - PROP_ABANDONEDUSAGETRACKING, - PROP_POOLPREPAREDSTATEMENTS, - PROP_MAXOPENPREPAREDSTATEMENTS, - PROP_CONNECTIONPROPERTIES, - PROP_MAXCONNLIFETIMEMILLIS, - PROP_LOGEXPIREDCONNECTIONS, - PROP_ROLLBACK_ON_RETURN, - PROP_ENABLE_AUTOCOMMIT_ON_RETURN, - PROP_DEFAULT_QUERYTIMEOUT, - PROP_FASTFAIL_VALIDATION, - PROP_DISCONNECTION_SQL_CODES, - PROP_JMX_NAME - }; + private static final String[] ALL_PROPERTIES = {PROP_DEFAULTAUTOCOMMIT, PROP_DEFAULTREADONLY, + PROP_DEFAULTTRANSACTIONISOLATION, PROP_DEFAULTCATALOG, PROP_CACHESTATE, PROP_DRIVERCLASSNAME, PROP_LIFO, + PROP_MAXTOTAL, PROP_MAXIDLE, PROP_MINIDLE, PROP_INITIALSIZE, PROP_MAXWAITMILLIS, PROP_TESTONCREATE, + PROP_TESTONBORROW, PROP_TESTONRETURN, PROP_TIMEBETWEENEVICTIONRUNSMILLIS, PROP_NUMTESTSPEREVICTIONRUN, + PROP_MINEVICTABLEIDLETIMEMILLIS, PROP_SOFTMINEVICTABLEIDLETIMEMILLIS, PROP_EVICTIONPOLICYCLASSNAME, + PROP_TESTWHILEIDLE, PROP_PASSWORD, PROP_URL, PROP_USERNAME, PROP_VALIDATIONQUERY, + PROP_VALIDATIONQUERY_TIMEOUT, PROP_CONNECTIONINITSQLS, PROP_ACCESSTOUNDERLYINGCONNECTIONALLOWED, + PROP_REMOVEABANDONEDONBORROW, PROP_REMOVEABANDONEDONMAINTENANCE, PROP_REMOVEABANDONEDTIMEOUT, + PROP_LOGABANDONED, PROP_ABANDONEDUSAGETRACKING, PROP_POOLPREPAREDSTATEMENTS, PROP_MAXOPENPREPAREDSTATEMENTS, + PROP_CONNECTIONPROPERTIES, PROP_MAXCONNLIFETIMEMILLIS, PROP_LOGEXPIREDCONNECTIONS, PROP_ROLLBACK_ON_RETURN, + PROP_ENABLE_AUTOCOMMIT_ON_RETURN, PROP_DEFAULT_QUERYTIMEOUT, PROP_FASTFAIL_VALIDATION, + PROP_DISCONNECTION_SQL_CODES, PROP_JMX_NAME }; /** - * Obsolete properties from DBCP 1.x. with warning strings suggesting - * new properties. LinkedHashMap will guarantee that properties will be listed - * to output in order of insertion into map. + * Obsolete properties from DBCP 1.x. with warning strings suggesting new properties. LinkedHashMap will guarantee + * that properties will be listed to output in order of insertion into map. */ private static final Map<String, String> NUPROP_WARNTEXT = new LinkedHashMap<>(); static { - NUPROP_WARNTEXT.put( - NUPROP_MAXACTIVE, + NUPROP_WARNTEXT.put(NUPROP_MAXACTIVE, "Property " + NUPROP_MAXACTIVE + " is not used in DBCP2, use " + PROP_MAXTOTAL + " instead. " - + PROP_MAXTOTAL + " default value is " + GenericObjectPoolConfig.DEFAULT_MAX_TOTAL+"."); - NUPROP_WARNTEXT.put( - NUPROP_REMOVEABANDONED, - "Property " + NUPROP_REMOVEABANDONED + " is not used in DBCP2," - + " use one or both of " + + PROP_MAXTOTAL + " default value is " + GenericObjectPoolConfig.DEFAULT_MAX_TOTAL + "."); + NUPROP_WARNTEXT.put(NUPROP_REMOVEABANDONED, + "Property " + NUPROP_REMOVEABANDONED + " is not used in DBCP2," + " use one or both of " + PROP_REMOVEABANDONEDONBORROW + " or " + PROP_REMOVEABANDONEDONMAINTENANCE + " instead. " + "Both have default value set to false."); - NUPROP_WARNTEXT.put( - NUPROP_MAXWAIT, - "Property " + NUPROP_MAXWAIT + " is not used in DBCP2" - + " , use " + PROP_MAXWAITMILLIS + " instead. " - + PROP_MAXWAITMILLIS + " default value is " + BaseObjectPoolConfig.DEFAULT_MAX_WAIT_MILLIS+"."); + NUPROP_WARNTEXT.put(NUPROP_MAXWAIT, + "Property " + NUPROP_MAXWAIT + " is not used in DBCP2" + " , use " + PROP_MAXWAITMILLIS + " instead. " + + PROP_MAXWAITMILLIS + " default value is " + BaseObjectPoolConfig.DEFAULT_MAX_WAIT_MILLIS + + "."); } /** - * Silent Properties. - * These properties will not be listed as ignored - we know that they may appear in JDBC Resource references, - * and we will not list them as ignored. + * Silent Properties. These properties will not be listed as ignored - we know that they may appear in JDBC Resource + * references, and we will not list them as ignored. */ private static final List<String> SILENT_PROPERTIES = new ArrayList<>(); @@ -224,23 +179,28 @@ public class BasicDataSourceFactory impl // -------------------------------------------------- ObjectFactory Methods /** - * <p>Create and return a new <code>BasicDataSource</code> instance. If no - * instance can be created, return <code>null</code> instead.</p> + * <p> + * Create and return a new <code>BasicDataSource</code> instance. If no instance can be created, return + * <code>null</code> instead. + * </p> * - * @param obj The possibly null object containing location or - * reference information that can be used in creating an object - * @param name The name of this object relative to <code>nameCtx</code> - * @param nameCtx The context relative to which the <code>name</code> - * parameter is specified, or <code>null</code> if <code>name</code> - * is relative to the default initial context - * @param environment The possibly null environment that is used in - * creating this object + * @param obj + * The possibly null object containing location or reference information that can be used in creating an + * object + * @param name + * The name of this object relative to <code>nameCtx</code> + * @param nameCtx + * The context relative to which the <code>name</code> parameter is specified, or <code>null</code> if + * <code>name</code> is relative to the default initial context + * @param environment + * The possibly null environment that is used in creating this object * - * @throws Exception if an exception occurs creating the instance + * @throws Exception + * if an exception occurs creating the instance */ @Override - public Object getObjectInstance(final Object obj, final Name name, final Context nameCtx, final Hashtable<?,?> environment) - throws Exception { + public Object getObjectInstance(final Object obj, final Name name, final Context nameCtx, + final Hashtable<?, ?> environment) throws Exception { // We only know how to deal with <code>javax.naming.Reference</code>s // that specify a class name of "javax.sql.DataSource" @@ -272,33 +232,34 @@ public class BasicDataSourceFactory impl } } - return createDataSourceInstance(properties); + return createDataSource(properties); } /** - * Collects warnings and info messages. Warnings are generated when an obsolete - * property is set. Unknown properties generate info messages. + * Collects warnings and info messages. Warnings are generated when an obsolete property is set. Unknown properties + * generate info messages. * - * @param ref Reference to check properties of - * @param name Name provided to getObject - * @param warnings container for warning messages - * @param infoMessages container for info messages + * @param ref + * Reference to check properties of + * @param name + * Name provided to getObject + * @param warnings + * container for warning messages + * @param infoMessages + * container for info messages */ private void validatePropertyNames(final Reference ref, final Name name, final List<String> warnings, - final List<String> infoMessages) { + final List<String> infoMessages) { final List<String> allPropsAsList = Arrays.asList(ALL_PROPERTIES); final String nameString = name != null ? "Name = " + name.toString() + " " : ""; - if (NUPROP_WARNTEXT!=null && !NUPROP_WARNTEXT.keySet().isEmpty()) { + if (NUPROP_WARNTEXT != null && !NUPROP_WARNTEXT.keySet().isEmpty()) { for (final String propertyName : NUPROP_WARNTEXT.keySet()) { final RefAddr ra = ref.get(propertyName); if (ra != null && !allPropsAsList.contains(ra.getType())) { final StringBuilder stringBuilder = new StringBuilder(nameString); final String propertyValue = ra.getContent().toString(); - stringBuilder.append(NUPROP_WARNTEXT.get(propertyName)) - .append(" You have set value of \"") - .append(propertyValue) - .append("\" for \"") - .append(propertyName) + stringBuilder.append(NUPROP_WARNTEXT.get(propertyName)).append(" You have set value of \"") + .append(propertyValue).append("\" for \"").append(propertyName) .append("\" property, which is being ignored."); warnings.add(stringBuilder.toString()); } @@ -311,58 +272,28 @@ public class BasicDataSourceFactory impl final String propertyName = ra.getType(); // If property name is not in the properties list, we haven't warned on it // and it is not in the "silent" list, tell user we are ignoring it. - if (!(allPropsAsList.contains(propertyName) - || NUPROP_WARNTEXT.keySet().contains(propertyName) + if (!(allPropsAsList.contains(propertyName) || NUPROP_WARNTEXT.keySet().contains(propertyName) || SILENT_PROPERTIES.contains(propertyName))) { final String propertyValue = ra.getContent().toString(); final StringBuilder stringBuilder = new StringBuilder(nameString); - stringBuilder.append("Ignoring unknown property: ") - .append("value of \"") - .append(propertyValue) - .append("\" for \"") - .append(propertyName) - .append("\" property"); + stringBuilder.append("Ignoring unknown property: ").append("value of \"").append(propertyValue) + .append("\" for \"").append(propertyName).append("\" property"); infoMessages.add(stringBuilder.toString()); } } } /** - * Creates and configures a {@link BasicDataSource} instance based on the - * given properties. + * Creates and configures a {@link BasicDataSource} instance based on the given properties. * - * @param properties the datasource configuration properties - * @return the data source instance - * @throws Exception if an error occurs creating the data source + * @param properties + * The data source configuration properties. + * @return A new a {@link BasicDataSource} instance based on the given properties. + * @throws Exception + * Thrown when an error occurs creating the data source. */ public static BasicDataSource createDataSource(final Properties properties) throws Exception { - return (new BasicDataSourceFactory()).createDataSourceInstance(properties); - } - - /** - * Creates and configures a {@link BasicDataSource} instance based on the - * given properties. - * Note: duplicates the static createDataSource to avoid an API change - * - * @param properties the datasource configuration properties - * @return the data source instance - * @throws Exception if an error occurs creating the data source - */ - public BasicDataSource createDataSourceInstance(final Properties properties) throws Exception { final BasicDataSource dataSource = new BasicDataSource(); - configureDataSource(dataSource, properties); - return dataSource; - } - - /** - * Configures a {@link BasicDataSource} instance based on the - * given properties. - * - * @param properties the datasource configuration properties - * @param dataSource the data source instance - * @throws Exception if an error occurs creating the data source - */ - public void configureDataSource(final BasicDataSource dataSource, final Properties properties) throws Exception { String value = null; value = properties.getProperty(PROP_DEFAULTAUTOCOMMIT); @@ -380,20 +311,15 @@ public class BasicDataSourceFactory impl int level = PoolableConnectionFactory.UNKNOWN_TRANSACTIONISOLATION; if ("NONE".equalsIgnoreCase(value)) { level = Connection.TRANSACTION_NONE; - } - else if ("READ_COMMITTED".equalsIgnoreCase(value)) { + } else if ("READ_COMMITTED".equalsIgnoreCase(value)) { level = Connection.TRANSACTION_READ_COMMITTED; - } - else if ("READ_UNCOMMITTED".equalsIgnoreCase(value)) { + } else if ("READ_UNCOMMITTED".equalsIgnoreCase(value)) { level = Connection.TRANSACTION_READ_UNCOMMITTED; - } - else if ("REPEATABLE_READ".equalsIgnoreCase(value)) { + } else if ("REPEATABLE_READ".equalsIgnoreCase(value)) { level = Connection.TRANSACTION_REPEATABLE_READ; - } - else if ("SERIALIZABLE".equalsIgnoreCase(value)) { + } else if ("SERIALIZABLE".equalsIgnoreCase(value)) { level = Connection.TRANSACTION_SERIALIZABLE; - } - else { + } else { try { level = Integer.parseInt(value); } catch (final NumberFormatException e) { @@ -568,12 +494,12 @@ public class BasicDataSourceFactory impl value = properties.getProperty(PROP_CONNECTIONPROPERTIES); if (value != null) { - final Properties p = getProperties(value); - final Enumeration<?> e = p.propertyNames(); - while (e.hasMoreElements()) { - final String propertyName = (String) e.nextElement(); - dataSource.addConnectionProperty(propertyName, p.getProperty(propertyName)); - } + final Properties p = getProperties(value); + final Enumeration<?> e = p.propertyNames(); + while (e.hasMoreElements()) { + final String propertyName = (String) e.nextElement(); + dataSource.addConnectionProperty(propertyName, p.getProperty(propertyName)); + } } value = properties.getProperty(PROP_MAXCONNLIFETIMEMILLIS); @@ -621,27 +547,35 @@ public class BasicDataSourceFactory impl if (dataSource.getInitialSize() > 0) { dataSource.getLogWriter(); } + + // Return the configured DataSource instance + return dataSource; } /** - * <p>Parse properties from the string. Format of the string must be [propertyName=property;]*<p> + * <p> + * Parse properties from the string. Format of the string must be [propertyName=property;]* + * <p> + * * @param propText * @return Properties * @throws Exception */ private static Properties getProperties(final String propText) throws Exception { - final Properties p = new Properties(); - if (propText != null) { - p.load(new ByteArrayInputStream( - propText.replace(';', '\n').getBytes(StandardCharsets.ISO_8859_1))); - } - return p; + final Properties p = new Properties(); + if (propText != null) { + p.load(new ByteArrayInputStream(propText.replace(';', '\n').getBytes(StandardCharsets.ISO_8859_1))); + } + return p; } /** * Parse list of property values from a delimited string - * @param value delimited list of values - * @param delimiter character used to separate values in the list + * + * @param value + * delimited list of values + * @param delimiter + * character used to separate values in the list * @return String Collection of values */ private static Collection<String> parseList(final String value, final char delimiter) {
Modified: tomcat/trunk/java/org/apache/tomcat/dbcp/dbcp2/BasicDataSourceMXBean.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/dbcp/dbcp2/BasicDataSourceMXBean.java?rev=1833794&r1=1833793&r2=1833794&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/tomcat/dbcp/dbcp2/BasicDataSourceMXBean.java (original) +++ tomcat/trunk/java/org/apache/tomcat/dbcp/dbcp2/BasicDataSourceMXBean.java Tue Jun 19 09:04:08 2018 @@ -25,198 +25,231 @@ public interface BasicDataSourceMXBean { /** * See {@link BasicDataSource#getAbandonedUsageTracking()} + * * @return {@link BasicDataSource#getAbandonedUsageTracking()} */ boolean getAbandonedUsageTracking(); /** * See {@link BasicDataSource#getDefaultAutoCommit()} + * * @return {@link BasicDataSource#getDefaultAutoCommit()} */ Boolean getDefaultAutoCommit(); /** * See {@link BasicDataSource#getDefaultReadOnly()} + * * @return {@link BasicDataSource#getDefaultReadOnly()} */ Boolean getDefaultReadOnly(); /** * See {@link BasicDataSource#getDefaultTransactionIsolation()} + * * @return {@link BasicDataSource#getDefaultTransactionIsolation()} */ int getDefaultTransactionIsolation(); /** * See {@link BasicDataSource#getDefaultCatalog()} + * * @return {@link BasicDataSource#getDefaultCatalog()} */ String getDefaultCatalog(); /** * See {@link BasicDataSource#getCacheState()} + * * @return {@link BasicDataSource#getCacheState()} */ boolean getCacheState(); /** * See {@link BasicDataSource#getDriverClassName()} + * * @return {@link BasicDataSource#getDriverClassName()} */ String getDriverClassName(); /** * See {@link BasicDataSource#getLifo()} + * * @return {@link BasicDataSource#getLifo()} */ boolean getLifo(); /** * See {@link BasicDataSource#getMaxTotal()} + * * @return {@link BasicDataSource#getMaxTotal()} */ int getMaxTotal(); /** * See {@link BasicDataSource#getMaxIdle()} + * * @return {@link BasicDataSource#getMaxIdle()} */ int getMaxIdle(); /** * See {@link BasicDataSource#getMinIdle()} + * * @return {@link BasicDataSource#getMinIdle()} */ int getMinIdle(); /** * See {@link BasicDataSource#getInitialSize()} + * * @return {@link BasicDataSource#getInitialSize()} */ int getInitialSize(); /** * See {@link BasicDataSource#getMaxWaitMillis()} + * * @return {@link BasicDataSource#getMaxWaitMillis()} */ long getMaxWaitMillis(); /** * See {@link BasicDataSource#isPoolPreparedStatements()} + * * @return {@link BasicDataSource#isPoolPreparedStatements()} */ boolean isPoolPreparedStatements(); /** * See {@link BasicDataSource#getMaxOpenPreparedStatements()} + * * @return {@link BasicDataSource#getMaxOpenPreparedStatements()} */ int getMaxOpenPreparedStatements(); /** * See {@link BasicDataSource#getTestOnCreate()} + * * @return {@link BasicDataSource#getTestOnCreate()} */ boolean getTestOnCreate(); /** * See {@link BasicDataSource#getTestOnBorrow()} + * * @return {@link BasicDataSource#getTestOnBorrow()} */ boolean getTestOnBorrow(); /** * See {@link BasicDataSource#getTimeBetweenEvictionRunsMillis()} + * * @return {@link BasicDataSource#getTimeBetweenEvictionRunsMillis()} */ long getTimeBetweenEvictionRunsMillis(); /** * See {@link BasicDataSource#getNumTestsPerEvictionRun()} + * * @return {@link BasicDataSource#getNumTestsPerEvictionRun()} */ int getNumTestsPerEvictionRun(); /** * See {@link BasicDataSource#getMinEvictableIdleTimeMillis()} + * * @return {@link BasicDataSource#getMinEvictableIdleTimeMillis()} */ long getMinEvictableIdleTimeMillis(); /** * See {@link BasicDataSource#getSoftMinEvictableIdleTimeMillis()} + * * @return {@link BasicDataSource#getSoftMinEvictableIdleTimeMillis()} */ long getSoftMinEvictableIdleTimeMillis(); /** * See {@link BasicDataSource#getTestWhileIdle()} + * * @return {@link BasicDataSource#getTestWhileIdle()} */ boolean getTestWhileIdle(); /** * See {@link BasicDataSource#getNumActive()} + * * @return {@link BasicDataSource#getNumActive()} */ int getNumActive(); /** * See {@link BasicDataSource#getNumIdle()} + * * @return {@link BasicDataSource#getNumIdle()} */ int getNumIdle(); /** * See {@link BasicDataSource#getPassword()} + * * @return {@link BasicDataSource#getPassword()} */ String getPassword(); /** * See {@link BasicDataSource#getUrl()} + * * @return {@link BasicDataSource#getUrl()} */ String getUrl(); /** * See {@link BasicDataSource#getUsername()} + * * @return {@link BasicDataSource#getUsername()} */ String getUsername(); /** * See {@link BasicDataSource#getValidationQuery()} + * * @return {@link BasicDataSource#getValidationQuery()} */ String getValidationQuery(); /** * See {@link BasicDataSource#getValidationQueryTimeout()} + * * @return {@link BasicDataSource#getValidationQueryTimeout()} */ int getValidationQueryTimeout(); /** * See {@link BasicDataSource#getConnectionInitSqlsAsArray()} + * * @return {@link BasicDataSource#getConnectionInitSqlsAsArray()} */ String[] getConnectionInitSqlsAsArray(); /** * See {@link BasicDataSource#isAccessToUnderlyingConnectionAllowed()} + * * @return {@link BasicDataSource#isAccessToUnderlyingConnectionAllowed()} */ boolean isAccessToUnderlyingConnectionAllowed(); /** * See {@link BasicDataSource#getMaxConnLifetimeMillis()} + * * @return {@link BasicDataSource#getMaxConnLifetimeMillis()} */ long getMaxConnLifetimeMillis(); /** * See {@link BasicDataSource#getLogExpiredConnections()} + * * @return {@link BasicDataSource#getLogExpiredConnections()} * @since 2.1 */ @@ -224,36 +257,42 @@ public interface BasicDataSourceMXBean { /** * See {@link BasicDataSource#getRemoveAbandonedOnBorrow()} + * * @return {@link BasicDataSource#getRemoveAbandonedOnBorrow()} */ boolean getRemoveAbandonedOnBorrow(); /** * See {@link BasicDataSource#getRemoveAbandonedOnMaintenance()} + * * @return {@link BasicDataSource#getRemoveAbandonedOnMaintenance()} */ boolean getRemoveAbandonedOnMaintenance(); /** * See {@link BasicDataSource#getRemoveAbandonedTimeout()} + * * @return {@link BasicDataSource#getRemoveAbandonedTimeout()} */ int getRemoveAbandonedTimeout(); /** * See {@link BasicDataSource#getLogAbandoned()} + * * @return {@link BasicDataSource#getLogAbandoned()} */ boolean getLogAbandoned(); /** * See {@link BasicDataSource#isClosed()} + * * @return {@link BasicDataSource#isClosed()} */ boolean isClosed(); /** * See {@link BasicDataSource#getFastFailValidation()} + * * @return {@link BasicDataSource#getFastFailValidation()} * @since 2.1 */ @@ -261,6 +300,7 @@ public interface BasicDataSourceMXBean { /** * See {@link BasicDataSource#getDisconnectionSqlCodesAsArray()} + * * @return {@link BasicDataSource#getDisconnectionSqlCodesAsArray()} * @since 2.1 */ Modified: tomcat/trunk/java/org/apache/tomcat/dbcp/dbcp2/ConnectionFactory.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/dbcp/dbcp2/ConnectionFactory.java?rev=1833794&r1=1833793&r2=1833794&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/tomcat/dbcp/dbcp2/ConnectionFactory.java (original) +++ tomcat/trunk/java/org/apache/tomcat/dbcp/dbcp2/ConnectionFactory.java Tue Jun 19 09:04:08 2018 @@ -22,16 +22,15 @@ import java.sql.SQLException; /** * Abstract factory interface for creating {@link java.sql.Connection}s. * - * @author Rodney Waldhoff * @since 2.0 */ public interface ConnectionFactory { /** - * Create a new {@link java.sql.Connection} in an - * implementation specific fashion. + * Create a new {@link java.sql.Connection} in an implementation specific fashion. * * @return a new {@link java.sql.Connection} - * @throws SQLException if a database error occurs creating the connection + * @throws SQLException + * if a database error occurs creating the connection */ Connection createConnection() throws SQLException; } Modified: tomcat/trunk/java/org/apache/tomcat/dbcp/dbcp2/Constants.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/dbcp/dbcp2/Constants.java?rev=1833794&r1=1833793&r2=1833794&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/tomcat/dbcp/dbcp2/Constants.java (original) +++ tomcat/trunk/java/org/apache/tomcat/dbcp/dbcp2/Constants.java Tue Jun 19 09:04:08 2018 @@ -17,19 +17,18 @@ package org.apache.tomcat.dbcp.dbcp2; /** - * Constants for use with JMX + * Constants for use with JMX. + * * @since 2.0 */ public class Constants { + public static final String JMX_CONNECTION_POOL_BASE_EXT = ",connectionpool="; public static final String JMX_CONNECTION_POOL_PREFIX = "connections"; - public static final String JMX_CONNECTION_BASE_EXT = - JMX_CONNECTION_POOL_BASE_EXT + - JMX_CONNECTION_POOL_PREFIX + - ",connection="; + public static final String JMX_CONNECTION_BASE_EXT = JMX_CONNECTION_POOL_BASE_EXT + JMX_CONNECTION_POOL_PREFIX + + ",connection="; - public static final String JMX_STATEMENT_POOL_BASE_EXT = - JMX_CONNECTION_BASE_EXT; + public static final String JMX_STATEMENT_POOL_BASE_EXT = JMX_CONNECTION_BASE_EXT; public static final String JMX_STATEMENT_POOL_PREFIX = ",statementpool=statements"; } Modified: tomcat/trunk/java/org/apache/tomcat/dbcp/dbcp2/DataSourceConnectionFactory.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/dbcp/dbcp2/DataSourceConnectionFactory.java?rev=1833794&r1=1833793&r2=1833794&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/tomcat/dbcp/dbcp2/DataSourceConnectionFactory.java (original) +++ tomcat/trunk/java/org/apache/tomcat/dbcp/dbcp2/DataSourceConnectionFactory.java Tue Jun 19 09:04:08 2018 @@ -24,29 +24,64 @@ import javax.sql.DataSource; /** * A {@link DataSource}-based implementation of {@link ConnectionFactory}. * - * @author Rodney Waldhoff * @since 2.0 */ public class DataSourceConnectionFactory implements ConnectionFactory { - public DataSourceConnectionFactory(final DataSource source) { - this(source,null,null); + + private final DataSource dataSource; + + private final String userName; + + private final char[] userPassword; + + /** + * Constructs an instance for the given DataSource. + * + * @param dataSource + * The DataSource for this factory. + */ + public DataSourceConnectionFactory(final DataSource dataSource) { + this(dataSource, null, (char[]) null); } - public DataSourceConnectionFactory(final DataSource source, final String uname, final String passwd) { - _source = source; - _uname = uname; - _passwd = passwd; + /** + * Constructs an instance for the given DataSource. + * + * @param dataSource + * The DataSource for this factory. + * @param userName + * The user name. + * @param userPassword + * The user password. + * @since 2.4.0 + */ + public DataSourceConnectionFactory(final DataSource dataSource, final String userName, final char[] userPassword) { + this.dataSource = dataSource; + this.userName = userName; + this.userPassword = userPassword; + } + + /** + * Constructs an instance for the given DataSource. + * + * @param dataSource + * The DataSource for this factory. + * @param userName + * The user name. + * @param password + * The user password. + */ + public DataSourceConnectionFactory(final DataSource dataSource, final String userName, final String password) { + this.dataSource = dataSource; + this.userName = userName; + this.userPassword = Utils.toCharArray(password); } @Override public Connection createConnection() throws SQLException { - if(null == _uname && null == _passwd) { - return _source.getConnection(); + if (null == userName && null == userPassword) { + return dataSource.getConnection(); } - return _source.getConnection(_uname,_passwd); + return dataSource.getConnection(userName, Utils.toString(userPassword)); } - - private final String _uname; - private final String _passwd; - private final DataSource _source; } --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org