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=1852459&r1=1852458&r2=1852459&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/tomcat/dbcp/dbcp2/BasicDataSourceFactory.java (original) +++ tomcat/trunk/java/org/apache/tomcat/dbcp/dbcp2/BasicDataSourceFactory.java Tue Jan 29 15:03:15 2019 @@ -59,54 +59,54 @@ public class BasicDataSourceFactory impl private static final Log log = LogFactory.getLog(BasicDataSourceFactory.class); - private static final String PROP_DEFAULTAUTOCOMMIT = "defaultAutoCommit"; - 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_DEFAULTSCHEMA = "defaultSchema"; - private static final String PROP_CACHESTATE = "cacheState"; - private static final String PROP_DRIVERCLASSNAME = "driverClassName"; + private static final String PROP_DEFAULT_AUTO_COMMIT = "defaultAutoCommit"; + private static final String PROP_DEFAULT_READ_ONLY = "defaultReadOnly"; + private static final String PROP_DEFAULT_TRANSACTION_ISOLATION = "defaultTransactionIsolation"; + private static final String PROP_DEFAULT_CATALOG = "defaultCatalog"; + private static final String PROP_DEFAULT_SCHEMA = "defaultSchema"; + private static final String PROP_CACHE_STATE = "cacheState"; + private static final String PROP_DRIVER_CLASS_NAME = "driverClassName"; private static final String PROP_LIFO = "lifo"; - private static final String PROP_MAXTOTAL = "maxTotal"; - private static final String PROP_MAXIDLE = "maxIdle"; - private static final String PROP_MINIDLE = "minIdle"; - private static final String PROP_INITIALSIZE = "initialSize"; - private static final String PROP_MAXWAITMILLIS = "maxWaitMillis"; - private static final String PROP_TESTONCREATE = "testOnCreate"; - private static final String PROP_TESTONBORROW = "testOnBorrow"; - private static final String PROP_TESTONRETURN = "testOnReturn"; - private static final String PROP_TIMEBETWEENEVICTIONRUNSMILLIS = "timeBetweenEvictionRunsMillis"; - private static final String PROP_NUMTESTSPEREVICTIONRUN = "numTestsPerEvictionRun"; - private static final String PROP_MINEVICTABLEIDLETIMEMILLIS = "minEvictableIdleTimeMillis"; - private static final String PROP_SOFTMINEVICTABLEIDLETIMEMILLIS = "softMinEvictableIdleTimeMillis"; - private static final String PROP_EVICTIONPOLICYCLASSNAME = "evictionPolicyClassName"; - private static final String PROP_TESTWHILEIDLE = "testWhileIdle"; + private static final String PROP_MAX_TOTAL = "maxTotal"; + private static final String PROP_MAX_IDLE = "maxIdle"; + private static final String PROP_MIN_IDLE = "minIdle"; + private static final String PROP_INITIAL_SIZE = "initialSize"; + private static final String PROP_MAX_WAIT_MILLIS = "maxWaitMillis"; + private static final String PROP_TEST_ON_CREATE = "testOnCreate"; + private static final String PROP_TEST_ON_BORROW = "testOnBorrow"; + private static final String PROP_TEST_ON_RETURN = "testOnReturn"; + private static final String PROP_TIME_BETWEEN_EVICTION_RUNS_MILLIS = "timeBetweenEvictionRunsMillis"; + private static final String PROP_NUM_TESTS_PER_EVICTION_RUN = "numTestsPerEvictionRun"; + private static final String PROP_MIN_EVICTABLE_IDLE_TIME_MILLIS = "minEvictableIdleTimeMillis"; + private static final String PROP_SOFT_MIN_EVICTABLE_IDLE_TIME_MILLIS = "softMinEvictableIdleTimeMillis"; + private static final String PROP_EVICTION_POLICY_CLASS_NAME = "evictionPolicyClassName"; + private static final String PROP_TEST_WHILE_IDLE = "testWhileIdle"; private static final String PROP_PASSWORD = "password"; private static final String PROP_URL = "url"; - private static final String PROP_USERNAME = "username"; - private static final String PROP_VALIDATIONQUERY = "validationQuery"; - private static final String PROP_VALIDATIONQUERY_TIMEOUT = "validationQueryTimeout"; + private static final String PROP_USER_NAME = "username"; + private static final String PROP_VALIDATION_QUERY = "validationQuery"; + private static final String PROP_VALIDATION_QUERY_TIMEOUT = "validationQueryTimeout"; private static final String PROP_JMX_NAME = "jmxName"; /** * 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"; - private static final String PROP_REMOVEABANDONEDONBORROW = "removeAbandonedOnBorrow"; - private static final String PROP_REMOVEABANDONEDONMAINTENANCE = "removeAbandonedOnMaintenance"; - private static final String PROP_REMOVEABANDONEDTIMEOUT = "removeAbandonedTimeout"; - private static final String PROP_LOGABANDONED = "logAbandoned"; - private static final String PROP_ABANDONEDUSAGETRACKING = "abandonedUsageTracking"; - private static final String PROP_POOLPREPAREDSTATEMENTS = "poolPreparedStatements"; - private static final String PROP_MAXOPENPREPAREDSTATEMENTS = "maxOpenPreparedStatements"; - private static final String PROP_CONNECTIONPROPERTIES = "connectionProperties"; - private static final String PROP_MAXCONNLIFETIMEMILLIS = "maxConnLifetimeMillis"; - private static final String PROP_LOGEXPIREDCONNECTIONS = "logExpiredConnections"; + private static final String PROP_CONNECTION_INIT_SQLS = "connectionInitSqls"; + private static final String PROP_ACCESS_TO_UNDERLYING_CONNECTION_ALLOWED = "accessToUnderlyingConnectionAllowed"; + private static final String PROP_REMOVE_ABANDONED_ON_BORROW = "removeAbandonedOnBorrow"; + private static final String PROP_REMOVE_ABANDONED_ON_MAINTENANCE = "removeAbandonedOnMaintenance"; + private static final String PROP_REMOVE_ABANDONED_TIMEOUT = "removeAbandonedTimeout"; + private static final String PROP_LOG_ABANDONED = "logAbandoned"; + private static final String PROP_ABANDONED_USAGE_TRACKING = "abandonedUsageTracking"; + private static final String PROP_POOL_PREPARED_STATEMENTS = "poolPreparedStatements"; + private static final String PROP_MAX_OPEN_PREPARED_STATEMENTS = "maxOpenPreparedStatements"; + private static final String PROP_CONNECTION_PROPERTIES = "connectionProperties"; + private static final String PROP_MAX_CONN_LIFETIME_MILLIS = "maxConnLifetimeMillis"; + private static final String PROP_LOG_EXPIRED_CONNECTIONS = "logExpiredConnections"; private static final String PROP_ROLLBACK_ON_RETURN = "rollbackOnReturn"; - private static final String PROP_ENABLE_AUTOCOMMIT_ON_RETURN = "enableAutoCommitOnReturn"; - private static final String PROP_DEFAULT_QUERYTIMEOUT = "defaultQueryTimeout"; - private static final String PROP_FASTFAIL_VALIDATION = "fastFailValidation"; + private static final String PROP_ENABLE_AUTO_COMMIT_ON_RETURN = "enableAutoCommitOnReturn"; + private static final String PROP_DEFAULT_QUERY_TIMEOUT = "defaultQueryTimeout"; + private static final String PROP_FAST_FAIL_VALIDATION = "fastFailValidation"; /** * Value string must be of the form [STATE_CODE,]* @@ -117,31 +117,31 @@ public class BasicDataSourceFactory impl * 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_MAX_ACTIVE = "maxActive"; + private static final String NUPROP_REMOVE_ABANDONED = "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. */ - 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_DEFAULTSCHEMA, 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 SILENT_PROP_FACTORY = "factory"; + private static final String SILENT_PROP_SCOPE = "scope"; + private static final String SILENT_PROP_SINGLETON = "singleton"; + private static final String SILENT_PROP_AUTH = "auth"; + + private static final String[] ALL_PROPERTIES = {PROP_DEFAULT_AUTO_COMMIT, PROP_DEFAULT_READ_ONLY, + PROP_DEFAULT_TRANSACTION_ISOLATION, PROP_DEFAULT_CATALOG, PROP_DEFAULT_SCHEMA, PROP_CACHE_STATE, + PROP_DRIVER_CLASS_NAME, PROP_LIFO, PROP_MAX_TOTAL, PROP_MAX_IDLE, PROP_MIN_IDLE, PROP_INITIAL_SIZE, + PROP_MAX_WAIT_MILLIS, PROP_TEST_ON_CREATE, PROP_TEST_ON_BORROW, PROP_TEST_ON_RETURN, + PROP_TIME_BETWEEN_EVICTION_RUNS_MILLIS, PROP_NUM_TESTS_PER_EVICTION_RUN, PROP_MIN_EVICTABLE_IDLE_TIME_MILLIS, + PROP_SOFT_MIN_EVICTABLE_IDLE_TIME_MILLIS, PROP_EVICTION_POLICY_CLASS_NAME, PROP_TEST_WHILE_IDLE, PROP_PASSWORD, + PROP_URL, PROP_USER_NAME, PROP_VALIDATION_QUERY, PROP_VALIDATION_QUERY_TIMEOUT, PROP_CONNECTION_INIT_SQLS, + PROP_ACCESS_TO_UNDERLYING_CONNECTION_ALLOWED, PROP_REMOVE_ABANDONED_ON_BORROW, PROP_REMOVE_ABANDONED_ON_MAINTENANCE, + PROP_REMOVE_ABANDONED_TIMEOUT, PROP_LOG_ABANDONED, PROP_ABANDONED_USAGE_TRACKING, PROP_POOL_PREPARED_STATEMENTS, + PROP_MAX_OPEN_PREPARED_STATEMENTS, PROP_CONNECTION_PROPERTIES, PROP_MAX_CONN_LIFETIME_MILLIS, + PROP_LOG_EXPIRED_CONNECTIONS, PROP_ROLLBACK_ON_RETURN, PROP_ENABLE_AUTO_COMMIT_ON_RETURN, + PROP_DEFAULT_QUERY_TIMEOUT, PROP_FAST_FAIL_VALIDATION, PROP_DISCONNECTION_SQL_CODES, PROP_JMX_NAME }; /** * Obsolete properties from DBCP 1.x. with warning strings suggesting new properties. LinkedHashMap will guarantee @@ -150,16 +150,16 @@ public class BasicDataSourceFactory impl private static final Map<String, String> NUPROP_WARNTEXT = new LinkedHashMap<>(); static { - 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_REMOVEABANDONEDONBORROW + " or " + PROP_REMOVEABANDONEDONMAINTENANCE + " instead. " + NUPROP_WARNTEXT.put(NUPROP_MAX_ACTIVE, + "Property " + NUPROP_MAX_ACTIVE + " is not used in DBCP2, use " + PROP_MAX_TOTAL + " instead. " + + PROP_MAX_TOTAL + " default value is " + GenericObjectPoolConfig.DEFAULT_MAX_TOTAL + "."); + NUPROP_WARNTEXT.put(NUPROP_REMOVE_ABANDONED, + "Property " + NUPROP_REMOVE_ABANDONED + " is not used in DBCP2," + " use one or both of " + + PROP_REMOVE_ABANDONED_ON_BORROW + " or " + PROP_REMOVE_ABANDONED_ON_MAINTENANCE + " 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 + "Property " + NUPROP_MAXWAIT + " is not used in DBCP2" + " , use " + PROP_MAX_WAIT_MILLIS + " instead. " + + PROP_MAX_WAIT_MILLIS + " default value is " + BaseObjectPoolConfig.DEFAULT_MAX_WAIT_MILLIS + "."); } @@ -170,10 +170,10 @@ public class BasicDataSourceFactory impl private static final List<String> SILENT_PROPERTIES = new ArrayList<>(); static { - SILENT_PROPERTIES.add(SILENTPROP_FACTORY); - SILENT_PROPERTIES.add(SILENTPROP_SCOPE); - SILENT_PROPERTIES.add(SILENTPROP_SINGLETON); - SILENT_PROPERTIES.add(SILENTPROP_AUTH); + SILENT_PROPERTIES.add(SILENT_PROP_FACTORY); + SILENT_PROPERTIES.add(SILENT_PROP_SCOPE); + SILENT_PROPERTIES.add(SILENT_PROP_SINGLETON); + SILENT_PROPERTIES.add(SILENT_PROP_AUTH); } @@ -297,19 +297,19 @@ public class BasicDataSourceFactory impl final BasicDataSource dataSource = new BasicDataSource(); String value = null; - value = properties.getProperty(PROP_DEFAULTAUTOCOMMIT); + value = properties.getProperty(PROP_DEFAULT_AUTO_COMMIT); if (value != null) { dataSource.setDefaultAutoCommit(Boolean.valueOf(value)); } - value = properties.getProperty(PROP_DEFAULTREADONLY); + value = properties.getProperty(PROP_DEFAULT_READ_ONLY); if (value != null) { dataSource.setDefaultReadOnly(Boolean.valueOf(value)); } - value = properties.getProperty(PROP_DEFAULTTRANSACTIONISOLATION); + value = properties.getProperty(PROP_DEFAULT_TRANSACTION_ISOLATION); if (value != null) { - int level = PoolableConnectionFactory.UNKNOWN_TRANSACTIONISOLATION; + int level = PoolableConnectionFactory.UNKNOWN_TRANSACTION_ISOLATION; if ("NONE".equalsIgnoreCase(value)) { level = Connection.TRANSACTION_NONE; } else if ("READ_COMMITTED".equalsIgnoreCase(value)) { @@ -327,28 +327,28 @@ public class BasicDataSourceFactory impl System.err.println("Could not parse defaultTransactionIsolation: " + value); System.err.println("WARNING: defaultTransactionIsolation not set"); System.err.println("using default value of database driver"); - level = PoolableConnectionFactory.UNKNOWN_TRANSACTIONISOLATION; + level = PoolableConnectionFactory.UNKNOWN_TRANSACTION_ISOLATION; } } dataSource.setDefaultTransactionIsolation(level); } - value = properties.getProperty(PROP_DEFAULTCATALOG); + value = properties.getProperty(PROP_DEFAULT_CATALOG); if (value != null) { dataSource.setDefaultCatalog(value); } - value = properties.getProperty(PROP_DEFAULTSCHEMA); + value = properties.getProperty(PROP_DEFAULT_SCHEMA); if (value != null) { dataSource.setDefaultSchema(value); } - value = properties.getProperty(PROP_CACHESTATE); + value = properties.getProperty(PROP_CACHE_STATE); if (value != null) { dataSource.setCacheState(Boolean.valueOf(value).booleanValue()); } - value = properties.getProperty(PROP_DRIVERCLASSNAME); + value = properties.getProperty(PROP_DRIVER_CLASS_NAME); if (value != null) { dataSource.setDriverClassName(value); } @@ -358,72 +358,72 @@ public class BasicDataSourceFactory impl dataSource.setLifo(Boolean.valueOf(value).booleanValue()); } - value = properties.getProperty(PROP_MAXTOTAL); + value = properties.getProperty(PROP_MAX_TOTAL); if (value != null) { dataSource.setMaxTotal(Integer.parseInt(value)); } - value = properties.getProperty(PROP_MAXIDLE); + value = properties.getProperty(PROP_MAX_IDLE); if (value != null) { dataSource.setMaxIdle(Integer.parseInt(value)); } - value = properties.getProperty(PROP_MINIDLE); + value = properties.getProperty(PROP_MIN_IDLE); if (value != null) { dataSource.setMinIdle(Integer.parseInt(value)); } - value = properties.getProperty(PROP_INITIALSIZE); + value = properties.getProperty(PROP_INITIAL_SIZE); if (value != null) { dataSource.setInitialSize(Integer.parseInt(value)); } - value = properties.getProperty(PROP_MAXWAITMILLIS); + value = properties.getProperty(PROP_MAX_WAIT_MILLIS); if (value != null) { dataSource.setMaxWaitMillis(Long.parseLong(value)); } - value = properties.getProperty(PROP_TESTONCREATE); + value = properties.getProperty(PROP_TEST_ON_CREATE); if (value != null) { dataSource.setTestOnCreate(Boolean.valueOf(value).booleanValue()); } - value = properties.getProperty(PROP_TESTONBORROW); + value = properties.getProperty(PROP_TEST_ON_BORROW); if (value != null) { dataSource.setTestOnBorrow(Boolean.valueOf(value).booleanValue()); } - value = properties.getProperty(PROP_TESTONRETURN); + value = properties.getProperty(PROP_TEST_ON_RETURN); if (value != null) { dataSource.setTestOnReturn(Boolean.valueOf(value).booleanValue()); } - value = properties.getProperty(PROP_TIMEBETWEENEVICTIONRUNSMILLIS); + value = properties.getProperty(PROP_TIME_BETWEEN_EVICTION_RUNS_MILLIS); if (value != null) { dataSource.setTimeBetweenEvictionRunsMillis(Long.parseLong(value)); } - value = properties.getProperty(PROP_NUMTESTSPEREVICTIONRUN); + value = properties.getProperty(PROP_NUM_TESTS_PER_EVICTION_RUN); if (value != null) { dataSource.setNumTestsPerEvictionRun(Integer.parseInt(value)); } - value = properties.getProperty(PROP_MINEVICTABLEIDLETIMEMILLIS); + value = properties.getProperty(PROP_MIN_EVICTABLE_IDLE_TIME_MILLIS); if (value != null) { dataSource.setMinEvictableIdleTimeMillis(Long.parseLong(value)); } - value = properties.getProperty(PROP_SOFTMINEVICTABLEIDLETIMEMILLIS); + value = properties.getProperty(PROP_SOFT_MIN_EVICTABLE_IDLE_TIME_MILLIS); if (value != null) { dataSource.setSoftMinEvictableIdleTimeMillis(Long.parseLong(value)); } - value = properties.getProperty(PROP_EVICTIONPOLICYCLASSNAME); + value = properties.getProperty(PROP_EVICTION_POLICY_CLASS_NAME); if (value != null) { dataSource.setEvictionPolicyClassName(value); } - value = properties.getProperty(PROP_TESTWHILEIDLE); + value = properties.getProperty(PROP_TEST_WHILE_IDLE); if (value != null) { dataSource.setTestWhileIdle(Boolean.valueOf(value).booleanValue()); } @@ -438,67 +438,67 @@ public class BasicDataSourceFactory impl dataSource.setUrl(value); } - value = properties.getProperty(PROP_USERNAME); + value = properties.getProperty(PROP_USER_NAME); if (value != null) { dataSource.setUsername(value); } - value = properties.getProperty(PROP_VALIDATIONQUERY); + value = properties.getProperty(PROP_VALIDATION_QUERY); if (value != null) { dataSource.setValidationQuery(value); } - value = properties.getProperty(PROP_VALIDATIONQUERY_TIMEOUT); + value = properties.getProperty(PROP_VALIDATION_QUERY_TIMEOUT); if (value != null) { dataSource.setValidationQueryTimeout(Integer.parseInt(value)); } - value = properties.getProperty(PROP_ACCESSTOUNDERLYINGCONNECTIONALLOWED); + value = properties.getProperty(PROP_ACCESS_TO_UNDERLYING_CONNECTION_ALLOWED); if (value != null) { dataSource.setAccessToUnderlyingConnectionAllowed(Boolean.valueOf(value).booleanValue()); } - value = properties.getProperty(PROP_REMOVEABANDONEDONBORROW); + value = properties.getProperty(PROP_REMOVE_ABANDONED_ON_BORROW); if (value != null) { dataSource.setRemoveAbandonedOnBorrow(Boolean.valueOf(value).booleanValue()); } - value = properties.getProperty(PROP_REMOVEABANDONEDONMAINTENANCE); + value = properties.getProperty(PROP_REMOVE_ABANDONED_ON_MAINTENANCE); if (value != null) { dataSource.setRemoveAbandonedOnMaintenance(Boolean.valueOf(value).booleanValue()); } - value = properties.getProperty(PROP_REMOVEABANDONEDTIMEOUT); + value = properties.getProperty(PROP_REMOVE_ABANDONED_TIMEOUT); if (value != null) { dataSource.setRemoveAbandonedTimeout(Integer.parseInt(value)); } - value = properties.getProperty(PROP_LOGABANDONED); + value = properties.getProperty(PROP_LOG_ABANDONED); if (value != null) { dataSource.setLogAbandoned(Boolean.valueOf(value).booleanValue()); } - value = properties.getProperty(PROP_ABANDONEDUSAGETRACKING); + value = properties.getProperty(PROP_ABANDONED_USAGE_TRACKING); if (value != null) { dataSource.setAbandonedUsageTracking(Boolean.valueOf(value).booleanValue()); } - value = properties.getProperty(PROP_POOLPREPAREDSTATEMENTS); + value = properties.getProperty(PROP_POOL_PREPARED_STATEMENTS); if (value != null) { dataSource.setPoolPreparedStatements(Boolean.valueOf(value).booleanValue()); } - value = properties.getProperty(PROP_MAXOPENPREPAREDSTATEMENTS); + value = properties.getProperty(PROP_MAX_OPEN_PREPARED_STATEMENTS); if (value != null) { dataSource.setMaxOpenPreparedStatements(Integer.parseInt(value)); } - value = properties.getProperty(PROP_CONNECTIONINITSQLS); + value = properties.getProperty(PROP_CONNECTION_INIT_SQLS); if (value != null) { dataSource.setConnectionInitSqls(parseList(value, ';')); } - value = properties.getProperty(PROP_CONNECTIONPROPERTIES); + value = properties.getProperty(PROP_CONNECTION_PROPERTIES); if (value != null) { final Properties p = getProperties(value); final Enumeration<?> e = p.propertyNames(); @@ -508,12 +508,12 @@ public class BasicDataSourceFactory impl } } - value = properties.getProperty(PROP_MAXCONNLIFETIMEMILLIS); + value = properties.getProperty(PROP_MAX_CONN_LIFETIME_MILLIS); if (value != null) { dataSource.setMaxConnLifetimeMillis(Long.parseLong(value)); } - value = properties.getProperty(PROP_LOGEXPIREDCONNECTIONS); + value = properties.getProperty(PROP_LOG_EXPIRED_CONNECTIONS); if (value != null) { dataSource.setLogExpiredConnections(Boolean.valueOf(value).booleanValue()); } @@ -523,9 +523,9 @@ public class BasicDataSourceFactory impl dataSource.setJmxName(value); } - value = properties.getProperty(PROP_ENABLE_AUTOCOMMIT_ON_RETURN); + value = properties.getProperty(PROP_ENABLE_AUTO_COMMIT_ON_RETURN); if (value != null) { - dataSource.setEnableAutoCommitOnReturn(Boolean.valueOf(value).booleanValue()); + dataSource.setAutoCommitOnReturn(Boolean.valueOf(value).booleanValue()); } value = properties.getProperty(PROP_ROLLBACK_ON_RETURN); @@ -533,12 +533,12 @@ public class BasicDataSourceFactory impl dataSource.setRollbackOnReturn(Boolean.valueOf(value).booleanValue()); } - value = properties.getProperty(PROP_DEFAULT_QUERYTIMEOUT); + value = properties.getProperty(PROP_DEFAULT_QUERY_TIMEOUT); if (value != null) { dataSource.setDefaultQueryTimeout(Integer.valueOf(value)); } - value = properties.getProperty(PROP_FASTFAIL_VALIDATION); + value = properties.getProperty(PROP_FAST_FAIL_VALIDATION); if (value != null) { dataSource.setFastFailValidation(Boolean.valueOf(value).booleanValue()); }
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=1852459&r1=1852458&r2=1852459&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/tomcat/dbcp/dbcp2/DataSourceConnectionFactory.java (original) +++ tomcat/trunk/java/org/apache/tomcat/dbcp/dbcp2/DataSourceConnectionFactory.java Tue Jan 29 15:03:15 2019 @@ -58,7 +58,7 @@ public class DataSourceConnectionFactory public DataSourceConnectionFactory(final DataSource dataSource, final String userName, final char[] userPassword) { this.dataSource = dataSource; this.userName = userName; - this.userPassword = userPassword; + this.userPassword = Utils.clone(userPassword); } /** @@ -84,4 +84,28 @@ public class DataSourceConnectionFactory } return dataSource.getConnection(userName, Utils.toString(userPassword)); } + + /** + * @return The data source. + * @since 2.6.0 + */ + public DataSource getDataSource() { + return dataSource; + } + + /** + * @return The user name. + * @since 2.6.0 + */ + public String getUserName() { + return userName; + } + + /** + * @return The user password. + * @since 2.6.0 + */ + public char[] getUserPassword() { + return userPassword; + } } Modified: tomcat/trunk/java/org/apache/tomcat/dbcp/dbcp2/DelegatingConnection.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/dbcp/dbcp2/DelegatingConnection.java?rev=1852459&r1=1852458&r2=1852459&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/tomcat/dbcp/dbcp2/DelegatingConnection.java (original) +++ tomcat/trunk/java/org/apache/tomcat/dbcp/dbcp2/DelegatingConnection.java Tue Jan 29 15:03:15 2019 @@ -88,7 +88,7 @@ public class DelegatingConnection<C exte * Returns a string representation of the metadata associated with the innermost delegate connection. */ @Override - public String toString() { + public synchronized String toString() { String s = null; final Connection c = this.getInnermostDelegateInternal(); @@ -928,7 +928,7 @@ public class DelegatingConnection<C exte public void setSchema(final String schema) throws SQLException { checkOpen(); try { - connection.setSchema(schema); + Jdbc41Bridge.setSchema(connection, schema); } catch (final SQLException e) { handleException(e); } @@ -938,7 +938,7 @@ public class DelegatingConnection<C exte public String getSchema() throws SQLException { checkOpen(); try { - return connection.getSchema(); + return Jdbc41Bridge.getSchema(connection); } catch (final SQLException e) { handleException(e); return null; @@ -949,7 +949,7 @@ public class DelegatingConnection<C exte public void abort(final Executor executor) throws SQLException { checkOpen(); try { - connection.abort(executor); + Jdbc41Bridge.abort(connection, executor); } catch (final SQLException e) { handleException(e); } @@ -959,7 +959,7 @@ public class DelegatingConnection<C exte public void setNetworkTimeout(final Executor executor, final int milliseconds) throws SQLException { checkOpen(); try { - connection.setNetworkTimeout(executor, milliseconds); + Jdbc41Bridge.setNetworkTimeout(connection, executor, milliseconds); } catch (final SQLException e) { handleException(e); } @@ -969,7 +969,7 @@ public class DelegatingConnection<C exte public int getNetworkTimeout() throws SQLException { checkOpen(); try { - return connection.getNetworkTimeout(); + return Jdbc41Bridge.getNetworkTimeout(connection); } catch (final SQLException e) { handleException(e); return 0; Modified: tomcat/trunk/java/org/apache/tomcat/dbcp/dbcp2/DelegatingDatabaseMetaData.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/dbcp/dbcp2/DelegatingDatabaseMetaData.java?rev=1852459&r1=1852458&r2=1852459&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/tomcat/dbcp/dbcp2/DelegatingDatabaseMetaData.java (original) +++ tomcat/trunk/java/org/apache/tomcat/dbcp/dbcp2/DelegatingDatabaseMetaData.java Tue Jan 29 15:03:15 2019 @@ -130,7 +130,7 @@ public class DelegatingDatabaseMetaData public boolean generatedKeyAlwaysReturned() throws SQLException { connection.checkOpen(); try { - return databaseMetaData.generatedKeyAlwaysReturned(); + return Jdbc41Bridge.generatedKeyAlwaysReturned(databaseMetaData); } catch (final SQLException e) { handleException(e); return false; @@ -744,8 +744,8 @@ public class DelegatingDatabaseMetaData final String columnNamePattern) throws SQLException { connection.checkOpen(); try { - return DelegatingResultSet.wrapResultSet(connection, - databaseMetaData.getPseudoColumns(catalog, schemaPattern, tableNamePattern, columnNamePattern)); + return DelegatingResultSet.wrapResultSet(connection, Jdbc41Bridge.getPseudoColumns(databaseMetaData, + catalog, schemaPattern, tableNamePattern, columnNamePattern)); } catch (final SQLException e) { handleException(e); throw new AssertionError(); Modified: tomcat/trunk/java/org/apache/tomcat/dbcp/dbcp2/DelegatingPreparedStatement.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/dbcp/dbcp2/DelegatingPreparedStatement.java?rev=1852459&r1=1852458&r2=1852459&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/tomcat/dbcp/dbcp2/DelegatingPreparedStatement.java (original) +++ tomcat/trunk/java/org/apache/tomcat/dbcp/dbcp2/DelegatingPreparedStatement.java Tue Jan 29 15:03:15 2019 @@ -688,7 +688,7 @@ public class DelegatingPreparedStatement */ @SuppressWarnings("resource") @Override - public String toString() { + public synchronized String toString() { final Statement statement = getDelegate(); return statement == null ? "NULL" : statement.toString(); } Modified: tomcat/trunk/java/org/apache/tomcat/dbcp/dbcp2/DelegatingResultSet.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/dbcp/dbcp2/DelegatingResultSet.java?rev=1852459&r1=1852458&r2=1852459&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/tomcat/dbcp/dbcp2/DelegatingResultSet.java (original) +++ tomcat/trunk/java/org/apache/tomcat/dbcp/dbcp2/DelegatingResultSet.java Tue Jan 29 15:03:15 2019 @@ -740,7 +740,7 @@ public final class DelegatingResultSet e @Override public <T> T getObject(final int columnIndex, final Class<T> type) throws SQLException { try { - return resultSet.getObject(columnIndex, type); + return Jdbc41Bridge.getObject(resultSet, columnIndex, type); } catch (final SQLException e) { handleException(e); return null; @@ -770,7 +770,7 @@ public final class DelegatingResultSet e @Override public <T> T getObject(final String columnLabel, final Class<T> type) throws SQLException { try { - return resultSet.getObject(columnLabel, type); + return Jdbc41Bridge.getObject(resultSet, columnLabel, type); } catch (final SQLException e) { handleException(e); return null; @@ -1242,8 +1242,8 @@ public final class DelegatingResultSet e } @Override - public String toString() { - return super.toString() + "[_res=" + resultSet + ", _stmt=" + statement + ", _conn=" + connection + "]"; + public synchronized String toString() { + return super.toString() + "[resultSet=" + resultSet + ", statement=" + statement + ", connection=" + connection + "]"; } @Override Modified: tomcat/trunk/java/org/apache/tomcat/dbcp/dbcp2/DelegatingStatement.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/dbcp/dbcp2/DelegatingStatement.java?rev=1852459&r1=1852458&r2=1852459&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/tomcat/dbcp/dbcp2/DelegatingStatement.java (original) +++ tomcat/trunk/java/org/apache/tomcat/dbcp/dbcp2/DelegatingStatement.java Tue Jan 29 15:03:15 2019 @@ -161,7 +161,7 @@ public class DelegatingStatement extends public void closeOnCompletion() throws SQLException { checkOpen(); try { - statement.closeOnCompletion(); + Jdbc41Bridge.closeOnCompletion(statement); } catch (final SQLException e) { handleException(e); } @@ -630,7 +630,7 @@ public class DelegatingStatement extends public boolean isCloseOnCompletion() throws SQLException { checkOpen(); try { - return statement.isCloseOnCompletion(); + return Jdbc41Bridge.isCloseOnCompletion(statement); } catch (final SQLException e) { handleException(e); return false; @@ -790,7 +790,7 @@ public class DelegatingStatement extends * @return String */ @Override - public String toString() { + public synchronized String toString() { return statement == null ? "NULL" : statement.toString(); } Modified: tomcat/trunk/java/org/apache/tomcat/dbcp/dbcp2/DriverConnectionFactory.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/dbcp/dbcp2/DriverConnectionFactory.java?rev=1852459&r1=1852458&r2=1852459&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/tomcat/dbcp/dbcp2/DriverConnectionFactory.java (original) +++ tomcat/trunk/java/org/apache/tomcat/dbcp/dbcp2/DriverConnectionFactory.java Tue Jan 29 15:03:15 2019 @@ -53,6 +53,30 @@ public class DriverConnectionFactory imp return driver.connect(connectionString, properties); } + /** + * @return The connection String. + * @since 2.6.0 + */ + public String getConnectionString() { + return connectionString; + } + + /** + * @return The Driver. + * @since 2.6.0 + */ + public Driver getDriver() { + return driver; + } + + /** + * @return The Properties. + * @since 2.6.0 + */ + public Properties getProperties() { + return properties; + } + @Override public String toString() { return this.getClass().getName() + " [" + String.valueOf(driver) + ";" + String.valueOf(connectionString) + ";" Modified: tomcat/trunk/java/org/apache/tomcat/dbcp/dbcp2/DriverManagerConnectionFactory.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/dbcp/dbcp2/DriverManagerConnectionFactory.java?rev=1852459&r1=1852458&r2=1852459&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/tomcat/dbcp/dbcp2/DriverManagerConnectionFactory.java (original) +++ tomcat/trunk/java/org/apache/tomcat/dbcp/dbcp2/DriverManagerConnectionFactory.java Tue Jan 29 15:03:15 2019 @@ -38,6 +38,14 @@ public class DriverManagerConnectionFact DriverManager.getDrivers(); } + private final String connectionUri; + + private final String userName; + + private final char[] userPassword; + + private final Properties properties; + /** * Constructor for DriverManagerConnectionFactory. * @@ -48,6 +56,8 @@ public class DriverManagerConnectionFact public DriverManagerConnectionFactory(final String connectionUri) { this.connectionUri = connectionUri; this.properties = new Properties(); + this.userName = null; + this.userPassword = null; } /** @@ -62,6 +72,26 @@ public class DriverManagerConnectionFact public DriverManagerConnectionFactory(final String connectionUri, final Properties properties) { this.connectionUri = connectionUri; this.properties = properties; + this.userName = null; + this.userPassword = null; + } + + /** + * Constructor for DriverManagerConnectionFactory. + * + * @param connectionUri + * a database url of the form <code>jdbc:<em>subprotocol</em>:<em>subname</em></code> + * @param userName + * the database user + * @param userPassword + * the user's password + */ + public DriverManagerConnectionFactory(final String connectionUri, final String userName, + final char[] userPassword) { + this.connectionUri = connectionUri; + this.userName = userName; + this.userPassword = Utils.clone(userPassword); + this.properties = null; } /** @@ -78,7 +108,8 @@ public class DriverManagerConnectionFact final String userPassword) { this.connectionUri = connectionUri; this.userName = userName; - this.userPassword = userPassword; + this.userPassword = Utils.toCharArray(userPassword); + this.properties = null; } @Override @@ -87,13 +118,32 @@ public class DriverManagerConnectionFact if (userName == null && userPassword == null) { return DriverManager.getConnection(connectionUri); } - return DriverManager.getConnection(connectionUri, userName, userPassword); + return DriverManager.getConnection(connectionUri, userName, Utils.toString(userPassword)); } return DriverManager.getConnection(connectionUri, properties); } - private final String connectionUri; - private String userName; - private String userPassword; - private Properties properties; + /** + * @return The connection URI. + * @since 2.6.0 + */ + public String getConnectionUri() { + return connectionUri; + } + + /** + * @return The Properties. + * @since 2.6.0 + */ + public Properties getProperties() { + return properties; + } + + /** + * @return The user name. + * @since 2.6.0 + */ + public String getUserName() { + return userName; + } } Added: tomcat/trunk/java/org/apache/tomcat/dbcp/dbcp2/Jdbc41Bridge.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/dbcp/dbcp2/Jdbc41Bridge.java?rev=1852459&view=auto ============================================================================== --- tomcat/trunk/java/org/apache/tomcat/dbcp/dbcp2/Jdbc41Bridge.java (added) +++ tomcat/trunk/java/org/apache/tomcat/dbcp/dbcp2/Jdbc41Bridge.java Tue Jan 29 15:03:15 2019 @@ -0,0 +1,483 @@ +/** + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + */ +package org.apache.tomcat.dbcp.dbcp2; + +import java.io.InputStream; +import java.io.Reader; +import java.math.BigDecimal; +import java.net.URL; +import java.sql.Array; +import java.sql.Blob; +import java.sql.Clob; +import java.sql.Connection; +import java.sql.DatabaseMetaData; +import java.sql.Date; +import java.sql.Ref; +import java.sql.ResultSet; +import java.sql.RowId; +import java.sql.SQLException; +import java.sql.SQLFeatureNotSupportedException; +import java.sql.SQLXML; +import java.sql.Statement; +import java.sql.Time; +import java.sql.Timestamp; +import java.util.concurrent.Executor; +import java.util.logging.Logger; + +import javax.sql.CommonDataSource; + +/** + * Defines bridge methods to JDBC 4.1 (Java 7) methods to allow call sites to operate safely (without + * {@link AbstractMethodError}) when using a JDBC driver written for JDBC 4.0 (Java 6). + * + * @since 2.6.0 + */ +public class Jdbc41Bridge { + + /** + * Delegates to {@link Connection#abort(Executor)} without throwing a {@link AbstractMethodError}. + * <p> + * If the JDBC driver does not implement {@link Connection#abort(Executor)}, then call {@link Connection#close()}. + * </p> + * + * @param connection + * the receiver + * @param executor + * See {@link Connection#abort(Executor)}. + * @throws SQLException + * See {@link Connection#abort(Executor)}. + * @see Connection#abort(Executor) + */ + public static void abort(final Connection connection, final Executor executor) throws SQLException { + try { + connection.abort(executor); + } catch (final AbstractMethodError e) { + connection.close(); + } + } + + /** + * Delegates to {@link DatabaseMetaData#generatedKeyAlwaysReturned()} without throwing a + * {@link AbstractMethodError}. + * <p> + * If the JDBC driver does not implement {@link DatabaseMetaData#generatedKeyAlwaysReturned()}, then return false. + * </p> + * + * @param databaseMetaData + * See {@link DatabaseMetaData#generatedKeyAlwaysReturned()} + * @return See {@link DatabaseMetaData#generatedKeyAlwaysReturned()} + * @throws SQLException + * See {@link DatabaseMetaData#generatedKeyAlwaysReturned()} + * @see DatabaseMetaData#generatedKeyAlwaysReturned() + */ + public static boolean generatedKeyAlwaysReturned(final DatabaseMetaData databaseMetaData) throws SQLException { + try { + return databaseMetaData.generatedKeyAlwaysReturned(); + } catch (final AbstractMethodError e) { + // do nothing + return false; + } + } + + /** + * Delegates to {@link Connection#getNetworkTimeout()} without throwing a {@link AbstractMethodError}. + * <p> + * If the JDBC driver does not implement {@link Connection#getNetworkTimeout()}, then return 0. + * </p> + * + * @param connection + * the receiver + * @return See {@link Connection#getNetworkTimeout()} + * @throws SQLException + * See {@link Connection#getNetworkTimeout()} + * @see Connection#getNetworkTimeout() + */ + public static int getNetworkTimeout(final Connection connection) throws SQLException { + try { + return connection.getNetworkTimeout(); + } catch (final AbstractMethodError e) { + return 0; + } + } + + /** + * Delegates to {@link ResultSet#getObject(int, Class)} without throwing a {@link AbstractMethodError}. + * <p> + * If the JDBC driver does not implement {@link ResultSet#getObject(int, Class)}, then return 0. + * </p> + * + * @param <T> + * See {@link ResultSet#getObject(int, Class)} + * @param resultSet + * See {@link ResultSet#getObject(int, Class)} + * @param columnIndex + * See {@link ResultSet#getObject(int, Class)} + * @param type + * See {@link ResultSet#getObject(int, Class)} + * @return See {@link ResultSet#getObject(int, Class)} + * @throws SQLException + * See {@link ResultSet#getObject(int, Class)} + * @see ResultSet#getObject(int, Class) + */ + @SuppressWarnings("unchecked") + public static <T> T getObject(final ResultSet resultSet, final int columnIndex, final Class<T> type) + throws SQLException { + try { + return resultSet.getObject(columnIndex, type); + } catch (final AbstractMethodError e) { + if (type == String.class) { + return (T) resultSet.getString(columnIndex); + } + // Numbers + if (type == Integer.class) { + return (T) Integer.valueOf(resultSet.getInt(columnIndex)); + } + if (type == Long.class) { + return (T) Long.valueOf(resultSet.getLong(columnIndex)); + } + if (type == Double.class) { + return (T) Double.valueOf(resultSet.getDouble(columnIndex)); + } + if (type == Float.class) { + return (T) Float.valueOf(resultSet.getFloat(columnIndex)); + } + if (type == Short.class) { + return (T) Short.valueOf(resultSet.getShort(columnIndex)); + } + if (type == BigDecimal.class) { + return (T) resultSet.getBigDecimal(columnIndex); + } + if (type == Byte.class) { + return (T) Byte.valueOf(resultSet.getByte(columnIndex)); + } + // Dates + if (type == Date.class) { + return (T) resultSet.getDate(columnIndex); + } + if (type == Time.class) { + return (T) resultSet.getTime(columnIndex); + } + if (type == Timestamp.class) { + return (T) resultSet.getTimestamp(columnIndex); + } + // Streams + if (type == InputStream.class) { + return (T) resultSet.getBinaryStream(columnIndex); + } + if (type == Reader.class) { + return (T) resultSet.getCharacterStream(columnIndex); + } + // Other + if (type == Object.class) { + return (T) resultSet.getObject(columnIndex); + } + if (type == Boolean.class) { + return (T) Boolean.valueOf(resultSet.getBoolean(columnIndex)); + } + if (type == Array.class) { + return (T) resultSet.getArray(columnIndex); + } + if (type == Blob.class) { + return (T) resultSet.getBlob(columnIndex); + } + if (type == Clob.class) { + return (T) resultSet.getClob(columnIndex); + } + if (type == Ref.class) { + return (T) resultSet.getRef(columnIndex); + } + if (type == RowId.class) { + return (T) resultSet.getRowId(columnIndex); + } + if (type == SQLXML.class) { + return (T) resultSet.getSQLXML(columnIndex); + } + if (type == URL.class) { + return (T) resultSet.getURL(columnIndex); + } + throw new SQLFeatureNotSupportedException( + String.format("resultSet=%s, columnIndex=%,d, type=%s", resultSet, Integer.valueOf(columnIndex), type)); + } + } + + /** + * Delegates to {@link ResultSet#getObject(String, Class)} without throwing a {@link AbstractMethodError}. + * + * @param <T> + * See {@link ResultSet#getObject(String, Class)} + * @param resultSet + * See {@link ResultSet#getObject(String, Class)} + * @param columnLabel + * See {@link ResultSet#getObject(String, Class)} + * @param type + * See {@link ResultSet#getObject(String, Class)} + * @return See {@link ResultSet#getObject(String, Class)} + * @throws SQLException + * See {@link ResultSet#getObject(String, Class)} + * @see ResultSet#getObject(int, Class) + */ + @SuppressWarnings("unchecked") + public static <T> T getObject(final ResultSet resultSet, final String columnLabel, final Class<T> type) + throws SQLException { + try { + return resultSet.getObject(columnLabel, type); + } catch (final AbstractMethodError e) { + // Numbers + if (type == Integer.class) { + return (T) Integer.valueOf(resultSet.getInt(columnLabel)); + } + if (type == Long.class) { + return (T) Long.valueOf(resultSet.getLong(columnLabel)); + } + if (type == Double.class) { + return (T) Double.valueOf(resultSet.getDouble(columnLabel)); + } + if (type == Float.class) { + return (T) Float.valueOf(resultSet.getFloat(columnLabel)); + } + if (type == Short.class) { + return (T) Short.valueOf(resultSet.getShort(columnLabel)); + } + if (type == BigDecimal.class) { + return (T) resultSet.getBigDecimal(columnLabel); + } + if (type == Byte.class) { + return (T) Byte.valueOf(resultSet.getByte(columnLabel)); + } + // Dates + if (type == Date.class) { + return (T) resultSet.getDate(columnLabel); + } + if (type == Time.class) { + return (T) resultSet.getTime(columnLabel); + } + if (type == Timestamp.class) { + return (T) resultSet.getTimestamp(columnLabel); + } + // Streams + if (type == InputStream.class) { + return (T) resultSet.getBinaryStream(columnLabel); + } + if (type == Reader.class) { + return (T) resultSet.getCharacterStream(columnLabel); + } + // Other + if (type == Object.class) { + return (T) resultSet.getObject(columnLabel); + } + if (type == Boolean.class) { + return (T) Boolean.valueOf(resultSet.getBoolean(columnLabel)); + } + if (type == Array.class) { + return (T) resultSet.getArray(columnLabel); + } + if (type == Blob.class) { + return (T) resultSet.getBlob(columnLabel); + } + if (type == Clob.class) { + return (T) resultSet.getClob(columnLabel); + } + if (type == Ref.class) { + return (T) resultSet.getRef(columnLabel); + } + if (type == RowId.class) { + return (T) resultSet.getRowId(columnLabel); + } + if (type == SQLXML.class) { + return (T) resultSet.getSQLXML(columnLabel); + } + if (type == URL.class) { + return (T) resultSet.getURL(columnLabel); + } + throw new SQLFeatureNotSupportedException( + String.format("resultSet=%s, columnLabel=%,d, type=%s", resultSet, columnLabel, type)); + } + } + + /** + * Delegates to {@link DatabaseMetaData#getPseudoColumns(String, String, String, String)} without throwing a + * {@link AbstractMethodError}. + * <p> + * If the JDBC driver does not implement {@link DatabaseMetaData#getPseudoColumns(String, String, String, String)}, + * then return null. + * </p> + * + * @param databaseMetaData + * the receiver + * @param catalog + * See {@link DatabaseMetaData#getPseudoColumns(String, String, String, String)} + * @param schemaPattern + * See {@link DatabaseMetaData#getPseudoColumns(String, String, String, String)} + * @param tableNamePattern + * See {@link DatabaseMetaData#getPseudoColumns(String, String, String, String)} + * @param columnNamePattern + * See {@link DatabaseMetaData#getPseudoColumns(String, String, String, String)} + * @return See {@link DatabaseMetaData#getPseudoColumns(String, String, String, String)} + * @throws SQLException + * See {@link DatabaseMetaData#getPseudoColumns(String, String, String, String)} + * @see DatabaseMetaData#getPseudoColumns(String, String, String, String) + */ + public static ResultSet getPseudoColumns(final DatabaseMetaData databaseMetaData, final String catalog, + final String schemaPattern, final String tableNamePattern, final String columnNamePattern) + throws SQLException { + try { + return databaseMetaData.getPseudoColumns(catalog, schemaPattern, tableNamePattern, columnNamePattern); + } catch (final AbstractMethodError e) { + // do nothing + return null; + } + } + + /** + * Delegates to {@link Connection#getSchema()} without throwing a {@link AbstractMethodError}. + * <p> + * If the JDBC driver does not implement {@link Connection#getSchema()}, then return null. + * </p> + * + * @param connection + * the receiver + * @return null for a JDBC 4 driver or a value per {@link Connection#getSchema()}. + * @throws SQLException + * See {@link Connection#getSchema()}. + * @see Connection#getSchema() + */ + public static String getSchema(final Connection connection) throws SQLException { + try { + return connection.getSchema(); + } catch (final AbstractMethodError e) { + // do nothing + return null; + } + } + + /** + * Delegates to {@link Connection#setNetworkTimeout(Executor, int)} without throwing a {@link AbstractMethodError}. + * <p> + * If the JDBC driver does not implement {@link Connection#setNetworkTimeout(Executor, int)}, then do nothing. + * </p> + * + * @param connection + * the receiver + * @param executor + * See {@link Connection#setNetworkTimeout(Executor, int)} + * @param milliseconds + * {@link Connection#setNetworkTimeout(Executor, int)} + * @throws SQLException + * {@link Connection#setNetworkTimeout(Executor, int)} + * @see Connection#setNetworkTimeout(Executor, int) + */ + public static void setNetworkTimeout(final Connection connection, final Executor executor, final int milliseconds) + throws SQLException { + try { + connection.setNetworkTimeout(executor, milliseconds); + } catch (final AbstractMethodError e) { + // do nothing + } + } + + /** + * Delegates to {@link Connection#setSchema(String)} without throwing a {@link AbstractMethodError}. + * <p> + * If the JDBC driver does not implement {@link Connection#setSchema(String)}, then do nothing. + * </p> + * + * @param connection + * the receiver + * @param schema + * See {@link Connection#setSchema(String)}. + * @throws SQLException + * See {@link Connection#setSchema(String)}. + * @see Connection#setSchema(String) + */ + public static void setSchema(final Connection connection, final String schema) throws SQLException { + try { + connection.setSchema(schema); + } catch (final AbstractMethodError e) { + // do nothing + } + } + + /** + * Delegates to {@link Statement#closeOnCompletion()} without throwing a {@link AbstractMethodError}. + * <p> + * If the JDBC driver does not implement {@link Statement#closeOnCompletion()}, then just check that the connection + * is closed to then throw a SQLException. + * </p> + * + * @param statement + * See {@link Statement#closeOnCompletion()} + * @throws SQLException + * See {@link Statement#closeOnCompletion()} + * @see Statement#closeOnCompletion() + */ + public static void closeOnCompletion(final Statement statement) throws SQLException { + try { + statement.closeOnCompletion(); + } catch (final AbstractMethodError e) { + if (statement.isClosed()) { + throw new SQLException("Statement closed"); + } + } + } + + /** + * Delegates to {@link Statement#isCloseOnCompletion()} without throwing a {@link AbstractMethodError}. + * <p> + * If the JDBC driver does not implement {@link Statement#isCloseOnCompletion()}, then just check that the + * connection is closed to then throw a SQLException. + * </p> + * + * @param statement + * See {@link Statement#isCloseOnCompletion()} + * @return See {@link Statement#isCloseOnCompletion()} + * @throws SQLException + * See {@link Statement#isCloseOnCompletion()} + * @see Statement#closeOnCompletion() + */ + public static boolean isCloseOnCompletion(final Statement statement) throws SQLException { + try { + return statement.isCloseOnCompletion(); + } catch (final AbstractMethodError e) { + if (statement.isClosed()) { + throw new SQLException("Statement closed"); + } + return false; + } + } + + /** + * Delegates to {@link CommonDataSource#getParentLogger()} without throwing a {@link AbstractMethodError}. + * <p> + * If the JDBC driver does not implement {@link CommonDataSource#getParentLogger()}, then return null. + * </p> + * + * @param commonDataSource + * See {@link CommonDataSource#getParentLogger()} + * @return See {@link CommonDataSource#getParentLogger()} + * @throws SQLFeatureNotSupportedException + * See {@link CommonDataSource#getParentLogger()} + */ + public static Logger getParentLogger(final CommonDataSource commonDataSource) throws SQLFeatureNotSupportedException { + try { + return commonDataSource.getParentLogger(); + } catch (final AbstractMethodError e) { + throw new SQLFeatureNotSupportedException("javax.sql.CommonDataSource#getParentLogger()"); + } + } + +} Propchange: tomcat/trunk/java/org/apache/tomcat/dbcp/dbcp2/Jdbc41Bridge.java ------------------------------------------------------------------------------ svn:eol-style = native Modified: tomcat/trunk/java/org/apache/tomcat/dbcp/dbcp2/PoolableConnection.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/dbcp/dbcp2/PoolableConnection.java?rev=1852459&r1=1852458&r2=1852459&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/tomcat/dbcp/dbcp2/PoolableConnection.java (original) +++ tomcat/trunk/java/org/apache/tomcat/dbcp/dbcp2/PoolableConnection.java Tue Jan 29 15:03:15 2019 @@ -329,4 +329,20 @@ public class PoolableConnection extends fatalSqlExceptionThrown |= isDisconnectionSqlException(e); super.handleException(e); } + + /** + * @return The disconnection SQL codes. + * @since 2.6.0 + */ + public Collection<String> getDisconnectionSqlCodes() { + return disconnectionSqlCodes; + } + + /** + * @return Whether to fail-fast. + * @since 2.6.0 + */ + public boolean isFastFailValidation() { + return fastFailValidation; + } } --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
