Skip to content

Commit

Permalink
Eliminate effectiveStatementCache field from C3P0PooledConnectionPool.
Browse files Browse the repository at this point in the history
  • Loading branch information
swaldman committed Feb 25, 2024
1 parent 16ccfea commit 372cb43
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
1 change: 0 additions & 1 deletion TODO.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
* Eliminate source headers
* Revise / update documentation
- Especially threading and connection testing
* Make loom warning about context classloader / privilege threads conditional on those actually being requested.
* Maybe optimize away effectiveStatementCache field from C3P0PooledConnectionPool.
30 changes: 17 additions & 13 deletions src/com/mchange/v2/c3p0/impl/C3P0PooledConnectionPool.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ public final class C3P0PooledConnectionPool
final GooGooStatementCache scache;

final boolean c3p0PooledConnections;
final boolean effectiveStatementCache; //configured for caching and using c3p0 pooled Connections

final int checkoutTimeout;
final int connectionIsValidTimeout;
Expand Down Expand Up @@ -264,7 +263,15 @@ private synchronized RequestBoundaryMarker findRequestBoundaryMarker(PooledConne
{
try
{
if (maxStatements > 0 && maxStatementsPerConnection > 0)
this.c3p0PooledConnections = (cpds instanceof WrapperConnectionPoolDataSource);

if (!c3p0PooledConnections)
{
if (logger.isLoggable(MLevel.WARNING) && (maxStatements > 0 || maxStatementsPerConnection > 0))
logger.log(MLevel.WARNING, "Statement caching is configured, but cannot be supported, because the provided ConnectionPoolDataSource is not a c3p0 implementation. Initializing with no statement cache.");
this.scache = null;
}
else if (maxStatements > 0 && maxStatementsPerConnection > 0)
this.scache = new DoubleMaxStatementCache( taskRunner, deferredStatementDestroyer, maxStatements, maxStatementsPerConnection );
else if (maxStatementsPerConnection > 0)
this.scache = new PerConnectionMaxOnlyStatementCache( taskRunner, deferredStatementDestroyer, maxStatementsPerConnection );
Expand All @@ -282,9 +289,6 @@ else if (maxStatements > 0)
this.sharedTaskRunner = taskRunner;
this.deferredStatementDestroyer = deferredStatementDestroyer;

this.c3p0PooledConnections = (cpds instanceof WrapperConnectionPoolDataSource);
this.effectiveStatementCache = c3p0PooledConnections && (scache != null);

this.inUseLockFetcher = (c3p0PooledConnections ? C3P0_POOLED_CONNECION_NESTED_LOCK_LOCK_FETCHER : RESOURCE_ITSELF_IN_USE_LOCK_FETCHER);

class PooledConnectionResourcePoolManager implements ResourcePool.Manager
Expand Down Expand Up @@ -734,16 +738,16 @@ public PooledConnection checkoutPooledConnection() throws SQLException

private void waitMarkPhysicalConnectionInUse(Connection physicalConnection) throws InterruptedException
{
if (effectiveStatementCache)
if (scache != null)
scache.waitMarkConnectionInUse(physicalConnection);
}

private boolean tryMarkPhysicalConnectionInUse(Connection physicalConnection)
{ return (effectiveStatementCache ? scache.tryMarkConnectionInUse(physicalConnection) : true); }
{ return (scache != null ? scache.tryMarkConnectionInUse(physicalConnection) : true); }

private void unmarkPhysicalConnectionInUse(Connection physicalConnection)
{
if (effectiveStatementCache)
if (scache != null)
scache.unmarkConnectionInUse(physicalConnection);
}

Expand All @@ -769,15 +773,15 @@ private void unmarkPooledConnectionInUse(PooledConnection pooledCon)

private Boolean physicalConnectionInUse(Connection physicalConnection) throws InterruptedException
{
if (physicalConnection != null && effectiveStatementCache)
if (physicalConnection != null && scache != null)
return scache.inUse(physicalConnection);
else
return null;
}

private Boolean pooledConnectionInUse(PooledConnection pc) throws InterruptedException
{
if (pc != null && effectiveStatementCache)
if (pc != null && scache != null)
return scache.inUse(((AbstractC3P0PooledConnection) pc).getPhysicalConnection());
else
return null;
Expand All @@ -796,7 +800,7 @@ private Object checkoutAndMarkConnectionInUse() throws TimeoutException, CannotA
out = rp.checkoutResource( checkoutTimeout );
if (out instanceof AbstractC3P0PooledConnection)
{
// cast should succeed, because effectiveStatementCache implies c3p0 pooled Connections
// cast should succeed, because scache != null implies c3p0 pooled Connections
AbstractC3P0PooledConnection acpc = (AbstractC3P0PooledConnection) out;
Connection physicalConnection = acpc.getPhysicalConnection();
success = tryMarkPhysicalConnectionInUse(physicalConnection);
Expand All @@ -815,11 +819,11 @@ private Object checkoutAndMarkConnectionInUse() throws TimeoutException, CannotA

private void unmarkConnectionInUseAndCheckin(PooledConnection pcon) throws ResourcePoolException
{
if (effectiveStatementCache)
if (scache != null)
{
try
{
// cast should generally succeed, because effectiveStatementCache implies c3p0 pooled Connections
// cast should generally succeed, because scache != null implies c3p0 pooled Connections
// but clients can try to check-in whatever they want, so there are potential failures here
AbstractC3P0PooledConnection acpc = (AbstractC3P0PooledConnection) pcon;
Connection physicalConnection = acpc.getPhysicalConnection();
Expand Down

0 comments on commit 372cb43

Please sign in to comment.