This is an automated email from the ASF dual-hosted git repository. rmaucher pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/tomcat.git
commit 89570cdcb197fea315d65716e3b588c7bfb28288 Author: opencode <[email protected]> AuthorDate: Tue Dec 1 23:07:48 2026 +0100 Correct jdbc-pool documentation and JMX metadata Document that a custom Validator suppresses initSQLs and testOnConnect validation, clarify that initialSize writes are rejected during pool construction, remove the stale loginTimeout attribute from the JMX descriptor, fix the ALL_PROPERTIES extensibility comment, and rewrite both read-only getter Javadocs as getters. Extend the construction-setter test to assert that initialSize is rejected while the pool is being built. mvn test passes: 1187 tests, 0 failures. --- .../apache/tomcat/jdbc/pool/DataSourceFactory.java | 7 ++--- .../apache/tomcat/jdbc/pool/DataSourceProxy.java | 6 ++--- .../apache/tomcat/jdbc/pool/PoolConfiguration.java | 31 +++++++++++++--------- .../apache/tomcat/jdbc/pool/mbeans-descriptors.xml | 6 ----- .../DataSourceProxyConstructionSettersBase.java | 25 +++++++++-------- 5 files changed, 37 insertions(+), 38 deletions(-) diff --git a/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/DataSourceFactory.java b/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/DataSourceFactory.java index 7bf80c560a..e7e89bf138 100644 --- a/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/DataSourceFactory.java +++ b/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/DataSourceFactory.java @@ -403,9 +403,10 @@ public class DataSourceFactory implements ObjectFactory { // with defaults. Names the JNDI container itself uses to build the // reference are not pool properties and stay unmentioned. The set is // read from ALL_PROPERTIES at lookup time rather than snapshotted at - // class-initialisation: the array is protected so a subclass can - // extend it, and a snapshot would leave the loop reading one list - // while this sweep judged against another. + // class-initialisation, so a subclass that customizes the protected + // array before the lookup is reflected in this sweep. The array is + // final and fixed-length, so a subclass cannot append a new name; the + // base array is the complete supported set. Set<String> knownPropertyNames = new HashSet<>(Arrays.asList(ALL_PROPERTIES)); Enumeration<RefAddr> addresses = ref.getAll(); while (addresses.hasMoreElements()) { diff --git a/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/DataSourceProxy.java b/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/DataSourceProxy.java index 8b362712fd..c5b2dca338 100644 --- a/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/DataSourceProxy.java +++ b/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/DataSourceProxy.java @@ -684,7 +684,7 @@ public class DataSourceProxy implements PoolConfiguration { /** * Sets the number of connections pre-loaded when the pool starts. The value is used when the pool is created; a * later write would only change the configuration without pre-loading any connection, so it is rejected like the - * other start-time properties. + * other start-time properties, including a write that lands while the pool is being constructed. * * @param initialSize the number of connections to pre-load * @@ -921,9 +921,7 @@ public class DataSourceProxy implements PoolConfiguration { * * @param property the property name * @param rejectConstructing whether a write that lands while the pool is - * being built is rejected; {@code initialSize} - * is deliberately not, as its consumption is - * bounded where the pre-load array is allocated + * being built is rejected * * @throws UnsupportedOperationException if the pool exists, the construction * rejects start-time writes, or this diff --git a/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/PoolConfiguration.java b/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/PoolConfiguration.java index ff2bd088b7..3cdae098ee 100644 --- a/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/PoolConfiguration.java +++ b/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/PoolConfiguration.java @@ -207,22 +207,24 @@ public interface PoolConfiguration { void setDefaultCatalog(String defaultCatalog); /** - * If non null, during connection creation the method {@link java.sql.Connection#setReadOnly(boolean)} will be - * called with the set value. When the {@link org.apache.tomcat.jdbc.pool.interceptor.ConnectionState} interceptor - * is configured, it applies this setting on every borrow rather than at connection creation, and re-applies it - * whenever a borrower has changed it. + * Returns the default read-only state configured for connections created by this pool. When the + * {@link org.apache.tomcat.jdbc.pool.interceptor.ConnectionState} interceptor is configured, it applies this + * setting on every borrow rather than at connection creation, and re-applies it whenever a borrower has changed + * it. * - * @return null if not set and accepting the driver default otherwise the read only value + * @return the configured default read-only value, or {@code null} when the pool does not configure one and the + * driver default applies */ Boolean isDefaultReadOnly(); /** - * If non null, during connection creation the method {@link java.sql.Connection#setReadOnly(boolean)} will be - * called with the set value. When the {@link org.apache.tomcat.jdbc.pool.interceptor.ConnectionState} interceptor - * is configured, it applies this setting on every borrow rather than at connection creation, and re-applies it - * whenever a borrower has changed it. + * Returns the default read-only state configured for connections created by this pool. When the + * {@link org.apache.tomcat.jdbc.pool.interceptor.ConnectionState} interceptor is configured, it applies this + * setting on every borrow rather than at connection creation, and re-applies it whenever a borrower has changed + * it. * - * @return null if not set and accepting the driver default otherwise the read only value + * @return the configured default read-only value, or {@code null} when the pool does not configure one and the + * driver default applies */ Boolean getDefaultReadOnly(); @@ -804,6 +806,9 @@ public interface PoolConfiguration { * after the last one succeeds; a failure rolls the whole initialization back and takes the session out of service. * Blank entries are not statements and are ignored. * <p> + * A configured custom {@link Validator} replaces the statement-based validation, so while one is set these + * statements are not executed. See {@link Validator#validate(java.sql.Connection, int)} for the validation contract. + * <p> * This is a programmatic configuration surface. A JNDI/XML attribute cannot carry a collection; the single * {@link #setInitSQL(String)} attribute remains the declarative route. * @@ -817,7 +822,8 @@ public interface PoolConfiguration { * configuration and leaves the single init SQL, if set, in effect. * <p> * The collection is copied. Blank entries are ignored, and the remaining statements run in the order supplied, - * under the transaction rules described by {@link #getInitSQLs()}. + * under the transaction rules described by {@link #getInitSQLs()}. A configured custom {@link Validator} + * suppresses the statements, as {@link #getInitSQLs()} describes. * * @param initSQLs the initialization statements in execution order, or {@code null} to clear them */ @@ -835,7 +841,8 @@ public interface PoolConfiguration { * Set to true if we should run the validation query when connecting to the database for the first time on a * connection. Normally this is always set to false, unless one wants to use the validationQuery as an init query. * Setting an {@link #setInitSQL(String)} will override this setting, as the init SQL will be used instead of the - * validation query + * validation query. A configured custom {@link Validator} replaces both the validation query and the init SQL, + * as {@link Validator#validate(java.sql.Connection, int)} describes. * * @param testOnConnect set to true if we should run the validation query upon connect */ diff --git a/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/mbeans-descriptors.xml b/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/mbeans-descriptors.xml index a4c9acda4c..6a62858cb9 100644 --- a/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/mbeans-descriptors.xml +++ b/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/mbeans-descriptors.xml @@ -185,12 +185,6 @@ is="true" writeable="false"/> - <attribute name="loginTimeout" - description="The login timeout in seconds, mapped to the pool's maxWait" - type="java.lang.Integer" - writeable="false"/> - - <attribute name="name" description="The name of the connection pool, will be used in the ObjectName of the actual pool" type="java.lang.String" diff --git a/modules/jdbc-pool/src/test/java/org/apache/tomcat/jdbc/pool/DataSourceProxyConstructionSettersBase.java b/modules/jdbc-pool/src/test/java/org/apache/tomcat/jdbc/pool/DataSourceProxyConstructionSettersBase.java index 9f98c8f31c..5abe803914 100644 --- a/modules/jdbc-pool/src/test/java/org/apache/tomcat/jdbc/pool/DataSourceProxyConstructionSettersBase.java +++ b/modules/jdbc-pool/src/test/java/org/apache/tomcat/jdbc/pool/DataSourceProxyConstructionSettersBase.java @@ -27,19 +27,15 @@ import org.junit.jupiter.api.Test; import org.apache.tomcat.jdbc.JdbcPoolBaseTest; /** - * The start-time properties ({@code poolProperties}, {@code fairQueue}, - * {@code jmxEnabled} and {@code ignoreExceptionOnPreLoad}) decide what the pool - * constructor builds, from which configuration it builds it, and how the - * published pool is validated. A write that lands while the constructor is - * already running can no longer change any of those decisions, so it must be - * rejected. Accepting it leaves the data source reporting a configuration that - * the pool was not built from - in particular a replacement configuration whose - * credential writes never reach the connections the pool creates. - * <p> - * {@code initialSize} is deliberately not in that group: the pre-load count is - * bounded where the array that consumes it is allocated, so a write racing the - * construction changes only the reported configuration and cannot make the - * creation die on the value. The existing lifecycle test covers that tolerance. + * The start-time properties ({@code poolProperties}, {@code initialSize}, + * {@code fairQueue}, {@code jmxEnabled} and {@code ignoreExceptionOnPreLoad}) + * decide what the pool constructor builds, from which configuration it builds + * it, and how the published pool is validated. A write that lands while the + * constructor is already running can no longer change any of those decisions, + * so it must be rejected. Accepting it leaves the data source reporting a + * configuration that the pool was not built from - in particular a replacement + * configuration whose credential writes never reach the connections the pool + * creates. */ abstract class DataSourceProxyConstructionSettersBase extends JdbcPoolBaseTest { @@ -120,6 +116,9 @@ abstract class DataSourceProxyConstructionSettersBase extends JdbcPoolBaseTest { Assertions.assertThrows(UnsupportedOperationException.class, () -> ds.setIgnoreExceptionOnPreLoad(true), "the pre-load policy is already running, so ignoreExceptionOnPreLoad must not be changed during construction"); + Assertions.assertThrows(UnsupportedOperationException.class, + () -> ds.setInitialSize(-1), + "the pre-load count must not change while the pool is being constructed"); Assertions.assertSame(props, ds.getPoolProperties(), "the data source must keep the configuration the pool is being built from"); --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
