├── .gitignore ├── .mill-version ├── CHANGELOG ├── LICENSE ├── LICENSE-EPL ├── LICENSE-LGPL ├── README.md ├── RELEASE_NOTES-c3p0-0.11.0 ├── RELEASE_NOTES-c3p0-0.11.1 ├── adding-properties.md ├── bean ├── beangen │ └── com │ │ └── mchange │ │ └── v2 │ │ └── c3p0 │ │ └── impl │ │ ├── DriverManagerDataSourceBase.beangen-xml │ │ ├── JndiRefDataSourceBase.beangen-xml │ │ ├── PoolBackedDataSourceBase.beangen-xml │ │ └── WrapperConnectionPoolDataSourceBase.beangen-xml └── src │ └── com │ └── mchange │ └── v2 │ └── c3p0 │ └── codegen │ ├── BeangenDataSourceGenerator.java │ ├── C3P0ImplUtilsParentLoggerGeneratorExtension.java │ └── UnsupportedParentLoggerGeneratorExtension.java ├── build.mill ├── dev-notes.md ├── doc ├── docsrc │ ├── arrow_sm.png │ ├── extra.xml │ └── index.html └── old │ └── doc-outtakes.html ├── example ├── JndiBindDataSource.java ├── UseJndiDataSource.java ├── UsePoolBackedDataSource.java ├── UseUnpooledDataSource.java └── c3p0-service.xml ├── mill-build └── build.mill ├── millw ├── proxy └── src │ └── com │ └── mchange │ └── v2 │ └── c3p0 │ └── codegen │ └── JdbcProxyGenerator.java ├── publishMainSonatypeTestLocal ├── release-notes-past ├── RELEASE_NOTES-c3p0-0.10.0 ├── RELEASE_NOTES-c3p0-0.10.1 ├── RELEASE_NOTES-c3p0-0.10.2 ├── RELEASE_NOTES-c3p0-0.9.2 ├── RELEASE_NOTES-c3p0-0.9.5.1 ├── RELEASE_NOTES-c3p0-0.9.5.2 ├── RELEASE_NOTES-c3p0-0.9.5.3 └── RELEASE_NOTES-c3p0-0.9.5.4 ├── resources └── mchange-config-resource-paths.txt ├── src-proxy-interface └── com │ └── mchange │ └── v2 │ └── c3p0 │ ├── C3P0ProxyConnection.java │ ├── C3P0ProxyStatement.java │ └── impl │ └── ProxyResultSetDetachable.java ├── src └── com │ └── mchange │ └── v2 │ ├── c3p0 │ ├── AbstractComboPooledDataSource.java │ ├── AbstractConnectionCustomizer.java │ ├── AbstractConnectionTester.java │ ├── AbstractExecutorTaskRunnerFactory.java │ ├── C3P0Registry.java │ ├── ComboPooledDataSource.java │ ├── ConnectionCustomizer.java │ ├── ConnectionTester.java │ ├── DataSources.java │ ├── DriverManagerDataSource.java │ ├── DriverManagerDataSourceFactory.java │ ├── FixedThreadPoolExecutorTaskRunnerFactory.java │ ├── FullQueryConnectionTester.java │ ├── JndiRefConnectionPoolDataSource.java │ ├── JndiRefForwardingDataSource.java │ ├── PoolBackedDataSource.java │ ├── PoolBackedDataSourceFactory.java │ ├── PooledDataSource.java │ ├── QueryConnectionTester.java │ ├── SQLWarnings.java │ ├── TaskRunnerFactory.java │ ├── TaskRunnerInit.java │ ├── TaskRunnerThreadFactory.java │ ├── UnifiedConnectionTester.java │ ├── WrapperConnectionPoolDataSource.java │ ├── cfg │ │ ├── C3P0Config.java │ │ ├── C3P0ConfigFinder.java │ │ ├── C3P0ConfigUtils.java │ │ ├── C3P0ConfigXmlUtils.java │ │ ├── DefaultC3P0ConfigFinder.java │ │ ├── InvalidConfigException.java │ │ ├── NamedScope.java │ │ ├── Validator.java │ │ └── Validators.java │ ├── debug │ │ ├── AfterCloseLoggingComboPooledDataSource.java │ │ ├── AfterCloseLoggingConnectionWrapper.java │ │ ├── CloseLoggingComboPooledDataSource.java │ │ ├── CloseLoggingConnectionWrapper.java │ │ └── ConstructionLoggingComboPooledDataSource.java │ ├── example │ │ ├── InitSqlConnectionCustomizer.java │ │ └── IsValidOnlyConnectionTester30.java │ ├── filter │ │ └── FilterDataSource.java │ ├── impl │ │ ├── AbstractC3P0PooledConnection.java │ │ ├── AbstractIdentityTokenized.java │ │ ├── AbstractPoolBackedDataSource.java │ │ ├── AuthMaskingProperties.java │ │ ├── C3P0Defaults.java │ │ ├── C3P0ImplUtils.java │ │ ├── C3P0JavaBeanObjectFactory.java │ │ ├── C3P0PooledConnectionPool.java │ │ ├── C3P0PooledConnectionPoolManager.java │ │ ├── ConnectionTestPath.java │ │ ├── ConnectionTesterConnectionTestPath.java │ │ ├── DbAuth.java │ │ ├── DefaultConnectionTester.java │ │ ├── DefaultTaskRunnerFactory.java │ │ ├── IdentityTokenResolvable.java │ │ ├── IdentityTokenized.java │ │ ├── IdentityTokenizedCoalesceChecker.java │ │ ├── InternalPooledConnection.java │ │ ├── IsValidSimplifiedConnectionTestPath.java │ │ ├── NewPooledConnection.java │ │ ├── NullStatementSetManagedResultSet.java │ │ ├── SetManagedDatabaseMetaData.java │ │ ├── SetManagedResultSet.java │ │ └── SnatchFromSetResultSet.java │ ├── jboss │ │ ├── C3P0PooledDataSource.java │ │ └── C3P0PooledDataSourceMBean.java │ ├── management │ │ ├── ActiveManagementCoordinator.java │ │ ├── C3P0RegistryManager.java │ │ ├── C3P0RegistryManagerMBean.java │ │ ├── DynamicPooledDataSourceManagerMBean.java │ │ ├── ManagementCoordinator.java │ │ ├── NullManagementCoordinator.java │ │ ├── PooledDataSourceManager.java │ │ └── PooledDataSourceManagerMBean.java │ ├── mbean │ │ ├── C3P0PooledDataSource.java │ │ └── C3P0PooledDataSourceMBean.java │ ├── stmt │ │ ├── DoubleMaxStatementCache.java │ │ ├── GlobalMaxOnlyStatementCache.java │ │ ├── GooGooStatementCache.java │ │ ├── MemoryCoalescedStatementCacheKey.java │ │ ├── PerConnectionMaxOnlyStatementCache.java │ │ ├── SimpleStatementCacheKey.java │ │ ├── StatementCache.java │ │ ├── StatementCacheBenchmark.java │ │ ├── StatementCacheKey.java │ │ └── ValueIdentityStatementCacheKey.java │ └── util │ │ ├── CloseReportingConnectionWrapper.java │ │ ├── ConnectionEventSupport.java │ │ ├── IsValidOnlyConnectionTester.java │ │ ├── StatementEventSupport.java │ │ └── TestUtils.java │ └── resourcepool │ ├── BasicResourcePool.java │ ├── BasicResourcePoolFactory.java │ ├── CannotAcquireResourceException.java │ ├── EventSupportingResourcePool.java │ ├── NoGoodResourcesException.java │ ├── ResourcePool.java │ ├── ResourcePoolEvent.java │ ├── ResourcePoolEventSupport.java │ ├── ResourcePoolException.java │ ├── ResourcePoolFactory.java │ ├── ResourcePoolListener.java │ ├── ResourcePoolUtils.java │ └── TimeoutException.java ├── test ├── conf-logging │ └── logging.properties ├── resources-local-rough │ └── c3p0.properties ├── resources-local │ └── c3p0.properties └── src │ └── com │ └── mchange │ └── v2 │ └── c3p0 │ └── test │ ├── AlwaysFailConnectionTester.java │ ├── AlwaysFailDataSource.java │ ├── C3P0BenchmarkApp.java │ ├── ConnectionDispersionTest.java │ ├── DynamicPreparedStatementTest.java │ ├── FreezableDriverManagerDataSource.java │ ├── InterruptedBatchTest.java │ ├── JavaBeanRefTest.java │ ├── JndiBindTest.java │ ├── JndiLookupTest.java │ ├── ListTablesTest.java │ ├── LoadPoolBackedDataSource.java │ ├── LogCreationTaskRunnerFactory.java │ ├── OneThreadRepeatedInsertOrQueryTest.java │ ├── PSLoadPoolBackedDataSource.java │ ├── Percent20FailConnectionTester.java │ ├── Percent80FailConnectionTester.java │ ├── PercentXXFailConnectionTester.java │ ├── ProxyWrappersTest.java │ ├── RawConnectionOpTest.java │ ├── StatsTest.java │ ├── TestConnectionCustomizer.java │ ├── TestRefSerStuff.java │ ├── ThreadPerTaskRunnerFactory.java │ └── junit │ ├── C3P0JUnitTestCaseBase.java │ ├── ConnectionBoundariesJUnitTestCase.java │ ├── ConnectionPropertiesResetJUnitTestCase.java │ ├── MarshallUnmarshallDataSourcesJUnitTestCase.java │ ├── MockConnectionWithBoundaries.java │ ├── MockConnectionWithoutBoundaries.java │ └── MockDriver.java └── unsupported ├── dbms └── oracle-thin │ ├── .gitignore │ ├── build.properties │ ├── build.xml │ └── src │ └── classes │ └── com │ └── mchange │ └── v2 │ └── c3p0 │ └── dbms │ ├── Debug.java │ └── OracleUtils.java ├── old-build ├── build.properties ├── build.xml └── src │ ├── dist-static │ ├── LICENSE │ ├── LICENSE-EPL │ ├── LICENSE-LGPL │ ├── README │ ├── RELEASE_NOTES-c3p0-0.9.2 │ ├── RELEASE_NOTES-c3p0-0.9.5.1 │ ├── RELEASE_NOTES-c3p0-0.9.5.2 │ ├── RELEASE_NOTES-c3p0-0.9.5.3 │ ├── RELEASE_NOTES-c3p0-0.9.5.4 │ ├── TODO │ ├── old │ │ ├── KNOWN-ISSUES-0.9.0 │ │ ├── LICENSE │ │ ├── README │ │ ├── RELEASE-NOTES-0.8.5-pre4.txt │ │ ├── RELEASE-NOTES-0.8.5-pre7.txt │ │ └── RELEASE_NOTES-c3p0-0.9.1-pre7 │ └── src │ │ └── README │ ├── docweb │ ├── docwebapp │ │ └── WEB-INF │ │ │ ├── jboss-web.xml │ │ │ └── web.xml │ └── docwebear │ │ └── META-INF │ │ └── application.xml │ └── maven │ └── pom.xml ├── src-off └── com │ └── mchange │ └── v2 │ └── c3p0 │ └── off │ └── servlet │ └── C3P0StatusServlet.java └── test-properties ├── META-INF └── poop.xml ├── application.conf ├── application.properties ├── c3p0-config.xml ├── c3p0.properties ├── c3p0.properties.rough ├── log4j.properties ├── logback.xml ├── logging.properties └── other.json /.gitignore: -------------------------------------------------------------------------------- 1 | out 2 | -------------------------------------------------------------------------------- /.mill-version: -------------------------------------------------------------------------------- 1 | 0.12.7 2 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | /* 2 | * This library is free software; you can redistribute it and/or modify 3 | * it under the terms of EITHER: 4 | * 5 | * 1) The GNU Lesser General Public License (LGPL), version 2.1, 6 | * or (at your option) any later version, as published by the 7 | * Free Software Foundation. 8 | * 9 | * OR 10 | * 11 | * 2) The Eclipse Public License (EPL), version 1.0 12 | * 13 | * You may choose which license to accept if you wish to redistribute 14 | * or modify this work. You may offer derivatives of this work 15 | * under the license you have chosen, or you may provide the same 16 | * choice of license which you have been offered here. 17 | * 18 | * This software is distributed in the hope that it will be useful, 19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 21 | * 22 | * You should have received copies of both LGPL v2.1 and EPL v1.0 23 | * along with this software; see the files LICENSE-EPL and LICENSE-LGPL. 24 | * If not, the text of these licenses are currently available at 25 | * 26 | * LGPL v2.1: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html 27 | * EPL v1.0: http://www.eclipse.org/org/documents/epl-v10.php 28 | */ 29 | -------------------------------------------------------------------------------- /RELEASE_NOTES-c3p0-0.11.0: -------------------------------------------------------------------------------- 1 | RELEASE NOTES, c3p0-0.11.0 2 | ========================== 3 | 4 | The main new feature of c3p0-0.11.0 is fuller support of Java 21+ "loom" virtual 5 | threads. While as of c3p0-0.10.x, c3p0 itself supported relying on virtual threads 6 | for its internals, c3p0 continued to manage client threads with Java's native 7 | wait()/notify() mechanism, which "pins" virtual threads. 8 | 9 | Elements relying on wait()/notify() have been rewritten in terms of 10 | java.util.concurrent.locks.ReentrantLock and its Condition mechanism. 11 | 12 | Many thanks to Alex Kormukhin for pointing this out and suggesting the fix. 13 | 14 | Other improvements include 15 | 16 | * a long-requested ability to have cancel() called on statements 17 | automatically closed; 18 | 19 | * a double-check to prevent rare occurrences of NullPointerException on Connection checkout. 20 | 21 | * use jdbc-version sensitive proxies to prevent NoClassDefFoundErrors when proxies compiled 22 | against newer JDBC versions try to reference e.g. java.sql.ShardingKey 23 | 24 | 25 | Config parameters added: 26 | ------------------------ 27 | cancelAutomaticallyClosedStatements 28 | 29 | 30 | Deprecated config parameter removed: 31 | ------------------------------------ 32 | [none] 33 | 34 | 35 | Thanks to... 36 | 37 | Andreas Dangel 38 | Alex Kormukhin 39 | C3Stones on github 40 | Force Rs on github 41 | Luis Paolini 42 | xtb359 on github 43 | 44 | and everyone else I may have forgotten! 45 | 46 | -------------------------------------------------------------------------------- /RELEASE_NOTES-c3p0-0.11.1: -------------------------------------------------------------------------------- 1 | RELEASE NOTES, c3p0-0.11.1 2 | ========================== 3 | 4 | This is a quick, bug-fix release. 5 | 6 | In c3p0-0.11.0, forceKillAcquires() accidentally failed to surrender its lock, 7 | leading to deadlocks in applications following a full round of acquisition failures. 8 | 9 | Many thanks to @pwielgolaski on github for tracking down the issue, and to 10 | @michalgutkowski on github for providing a pull request with the fix. 11 | 12 | Thanks also to @driseley on github for providing a reproduction of the issue. 13 | -------------------------------------------------------------------------------- /bean/beangen/com/mchange/v2/c3p0/impl/JndiRefDataSourceBase.beangen-xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | com.mchange.v2.c3p0.impl 5 | 6 | java.util.Hashtable 7 | javax.naming.Name 8 | com.mchange.v2.c3p0.cfg.C3P0Config 9 | 10 | JndiRefDataSourceBase 11 | IdentityTokenResolvable 12 | 13 | 14 | Object 15 | jndiName 16 | 17 | (jndiName instanceof Name ? ((Name) jndiName).clone() : jndiName /* String */) 18 | 19 | 20 | 21 | 22 | 23 | Hashtable 24 | jndiEnv 25 | 26 | (jndiEnv != null ? (Hashtable) jndiEnv.clone() : null) 27 | 28 | 29 | 30 | 31 | boolean 32 | caching 33 | true 34 | 35 | 36 | 37 | 38 | 51 | 52 | privatevolatile 53 | String 54 | identityToken 55 | 56 | public 57 | public 58 | 59 | 60 | String 61 | factoryClassLocation 62 | C3P0Config.initializeStringPropertyVar("factoryClassLocation", C3P0Defaults.factoryClassLocation()) 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | -------------------------------------------------------------------------------- /bean/src/com/mchange/v2/c3p0/codegen/C3P0ImplUtilsParentLoggerGeneratorExtension.java: -------------------------------------------------------------------------------- 1 | package com.mchange.v2.c3p0.codegen; 2 | 3 | import java.util.*; 4 | import com.mchange.v2.codegen.*; 5 | import com.mchange.v2.codegen.bean.*; 6 | import java.io.IOException; 7 | import com.mchange.v2.codegen.IndentedWriter; 8 | 9 | public class C3P0ImplUtilsParentLoggerGeneratorExtension implements GeneratorExtension 10 | { 11 | public Collection extraGeneralImports() 12 | { return Collections.EMPTY_SET; } 13 | 14 | public Collection extraSpecificImports() 15 | { return Arrays.asList( new String[]{"java.util.logging.Logger", "com.mchange.v2.c3p0.impl.C3P0ImplUtils", "java.sql.SQLFeatureNotSupportedException"} ); } 16 | 17 | public Collection extraInterfaceNames() 18 | { return Collections.EMPTY_SET; } 19 | 20 | public void generate(ClassInfo info, Class superclassType, Property[] props, Class[] propTypes, IndentedWriter iw) 21 | throws IOException 22 | { 23 | iw.println("// JDK7 add-on"); 24 | iw.println("public Logger getParentLogger() throws SQLFeatureNotSupportedException"); 25 | iw.println("{ return C3P0ImplUtils.PARENT_LOGGER;}"); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /bean/src/com/mchange/v2/c3p0/codegen/UnsupportedParentLoggerGeneratorExtension.java: -------------------------------------------------------------------------------- 1 | package com.mchange.v2.c3p0.codegen; 2 | 3 | import java.util.*; 4 | import com.mchange.v2.codegen.*; 5 | import com.mchange.v2.codegen.bean.*; 6 | import java.io.IOException; 7 | import com.mchange.v2.codegen.IndentedWriter; 8 | 9 | public class UnsupportedParentLoggerGeneratorExtension implements GeneratorExtension 10 | { 11 | public Collection extraGeneralImports() 12 | { return Collections.EMPTY_SET; } 13 | 14 | public Collection extraSpecificImports() 15 | { return Arrays.asList( new String[]{"java.util.logging.Logger", "java.sql.SQLFeatureNotSupportedException"} ); } 16 | 17 | public Collection extraInterfaceNames() 18 | { return Collections.EMPTY_SET; } 19 | 20 | public void generate(ClassInfo info, Class superclassType, Property[] props, Class[] propTypes, IndentedWriter iw) 21 | throws IOException 22 | { 23 | iw.println("// JDK7 add-on"); 24 | iw.println("public Logger getParentLogger() throws SQLFeatureNotSupportedException"); 25 | iw.println("{ throw new SQLFeatureNotSupportedException(\042javax.sql.DataSource.getParentLogger() is not currently supported by \042 + this.getClass().getName());}"); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /dev-notes.md: -------------------------------------------------------------------------------- 1 | # dev-notes 2 | 3 | * It looks like throwing of PropertyVetoException may not be implemented for ostensibly constrained parameters: 4 | - `connectionTesterClassName` (should classname params be constrained? no actual implementation I think) 5 | - `contextClassLoaderSource` 6 | - `markSessionBoundaries` 7 | - `taskRunnerFactoryClassName` (should classname params be constrained? no actual implementation I think) 8 | - `userOverridesAsString` 9 | It might be disruptive to "fix" this now, as installations may have configs that are stable despite 10 | bad (vetoable) settings. 11 | 12 | PropertyVetoException appears to be thrown with explicit calls to setters, but not on implementation via config. 13 | Variables are initialized to config values, circumventing validation. 14 | 15 | Okay. We've added a way to validate String config properties, and validation for `contextClassLoaderSource` and `markSessionBoundaries`. 16 | 17 | If class name properties should be constrained, probably so too ought be 18 | - `connectionCustomizerClassName` 19 | but making it so would be an incompatible API change at this point, callers of the setter would have to prepare 20 | for `ProppertyVetoException`, which now they do not. 21 | 22 | * When testing against intentionally chaotic configs, we occasionally see, at debug level FINE: 23 | ```plaintext 24 | 2024-05-06@00:53:59 [FINE] [com.mchange.v2.c3p0.impl.NewPooledConnection] An exception occurred while resetting a closed Connection. Invalidating Connection. 25 | org.postgresql.util.PSQLException: This connection has been closed. 26 | at org.postgresql.jdbc.PgConnection.checkClosed(PgConnection.java:993) 27 | at org.postgresql.jdbc.PgConnection.getAutoCommit(PgConnection.java:953) 28 | at com.mchange.v2.c3p0.impl.C3P0ImplUtils.resetTxnState(C3P0ImplUtils.java:207) 29 | at com.mchange.v2.c3p0.impl.NewPooledConnection.reset(NewPooledConnection.java:429) 30 | at com.mchange.v2.c3p0.impl.NewPooledConnection.markClosedProxyConnection(NewPooledConnection.java:385) 31 | at com.mchange.v2.c3p0.impl.NewProxyConnection.close(NewProxyConnection.java:2150) 32 | at com.mchange.v1.db.sql.ConnectionUtils.attemptClose(ConnectionUtils.java:53) 33 | at com.mchange.v2.c3p0.impl.ConnectionTesterConnectionTestPath.testPooledConnection(ConnectionTesterConnectionTestPath.java:123) 34 | at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.testPooledConnection(C3P0PooledConnectionPool.java:784) 35 | at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.testPooledConnection(C3P0PooledConnectionPool.java:775) 36 | at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.refurbishIdleResource(C3P0PooledConnectionPool.java:743) 37 | at com.mchange.v2.resourcepool.BasicResourcePool$AsyncTestIdleResourceTask.run(BasicResourcePool.java:2048) 38 | at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:696) 39 | ``` 40 | It appears to be harmless -- just a debug notification that a physical Connection has already been closed 41 | when it is tested as an idle resource. Still, why? 42 | - It looks like it's just multiple tests backed up in the Connection pool, the first one causes the Connection to be closed, 43 | a second one sees the Connection already closed. It appears no longer to appear if all of the following params are not set 44 | * maxConnectionAge 45 | * maxIdleTime 46 | * maxIdleTimeExcessConnections 47 | That is, if Connections aren't timed out, the condition does not appear. 48 | -------------------------------------------------------------------------------- /doc/docsrc/arrow_sm.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swaldman/c3p0/73e77ed2cdddf0211940f34761ae454e0ec7e2d9/doc/docsrc/arrow_sm.png -------------------------------------------------------------------------------- /doc/docsrc/extra.xml: -------------------------------------------------------------------------------- 1 | 2 | 25 3 | true 4 | 5 | 6 | -------------------------------------------------------------------------------- /doc/old/doc-outtakes.html: -------------------------------------------------------------------------------- 1 | you should first create a PoolConfig Object, 2 | call the appropriate property setters on that PoolConfig, 3 | and pass your configuration as an argument to 4 | DataSources.pooledDataSource( ... ). 5 | See the example above. 6 | -------------------------------------------------------------------------------- /example/UseUnpooledDataSource.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Distributed as part of c3p0 v.0.9.5.1 3 | * 4 | * Copyright (C) 2015 Machinery For Change, Inc. 5 | * 6 | * Author: Steve Waldman 7 | * 8 | * This library is free software; you can redistribute it and/or modify 9 | * it under the terms of EITHER: 10 | * 11 | * 1) The GNU Lesser General Public License (LGPL), version 2.1, as 12 | * published by the Free Software Foundation 13 | * 14 | * OR 15 | * 16 | * 2) The Eclipse Public License (EPL), version 1.0 17 | * 18 | * You may choose which license to accept if you wish to redistribute 19 | * or modify this work. You may offer derivatives of this work 20 | * under the license you have chosen, or you may provide the same 21 | * choice of license which you have been offered here. 22 | * 23 | * This software is distributed in the hope that it will be useful, 24 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 25 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 26 | * 27 | * You should have received copies of both LGPL v2.1 and EPL v1.0 28 | * along with this software; see the files LICENSE-EPL and LICENSE-LGPL. 29 | * If not, the text of these licenses are currently available at 30 | * 31 | * LGPL v2.1: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html 32 | * EPL v1.0: http://www.eclipse.org/org/documents/epl-v10.php 33 | * 34 | */ 35 | 36 | import java.sql.*; 37 | import javax.sql.DataSource; 38 | import com.mchange.v2.c3p0.DataSources; 39 | 40 | 41 | /** 42 | * This example shows how to programmatically get and directly use 43 | * an unpooled DataSource 44 | */ 45 | public final class UseUnpooledDataSource 46 | { 47 | 48 | public static void main(String[] argv) 49 | { 50 | try 51 | { 52 | 53 | // Note: your JDBC driver must be loaded [via Class.forName( ... ) or -Djdbc.properties] 54 | // prior to acquiring your DataSource! 55 | 56 | // Acquire the DataSource... this is the only c3p0 specific code here 57 | DataSource ds = DataSources.unpooledDataSource("jdbc:postgresql://localhost/test", 58 | "swaldman", 59 | "test"); 60 | 61 | // get hold of a Connection an do stuff, in the usual way 62 | Connection con = null; 63 | Statement stmt = null; 64 | ResultSet rs = null; 65 | try 66 | { 67 | con = ds.getConnection(); 68 | stmt = con.createStatement(); 69 | rs = stmt.executeQuery("SELECT * FROM foo"); 70 | while (rs.next()) 71 | System.out.println( rs.getString(1) ); 72 | } 73 | finally 74 | { 75 | //i try to be neurotic about ResourceManagement, 76 | //explicitly closing each resource 77 | //but if you are in the habit of only closing 78 | //parent resources (e.g. the Connection) and 79 | //letting them close their children, all 80 | //c3p0 DataSources will properly deal. 81 | attemptClose(rs); 82 | attemptClose(stmt); 83 | attemptClose(con); 84 | } 85 | } 86 | catch (Exception e) 87 | { e.printStackTrace(); } 88 | } 89 | 90 | static void attemptClose(ResultSet o) 91 | { 92 | try 93 | { if (o != null) o.close();} 94 | catch (Exception e) 95 | { e.printStackTrace();} 96 | } 97 | 98 | static void attemptClose(Statement o) 99 | { 100 | try 101 | { if (o != null) o.close();} 102 | catch (Exception e) 103 | { e.printStackTrace();} 104 | } 105 | 106 | static void attemptClose(Connection o) 107 | { 108 | try 109 | { if (o != null) o.close();} 110 | catch (Exception e) 111 | { e.printStackTrace();} 112 | } 113 | 114 | private UseUnpooledDataSource() 115 | {} 116 | } 117 | -------------------------------------------------------------------------------- /example/c3p0-service.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 8 | 9 | java:PooledDS 10 | jdbc:postgresql://localhost/c3p0-test 11 | org.postgresql.Driver 12 | swaldman 13 | test 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | jboss:service=Naming 45 | 46 | 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /mill-build/build.mill: -------------------------------------------------------------------------------- 1 | package build 2 | 3 | import mill._, scalalib._ 4 | 5 | // modified from https://mill-build.org/mill/extending/meta-build.html 6 | 7 | object `package` extends MillBuildRootModule { 8 | 9 | val McjVersion = "0.3.2" 10 | 11 | object Dependency { 12 | val MchangeCommonsJava = ivy"com.mchange:mchange-commons-java:${McjVersion}" 13 | } 14 | 15 | override def ivyDeps = T{ 16 | super.ivyDeps() ++ Agg(Dependency.MchangeCommonsJava) 17 | } 18 | 19 | val MillBuildCommonDependenciesSource = 20 | s"""|package millbuild 21 | | 22 | |object MillBuildCommonDependencies { 23 | | val McjVersion = "${McjVersion}" 24 | |} 25 | |""".stripMargin 26 | 27 | def generatedSources = Task { 28 | os.write( Task.dest / "MillBuildCommonDependencies.scala", MillBuildCommonDependenciesSource ) 29 | super.generatedSources() ++ Seq(PathRef(Task.dest)) 30 | } 31 | } 32 | 33 | -------------------------------------------------------------------------------- /publishMainSonatypeTestLocal: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env -S scala-cli shebang 2 | 3 | //> using dep "com.lihaoyi::os-lib:0.11.3" 4 | 5 | import java.io.File 6 | 7 | // expects SONATYPE_USERNAME and SONATYPE_PASSWORD to be set prior to running! 8 | 9 | val console = System.console() 10 | if (console == null) { 11 | System.err.println("Could not initialize system console. Exiting.") 12 | System.exit(1) 13 | } 14 | 15 | val sonatypeUsername = System.getenv("SONATYPE_USERNAME") 16 | val sonatypePassword = System.getenv("SONATYPE_PASSWORD") 17 | if (sonatypeUsername == null) { 18 | System.err.println(s"Environment variable 'SONATYPE_USERNAME' not set. Exiting.") 19 | System.exit(1) 20 | } 21 | if (sonatypePassword == null) { 22 | System.err.println(s"Environment variable 'SONATYPE_PASSWORD' not set. Exiting.") 23 | System.exit(1) 24 | } 25 | 26 | val gpgPassphrase = console.readPassword("Please enter GPG passphrase for signing: ") 27 | 28 | val millBinary = 29 | val tryme = List("./millw", "./mill" ) 30 | tryme.find( path => new File(path).exists ).getOrElse("mill") 31 | 32 | val sonatypePublishCommand = Seq( 33 | millBinary, 34 | "publish", 35 | "--signed=true", 36 | "--release=false" 37 | ) 38 | 39 | val testPublishLocalCommand = Seq( 40 | millBinary, "test.publishLocal" 41 | ) 42 | 43 | println("Publishing main library to Sonatype.") 44 | os.call(sonatypePublishCommand, env=Map("PGP_PASSPHRASE" -> new String(gpgPassphrase))) 45 | 46 | println("Publishing test library to local ivy repository.") 47 | os.call(testPublishLocalCommand) 48 | 49 | 50 | -------------------------------------------------------------------------------- /release-notes-past/RELEASE_NOTES-c3p0-0.10.0: -------------------------------------------------------------------------------- 1 | RELEASE NOTES, c3p0-0.10.0 2 | ========================== 3 | 4 | This is a pretty major c3p0 release. (It should be. It's the first in... a while.) 5 | 6 | Some highlights: 7 | 8 | * c3p0 now sports a modern, automated mill build, which will render it much 9 | more appealing to incrementally maintain than its very manual 2002-era ant build 10 | 11 | * Pluggable threading / thread pool, including support for delegating threading 12 | to existing Executors and Java 21 loom virtual threads 13 | 14 | * Much simplified Connection testing by default, and simpler configuration of JDBC 6+ 15 | timeout for Connection.isValid(...) 16 | 17 | * c3p0 includes richer support for JDBC 4.3, including support for begin and end 18 | request methods 19 | 20 | * Many, many small improvements and bug fixes. 21 | 22 | Config parameters added: 23 | ------------------------ 24 | attemptResurrectOnCheckin 25 | connectionIsValidTimeout 26 | taskRunnerFactoryClassName 27 | 28 | Deprecated config parameter removed: 29 | ------------------------------------ 30 | usesTraditionalReflectiveProxies 31 | 32 | Thanks to... 33 | 34 | Andy at Privitar 35 | Thomas Beckmann 36 | Hermann Bergqvist 37 | Joel Caplin 38 | chinhodado 39 | Mathilde Ffrench 40 | Github ghost 41 | Metin Gürleyen 42 | François JACQUES 43 | Bill Kehoe 44 | koszta5 45 | Hakan 46 | Lorenzo Gabriele 47 | Jörg Hohwiller 48 | Igor Khromov 49 | Thomas Leytrick 50 | Li Haoyi 51 | Li Rh 52 | marcatl 53 | Matteo Mazza 54 | Fernanda Meheust 55 | Rodrigo Merino 56 | MichaelMih 57 | Horacio Miranda 58 | Leona Nezvalova 59 | philippscs 60 | Bartosz Radaczyński 61 | Bernhard E. Reiter 62 | Tobias Roeser 63 | Michele Rossi 64 | sbaeumlisberger 65 | Bernhard M. Wiedemann 66 | 67 | and everyone else I may have forgotten! 68 | 69 | -------------------------------------------------------------------------------- /release-notes-past/RELEASE_NOTES-c3p0-0.10.1: -------------------------------------------------------------------------------- 1 | RELEASE NOTES, c3p0-0.10.1 2 | ========================== 3 | 4 | This is a minor c3p0 release, but includes some important fixes. 5 | Thank to every one who reported issues. 6 | 7 | Highlights: 8 | 9 | * Eliminates pinning within c3p0 proxies when clients are using loom virtual threads, 10 | as long the underlying JDBC driver avoids pinning. 11 | 12 | * Fixes problems under Oracle drivers related to JDBC 4.3 beginRequest() / endRequest() 13 | hints when running under JDBC 4.2 / Java 8 or lower 14 | 15 | * Adds config parameter to disable JDBC 4.3 beginRequest() / endRequest() hints. 16 | Some JDBC drivers close() outstanding Statements when a session is reported completed 17 | (when endRequest() is called). This is incompatible with c3p0 statement caching, as 18 | the very purpose of that is to retain Statements through multiple sessions. To address 19 | this, and any other issues associated with driver handling of JDBC 4.3 beginRequest() / 20 | endRequest() hints, c3p0 adds a new config parameter -- markSessionBoundaries -- which 21 | may take values 'always', 'never', or 'if-no-statement-cache'. See the documentation 22 | for more. 23 | 24 | * Other more minor improvements and fixes. 25 | 26 | Config parameters added: 27 | ------------------------ 28 | markSessionBoundaries 29 | 30 | Deprecated config parameter removed: 31 | ------------------------------------ 32 | 33 | 34 | Thanks to... 35 | 36 | Anand Bikas 37 | Alex Kormukhin 38 | khushboo11-dotcom 39 | Vlad Skarzhevskyy 40 | Jeffrey Tucker 41 | 42 | and anyone else I may have forgotten! 43 | 44 | -------------------------------------------------------------------------------- /release-notes-past/RELEASE_NOTES-c3p0-0.10.2: -------------------------------------------------------------------------------- 1 | RELEASE NOTES, c3p0-0.10.2 2 | ========================== 3 | 4 | This is a very minor c3p0 release. Substantively, it includes one fix of a rare freeze. 5 | The build has been upgraded for mill v0.12.x. There have been minor logging and testing changes. 6 | 7 | (The main motivation for publishing this release now is I'm to starting the 0.11.x prerelease 8 | series, but I want this very non-disruptive fix in 0.10.x.) 9 | 10 | Substantive fix: 11 | 12 | * Acquisition of a new PreparedStatement by the Statement cache could hang indefinitely 13 | if the attempt to acquire provoked a non-Exception Throwable (i.e. an Error). 14 | Many thanks to Totyo Totev! -------------------------------------------------------------------------------- /release-notes-past/RELEASE_NOTES-c3p0-0.9.2: -------------------------------------------------------------------------------- 1 | RELEASE NOTES, c3p0-0.9.2 2 | ========================= 3 | 4 | Some highlights: 5 | 6 | + Some JDBC drivers freeze up if cached Statements are close()ed while their parent 7 | Connections are in use. Previously users of these drivers (Oracle, JTDS) generally 8 | had to forego Statement caching to avoid deadlocks. C3P0's statement cache can now 9 | be set to cautiously close Statements only when the parent Connections are known 10 | to be idle. If you experience "APPARENT DEADLOCKS" due to StatementCloseTasks, set 11 | 12 | c3p0.statementCacheNumDeferredCloseThreads=1 13 | 14 | and they should go away! 15 | 16 | + There are some other minor improvements and fixes: 17 | 18 | -- the more granular and efficient "scattered" Connection acquisition algorithm that 19 | was "experimental" in the previous release is enabled by default 20 | 21 | -- unreturned Connections that are timed out (bad! bad!) are either rolled back (default) 22 | or committed before close(), respecting your unresolved transaction configuration. 23 | (see config parameter unresolvedConnectionTimeout in docs) 24 | 25 | -- c3p0 is now actively maintained for deployment as a managed dependency on 26 | Sonatype's central maven repository 27 | 28 | -- You can use the dataSourceName config parameter to create stable patterns in 29 | JMX mBeans, so that you can distinguish your DataSources and monitor then across 30 | application restarts. 31 | 32 | -- Miscellaneous fixes for bugs/deadlocks/resource-leaks, see CHANGELOG (and many thanks 33 | to users who've helped track these issues down!) 34 | 35 | + You must now include two jar files (c3p0 and mchange-commons-java) in your CLASSPATH 36 | rather than just one. Both can be found in the lib directory of the binary distribution. 37 | (Please provide feedback; if this is very inconvenient I can bundle it all up into 38 | a unified jar.) 39 | 40 | Some structural changes: 41 | 42 | + Development of c3p0 and mchange-commons-java have migrated to github: 43 | 44 | https://github.com/swaldman/c3p0 45 | https://github.com/swaldman/mchange-commons-java 46 | 47 | Note that c3p0 depends (heavily) on the mchange-commons library. 48 | 49 | I apologize very, very much for disappearing for a few of years. Your guess is as 50 | good as mine as to where I have been. 51 | 52 | As always, please give the library a very thorough beating. Your testing and feedback 53 | are very much appreciated, to Steve Waldman , please. 54 | 55 | -------------------------------------------------------------------------------- /release-notes-past/RELEASE_NOTES-c3p0-0.9.5.1: -------------------------------------------------------------------------------- 1 | RELEASE NOTES, c3p0-0.9.5.1 2 | =========================== 3 | 4 | + Full JDBC4 support. 5 | 6 | + Support for logging the SLF4J / logback library 7 | 8 | + Support for configuration via HOCON / typesafe-config files 9 | 10 | + Support for dynamic configuration reloading (to support autorestarting appservers like playframework) 11 | 12 | + Support for predictable, reproducible JMX names (whose uniqueness users must ensure!) via config parmeter 13 | com.mchange.v2.c3p0.management.ExcludeIdentityToken 14 | 15 | + Configuration param 'forceUseNamedDriverClass' allows users to circumvent DriverManager resolution 16 | of JDBC-url appropriate Driver classes and use the class specified in the 'driverClass' config param 17 | unconditionally 18 | 19 | + Configuaration params 'privilegeSpawnedThreads' and 'contextClassLoaderSource' can be set to 20 | help avoid memory leaks following multiple hot redeploys (references to ClassLoaders from stale deployments) 21 | in some application servers (most prominently Tomcat). 22 | 23 | + Added support for easily deriving instrumented debug versions of ComboPooledDataSource, and implemented 24 | two of those: 25 | com.mchange.v2.c3p0.debug.AfterCloseLoggingComboPooledDataSource and 26 | com.mchange.v2.c3p0.debug.CloseLoggingComboPooledDataSource 27 | 28 | + Added support for a new configurataion parameter, forceSynchronousCheckins, which can offer significantly 29 | improved performance when no Connection tests are performed on check-in and no difficult work is performed 30 | in ConnectionCustomizer.onCheckIn(...) 31 | 32 | + Lots and lots of bug fixes, tweaks, etc. 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /release-notes-past/RELEASE_NOTES-c3p0-0.9.5.2: -------------------------------------------------------------------------------- 1 | RELEASE NOTES, c3p0-0.9.5.2 2 | =========================== 3 | 4 | + This minor bugfix release fixed a bug that caused useless allocation of below-logging-threshold 5 | Strings, and added better debugging information on failed attempts to acquire database Connections. 6 | 7 | 8 | -------------------------------------------------------------------------------- /release-notes-past/RELEASE_NOTES-c3p0-0.9.5.3: -------------------------------------------------------------------------------- 1 | RELEASE NOTES, c3p0-0.9.5.3 2 | =========================== 3 | 4 | + This minor bugfix release addresses a security issue: 5 | 6 | CVE-2018-20433, https://nvd.nist.gov/vuln/detail/CVE-2018-20433 7 | 8 | The c3p0 parsed XML config files liberally, including resolving external 9 | entity references. Incautious use of this feature could permit injection 10 | of malicious config. Now c3p0 does not resolve external entity references 11 | in its the XML config file. 12 | 13 | HOWEVER, in the EXCEEDINGLY RARE CASE that your configuration depends on 14 | the old behavior, if you have UNDERSTOOD the security concern, you may 15 | restore external entity resolution with the following config parameter 16 | (in c3p0.properties, as HOCON config, or as a System property): 17 | 18 | com.mchange.v2.c3p0.cfg.xml.expandEntityReferences=true 19 | 20 | Thanks to user zhutougg on GitHub for calling attention to and suggesting 21 | a fix for this issue. 22 | 23 | + c3p0 now supports logging to log4j2. (Logging to the old, original log4j 24 | library remains supported as well.) Thanks to user fireandfuel on GitHub 25 | for implementing this feature! (In the mchange-commons-java library.) 26 | -------------------------------------------------------------------------------- /release-notes-past/RELEASE_NOTES-c3p0-0.9.5.4: -------------------------------------------------------------------------------- 1 | RELEASE NOTES, c3p0-0.9.5.4 2 | =========================== 3 | 4 | + This minor bugfix release continues to address security issues associated 5 | with parsing configuration in XML format. The solution provided in 0.9.5.3 6 | was not sufficiently general to address all "XXE" attacks. For more on 7 | those in general, see https://vsecurity.com//download/papers/XMLDTDEntityAttacks.pdf 8 | 9 | The current release includes implementing the suggestions offered here: 10 | https://github.com/OWASP/CheatSheetSeries/blob/31c94f233c40af4237432008106f42a9c4bff05e/cheatsheets/XML_External_Entity_Prevention_Cheat_Sheet.md 11 | 12 | Because more than entity reference expansion is implicated, the configuration 13 | key introduced in 0.9.5.3... 14 | 15 | com.mchange.v2.c3p0.cfg.xml.expandEntityReferences 16 | 17 | is now deprecated. Instead, if you wish to restore prior versions' permissive 18 | parsing of XML -- and if you strictly control your XML configuration and 19 | understand the security issues enabled by permissive parsing, you can set 20 | 21 | com.mchange.v2.c3p0.cfg.xml.usePermissiveParser=true 22 | 23 | (The deprecated key introduced in 0.9.5.3 will continue to work, but will 24 | provoke warnings.) 25 | 26 | Many thanks to Aaron Massey (amassey) at HackerOne and zhutougg on GitHub 27 | for calling attention to these issues. 28 | 29 | + The release also includes a change in how c3p0 handles the rare condition 30 | in which 31 | 32 | 1. A round of attempts to acquire Connections fails 33 | 2. c3p0 attempts to wake and throw Exceptions to client threads waiting for 34 | Connections to arrive, but a Thread interrupt or some unexpected Throwable 35 | occurs before that process has completed. 36 | 37 | Previously, a failure within "forceKillAcquires()" would leave the pool in a broken 38 | state, so that after database recovery clients might still fail to acquire Connections. 39 | Now c3p0 uses Thread.interrupt() to make a best-effort attempt to free the clients, 40 | logs a warning, then resets the pool to a recoverable state. 41 | 42 | This should be an extraordinarily rare occurrence, and c3p0 will emit warnings when 43 | it does occur. 44 | 45 | If by some hard-to-understand cause, waiting client Threads become somehow impossible 46 | to wake, despite use of notifyAll(), even after Thread.interrupt(), and even as new 47 | Connections become available to satisfy them, then recovery after the incomplete wake 48 | might lead to more aggressive tha intended (faster) pool growth (as Threads waiting 49 | for new Connections are taken into account when c3p0 calculates its target_pool_size. 50 | But it is very difficult to imagine any condition under which the semantics of the 51 | JVM threading model are respected and yet wait()ing Threads remain stuck despite 52 | notifyAll() and interrupt() calls. 53 | 54 | Many thanks to Stefan Cordes (rscadrde on github), Vipin Nair (swvist on github), and 55 | Łukasz Jąder (ljader on github) for their work on this issue. 56 | 57 | -------------------------------------------------------------------------------- /resources/mchange-config-resource-paths.txt: -------------------------------------------------------------------------------- 1 | # 2 | # note that later files "shadow" earlier ones, and that 3 | # the name '/' is reserved as a special token for 4 | # System properties. 5 | # 6 | 7 | /mchange-commons.properties 8 | /mchange-log.properties 9 | /c3p0.properties 10 | hocon:/reference,/application,/c3p0,/ 11 | / 12 | 13 | 14 | -------------------------------------------------------------------------------- /src-proxy-interface/com/mchange/v2/c3p0/C3P0ProxyConnection.java: -------------------------------------------------------------------------------- 1 | package com.mchange.v2.c3p0; 2 | 3 | import java.sql.Connection; 4 | import java.sql.SQLException; 5 | import java.lang.reflect.Method; 6 | import java.lang.reflect.InvocationTargetException; 7 | 8 | /** 9 | *

Most clients need never use or know about this interface -- c3p0-provided Connections 10 | * can be treated like any other Connection.

11 | * 12 | *

An interface implemented by proxy Connections returned 13 | * by c3p0 PooledDataSources. It provides protected access to the underlying 14 | * dbms-vendor specific Connection, which may be useful if you want to 15 | * access non-standard API offered by your jdbc driver. 16 | */ 17 | public interface C3P0ProxyConnection extends Connection 18 | { 19 | /** 20 | * A token representing an unwrapped, unproxied jdbc Connection 21 | * for use in {@link #rawConnectionOperation} 22 | */ 23 | public final static Object RAW_CONNECTION = new Object(); 24 | 25 | /** 26 | *

Allows one to work with the unproxied, raw Connection. Some 27 | * database companies never got over the "common interfaces mean 28 | * no more vendor lock-in!" thing, and offer non-standard API 29 | * on their Connections. This method permits you to "pierce" the 30 | * connection-pooling layer to call non-standard methods on the 31 | * original Connection, or to pass the original Connections to 32 | * functions that are not implementation neutral.

33 | * 34 | *

To use this functionality, you'll need to cast a Connection 35 | * retrieved from a c3p0 PooledDataSource to a 36 | * C3P0ProxyConnection.

37 | * 38 | *

This method works by making a reflective call of method m on 39 | * Object target (which may be null for static methods), passing 40 | * and argument list args. For the method target, or for any argument, 41 | * you may substitute the special token C3P0ProxyConnection.RAW_CONNECTION

42 | * 43 | *

Any Statements or ResultSets returned by the operation will be proxied 44 | * and c3p0-managed, meaning that these resources will be automatically closed 45 | * if the user does not close them first when this Connection is checked back 46 | * into the pool. Any other resources returned by the operation are the user's 47 | * responsibility to clean up!

48 | * 49 | *

Incautious use of this method can corrupt the Connection pool, by breaking the invariant 50 | * that all checked-in Connections should be equivalent. If your vendor supplies API 51 | * that allows you to modify the state or configuration of a Connection in some nonstandard way, 52 | * you might use this method to do so, and then check the Connection back into the pool. 53 | * When you fetch another Connection from the PooledDataSource, it will be undefined 54 | * whether the Connection returned will have your altered configuration, or the default 55 | * configuration of a "fresh" Connection. Thus, it is inadvisable to use this method to call 56 | * nonstandard mutators. 57 | */ 58 | public Object rawConnectionOperation(Method m, Object target, Object[] args) 59 | throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, SQLException; 60 | } 61 | -------------------------------------------------------------------------------- /src-proxy-interface/com/mchange/v2/c3p0/C3P0ProxyStatement.java: -------------------------------------------------------------------------------- 1 | package com.mchange.v2.c3p0; 2 | 3 | import java.sql.Statement; 4 | import java.sql.SQLException; 5 | import java.lang.reflect.Method; 6 | import java.lang.reflect.InvocationTargetException; 7 | 8 | /** 9 | *

Most clients need never use or know about this interface -- c3p0-provided Statements 10 | * can be treated like any other Statement.

11 | * 12 | *

An interface implemented by proxy Connections returned 13 | * by c3p0 PooledDataSources. It provides protected access to the underlying 14 | * dbms-vendor specific Connection, which may be useful if you want to 15 | * access non-standard API offered by your jdbc driver. 16 | */ 17 | public interface C3P0ProxyStatement extends Statement 18 | { 19 | /** 20 | * A token representing an unwrapped, unproxied jdbc Connection 21 | * for use in {@link #rawStatementOperation} 22 | */ 23 | public final static Object RAW_STATEMENT = new Object(); 24 | 25 | /** 26 | *

Allows one to work with the unproxied, raw vendor-provided Statement . Some 27 | * database companies never got over the "common interfaces mean 28 | * no more vendor lock-in!" thing, and offer non-standard API 29 | * on their Statements. This method permits you to "pierce" the 30 | * connection-pooling layer to call non-standard methods on the 31 | * original Statement, or to pass the original Statement to 32 | * functions that are not implementation neutral.

33 | * 34 | *

To use this functionality, you'll need to cast a Statement 35 | * retrieved from a c3p0-provided Connection to a 36 | * C3P0ProxyStatement.

37 | * 38 | *

This method works by making a reflective call of method m on 39 | * Object target (which may be null for static methods), passing 40 | * and argument list args. For the method target, or for any argument, 41 | * you may substitute the special token C3P0ProxyStatement.RAW_STATEMENT

42 | * 43 | *

Any ResultSets returned by the operation will be proxied 44 | * and c3p0-managed, meaning that these resources will be automatically closed 45 | * if the user does not close them first when this Statement is closed or checked 46 | * into the statement cache. Any other resources returned by the operation are the user's 47 | * responsibility to clean up!

48 | * 49 | *

If you have turned statement pooling on, incautious use of this method can corrupt the 50 | * PreparedStatement cache, by breaking the invariant 51 | * that all cached PreparedStatements should be equivalent to a PreparedStatement newly created 52 | * with the same arguments to prepareStatement(...) or prepareCall(...). If your vendor supplies API 53 | * that allows you to modify the state or configuration of a Statement in some nonstandard way, 54 | * and you do not undo this modification prior to closing the Statement or the Connection that 55 | * prepared it, future preparers of the same Statement may or may not see your modification, 56 | * depending on your use of the cache. Thus, it is inadvisable to use this method to call 57 | * nonstandard mutators on PreparedStatements if statement pooling is turned on.. 58 | */ 59 | public Object rawStatementOperation(Method m, Object target, Object[] args) 60 | throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, SQLException; 61 | } 62 | -------------------------------------------------------------------------------- /src-proxy-interface/com/mchange/v2/c3p0/impl/ProxyResultSetDetachable.java: -------------------------------------------------------------------------------- 1 | package com.mchange.v2.c3p0.impl; 2 | 3 | import java.sql.ResultSet; 4 | 5 | /** 6 | * This is an internal interface, not intended for use by library users. 7 | * (It is exposed publicly only for use by c3p0's code generation library.) 8 | */ 9 | public interface ProxyResultSetDetachable 10 | { 11 | void detachProxyResultSet( ResultSet prs ); 12 | } 13 | 14 | -------------------------------------------------------------------------------- /src/com/mchange/v2/c3p0/AbstractConnectionCustomizer.java: -------------------------------------------------------------------------------- 1 | package com.mchange.v2.c3p0; 2 | 3 | import java.util.Map; 4 | import java.sql.Connection; 5 | import java.sql.SQLException; 6 | 7 | /** 8 | * An abstract implementation of the 9 | * ConnectionCustomizer interface 10 | * in which all methods are no-ops. 11 | * 12 | * Just a convenience class since 13 | * most clients will only need to 14 | * implement a single method. 15 | */ 16 | public abstract class AbstractConnectionCustomizer implements ConnectionCustomizer 17 | { 18 | protected Map extensionsForToken( String parentDataSourceIdentityToken ) 19 | { return C3P0Registry.extensionsForToken( parentDataSourceIdentityToken ); } 20 | 21 | public void onAcquire( Connection c, String parentDataSourceIdentityToken ) throws Exception 22 | {} 23 | 24 | public void onDestroy( Connection c, String parentDataSourceIdentityToken ) throws Exception 25 | {} 26 | 27 | public void onCheckOut( Connection c, String parentDataSourceIdentityToken ) throws Exception 28 | {} 29 | 30 | public void onCheckIn( Connection c, String parentDataSourceIdentityToken ) throws Exception 31 | {} 32 | 33 | public boolean equals( Object o ) { return this.getClass().equals( o.getClass() ); } 34 | public int hashCode() { return this.getClass().getName().hashCode(); } 35 | } 36 | -------------------------------------------------------------------------------- /src/com/mchange/v2/c3p0/AbstractConnectionTester.java: -------------------------------------------------------------------------------- 1 | package com.mchange.v2.c3p0; 2 | 3 | import java.sql.Connection; 4 | 5 | /** 6 | *

Having expanded the once-simple ConnectionTester interface to support both 7 | * user-specified queries and return of root cause Exceptions (via an out-param), 8 | * this interface has grown unnecessarily complex.

9 | * 10 | *

If you wish to implement a custom Connection tester, here is the simple 11 | * way to do it

12 | * 13 | *
    14 | *
  1. Extend {@link com.mchange.v2.c3p0.AbstractConnectionTester}
  2. 15 | *
  3. 16 | * Override only the two abstract methods 17 | *
      18 | *
    • public int activeCheckConnection(Connection c, String preferredTestQuery, Throwable[] rootCauseOutParamHolder)
    • 19 | *
    • public int statusOnException(Connection c, Throwable t, String preferredTestQuery, Throwable[] rootCauseOutParamHolder)
    • 20 | *
    21 | *
  4. 22 | *
  5. Take care to ensure that your methods are defined to allow preferredTestQuery and 23 | * rootCauseOutParamHolder to be null.
  6. 24 | *
25 | * 26 | *

Parameter rootCauseOutParamHolder is an optional parameter, which if supplied, will be a Throwable array whose size 27 | * it at least one. If a Connection test fails because of some Exception, the Connection tester may set this Exception as the 28 | * zero-th element of the array to provide information about why and how the test failed.

29 | */ 30 | public abstract class AbstractConnectionTester implements UnifiedConnectionTester 31 | { 32 | /** 33 | * Override, but remember that preferredTestQuery and rootCauseOutParamHolder 34 | * can be null. 35 | */ 36 | public abstract int activeCheckConnection(Connection c, String preferredTestQuery, Throwable[] rootCauseOutParamHolder); 37 | 38 | /** 39 | * Override, but remember that preferredTestQuery and rootCauseOutParamHolder 40 | * can be null. 41 | */ 42 | public abstract int statusOnException(Connection c, Throwable t, String preferredTestQuery, Throwable[] rootCauseOutParamHolder); 43 | 44 | //usually just leave the rest of these as-is 45 | public int activeCheckConnection(Connection c) 46 | { return activeCheckConnection( c, null, null); } 47 | 48 | public int activeCheckConnection(Connection c, Throwable[] rootCauseOutParamHolder) 49 | { return activeCheckConnection( c, null, rootCauseOutParamHolder); } 50 | 51 | public int activeCheckConnection(Connection c, String preferredTestQuery) 52 | { return activeCheckConnection( c, preferredTestQuery, null); } 53 | 54 | public int statusOnException(Connection c, Throwable t) 55 | { return statusOnException( c, t, null, null); } 56 | 57 | public int statusOnException(Connection c, Throwable t, Throwable[] rootCauseOutParamHolder) 58 | { return statusOnException( c, t, null, rootCauseOutParamHolder); } 59 | 60 | public int statusOnException(Connection c, Throwable t, String preferredTestQuery) 61 | { return statusOnException( c, t, preferredTestQuery, null); } 62 | 63 | public boolean equals( Object o ) { return this.getClass().equals( o.getClass() ); } 64 | public int hashCode() { return this.getClass().getName().hashCode(); } 65 | } 66 | -------------------------------------------------------------------------------- /src/com/mchange/v2/c3p0/ComboPooledDataSource.java: -------------------------------------------------------------------------------- 1 | package com.mchange.v2.c3p0; 2 | 3 | import java.io.*; 4 | import javax.naming.*; 5 | 6 | /** 7 | *

For the meaning of most of these properties, please see c3p0's top-level documentation!

8 | */ 9 | public final class ComboPooledDataSource extends AbstractComboPooledDataSource implements Serializable, Referenceable 10 | { 11 | public ComboPooledDataSource() 12 | { super(); } 13 | 14 | public ComboPooledDataSource( boolean autoregister ) 15 | { super( autoregister ); } 16 | 17 | public ComboPooledDataSource(String configName) 18 | { super( configName ); } 19 | 20 | 21 | // serialization stuff -- set up bound/constrained property event handlers on deserialization 22 | private static final long serialVersionUID = 1; 23 | private static final short VERSION = 0x0002; 24 | 25 | private void writeObject( ObjectOutputStream oos ) throws IOException 26 | { 27 | oos.writeShort( VERSION ); 28 | } 29 | 30 | private void readObject( ObjectInputStream ois ) throws IOException, ClassNotFoundException 31 | { 32 | short version = ois.readShort(); 33 | switch (version) 34 | { 35 | case VERSION: 36 | //ok 37 | break; 38 | default: 39 | throw new IOException("Unsupported Serialized Version: " + version); 40 | } 41 | } 42 | } 43 | 44 | -------------------------------------------------------------------------------- /src/com/mchange/v2/c3p0/ConnectionCustomizer.java: -------------------------------------------------------------------------------- 1 | package com.mchange.v2.c3p0; 2 | 3 | import java.sql.Connection; 4 | import java.sql.SQLException; 5 | 6 | /** 7 | *

Implementations of this interface should 8 | * be immutable, and should offer public, 9 | * no argument constructors.

10 | * 11 | *

The methods are handed raw, physical 12 | * database Connections, not c3p0-generated 13 | * proxies.

14 | * 15 | *

Although c3p0 will ensure this with 16 | * respect to state controlled by 17 | * standard JDBC methods, any modifications 18 | * of vendor-specific state shold be made 19 | * consistently so that all Connections 20 | * in the pool are interchangable.

21 | */ 22 | public interface ConnectionCustomizer 23 | { 24 | /** 25 | *

Called immediately after a 26 | * Connection is acquired from the 27 | * underlying database for 28 | * incorporation into the pool.

29 | * 30 | *

This method is only called once 31 | * per Connection. If standard JDBC 32 | * Connection properties are modified — 33 | * specifically catalog, holdability, transactionIsolation, 34 | * readOnly, and typeMap — those modifications 35 | * will override defaults throughout 36 | * the Connection's tenure in the 37 | * pool.

38 | */ 39 | public void onAcquire( Connection c, String parentDataSourceIdentityToken ) 40 | throws Exception; 41 | 42 | /** 43 | * Called immediately before a 44 | * Connection is destroyed after 45 | * being removed from the pool. 46 | */ 47 | public void onDestroy( Connection c, String parentDataSourceIdentityToken ) 48 | throws Exception; 49 | 50 | /** 51 | * Called immediately before a 52 | * Connection is made available to 53 | * a client upon checkout. 54 | */ 55 | public void onCheckOut( Connection c, String parentDataSourceIdentityToken ) 56 | throws Exception; 57 | 58 | /** 59 | * Called immediately after a 60 | * Connection is checked in, 61 | * prior to reincorporation 62 | * into the pool. 63 | */ 64 | public void onCheckIn( Connection c, String parentDataSourceIdentityToken ) 65 | throws Exception; 66 | } 67 | -------------------------------------------------------------------------------- /src/com/mchange/v2/c3p0/ConnectionTester.java: -------------------------------------------------------------------------------- 1 | package com.mchange.v2.c3p0; 2 | 3 | import java.io.Serializable; 4 | import java.sql.Connection; 5 | 6 | /** 7 | *

Define your own Connection tester if you want to 8 | * override c3p0's default behavior for testing the validity 9 | * of Connections and responding to Connection errors encountered.

10 | * 11 | *

Recommended: If you'd like your ConnectionTester 12 | * to support the user-configured preferredTestQuery 13 | * parameter, please implement {@link com.mchange.v2.c3p0.UnifiedConnectionTester}. 14 | * 15 | *

ConnectionTesters should be Serializable, immutable, 16 | * and must have public, no-arg constructors.

17 | * 18 | * @see com.mchange.v2.c3p0.UnifiedConnectionTester 19 | * @see com.mchange.v2.c3p0.AbstractConnectionTester 20 | */ 21 | public interface ConnectionTester extends Serializable 22 | { 23 | public final static int CONNECTION_IS_OKAY = 0; 24 | public final static int CONNECTION_IS_INVALID = -1; 25 | public final static int DATABASE_IS_INVALID = -8; 26 | 27 | public int activeCheckConnection(Connection c); 28 | 29 | public int statusOnException(Connection c, Throwable t); 30 | } 31 | -------------------------------------------------------------------------------- /src/com/mchange/v2/c3p0/FixedThreadPoolExecutorTaskRunnerFactory.java: -------------------------------------------------------------------------------- 1 | package com.mchange.v2.c3p0; 2 | 3 | import java.util.Timer; 4 | import java.util.concurrent.Executor; 5 | import java.util.concurrent.Executors; 6 | import java.util.concurrent.ThreadFactory; 7 | import javax.sql.ConnectionPoolDataSource; 8 | import com.mchange.v2.async.ThreadPoolReportingAsynchronousRunner; 9 | 10 | /** 11 | * This implementation supports all relevant config, including numHelperThreads, maxAdministrativeTaskTime, 12 | * contextClassLoaderSource, and privilegeSpawnedThreads. 13 | */ 14 | public final class FixedThreadPoolExecutorTaskRunnerFactory extends AbstractExecutorTaskRunnerFactory 15 | { 16 | // for lazy initialization, called only on first-use 17 | protected Executor findCreateExecutor( TaskRunnerInit init ) 18 | { 19 | ThreadFactory tf = new TaskRunnerThreadFactory( init.contextClassLoaderSourceIfSupported, init.privilege_spawned_threads_if_supported, init.threadLabelIfSupported, null ); 20 | return Executors.newFixedThreadPool( init.num_threads_if_supported, tf ); 21 | } 22 | 23 | protected boolean taskRunnerOwnsExecutor() { return true; } 24 | 25 | protected ThreadPoolReportingAsynchronousRunner createTaskRunner( TaskRunnerInit init, Timer timer ) 26 | { return new FixedThreadPoolExecutorAsynchronousRunner( init, timer ); } 27 | 28 | protected final class FixedThreadPoolExecutorAsynchronousRunner extends AbstractExecutorAsynchronousRunner 29 | { 30 | protected FixedThreadPoolExecutorAsynchronousRunner( TaskRunnerInit init, Timer timer ) 31 | { super( init, timer ); } 32 | 33 | public int getThreadCount() { return init.num_threads_if_supported; } 34 | public int getIdleCount() { return getThreadCount() - getActiveCount(); } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/com/mchange/v2/c3p0/FullQueryConnectionTester.java: -------------------------------------------------------------------------------- 1 | package com.mchange.v2.c3p0; 2 | 3 | import java.sql.Connection; 4 | 5 | public interface FullQueryConnectionTester extends QueryConnectionTester 6 | { 7 | public int statusOnException(Connection c, Throwable t, String preferredTestQuery); 8 | } 9 | 10 | -------------------------------------------------------------------------------- /src/com/mchange/v2/c3p0/PoolBackedDataSource.java: -------------------------------------------------------------------------------- 1 | package com.mchange.v2.c3p0; 2 | 3 | import com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource; 4 | 5 | public final class PoolBackedDataSource extends AbstractPoolBackedDataSource implements PooledDataSource 6 | { 7 | public PoolBackedDataSource( boolean autoregister ) 8 | { super( autoregister ); } 9 | 10 | public PoolBackedDataSource() 11 | { this( true ); } 12 | 13 | public PoolBackedDataSource(String configName) 14 | { 15 | this(); 16 | initializeNamedConfig( configName, false ); 17 | } 18 | 19 | // no support for a longer form with config 20 | public String toString( boolean show_config ) { return this.toString(); } 21 | 22 | } 23 | 24 | -------------------------------------------------------------------------------- /src/com/mchange/v2/c3p0/QueryConnectionTester.java: -------------------------------------------------------------------------------- 1 | package com.mchange.v2.c3p0; 2 | 3 | import java.sql.Connection; 4 | 5 | public interface QueryConnectionTester extends ConnectionTester 6 | { 7 | public int activeCheckConnection(Connection c, String preferredTestQuery); 8 | } 9 | 10 | -------------------------------------------------------------------------------- /src/com/mchange/v2/c3p0/SQLWarnings.java: -------------------------------------------------------------------------------- 1 | package com.mchange.v2.c3p0; 2 | 3 | import java.sql.Connection; 4 | import java.sql.SQLException; 5 | import java.sql.SQLWarning; 6 | 7 | import com.mchange.v2.log.MLevel; 8 | import com.mchange.v2.log.MLog; 9 | import com.mchange.v2.log.MLogger; 10 | 11 | public final class SQLWarnings 12 | { 13 | final static MLogger logger = MLog.getLogger( SQLWarnings.class ); 14 | 15 | public static void logAndClearWarnings(Connection con) throws SQLException 16 | { 17 | if (logger.isLoggable(MLevel.INFO)) 18 | { 19 | for(SQLWarning w = con.getWarnings(); w != null; w = w.getNextWarning()) 20 | logger.log(MLevel.INFO, w.getMessage(), w); 21 | } 22 | con.clearWarnings(); 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /src/com/mchange/v2/c3p0/TaskRunnerFactory.java: -------------------------------------------------------------------------------- 1 | package com.mchange.v2.c3p0; 2 | 3 | import java.util.Timer; 4 | import javax.sql.ConnectionPoolDataSource; 5 | import com.mchange.v2.async.*; 6 | 7 | /** 8 | * A TaskRunnerFactory should be an immutable class with a public, no-arg constructor, and implement equals and hashCode methods to help support canonicalization. 9 | * 10 | * The createTaskRunner method will receive values for all supportable 11 | * configuration. It is up to the implementation to decide and document what config it can or cannot support. 12 | * 13 | * Implementations may find it convenient to capture configuration information as a {@link TaskRunnerInit}. 14 | */ 15 | public interface TaskRunnerFactory 16 | { 17 | public ThreadPoolReportingAsynchronousRunner createTaskRunner( 18 | int num_threads_if_supported, 19 | int max_administrative_task_time_if_supported, // in seconds! 20 | String contextClassLoaderSourceIfSupported, 21 | boolean privilege_spawned_threads_if_supported, 22 | String threadLabelIfSupported, 23 | ConnectionPoolDataSource cpds, 24 | Timer timer 25 | ); 26 | } 27 | -------------------------------------------------------------------------------- /src/com/mchange/v2/c3p0/TaskRunnerInit.java: -------------------------------------------------------------------------------- 1 | package com.mchange.v2.c3p0; 2 | 3 | import java.util.*; 4 | 5 | /** 6 | * All fields will always be supplied from configuration and calling code, 7 | * the "if supported" stuff is just a reminder that TaskRunner implementations 8 | * need not and may not support the provided config. 9 | * 10 | * (It's a fine idea to log a note, if some config will be ignored!) 11 | */ 12 | public final class TaskRunnerInit 13 | { 14 | public final int num_threads_if_supported; 15 | public final int max_administrative_task_time_if_supported; // in seconds! 16 | public final String contextClassLoaderSourceIfSupported; 17 | public final boolean privilege_spawned_threads_if_supported; 18 | public final String threadLabelIfSupported; 19 | public final Map otherProperties; 20 | 21 | public TaskRunnerInit ( 22 | int num_threads_if_supported, 23 | int max_administrative_task_time_if_supported, // in seconds! 24 | String contextClassLoaderSourceIfSupported, 25 | boolean privilege_spawned_threads_if_supported, 26 | String threadLabelIfSupported, 27 | HashMap otherProperties 28 | ) 29 | { 30 | this.num_threads_if_supported = num_threads_if_supported; 31 | this.max_administrative_task_time_if_supported = max_administrative_task_time_if_supported; // in seconds! 32 | this.contextClassLoaderSourceIfSupported = contextClassLoaderSourceIfSupported; 33 | this.privilege_spawned_threads_if_supported = privilege_spawned_threads_if_supported; 34 | this.threadLabelIfSupported = threadLabelIfSupported; 35 | this.otherProperties = Collections.unmodifiableMap( (HashMap) otherProperties.clone() ); 36 | } 37 | 38 | public boolean equals( Object o ) 39 | { 40 | if (o instanceof TaskRunnerInit) 41 | { 42 | TaskRunnerInit other = (TaskRunnerInit) o; 43 | return 44 | this.num_threads_if_supported == other.num_threads_if_supported && 45 | this.max_administrative_task_time_if_supported == other.max_administrative_task_time_if_supported && 46 | this.contextClassLoaderSourceIfSupported.equals( other.contextClassLoaderSourceIfSupported ) && 47 | this.privilege_spawned_threads_if_supported == other.privilege_spawned_threads_if_supported && 48 | this.threadLabelIfSupported.equals( other.threadLabelIfSupported ) && 49 | this.otherProperties.equals(other.otherProperties); 50 | } 51 | else 52 | return false; 53 | } 54 | 55 | public int hashCode() 56 | { 57 | return 58 | this.num_threads_if_supported ^ 59 | this.max_administrative_task_time_if_supported ^ 60 | this.contextClassLoaderSourceIfSupported.hashCode() ^ 61 | (this.privilege_spawned_threads_if_supported ? 1 : 0) ^ 62 | this.threadLabelIfSupported.hashCode() ^ 63 | this.otherProperties.hashCode(); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/com/mchange/v2/c3p0/TaskRunnerThreadFactory.java: -------------------------------------------------------------------------------- 1 | package com.mchange.v2.c3p0; 2 | 3 | import com.mchange.v2.log.*; 4 | 5 | import java.security.AccessController; 6 | import java.security.PrivilegedAction; 7 | 8 | import java.util.concurrent.ThreadFactory; 9 | 10 | public final class TaskRunnerThreadFactory implements ThreadFactory 11 | { 12 | private final static MLogger logger = MLog.getLogger( TaskRunnerThreadFactory.class ); 13 | 14 | private final static ClassLoader LIBRARY_CLASSLOADER_INSTANCE = TaskRunnerThreadFactory.class.getClassLoader(); 15 | 16 | private static interface ContextClassLoaderSetter 17 | { 18 | public void set(Thread t); 19 | } 20 | 21 | private final static ContextClassLoaderSetter NO_CLASSLOADER = new ContextClassLoaderSetter() 22 | { 23 | public void set(Thread t) { t.setContextClassLoader(null); } 24 | }; 25 | private final static ContextClassLoaderSetter LIBRARY_CLASSLOADER = new ContextClassLoaderSetter() 26 | { 27 | public void set(Thread t) { t.setContextClassLoader(LIBRARY_CLASSLOADER_INSTANCE); } 28 | }; 29 | private final static ContextClassLoaderSetter CALLER_CLASSLOADER = new ContextClassLoaderSetter() 30 | { 31 | public void set(Thread t) { /* t.setContextClassLoader(Thread.currentThread().getContextClassLoader()); */ } // just let it propogate, it's the default 32 | }; 33 | 34 | //MT: Unchanging post-constuctor 35 | ContextClassLoaderSetter contextClassLoaderSetter; 36 | boolean privilege_spawned_threads; 37 | String threadLabel; 38 | ThreadGroup threadGroup; 39 | 40 | //MT: Protected by this' lock 41 | int count = 0; 42 | 43 | public TaskRunnerThreadFactory( String contextClassLoaderSource, boolean privilege_spawned_threads, String threadLabel, ThreadGroup threadGroup /* can be null */ ) 44 | { 45 | if ("none".equalsIgnoreCase(contextClassLoaderSource)) 46 | this.contextClassLoaderSetter = NO_CLASSLOADER; 47 | else if ("library".equalsIgnoreCase(contextClassLoaderSource)) 48 | this.contextClassLoaderSetter = LIBRARY_CLASSLOADER; 49 | else 50 | { 51 | if ( logger.isLoggable( MLevel.WARNING ) && ! "caller".equalsIgnoreCase( contextClassLoaderSource ) ) 52 | logger.log( MLevel.WARNING, "Unknown contextClassLoaderSource: " + contextClassLoaderSource + " -- should be 'caller', 'library', or 'none'. Using default value 'caller'." ); 53 | this.contextClassLoaderSetter = CALLER_CLASSLOADER; 54 | } 55 | this.privilege_spawned_threads = privilege_spawned_threads; 56 | this.threadLabel = threadLabel; 57 | this.threadGroup = threadGroup; 58 | } 59 | 60 | private synchronized int nextCount() 61 | { return ++count; } 62 | 63 | private Thread createUnprivileged(Runnable r) 64 | { 65 | Thread out = new Thread(threadGroup, r, threadLabel + "-" + nextCount()); 66 | contextClassLoaderSetter.set(out); 67 | return out; 68 | } 69 | 70 | public Thread newThread(final Runnable r) 71 | { 72 | if ( privilege_spawned_threads ) 73 | { 74 | PrivilegedAction privilegedRun = new PrivilegedAction() 75 | { 76 | public Object run() { return createUnprivileged(r); } 77 | }; 78 | return (Thread) AccessController.doPrivileged( privilegedRun ); 79 | } 80 | else 81 | return createUnprivileged(r); 82 | } 83 | } 84 | 85 | -------------------------------------------------------------------------------- /src/com/mchange/v2/c3p0/UnifiedConnectionTester.java: -------------------------------------------------------------------------------- 1 | package com.mchange.v2.c3p0; 2 | 3 | import java.sql.Connection; 4 | 5 | /** 6 | *

Having expanded the once-simple ConnectionTester interface to support both 7 | * user-specified queries and return of root cause Exceptions (via an out-param), 8 | * this interface has grown unnecessarily complex.

9 | * 10 | *

If you wish to implement a custom Connection tester, here is the simple 11 | * way to do it

12 | * 13 | *
    14 | *
  1. Extend {@link com.mchange.v2.c3p0.AbstractConnectionTester}
  2. 15 | *
  3. 16 | * Override only the two abstract methods 17 | *
      18 | *
    • public int activeCheckConnection(Connection c, String preferredTestQuery, Throwable[] rootCauseOutParamHolder)
    • 19 | *
    • public int statusOnException(Connection c, Throwable t, String preferredTestQuery, Throwable[] rootCauseOutParamHolder)
    • 20 | *
    21 | *
  4. 22 | *
  5. Take care to ensure that your methods are defined to allow preferredTestQuery and 23 | * rootCauseOutParamHolder to be null.
  6. 24 | *
25 | * 26 | *

Parameter rootCauseOutParamHolder is an optional parameter, which if supplied, will be a Throwable array whose size 27 | * it at least one. If a Connection test fails because of some Exception, the Connection tester may set this Exception as the 28 | * zero-th element of the array to provide information about why and how the test failed.

29 | */ 30 | public interface UnifiedConnectionTester extends FullQueryConnectionTester 31 | { 32 | public final static int CONNECTION_IS_OKAY = ConnectionTester.CONNECTION_IS_OKAY; 33 | public final static int CONNECTION_IS_INVALID = ConnectionTester.CONNECTION_IS_INVALID; 34 | public final static int DATABASE_IS_INVALID = ConnectionTester.DATABASE_IS_INVALID; 35 | 36 | public int activeCheckConnection(Connection c); 37 | public int activeCheckConnection(Connection c, Throwable[] rootCauseOutParamHolder); 38 | public int activeCheckConnection(Connection c, String preferredTestQuery); 39 | public int activeCheckConnection(Connection c, String preferredTestQuery, Throwable[] rootCauseOutParamHolder); 40 | 41 | public int statusOnException(Connection c, Throwable t); 42 | public int statusOnException(Connection c, Throwable t, Throwable[] rootCauseOutParamHolder); 43 | public int statusOnException(Connection c, Throwable t, String preferredTestQuery); 44 | public int statusOnException(Connection c, Throwable t, String preferredTestQuery, Throwable[] rootCauseOutParamHolder); 45 | 46 | public boolean equals(Object o); 47 | public int hashCode(); 48 | } 49 | -------------------------------------------------------------------------------- /src/com/mchange/v2/c3p0/cfg/C3P0ConfigFinder.java: -------------------------------------------------------------------------------- 1 | package com.mchange.v2.c3p0.cfg; 2 | 3 | import java.sql.SQLException; 4 | 5 | public interface C3P0ConfigFinder 6 | { 7 | public C3P0Config findConfig() throws Exception; 8 | } 9 | -------------------------------------------------------------------------------- /src/com/mchange/v2/c3p0/cfg/InvalidConfigException.java: -------------------------------------------------------------------------------- 1 | package com.mchange.v2.c3p0.cfg; 2 | 3 | public final class InvalidConfigException extends Exception 4 | { 5 | public InvalidConfigException( String message, Throwable cause ) 6 | { super( message, cause ); } 7 | 8 | public InvalidConfigException( String message ) 9 | { this( message, null ); } 10 | } 11 | -------------------------------------------------------------------------------- /src/com/mchange/v2/c3p0/cfg/NamedScope.java: -------------------------------------------------------------------------------- 1 | package com.mchange.v2.c3p0.cfg; 2 | 3 | import java.util.*; 4 | 5 | //all internal maps should be HashMaps (the implementation presumes HashMaps) 6 | 7 | class NamedScope 8 | { 9 | HashMap props; 10 | HashMap userNamesToOverrides; 11 | HashMap extensions; 12 | 13 | NamedScope() 14 | { 15 | this.props = new HashMap(); 16 | this.userNamesToOverrides = new HashMap(); 17 | this.extensions = new HashMap(); 18 | } 19 | 20 | NamedScope( HashMap props, HashMap userNamesToOverrides, HashMap extensions) 21 | { 22 | this.props = props; 23 | this.userNamesToOverrides = userNamesToOverrides; 24 | this.extensions = extensions; 25 | } 26 | 27 | NamedScope mergedOver( NamedScope underScope ) 28 | { 29 | HashMap mergedProps = (HashMap) underScope.props.clone(); 30 | mergedProps.putAll( this.props ); 31 | 32 | HashMap mergedUserNamesToOverrides = mergeUserNamesToOverrides( this.userNamesToOverrides, underScope.userNamesToOverrides ); 33 | 34 | HashMap mergedExtensions = mergeExtensions( this.extensions, underScope.extensions ); 35 | 36 | return new NamedScope( mergedProps, mergedUserNamesToOverrides, mergedExtensions ); 37 | } 38 | 39 | static HashMap mergeExtensions( HashMap over, HashMap under ) 40 | { 41 | HashMap out = (HashMap) under.clone(); 42 | out.putAll( over ); 43 | return out; 44 | } 45 | 46 | static HashMap mergeUserNamesToOverrides( HashMap over, HashMap under ) 47 | { 48 | HashMap out = (HashMap) under.clone(); 49 | 50 | HashSet underUserNames = new HashSet( under.keySet() ); 51 | HashSet overUserNames = new HashSet( over.keySet() ); 52 | 53 | HashSet newUserNames = (HashSet) overUserNames.clone(); 54 | newUserNames.removeAll( underUserNames ); 55 | 56 | for ( Iterator ii = newUserNames.iterator(); ii.hasNext(); ) 57 | { 58 | String name = (String) ii.next(); 59 | out.put( name, ((HashMap) over.get( name )).clone() ); 60 | } 61 | 62 | HashSet mergeUserNames = (HashSet) overUserNames.clone(); 63 | mergeUserNames.retainAll( underUserNames ); 64 | 65 | for ( Iterator ii = mergeUserNames.iterator(); ii.hasNext(); ) 66 | { 67 | String name = (String) ii.next(); 68 | ((HashMap) out.get(name)).putAll( (HashMap) over.get( name ) ); 69 | } 70 | 71 | return out; 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /src/com/mchange/v2/c3p0/cfg/Validator.java: -------------------------------------------------------------------------------- 1 | package com.mchange.v2.c3p0.cfg; 2 | 3 | interface Validator 4 | { 5 | public T validate( T value ) throws InvalidConfigException; 6 | } 7 | -------------------------------------------------------------------------------- /src/com/mchange/v2/c3p0/cfg/Validators.java: -------------------------------------------------------------------------------- 1 | package com.mchange.v2.c3p0.cfg; 2 | 3 | public final class Validators 4 | { 5 | static abstract class AbstractValidator implements Validator 6 | { 7 | String param; 8 | 9 | AbstractValidator( String param ) 10 | { this.param = param; } 11 | 12 | abstract T _validate( T value ) throws InvalidConfigException; 13 | 14 | public T validate( T value ) throws InvalidConfigException 15 | { 16 | try 17 | { return _validate(value); } 18 | catch (InvalidConfigException ice) 19 | { throw ice; } 20 | catch (Exception e) 21 | { throw new InvalidConfigException("While validating '" + param + "', encountered Exception: " + e, e); } 22 | } 23 | } 24 | 25 | public static Validator MarkSessionBoundaries = new AbstractValidator("markSessionBoundaries") 26 | { 27 | String _validate( String value ) throws InvalidConfigException 28 | { 29 | String out = value.toLowerCase(); 30 | if ("always".equals(out)||"never".equals(out)||"if-no-statement-cache".equals(out)) 31 | return out; 32 | else 33 | throw new InvalidConfigException(param + " must be one of 'always', 'never', or 'if-no-statement-cache'. Found '" + value + "'."); 34 | } 35 | }; 36 | 37 | public static Validator ContextClassLoaderSource = new AbstractValidator("contextClassLoaderSource") 38 | { 39 | String _validate( String value ) throws InvalidConfigException 40 | { 41 | String out = value.toLowerCase(); 42 | if ("caller".equals(out)||"library".equals(out)||"none".equals(out)) 43 | return out; 44 | else 45 | throw new InvalidConfigException(param + " must be one of 'caller', 'library', or 'none'. Found '" + value + "'."); 46 | } 47 | }; 48 | 49 | private Validators() 50 | {} 51 | } 52 | -------------------------------------------------------------------------------- /src/com/mchange/v2/c3p0/debug/AfterCloseLoggingComboPooledDataSource.java: -------------------------------------------------------------------------------- 1 | package com.mchange.v2.c3p0.debug; 2 | 3 | import java.io.*; 4 | import java.sql.*; 5 | import javax.naming.*; 6 | import com.mchange.v2.log.*; 7 | import com.mchange.v2.c3p0.*; 8 | 9 | /** 10 | *

For the meaning of most of these properties, please see c3p0's top-level documentation!

11 | */ 12 | public final class AfterCloseLoggingComboPooledDataSource extends AbstractComboPooledDataSource implements Serializable, Referenceable 13 | { 14 | public AfterCloseLoggingComboPooledDataSource() 15 | { super(); } 16 | 17 | public AfterCloseLoggingComboPooledDataSource( boolean autoregister ) 18 | { super( autoregister ); } 19 | 20 | public AfterCloseLoggingComboPooledDataSource(String configName) 21 | { super( configName ); } 22 | 23 | public Connection getConnection() throws SQLException 24 | { return AfterCloseLoggingConnectionWrapper.wrap( super.getConnection() ); } 25 | 26 | public Connection getConnection(String user, String password) throws SQLException 27 | { return AfterCloseLoggingConnectionWrapper.wrap( super.getConnection(user, password) ); } 28 | 29 | // serialization stuff 30 | private static final long serialVersionUID = 1; 31 | private static final short VERSION = 0x0001; 32 | 33 | private void writeObject( ObjectOutputStream oos ) throws IOException 34 | { 35 | oos.writeShort( VERSION ); 36 | } 37 | 38 | private void readObject( ObjectInputStream ois ) throws IOException, ClassNotFoundException 39 | { 40 | short version = ois.readShort(); 41 | switch (version) 42 | { 43 | case VERSION: 44 | //ok 45 | break; 46 | default: 47 | throw new IOException("Unsupported Serialized Version: " + version); 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/com/mchange/v2/c3p0/debug/AfterCloseLoggingConnectionWrapper.java: -------------------------------------------------------------------------------- 1 | package com.mchange.v2.c3p0.debug; 2 | 3 | import java.lang.reflect.*; 4 | import java.sql.*; 5 | import com.mchange.v2.log.*; 6 | import com.mchange.v2.c3p0.*; 7 | import com.mchange.v2.reflect.*; 8 | import com.mchange.v2.sql.filter.*; 9 | 10 | public class AfterCloseLoggingConnectionWrapper extends FilterConnection 11 | { 12 | final static MLogger logger = MLog.getLogger( AfterCloseLoggingConnectionWrapper.class ); 13 | 14 | public static Connection wrap( Connection inner ) 15 | { 16 | try 17 | { 18 | Constructor ctor = ReflectUtils.findProxyConstructor( AfterCloseLoggingConnectionWrapper.class.getClassLoader(), Connection.class ); 19 | return (Connection) ctor.newInstance( new AfterCloseLoggingInvocationHandler( inner ) ); 20 | } 21 | catch ( Exception e ) 22 | { 23 | if ( logger.isLoggable( MLevel.SEVERE ) ) 24 | logger.log( MLevel.SEVERE, "An unexpected Exception occured while trying to instantiate a dynamic proxy.", e ); 25 | 26 | throw new RuntimeException( e ); 27 | } 28 | } 29 | 30 | private static class AfterCloseLoggingInvocationHandler implements InvocationHandler 31 | { 32 | final Connection inner; 33 | 34 | volatile SQLWarning closeStackTrace = null; 35 | 36 | AfterCloseLoggingInvocationHandler( Connection inner ) 37 | { this.inner = inner; } 38 | 39 | public Object invoke(Object proxy, Method method, Object[] args) throws Throwable 40 | { 41 | if ( "close".equals( method.getName() ) && closeStackTrace == null ) 42 | closeStackTrace = new SQLWarning("DEBUG STACK TRACE -- " + inner + ".close() first-call stack trace."); 43 | else if ( closeStackTrace != null ) 44 | { 45 | if ( logger.isLoggable( MLevel.INFO ) ) 46 | logger.log( MLevel.INFO, String.format("Method '%s' called after call to Connection close().", method) ); 47 | if ( logger.isLoggable( MLevel.FINE ) ) 48 | { 49 | logger.log( MLevel.FINE, "After-close() method call stack trace:", new SQLWarning("DEBUG STACK TRACE -- ILLEGAL use of " + inner + " after call to close()." ) ); 50 | logger.log( MLevel.FINE, "Original close() call stack trace:", closeStackTrace ); 51 | } 52 | } 53 | 54 | return method.invoke( inner, args ); 55 | } 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /src/com/mchange/v2/c3p0/debug/CloseLoggingComboPooledDataSource.java: -------------------------------------------------------------------------------- 1 | package com.mchange.v2.c3p0.debug; 2 | 3 | import java.io.*; 4 | import java.sql.*; 5 | import javax.naming.*; 6 | import com.mchange.v2.log.*; 7 | import com.mchange.v2.c3p0.*; 8 | 9 | /** 10 | *

For the meaning of most of these properties, please see c3p0's top-level documentation!

11 | */ 12 | public final class CloseLoggingComboPooledDataSource extends AbstractComboPooledDataSource implements Serializable, Referenceable 13 | { 14 | volatile MLevel level = MLevel.INFO; 15 | 16 | public void setCloseLogLevel( MLevel level ) { this.level = level; } 17 | public MLevel getCloseLogLevel() { return level; } 18 | 19 | public CloseLoggingComboPooledDataSource() 20 | { super(); } 21 | 22 | public CloseLoggingComboPooledDataSource( boolean autoregister ) 23 | { super( autoregister ); } 24 | 25 | public CloseLoggingComboPooledDataSource(String configName) 26 | { super( configName ); } 27 | 28 | public Connection getConnection() throws SQLException 29 | { return new CloseLoggingConnectionWrapper( super.getConnection(), level ); } 30 | 31 | public Connection getConnection(String user, String password) throws SQLException 32 | { return new CloseLoggingConnectionWrapper( super.getConnection(user, password), level ); } 33 | 34 | // serialization stuff -- set up bound/constrained property event handlers on deserialization 35 | private static final long serialVersionUID = 1; 36 | private static final short VERSION = 0x0001; 37 | 38 | private void writeObject( ObjectOutputStream oos ) throws IOException 39 | { 40 | oos.writeShort( VERSION ); 41 | } 42 | 43 | private void readObject( ObjectInputStream ois ) throws IOException, ClassNotFoundException 44 | { 45 | short version = ois.readShort(); 46 | switch (version) 47 | { 48 | case VERSION: 49 | //ok 50 | break; 51 | default: 52 | throw new IOException("Unsupported Serialized Version: " + version); 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/com/mchange/v2/c3p0/debug/CloseLoggingConnectionWrapper.java: -------------------------------------------------------------------------------- 1 | package com.mchange.v2.c3p0.debug; 2 | 3 | import java.sql.*; 4 | import com.mchange.v2.log.*; 5 | import com.mchange.v2.c3p0.*; 6 | import com.mchange.v2.sql.filter.*; 7 | 8 | public class CloseLoggingConnectionWrapper extends FilterConnection 9 | { 10 | final static MLogger logger = MLog.getLogger( CloseLoggingConnectionWrapper.class ); 11 | 12 | final MLevel level; 13 | 14 | public CloseLoggingConnectionWrapper( Connection conn, MLevel level ) 15 | { 16 | super( conn ); 17 | this.level = level; 18 | } 19 | 20 | public void close() throws SQLException 21 | { 22 | super.close(); 23 | if ( logger.isLoggable( level ) ) 24 | logger.log( level, "DEBUG: A Connection has closed been close()ed without error.", new SQLWarning("DEBUG STACK TRACE -- Connection.close() was called.") ); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/com/mchange/v2/c3p0/debug/ConstructionLoggingComboPooledDataSource.java: -------------------------------------------------------------------------------- 1 | package com.mchange.v2.c3p0.debug; 2 | 3 | import java.io.*; 4 | import java.sql.*; 5 | import javax.naming.*; 6 | import com.mchange.v2.log.*; 7 | import com.mchange.v2.c3p0.*; 8 | 9 | /** 10 | *

For the meaning of most of these properties, please see c3p0's top-level documentation!

11 | */ 12 | public final class ConstructionLoggingComboPooledDataSource extends AbstractComboPooledDataSource implements Serializable, Referenceable 13 | { 14 | final static MLogger logger = MLog.getLogger( ConstructionLoggingComboPooledDataSource.class ); 15 | 16 | public ConstructionLoggingComboPooledDataSource() 17 | { 18 | super(); 19 | if ( logger.isLoggable( MLevel.FINE ) ) 20 | logger.log( MLevel.FINE, 21 | "Creation of ConstructionLoggingComboPooledDataSource.", 22 | new Exception("DEBUG STACK TRACE -- CREATION OF ConstructionLoggingComboPooledDataSource") ); 23 | } 24 | 25 | public ConstructionLoggingComboPooledDataSource( boolean autoregister ) 26 | { 27 | super( autoregister ); 28 | if ( logger.isLoggable( MLevel.FINE ) ) 29 | logger.log( MLevel.FINE, 30 | "Creation of ConstructionLoggingComboPooledDataSource.", 31 | new Exception("DEBUG STACK TRACE -- CREATION OF ConstructionLoggingComboPooledDataSource") ); 32 | } 33 | 34 | public ConstructionLoggingComboPooledDataSource(String configName) 35 | { 36 | super( configName ); 37 | if ( logger.isLoggable( MLevel.FINE ) ) 38 | logger.log( MLevel.FINE, 39 | "Creation of ConstructionLoggingComboPooledDataSource.", 40 | new Exception("DEBUG STACK TRACE -- CREATION OF ConstructionLoggingComboPooledDataSource") ); 41 | } 42 | 43 | // serialization stuff 44 | private static final long serialVersionUID = 1; 45 | private static final short VERSION = 0x0001; 46 | 47 | private void writeObject( ObjectOutputStream oos ) throws IOException 48 | { 49 | oos.writeShort( VERSION ); 50 | } 51 | 52 | private void readObject( ObjectInputStream ois ) throws IOException, ClassNotFoundException 53 | { 54 | short version = ois.readShort(); 55 | switch (version) 56 | { 57 | case VERSION: 58 | //ok 59 | break; 60 | default: 61 | throw new IOException("Unsupported Serialized Version: " + version); 62 | } 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/com/mchange/v2/c3p0/example/InitSqlConnectionCustomizer.java: -------------------------------------------------------------------------------- 1 | package com.mchange.v2.c3p0.example; 2 | 3 | import java.sql.*; 4 | import com.mchange.v2.log.*; 5 | import com.mchange.v2.c3p0.AbstractConnectionCustomizer; 6 | 7 | public class InitSqlConnectionCustomizer extends AbstractConnectionCustomizer 8 | { 9 | final static MLogger logger = MLog.getLogger( InitSqlConnectionCustomizer.class ); 10 | 11 | private String getInitSql( String parentDataSourceIdentityToken ) 12 | { return (String) extensionsForToken( parentDataSourceIdentityToken ).get ( "initSql" ); } 13 | 14 | public void onCheckOut( Connection c, String parentDataSourceIdentityToken ) throws Exception 15 | { 16 | String initSql = getInitSql( parentDataSourceIdentityToken ); 17 | if ( initSql != null ) 18 | { 19 | Statement stmt = null; 20 | try 21 | { 22 | stmt = c.createStatement(); 23 | int num = stmt.executeUpdate( initSql ); 24 | if ( logger.isLoggable( MLevel.FINEST ) ) 25 | logger.log( MLevel.FINEST, "Initialized checked-out Connection '" + c + "' with initSql '" + initSql + "'. Return value: " + num ); 26 | } 27 | finally 28 | { if ( stmt != null ) stmt.close(); } 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/com/mchange/v2/c3p0/example/IsValidOnlyConnectionTester30.java: -------------------------------------------------------------------------------- 1 | package com.mchange.v2.c3p0.example; 2 | 3 | import com.mchange.v2.c3p0.util.IsValidOnlyConnectionTester; 4 | 5 | public final class IsValidOnlyConnectionTester30 extends IsValidOnlyConnectionTester 6 | { 7 | protected int getIsValidTimeout() { return 30; } 8 | } 9 | -------------------------------------------------------------------------------- /src/com/mchange/v2/c3p0/filter/FilterDataSource.java: -------------------------------------------------------------------------------- 1 | package com.mchange.v2.c3p0.filter; 2 | 3 | import java.io.PrintWriter; 4 | import java.lang.String; 5 | import java.sql.Connection; 6 | import java.sql.SQLException; 7 | import javax.sql.DataSource; 8 | 9 | 10 | public abstract class FilterDataSource implements DataSource 11 | { 12 | protected DataSource inner; 13 | 14 | public FilterDataSource(DataSource inner) 15 | { 16 | this.inner = inner; 17 | } 18 | 19 | public Connection getConnection() throws SQLException 20 | { 21 | return inner.getConnection(); 22 | } 23 | 24 | public Connection getConnection(String a, String b) throws SQLException 25 | { 26 | return inner.getConnection(a, b); 27 | } 28 | 29 | public PrintWriter getLogWriter() throws SQLException 30 | { 31 | return inner.getLogWriter(); 32 | } 33 | 34 | public int getLoginTimeout() throws SQLException 35 | { 36 | return inner.getLoginTimeout(); 37 | } 38 | 39 | public void setLogWriter(PrintWriter a) throws SQLException 40 | { 41 | inner.setLogWriter(a); 42 | } 43 | 44 | public void setLoginTimeout(int a) throws SQLException 45 | { 46 | inner.setLoginTimeout(a); 47 | } 48 | 49 | } 50 | 51 | -------------------------------------------------------------------------------- /src/com/mchange/v2/c3p0/impl/AbstractC3P0PooledConnection.java: -------------------------------------------------------------------------------- 1 | package com.mchange.v2.c3p0.impl; 2 | 3 | import java.sql.Connection; 4 | import java.sql.SQLException; 5 | import javax.sql.PooledConnection; 6 | import java.util.concurrent.locks.ReentrantLock; 7 | import com.mchange.v2.c3p0.stmt.GooGooStatementCache; 8 | import com.mchange.v1.util.ClosableResource; 9 | 10 | abstract class AbstractC3P0PooledConnection implements PooledConnection, ClosableResource 11 | { 12 | // thread-safe post c'tor constant, accessed directly by C3P0PooledConnectionPool 13 | // since the StatementCache "in-use" marker doesn't nest, we have to ensure that 14 | // internal Connection tests don't overlap. (External use, due to checkout, 15 | // is no problem, no internal operation are performed on checked-out PooledConnections 16 | final ReentrantLock inInternalUseLock = new ReentrantLock(); 17 | 18 | abstract Connection getPhysicalConnection(); 19 | abstract void initStatementCache(GooGooStatementCache scache); 20 | abstract void closeMaybeCheckedOut( boolean checked_out ) throws SQLException; 21 | } 22 | -------------------------------------------------------------------------------- /src/com/mchange/v2/c3p0/impl/AbstractIdentityTokenized.java: -------------------------------------------------------------------------------- 1 | package com.mchange.v2.c3p0.impl; 2 | /* 3 | * It would be convenient to put the getter/setter methods 4 | * for the identity token here, but unfortunately we have no 5 | * way of setting up the for Referenceability in multiple 6 | * levels of a class hierarchy. So we leave the getters/setters, 7 | * and variable initialization to code-generators. 8 | */ 9 | public abstract class AbstractIdentityTokenized implements IdentityTokenized 10 | { 11 | public boolean equals(Object o) 12 | { 13 | if (this == o) 14 | return true; 15 | 16 | if (o instanceof IdentityTokenized) 17 | return this.getIdentityToken().equals( ((IdentityTokenized) o).getIdentityToken() ); 18 | else 19 | return false; 20 | } 21 | 22 | public int hashCode() 23 | { return ~this.getIdentityToken().hashCode(); } 24 | } 25 | -------------------------------------------------------------------------------- /src/com/mchange/v2/c3p0/impl/AuthMaskingProperties.java: -------------------------------------------------------------------------------- 1 | package com.mchange.v2.c3p0.impl; 2 | 3 | import java.util.Enumeration; 4 | import java.util.Properties; 5 | 6 | public class AuthMaskingProperties extends Properties 7 | { 8 | public AuthMaskingProperties() 9 | { super(); } 10 | 11 | public AuthMaskingProperties( Properties p ) 12 | { super( p ); } 13 | 14 | public static AuthMaskingProperties fromAnyProperties( Properties p ) 15 | { 16 | AuthMaskingProperties out = new AuthMaskingProperties(); 17 | for( Enumeration e = p.propertyNames(); e.hasMoreElements(); ) 18 | { 19 | String key = (String) e.nextElement(); 20 | out.setProperty( key, p.getProperty( key ) ); 21 | } 22 | return out; 23 | } 24 | 25 | private String normalToString() 26 | { return super.toString(); } 27 | 28 | public String toString() 29 | { 30 | boolean hasUser = (this.get("user") != null); 31 | boolean hasPassword = (this.get("password") != null); 32 | if ( hasUser || hasPassword ) 33 | { 34 | AuthMaskingProperties clone = (AuthMaskingProperties) this.clone(); 35 | if (hasUser) 36 | clone.put("user", "******"); 37 | if (hasPassword) 38 | clone.put("password", "******"); 39 | return clone.normalToString(); 40 | } 41 | else 42 | return this.normalToString(); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/com/mchange/v2/c3p0/impl/C3P0JavaBeanObjectFactory.java: -------------------------------------------------------------------------------- 1 | package com.mchange.v2.c3p0.impl; 2 | 3 | import java.lang.reflect.Constructor; 4 | import java.util.Map; 5 | import java.util.Set; 6 | import com.mchange.v2.c3p0.C3P0Registry; 7 | import com.mchange.v2.naming.JavaBeanObjectFactory; 8 | 9 | public class C3P0JavaBeanObjectFactory extends JavaBeanObjectFactory 10 | { 11 | private final static Class[] CTOR_ARG_TYPES = new Class[] { boolean.class }; 12 | private final static Object[] CTOR_ARGS = new Object[] { Boolean.FALSE }; 13 | 14 | protected Object createBlankInstance(Class beanClass) throws Exception 15 | { 16 | if ( IdentityTokenized.class.isAssignableFrom( beanClass ) ) 17 | { 18 | Constructor ctor = beanClass.getConstructor( CTOR_ARG_TYPES ); 19 | return ctor.newInstance( CTOR_ARGS ); 20 | } 21 | else 22 | return super.createBlankInstance( beanClass ); 23 | } 24 | 25 | protected Object findBean(Class beanClass, Map propertyMap, Set refProps ) throws Exception 26 | { 27 | Object out = super.findBean( beanClass, propertyMap, refProps ); 28 | if (out instanceof IdentityTokenized) 29 | out = C3P0Registry.reregister( (IdentityTokenized) out ); 30 | //System.err.println("--> findBean()"); 31 | //System.err.println(out); 32 | return out; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/com/mchange/v2/c3p0/impl/ConnectionTestPath.java: -------------------------------------------------------------------------------- 1 | package com.mchange.v2.c3p0.impl; 2 | 3 | import java.sql.Connection; 4 | import javax.sql.PooledConnection; 5 | 6 | interface ConnectionTestPath 7 | { 8 | // if proxyConn is provided, just test it. 9 | // if not, we have to get a proxy Connection from the PooledConnection, 10 | // then be sure to close() or detach the proxy 11 | public void testPooledConnection(PooledConnection pc, Connection proxyConn) throws Exception; 12 | } 13 | -------------------------------------------------------------------------------- /src/com/mchange/v2/c3p0/impl/DbAuth.java: -------------------------------------------------------------------------------- 1 | package com.mchange.v2.c3p0.impl; 2 | 3 | import java.io.*; 4 | import com.mchange.v2.lang.ObjectUtils; 5 | import com.mchange.v2.ser.UnsupportedVersionException; 6 | 7 | public final class DbAuth implements Serializable 8 | { 9 | transient String username; 10 | transient String password; 11 | 12 | public DbAuth(String username, String password) 13 | { 14 | this.username = username; 15 | this.password = password; 16 | } 17 | 18 | public String getUser() 19 | { return username; } 20 | 21 | public String getPassword() 22 | { return password; } 23 | 24 | public String getMaskedUserString() 25 | { return getMaskedUserString(2, 8); } 26 | 27 | private String getMaskedUserString( int chars_to_reveal, int total_chars ) 28 | { 29 | if ( username == null ) return "null"; 30 | else 31 | { 32 | StringBuffer sb = new StringBuffer(32); 33 | if ( username.length() >= chars_to_reveal ) 34 | { 35 | sb.append( username.substring(0, chars_to_reveal) ); 36 | for (int i = 0, len = total_chars - chars_to_reveal; i < len; ++i) 37 | sb.append('*'); 38 | } 39 | else 40 | sb.append( username ); 41 | return sb.toString(); 42 | } 43 | } 44 | 45 | public boolean equals(Object o) 46 | { 47 | if (this == o) 48 | return true; 49 | else if (o != null && this.getClass() == o.getClass()) 50 | { 51 | DbAuth other = (DbAuth) o; 52 | return 53 | ObjectUtils.eqOrBothNull(this.username, other.username) && 54 | ObjectUtils.eqOrBothNull(this.password, other.password); 55 | } 56 | else 57 | return false; 58 | } 59 | 60 | public int hashCode() 61 | { 62 | return 63 | ObjectUtils.hashOrZero(username) ^ 64 | ObjectUtils.hashOrZero(password); 65 | } 66 | 67 | //Serialization 68 | static final long serialVersionUID = 1; //override to take control of versioning 69 | private final static short VERSION = 0x0001; 70 | 71 | private void writeObject(ObjectOutputStream out) throws IOException 72 | { 73 | out.writeShort(VERSION); 74 | out.writeObject(username); //may be null 75 | out.writeObject(password); //may be null 76 | } 77 | 78 | private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException 79 | { 80 | short version = in.readShort(); 81 | switch (version) 82 | { 83 | case 0x0001: 84 | this.username = (String) in.readObject(); 85 | this.password = (String) in.readObject(); 86 | break; 87 | default: 88 | throw new UnsupportedVersionException(this, version); 89 | } 90 | } 91 | } 92 | 93 | 94 | 95 | 96 | 97 | -------------------------------------------------------------------------------- /src/com/mchange/v2/c3p0/impl/DefaultTaskRunnerFactory.java: -------------------------------------------------------------------------------- 1 | package com.mchange.v2.c3p0.impl; 2 | 3 | import java.util.Timer; 4 | import javax.sql.ConnectionPoolDataSource; 5 | import com.mchange.v2.async.*; 6 | import com.mchange.v2.c3p0.TaskRunnerFactory; 7 | 8 | public final class DefaultTaskRunnerFactory implements TaskRunnerFactory 9 | { 10 | public ThreadPoolReportingAsynchronousRunner createTaskRunner( 11 | final int num_threads, 12 | final int matt, // maxAdministrativeTaskTime, in seconds 13 | final String contextClassLoaderSource, 14 | final boolean privilege_spawned_threads, 15 | final String threadLabel, 16 | final ConnectionPoolDataSource cpds, 17 | final Timer timer 18 | ) 19 | { 20 | // we use the array as holder, because we need a final variable for the innner class 21 | final ThreadPoolAsynchronousRunner[] outHolder = new ThreadPoolAsynchronousRunner[1]; 22 | 23 | Runnable initializer = new Runnable() 24 | { 25 | public void run() 26 | { 27 | if ( matt > 0 ) 28 | { 29 | int matt_ms = matt * 1000; 30 | outHolder[0] = new ThreadPoolAsynchronousRunner( num_threads, 31 | true, // daemon thread 32 | matt_ms, // wait before interrupt() 33 | matt_ms * 3, // wait before deadlock declared if no tasks clear 34 | matt_ms * 6, // wait before deadlock tasks are interrupted (again) 35 | // after the hung thread has been cleared and replaced 36 | // (in hopes of getting the thread to terminate for 37 | // garbage collection) 38 | timer, 39 | threadLabel ); 40 | } 41 | else 42 | outHolder[0] = new ThreadPoolAsynchronousRunner( num_threads, true, timer, threadLabel ); 43 | } 44 | }; 45 | C3P0ImplUtils.runWithContextClassLoaderAndPrivileges( contextClassLoaderSource, privilege_spawned_threads, initializer ); 46 | 47 | return outHolder[0]; 48 | } 49 | 50 | public boolean equals( Object o ) { return this.getClass().equals( o.getClass() ); } 51 | public int hashCode() { return this.getClass().getName().hashCode(); } 52 | } 53 | -------------------------------------------------------------------------------- /src/com/mchange/v2/c3p0/impl/IdentityTokenResolvable.java: -------------------------------------------------------------------------------- 1 | package com.mchange.v2.c3p0.impl; 2 | 3 | import com.mchange.v2.c3p0.*; 4 | import java.io.ObjectStreamException; 5 | 6 | /** 7 | * This is a convenient base class for all classes 8 | * that wish to establish an initial identity which 9 | * will be the basis of a one-per vm identity: i.e. 10 | * in any vm there should only ever be a single object 11 | * with a given identity token (except transiently during 12 | * canonicalization) 13 | * 14 | * It would be convenient to put the getter/setter methods 15 | * for the identity token here, but unfortunately we have no 16 | * way of setting up the for Referenceability in multiple 17 | * levels of a class hierarchy. So we leave the getters/setters, 18 | * and variable initialization to code-generators. 19 | */ 20 | public abstract class IdentityTokenResolvable extends AbstractIdentityTokenized 21 | { 22 | public static Object doResolve(IdentityTokenized itd) 23 | { return C3P0Registry.reregister( itd ); } 24 | 25 | protected Object readResolve() throws ObjectStreamException 26 | { 27 | //System.err.println("READ RESOLVE!!!!"); 28 | Object out = doResolve( this ); 29 | verifyResolve( out ); 30 | //System.err.println("ORIG: " + this); 31 | //System.err.println("RSLV: " + out); 32 | return out; 33 | } 34 | 35 | protected void verifyResolve( Object o ) throws ObjectStreamException 36 | {} 37 | } 38 | -------------------------------------------------------------------------------- /src/com/mchange/v2/c3p0/impl/IdentityTokenized.java: -------------------------------------------------------------------------------- 1 | package com.mchange.v2.c3p0.impl; 2 | 3 | public interface IdentityTokenized 4 | { 5 | public String getIdentityToken(); 6 | public void setIdentityToken(String idToken); 7 | } 8 | -------------------------------------------------------------------------------- /src/com/mchange/v2/c3p0/impl/IdentityTokenizedCoalesceChecker.java: -------------------------------------------------------------------------------- 1 | package com.mchange.v2.c3p0.impl; 2 | 3 | import com.mchange.v2.coalesce.*; 4 | 5 | public final class IdentityTokenizedCoalesceChecker implements CoalesceChecker 6 | { 7 | public static IdentityTokenizedCoalesceChecker INSTANCE = new IdentityTokenizedCoalesceChecker(); 8 | 9 | public boolean checkCoalesce( Object a, Object b ) 10 | { 11 | IdentityTokenized aa = (IdentityTokenized) a; 12 | IdentityTokenized bb = (IdentityTokenized) b; 13 | 14 | String ta = aa.getIdentityToken(); 15 | String tb = bb.getIdentityToken(); 16 | 17 | if (ta == null || tb == null) 18 | throw new NullPointerException( "[c3p0 bug] An IdentityTokenized object has no identity token set?!?! " + (ta == null ? ta : tb) ); 19 | else 20 | return ta.equals(tb); 21 | } 22 | 23 | public int coalesceHash( Object a ) 24 | { 25 | String t = ((IdentityTokenized) a).getIdentityToken(); 26 | return (t != null ? t.hashCode() : 0); 27 | } 28 | 29 | private IdentityTokenizedCoalesceChecker() 30 | {} 31 | } 32 | -------------------------------------------------------------------------------- /src/com/mchange/v2/c3p0/impl/InternalPooledConnection.java: -------------------------------------------------------------------------------- 1 | package com.mchange.v2.c3p0.impl; 2 | 3 | import javax.sql.*; 4 | import com.mchange.v2.c3p0.stmt.*; 5 | 6 | interface InternalPooledConnection extends PooledConnection 7 | { 8 | public void initStatementCache( GooGooStatementCache scache ); 9 | public GooGooStatementCache getStatementCache(); 10 | public int getConnectionStatus(); 11 | } 12 | -------------------------------------------------------------------------------- /src/com/mchange/v2/c3p0/impl/IsValidSimplifiedConnectionTestPath.java: -------------------------------------------------------------------------------- 1 | package com.mchange.v2.c3p0.impl; 2 | 3 | import java.sql.Connection; 4 | import java.sql.SQLException; 5 | import javax.sql.PooledConnection; 6 | 7 | import com.mchange.v1.db.sql.ConnectionUtils; 8 | 9 | import com.mchange.v2.c3p0.*; 10 | import com.mchange.v2.log.*; 11 | import com.mchange.v2.resourcepool.*; 12 | 13 | 14 | final class IsValidSimplifiedConnectionTestPath implements ConnectionTestPath 15 | { 16 | private final static MLogger logger = MLog.getLogger( IsValidSimplifiedConnectionTestPath.class ); 17 | 18 | private final ResourcePool rp; 19 | private final int isValidTimeout; 20 | 21 | IsValidSimplifiedConnectionTestPath( ResourcePool rp, final int isValidTimeout ) 22 | { 23 | this.rp = rp; 24 | 25 | if (isValidTimeout < 0) 26 | { 27 | if (logger.isLoggable(MLevel.WARNING)) 28 | logger.log(MLevel.WARNING, "Negative values of connectionIsValidTimeout are not supported. Using default value of " + C3P0Defaults.connectionIsValidTimeout()); 29 | this.isValidTimeout = C3P0Defaults.connectionIsValidTimeout(); 30 | } 31 | else 32 | this.isValidTimeout = isValidTimeout; 33 | } 34 | 35 | public void testPooledConnection(PooledConnection pc, Connection proxyConn) throws Exception 36 | { 37 | if (proxyConn != null) 38 | doTestConnection( proxyConn ); 39 | else 40 | { 41 | Connection conn = null; 42 | try 43 | { 44 | conn = pc.getConnection(); 45 | doTestConnection( conn ); 46 | } 47 | finally 48 | { ConnectionUtils.attemptClose( conn ); } 49 | } 50 | } 51 | 52 | private void doTestConnection( Connection conn ) throws Exception 53 | { 54 | try 55 | { 56 | if (!conn.isValid( isValidTimeout )) 57 | throw new SQLException("Connection is invalid. (isValid returned false)."); 58 | } 59 | catch (SQLException e) 60 | { 61 | if ( DefaultConnectionTester.probableInvalidDb(e) ) 62 | rp.resetPool(); 63 | throw e; 64 | } 65 | catch (Exception e) // some unexpected Exception 66 | { 67 | // we might consider resetting the pool for entirely unexpected Exceptions. 68 | // It's arguable, but DefaultConnectionTester traditionally has not, we'll not upset 69 | // upgraders' expectations at least for now 70 | if ( logger.isLoggable( MLevel.FINER ) ) 71 | logger.log(MLevel.FINER, "An unexpected Exception occurred while testing a Connection.", e); 72 | throw e; 73 | } 74 | } 75 | 76 | public static int isValidTestConnectionForStatusOnly( Connection conn, int isValidTimeout ) 77 | { 78 | try 79 | { 80 | if (conn.isValid( isValidTimeout )) 81 | return ConnectionTester.CONNECTION_IS_OKAY; 82 | else 83 | return ConnectionTester.CONNECTION_IS_INVALID; 84 | } 85 | catch (SQLException e) 86 | { 87 | if ( DefaultConnectionTester.probableInvalidDb(e) ) 88 | return ConnectionTester.DATABASE_IS_INVALID; 89 | else 90 | return ConnectionTester.CONNECTION_IS_INVALID; 91 | } 92 | catch (Exception e) // some unexpected Exception 93 | { 94 | // we might consider resetting the pool for entirely unexpected Exceptions. 95 | // It's arguable, but DefaultConnectionTester traditionally has not, we'll not upset 96 | // upgraders expectations at least for now 97 | if ( logger.isLoggable( MLevel.FINER ) ) 98 | logger.log(MLevel.FINER, "An unexpected Exception occurred while testing a Connection.", e); 99 | return ConnectionTester.CONNECTION_IS_INVALID; 100 | } 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /src/com/mchange/v2/c3p0/impl/NullStatementSetManagedResultSet.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Created on Apr 6, 2004 3 | * 4 | * To change the template for this generated file go to 5 | * Window>Preferences>Java>Code Generation>Code and Comments 6 | */ 7 | package com.mchange.v2.c3p0.impl; 8 | 9 | import java.sql.ResultSet; 10 | import java.sql.Statement; 11 | import java.util.Set; 12 | 13 | 14 | final class NullStatementSetManagedResultSet extends SetManagedResultSet 15 | { 16 | NullStatementSetManagedResultSet(Set activeResultSets) 17 | { super( activeResultSets ); } 18 | 19 | NullStatementSetManagedResultSet(ResultSet inner, Set activeResultSets) 20 | { super( inner, activeResultSets); } 21 | 22 | public Statement getStatement() 23 | { return null; } 24 | } 25 | -------------------------------------------------------------------------------- /src/com/mchange/v2/c3p0/impl/SetManagedResultSet.java: -------------------------------------------------------------------------------- 1 | package com.mchange.v2.c3p0.impl; 2 | 3 | import java.sql.*; 4 | import java.util.Set; 5 | import com.mchange.v2.sql.filter.FilterResultSet; 6 | 7 | abstract class SetManagedResultSet extends FilterResultSet 8 | { 9 | Set activeResultSets; 10 | 11 | SetManagedResultSet(Set activeResultSets) 12 | { 13 | this.activeResultSets = activeResultSets; 14 | } 15 | 16 | SetManagedResultSet(ResultSet inner, Set activeResultSets) 17 | { 18 | super( inner ); 19 | this.activeResultSets = activeResultSets; 20 | } 21 | 22 | public synchronized void setInner(ResultSet inner) 23 | { 24 | this.inner = inner; 25 | activeResultSets.add( inner ); 26 | } 27 | 28 | public synchronized void close() throws SQLException 29 | { 30 | if ( inner != null ) 31 | { 32 | inner.close(); 33 | activeResultSets.remove( inner ); 34 | inner = null; 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/com/mchange/v2/c3p0/impl/SnatchFromSetResultSet.java: -------------------------------------------------------------------------------- 1 | package com.mchange.v2.c3p0.impl; 2 | 3 | import java.sql.*; 4 | import java.util.Set; 5 | import com.mchange.v2.sql.filter.FilterResultSet; 6 | 7 | final class SnatchFromSetResultSet extends FilterResultSet 8 | { 9 | Set activeResultSets; 10 | 11 | SnatchFromSetResultSet(Set activeResultSets) 12 | { this.activeResultSets = activeResultSets; } 13 | 14 | public synchronized void setInner(ResultSet inner) 15 | { 16 | this.inner = inner; 17 | activeResultSets.add( inner ); 18 | } 19 | 20 | public synchronized void close() throws SQLException 21 | { 22 | inner.close(); 23 | activeResultSets.remove( inner ); 24 | inner = null; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/com/mchange/v2/c3p0/management/C3P0RegistryManager.java: -------------------------------------------------------------------------------- 1 | package com.mchange.v2.c3p0.management; 2 | 3 | import java.util.*; 4 | import java.sql.SQLException; 5 | import com.mchange.v2.c3p0.C3P0Registry; 6 | import com.mchange.v2.c3p0.subst.C3P0Substitutions; 7 | 8 | public class C3P0RegistryManager implements C3P0RegistryManagerMBean 9 | { 10 | public String[] getAllIdentityTokens() 11 | { 12 | Set tokens = C3P0Registry.allIdentityTokens(); 13 | return (String[]) tokens.toArray( new String[ tokens.size() ] ); 14 | } 15 | 16 | public Set getAllIdentityTokenized() 17 | { return C3P0Registry.allIdentityTokenized(); } 18 | 19 | public Set getAllPooledDataSources() 20 | { return C3P0Registry.allPooledDataSources(); } 21 | 22 | public int getAllIdentityTokenCount() 23 | { return C3P0Registry.allIdentityTokens().size(); } 24 | 25 | public int getAllIdentityTokenizedCount() 26 | { return C3P0Registry.allIdentityTokenized().size(); } 27 | 28 | public int getAllPooledDataSourcesCount() 29 | { return C3P0Registry.allPooledDataSources().size(); } 30 | 31 | public String[] getAllIdentityTokenizedStringified() 32 | { return stringifySet( C3P0Registry.allIdentityTokenized() ); } 33 | 34 | public String[] getAllPooledDataSourcesStringified() 35 | { return stringifySet( C3P0Registry.allPooledDataSources() ); } 36 | 37 | public int getNumPooledDataSources() throws SQLException 38 | { return C3P0Registry.getNumPooledDataSources(); } 39 | 40 | public int getNumPoolsAllDataSources() throws SQLException 41 | { return C3P0Registry.getNumPoolsAllDataSources(); } 42 | 43 | public String getC3p0Version() 44 | { return C3P0Substitutions.VERSION ; } 45 | 46 | private String[] stringifySet(Set s) 47 | { 48 | String[] out = new String[ s.size() ]; 49 | int i = 0; 50 | for (Iterator ii = s.iterator(); ii.hasNext(); ) 51 | out[i++] = ii.next().toString(); 52 | return out; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/com/mchange/v2/c3p0/management/C3P0RegistryManagerMBean.java: -------------------------------------------------------------------------------- 1 | package com.mchange.v2.c3p0.management; 2 | 3 | import java.sql.SQLException; 4 | import java.util.Set; 5 | 6 | public interface C3P0RegistryManagerMBean 7 | { 8 | public String[] getAllIdentityTokens(); 9 | public Set getAllIdentityTokenized(); 10 | public Set getAllPooledDataSources(); 11 | 12 | public int getAllIdentityTokenCount(); 13 | public int getAllIdentityTokenizedCount(); 14 | public int getAllPooledDataSourcesCount(); 15 | 16 | public String[] getAllIdentityTokenizedStringified(); 17 | public String[] getAllPooledDataSourcesStringified(); 18 | 19 | public int getNumPooledDataSources() throws SQLException; 20 | public int getNumPoolsAllDataSources() throws SQLException; 21 | 22 | public String getC3p0Version(); 23 | } 24 | -------------------------------------------------------------------------------- /src/com/mchange/v2/c3p0/management/ManagementCoordinator.java: -------------------------------------------------------------------------------- 1 | package com.mchange.v2.c3p0.management; 2 | 3 | import com.mchange.v2.c3p0.PooledDataSource; 4 | 5 | public interface ManagementCoordinator 6 | { 7 | public void attemptManageC3P0Registry(); 8 | public void attemptUnmanageC3P0Registry(); 9 | public void attemptManagePooledDataSource(PooledDataSource pds); 10 | public void attemptUnmanagePooledDataSource( PooledDataSource pds ); 11 | } 12 | 13 | -------------------------------------------------------------------------------- /src/com/mchange/v2/c3p0/management/NullManagementCoordinator.java: -------------------------------------------------------------------------------- 1 | package com.mchange.v2.c3p0.management; 2 | 3 | import com.mchange.v2.c3p0.PooledDataSource; 4 | 5 | public class NullManagementCoordinator implements ManagementCoordinator 6 | { 7 | public void attemptManageC3P0Registry() 8 | {} 9 | 10 | public void attemptUnmanageC3P0Registry() 11 | {} 12 | 13 | public void attemptManagePooledDataSource(PooledDataSource pds) 14 | {} 15 | 16 | public void attemptUnmanagePooledDataSource( PooledDataSource pds ) 17 | {} 18 | } 19 | 20 | -------------------------------------------------------------------------------- /src/com/mchange/v2/c3p0/management/PooledDataSourceManagerMBean.java: -------------------------------------------------------------------------------- 1 | package com.mchange.v2.c3p0.management; 2 | 3 | import java.sql.SQLException; 4 | import java.util.Collection; 5 | 6 | public interface PooledDataSourceManagerMBean 7 | { 8 | public String getIdentityToken(); 9 | public String getDataSourceName(); 10 | public void setDataSourceName(String dataSourceName); 11 | public int getNumConnectionsDefaultUser() throws SQLException; 12 | public int getNumIdleConnectionsDefaultUser() throws SQLException; 13 | public int getNumBusyConnectionsDefaultUser() throws SQLException; 14 | public int getNumUnclosedOrphanedConnectionsDefaultUser() throws SQLException; 15 | public float getEffectivePropertyCycleDefaultUser() throws SQLException; 16 | public void softResetDefaultUser() throws SQLException; 17 | public int getNumConnections(String username, String password) throws SQLException; 18 | public int getNumIdleConnections(String username, String password) throws SQLException; 19 | public int getNumBusyConnections(String username, String password) throws SQLException; 20 | public int getNumUnclosedOrphanedConnections(String username, String password) throws SQLException; 21 | public float getEffectivePropertyCycle(String username, String password) throws SQLException; 22 | public void softReset(String username, String password) throws SQLException; 23 | public int getNumBusyConnectionsAllUsers() throws SQLException; 24 | public int getNumIdleConnectionsAllUsers() throws SQLException; 25 | public int getNumConnectionsAllUsers() throws SQLException; 26 | public int getNumUnclosedOrphanedConnectionsAllUsers() throws SQLException; 27 | public int getThreadPoolSize() throws SQLException; 28 | public int getThreadPoolNumActiveThreads() throws SQLException; 29 | public int getThreadPoolNumIdleThreads() throws SQLException; 30 | public int getThreadPoolNumTasksPending() throws SQLException; 31 | public String sampleThreadPoolStackTraces() throws SQLException; 32 | public String sampleThreadPoolStatus() throws SQLException; 33 | public void softResetAllUsers() throws SQLException; 34 | public int getNumUserPools() throws SQLException; 35 | public Collection getAllUsers() throws SQLException; 36 | public void hardReset() throws SQLException; 37 | public void close() throws SQLException; 38 | } 39 | -------------------------------------------------------------------------------- /src/com/mchange/v2/c3p0/stmt/DoubleMaxStatementCache.java: -------------------------------------------------------------------------------- 1 | package com.mchange.v2.c3p0.stmt; 2 | 3 | import java.sql.*; 4 | import com.mchange.v2.async.AsynchronousRunner; 5 | 6 | public final class DoubleMaxStatementCache extends GooGooStatementCache 7 | { 8 | //MT: protected by parent's mainLock 9 | int max_statements; 10 | Deathmarch globalDeathmarch = new Deathmarch(); 11 | 12 | int max_statements_per_connection; 13 | DeathmarchConnectionStatementManager dcsm; 14 | 15 | public DoubleMaxStatementCache( 16 | AsynchronousRunner blockingTaskAsyncRunner, 17 | AsynchronousRunner deferredStatementDestroyer, 18 | int max_statements, 19 | int max_statements_per_connection, 20 | boolean cancelAutomaticallyClosedStatements 21 | ) 22 | { 23 | super( blockingTaskAsyncRunner, deferredStatementDestroyer, cancelAutomaticallyClosedStatements ); 24 | this.max_statements = max_statements; 25 | this.max_statements_per_connection = max_statements_per_connection; 26 | } 27 | 28 | //called only in parent's constructor 29 | protected ConnectionStatementManager createConnectionStatementManager() 30 | { return (this.dcsm = new DeathmarchConnectionStatementManager()); } 31 | 32 | //all methods below called by parent only with parent's mainLock 33 | void addStatementToDeathmarches( Object pstmt, Connection physicalConnection ) 34 | { 35 | globalDeathmarch.deathmarchStatement( pstmt ); 36 | dcsm.getDeathmarch( physicalConnection ).deathmarchStatement( pstmt ); 37 | } 38 | 39 | void removeStatementFromDeathmarches( Object pstmt, Connection physicalConnection ) 40 | { 41 | globalDeathmarch.undeathmarchStatement( pstmt ); 42 | dcsm.getDeathmarch( physicalConnection ).undeathmarchStatement( pstmt ); 43 | } 44 | 45 | boolean prepareAssimilateNewStatement(Connection pcon) 46 | { 47 | int cxn_stmt_count = dcsm.getNumStatementsForConnection( pcon ); 48 | if (cxn_stmt_count < max_statements_per_connection) //okay... we can cache another for the connection, but how 'bout globally? 49 | { 50 | int global_size = this.countCachedStatements(); 51 | return ( global_size < max_statements || (global_size == max_statements && globalDeathmarch.cullNext()) ); 52 | } 53 | else //we can only cache if we can clear one from the Connection (which implies clearing one globally, so we needn't check max_statements) 54 | return (cxn_stmt_count == max_statements_per_connection && dcsm.getDeathmarch( pcon ).cullNext()); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/com/mchange/v2/c3p0/stmt/GlobalMaxOnlyStatementCache.java: -------------------------------------------------------------------------------- 1 | package com.mchange.v2.c3p0.stmt; 2 | 3 | import java.sql.*; 4 | import com.mchange.v2.async.AsynchronousRunner; 5 | 6 | public final class GlobalMaxOnlyStatementCache extends GooGooStatementCache 7 | { 8 | //MT: protected by parent's mainLock 9 | int max_statements; 10 | 11 | Deathmarch globalDeathmarch = new Deathmarch(); 12 | 13 | public GlobalMaxOnlyStatementCache(AsynchronousRunner blockingTaskAsyncRunner, AsynchronousRunner deferredStatementDestroyer, int max_statements, boolean cancelAutomaticallyClosedStatements ) 14 | { 15 | super( blockingTaskAsyncRunner, deferredStatementDestroyer, cancelAutomaticallyClosedStatements ); 16 | this.max_statements = max_statements; 17 | } 18 | 19 | //called only in parent's constructor 20 | protected ConnectionStatementManager createConnectionStatementManager() 21 | { return new SimpleConnectionStatementManager(); } 22 | 23 | //all below called by parent only with mainLock 24 | void addStatementToDeathmarches( Object pstmt, Connection physicalConnection ) 25 | { globalDeathmarch.deathmarchStatement( pstmt ); } 26 | 27 | void removeStatementFromDeathmarches( Object pstmt, Connection physicalConnection ) 28 | { globalDeathmarch.undeathmarchStatement( pstmt ); } 29 | 30 | boolean prepareAssimilateNewStatement(Connection pcon) 31 | { 32 | int global_size = this.countCachedStatements(); 33 | return ( global_size < max_statements || (global_size == max_statements && globalDeathmarch.cullNext()) ); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/com/mchange/v2/c3p0/stmt/PerConnectionMaxOnlyStatementCache.java: -------------------------------------------------------------------------------- 1 | package com.mchange.v2.c3p0.stmt; 2 | 3 | import java.sql.*; 4 | import com.mchange.v2.async.AsynchronousRunner; 5 | 6 | public final class PerConnectionMaxOnlyStatementCache extends GooGooStatementCache 7 | { 8 | //MT: protected by parent's mainLock 9 | int max_statements_per_connection; 10 | DeathmarchConnectionStatementManager dcsm; 11 | 12 | public PerConnectionMaxOnlyStatementCache ( 13 | AsynchronousRunner blockingTaskAsyncRunner, 14 | AsynchronousRunner deferredStatementDestroyer, 15 | int max_statements_per_connection, 16 | boolean cancelAutomaticallyClosedStatements 17 | ) 18 | { 19 | super( blockingTaskAsyncRunner, deferredStatementDestroyer, cancelAutomaticallyClosedStatements ); 20 | this.max_statements_per_connection = max_statements_per_connection; 21 | } 22 | 23 | //called only in parent's constructor 24 | protected ConnectionStatementManager createConnectionStatementManager() 25 | { return (this.dcsm = new DeathmarchConnectionStatementManager()); } 26 | 27 | //all below called by parent only with mainLock 28 | void addStatementToDeathmarches( Object pstmt, Connection physicalConnection ) 29 | { dcsm.getDeathmarch( physicalConnection ).deathmarchStatement( pstmt ); } 30 | 31 | void removeStatementFromDeathmarches( Object pstmt, Connection physicalConnection ) 32 | { dcsm.getDeathmarch( physicalConnection ).undeathmarchStatement( pstmt ); } 33 | 34 | boolean prepareAssimilateNewStatement(Connection pcon) 35 | { 36 | int cxn_stmt_count = dcsm.getNumStatementsForConnection( pcon ); 37 | return ( cxn_stmt_count < max_statements_per_connection || (cxn_stmt_count == max_statements_per_connection && dcsm.getDeathmarch( pcon ).cullNext()) ); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/com/mchange/v2/c3p0/stmt/StatementCache.java: -------------------------------------------------------------------------------- 1 | package com.mchange.v2.c3p0.stmt; 2 | 3 | import java.lang.reflect.*; 4 | import java.sql.*; 5 | import com.mchange.v1.util.ClosableResource; 6 | 7 | public interface StatementCache extends ClosableResource 8 | { 9 | public Object checkoutStatement( Connection physicalConnection, 10 | Method stmtProducingMethod, 11 | Object[] args ) 12 | throws SQLException; 13 | 14 | public void checkinStatement( Object pstmt ) 15 | throws SQLException; 16 | 17 | public void checkinAll( Connection pcon ) 18 | throws SQLException; 19 | 20 | public void closeAll( Connection pcon ) 21 | throws SQLException; 22 | 23 | public void close() 24 | throws SQLException; 25 | } 26 | 27 | -------------------------------------------------------------------------------- /src/com/mchange/v2/c3p0/util/CloseReportingConnectionWrapper.java: -------------------------------------------------------------------------------- 1 | package com.mchange.v2.c3p0.util; 2 | 3 | import java.sql.*; 4 | import com.mchange.v2.sql.filter.*; 5 | 6 | /** 7 | * @deprecated Please use com.mchange.v2.c3p0.debug.CloseLoggingConnectionWrapper 8 | */ 9 | public class CloseReportingConnectionWrapper extends FilterConnection 10 | { 11 | public CloseReportingConnectionWrapper( Connection conn ) 12 | { super( conn ); } 13 | 14 | public void close() throws SQLException 15 | { 16 | //System.err.print("ADRIAN -- "); 17 | new SQLWarning("Connection.close() called!").printStackTrace(); 18 | super.close(); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/com/mchange/v2/c3p0/util/ConnectionEventSupport.java: -------------------------------------------------------------------------------- 1 | package com.mchange.v2.c3p0.util; 2 | 3 | import java.util.*; 4 | import java.sql.*; 5 | import javax.sql.*; 6 | 7 | public class ConnectionEventSupport 8 | { 9 | private PooledConnection source; 10 | private HashSet mlisteners = new HashSet(); 11 | 12 | public ConnectionEventSupport(PooledConnection source) 13 | { this.source = source; } 14 | 15 | public synchronized void addConnectionEventListener(ConnectionEventListener mlistener) 16 | {mlisteners.add(mlistener);} 17 | 18 | public synchronized void removeConnectionEventListener(ConnectionEventListener mlistener) 19 | {mlisteners.remove(mlistener);} 20 | 21 | public synchronized void printListeners() 22 | { System.err.println( mlisteners ); } 23 | 24 | public synchronized int getListenerCount() 25 | { return mlisteners.size(); } 26 | 27 | public void fireConnectionClosed() 28 | { 29 | Set mlCopy; 30 | 31 | synchronized (this) 32 | { mlCopy = (Set) mlisteners.clone(); } 33 | 34 | ConnectionEvent evt = new ConnectionEvent(source); 35 | for (Iterator i = mlCopy.iterator(); i.hasNext();) 36 | { 37 | ConnectionEventListener cl = (ConnectionEventListener) i.next(); 38 | cl.connectionClosed(evt); 39 | } 40 | } 41 | 42 | public void fireConnectionErrorOccurred(SQLException error) 43 | { 44 | Set mlCopy; 45 | 46 | synchronized (this) 47 | { mlCopy = (Set) mlisteners.clone(); } 48 | 49 | ConnectionEvent evt = new ConnectionEvent(source, error); 50 | for (Iterator i = mlCopy.iterator(); i.hasNext();) 51 | { 52 | ConnectionEventListener cl = (ConnectionEventListener) i.next(); 53 | cl.connectionErrorOccurred(evt); 54 | } 55 | } 56 | } 57 | 58 | 59 | 60 | -------------------------------------------------------------------------------- /src/com/mchange/v2/c3p0/util/StatementEventSupport.java: -------------------------------------------------------------------------------- 1 | package com.mchange.v2.c3p0.util; 2 | 3 | import java.util.*; 4 | import java.sql.*; 5 | import javax.sql.*; 6 | 7 | public class StatementEventSupport 8 | { 9 | PooledConnection source; 10 | HashSet mlisteners = new HashSet(); 11 | 12 | public StatementEventSupport(PooledConnection source) 13 | { this.source = source; } 14 | 15 | public synchronized void addStatementEventListener(StatementEventListener mlistener) 16 | {mlisteners.add(mlistener);} 17 | 18 | public synchronized void removeStatementEventListener(StatementEventListener mlistener) 19 | {mlisteners.remove(mlistener);} 20 | 21 | public synchronized void printListeners() 22 | { System.err.println( mlisteners ); } 23 | 24 | public synchronized int getListenerCount() 25 | { return mlisteners.size(); } 26 | 27 | public void fireStatementClosed(PreparedStatement ps) 28 | { 29 | Set mlCopy; 30 | 31 | synchronized (this) 32 | { mlCopy = (Set) mlisteners.clone(); } 33 | 34 | StatementEvent evt = new StatementEvent(source, ps); 35 | for (Iterator i = mlCopy.iterator(); i.hasNext();) 36 | { 37 | StatementEventListener cl = (StatementEventListener) i.next(); 38 | cl.statementClosed(evt); 39 | } 40 | } 41 | 42 | public void fireStatementErrorOccurred(PreparedStatement ps, SQLException error) 43 | { 44 | Set mlCopy; 45 | 46 | synchronized (this) 47 | { mlCopy = (Set) mlisteners.clone(); } 48 | 49 | StatementEvent evt = new StatementEvent(source, ps, error); 50 | for (Iterator i = mlCopy.iterator(); i.hasNext();) 51 | { 52 | StatementEventListener cl = (StatementEventListener) i.next(); 53 | cl.statementErrorOccurred(evt); 54 | } 55 | } 56 | } 57 | 58 | 59 | 60 | -------------------------------------------------------------------------------- /src/com/mchange/v2/resourcepool/CannotAcquireResourceException.java: -------------------------------------------------------------------------------- 1 | package com.mchange.v2.resourcepool; 2 | 3 | public class CannotAcquireResourceException extends ResourcePoolException 4 | { 5 | public CannotAcquireResourceException(String msg, Throwable t) 6 | {super(msg, t);} 7 | 8 | public CannotAcquireResourceException(Throwable t) 9 | {super(t);} 10 | 11 | public CannotAcquireResourceException(String msg) 12 | {super(msg);} 13 | 14 | public CannotAcquireResourceException() 15 | {super();} 16 | } 17 | -------------------------------------------------------------------------------- /src/com/mchange/v2/resourcepool/EventSupportingResourcePool.java: -------------------------------------------------------------------------------- 1 | package com.mchange.v2.resourcepool; 2 | 3 | import com.mchange.v1.util.ClosableResource; 4 | 5 | public interface EventSupportingResourcePool extends ResourcePool 6 | { 7 | /** 8 | * Events may be fired asynchronously: listeners must not rely on 9 | * events to reflect the current state of the pool, but they will 10 | * accurately represent the state of the pool in the recent past 11 | * when the event-provoking incident occurred. 12 | */ 13 | public void addResourcePoolListener(ResourcePoolListener rpl) 14 | throws ResourcePoolException; 15 | 16 | public void removeResourcePoolListener(ResourcePoolListener rpl) 17 | throws ResourcePoolException; 18 | 19 | } 20 | -------------------------------------------------------------------------------- /src/com/mchange/v2/resourcepool/NoGoodResourcesException.java: -------------------------------------------------------------------------------- 1 | package com.mchange.v2.resourcepool; 2 | 3 | public class NoGoodResourcesException extends ResourcePoolException 4 | { 5 | public NoGoodResourcesException(String msg, Throwable t) 6 | {super(msg, t);} 7 | 8 | public NoGoodResourcesException(Throwable t) 9 | {super(t);} 10 | 11 | public NoGoodResourcesException(String msg) 12 | {super(msg);} 13 | 14 | public NoGoodResourcesException() 15 | {super();} 16 | } 17 | -------------------------------------------------------------------------------- /src/com/mchange/v2/resourcepool/ResourcePoolEvent.java: -------------------------------------------------------------------------------- 1 | package com.mchange.v2.resourcepool; 2 | 3 | import java.util.EventObject; 4 | 5 | public class ResourcePoolEvent extends EventObject 6 | { 7 | Object resc; 8 | boolean checked_out_resource; 9 | int pool_size; 10 | int available_size; 11 | int removed_but_unreturned_size; 12 | 13 | public ResourcePoolEvent( ResourcePool pool, 14 | Object resc, 15 | boolean checked_out_resource, 16 | int pool_size, 17 | int available_size, 18 | int removed_but_unreturned_size ) 19 | { 20 | super(pool); 21 | this.resc = resc; 22 | this.checked_out_resource = checked_out_resource; 23 | this.pool_size = pool_size; 24 | this.available_size = available_size; 25 | this.removed_but_unreturned_size = removed_but_unreturned_size; 26 | } 27 | 28 | public Object getResource() 29 | { return resc; } 30 | 31 | public boolean isCheckedOutResource() 32 | { return checked_out_resource; } 33 | 34 | public int getPoolSize() 35 | { return pool_size; } 36 | 37 | public int getAvailableSize() 38 | { return available_size; } 39 | 40 | public int getRemovedButUnreturnedSize() 41 | { return removed_but_unreturned_size; } 42 | } 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | -------------------------------------------------------------------------------- /src/com/mchange/v2/resourcepool/ResourcePoolEventSupport.java: -------------------------------------------------------------------------------- 1 | package com.mchange.v2.resourcepool; 2 | 3 | import java.util.*; 4 | 5 | public class ResourcePoolEventSupport 6 | { 7 | ResourcePool source; 8 | Set mlisteners = new HashSet(); 9 | 10 | public ResourcePoolEventSupport(ResourcePool source) 11 | { this.source = source; } 12 | 13 | public synchronized void addResourcePoolListener(ResourcePoolListener mlistener) 14 | {mlisteners.add(mlistener);} 15 | 16 | public synchronized void removeResourcePoolListener(ResourcePoolListener mlistener) 17 | {mlisteners.remove(mlistener);} 18 | 19 | public synchronized void fireResourceAcquired( Object resc, 20 | int pool_size, 21 | int available_size, 22 | int removed_but_unreturned_size ) 23 | { 24 | if (! mlisteners.isEmpty() ) 25 | { 26 | ResourcePoolEvent evt = new ResourcePoolEvent(source, 27 | resc, 28 | false, 29 | pool_size, 30 | available_size, 31 | removed_but_unreturned_size ); 32 | for (Iterator i = mlisteners.iterator(); i.hasNext();) 33 | { 34 | ResourcePoolListener rpl = (ResourcePoolListener) i.next(); 35 | rpl.resourceAcquired(evt); 36 | } 37 | } 38 | } 39 | 40 | public synchronized void fireResourceCheckedIn( Object resc, 41 | int pool_size, 42 | int available_size, 43 | int removed_but_unreturned_size ) 44 | { 45 | if (! mlisteners.isEmpty() ) 46 | { 47 | ResourcePoolEvent evt = new ResourcePoolEvent(source, 48 | resc, 49 | false, 50 | pool_size, 51 | available_size, 52 | removed_but_unreturned_size ); 53 | for (Iterator i = mlisteners.iterator(); i.hasNext();) 54 | { 55 | ResourcePoolListener rpl = (ResourcePoolListener) i.next(); 56 | rpl.resourceCheckedIn(evt); 57 | } 58 | } 59 | } 60 | 61 | public synchronized void fireResourceCheckedOut( Object resc, 62 | int pool_size, 63 | int available_size, 64 | int removed_but_unreturned_size ) 65 | { 66 | if (! mlisteners.isEmpty() ) 67 | { 68 | ResourcePoolEvent evt = new ResourcePoolEvent(source, 69 | resc, 70 | true, 71 | pool_size, 72 | available_size, 73 | removed_but_unreturned_size ); 74 | for (Iterator i = mlisteners.iterator(); i.hasNext();) 75 | { 76 | ResourcePoolListener rpl = (ResourcePoolListener) i.next(); 77 | rpl.resourceCheckedOut(evt); 78 | } 79 | } 80 | } 81 | 82 | public synchronized void fireResourceRemoved( Object resc, 83 | boolean checked_out_resource, 84 | int pool_size, 85 | int available_size, 86 | int removed_but_unreturned_size ) 87 | { 88 | if (! mlisteners.isEmpty() ) 89 | { 90 | ResourcePoolEvent evt = new ResourcePoolEvent(source, 91 | resc, 92 | checked_out_resource, 93 | pool_size, 94 | available_size, 95 | removed_but_unreturned_size ); 96 | for (Iterator i = mlisteners.iterator(); i.hasNext();) 97 | { 98 | ResourcePoolListener rpl = (ResourcePoolListener) i.next(); 99 | rpl.resourceRemoved(evt); 100 | } 101 | } 102 | } 103 | } 104 | 105 | 106 | 107 | -------------------------------------------------------------------------------- /src/com/mchange/v2/resourcepool/ResourcePoolException.java: -------------------------------------------------------------------------------- 1 | package com.mchange.v2.resourcepool; 2 | 3 | import com.mchange.lang.PotentiallySecondaryException; 4 | 5 | public class ResourcePoolException extends PotentiallySecondaryException 6 | { 7 | public ResourcePoolException(String msg, Throwable t) 8 | {super(msg, t);} 9 | 10 | public ResourcePoolException(Throwable t) 11 | {super(t);} 12 | 13 | public ResourcePoolException(String msg) 14 | {super(msg);} 15 | 16 | public ResourcePoolException() 17 | {super();} 18 | } 19 | -------------------------------------------------------------------------------- /src/com/mchange/v2/resourcepool/ResourcePoolListener.java: -------------------------------------------------------------------------------- 1 | package com.mchange.v2.resourcepool; 2 | 3 | import java.util.EventListener; 4 | 5 | public interface ResourcePoolListener extends EventListener 6 | { 7 | public void resourceAcquired(ResourcePoolEvent evt); 8 | 9 | public void resourceCheckedIn(ResourcePoolEvent evt); 10 | 11 | public void resourceCheckedOut(ResourcePoolEvent evt); 12 | 13 | public void resourceRemoved(ResourcePoolEvent evt); 14 | } 15 | -------------------------------------------------------------------------------- /src/com/mchange/v2/resourcepool/ResourcePoolUtils.java: -------------------------------------------------------------------------------- 1 | package com.mchange.v2.resourcepool; 2 | 3 | import com.mchange.v2.log.*; 4 | 5 | final class ResourcePoolUtils 6 | { 7 | final static MLogger logger = MLog.getLogger( ResourcePoolUtils.class ); 8 | 9 | final static ResourcePoolException convertThrowable( String msg, Throwable t ) 10 | { 11 | if (Debug.DEBUG) 12 | { 13 | //t.printStackTrace(); 14 | if (logger.isLoggable( MLevel.FINE ) ) 15 | logger.log( MLevel.FINE , "Converting throwable to ResourcePoolException..." , t ); 16 | } 17 | if ( t instanceof ResourcePoolException) 18 | return (ResourcePoolException) t; 19 | else 20 | return new ResourcePoolException( msg, t ); 21 | } 22 | 23 | final static ResourcePoolException convertThrowable( Throwable t ) 24 | { return convertThrowable("Ouch! " + t.toString(), t ); } 25 | } 26 | -------------------------------------------------------------------------------- /src/com/mchange/v2/resourcepool/TimeoutException.java: -------------------------------------------------------------------------------- 1 | package com.mchange.v2.resourcepool; 2 | 3 | public class TimeoutException extends ResourcePoolException 4 | { 5 | public TimeoutException(String msg, Throwable t) 6 | {super(msg, t);} 7 | 8 | public TimeoutException(Throwable t) 9 | {super(t);} 10 | 11 | public TimeoutException(String msg) 12 | {super(msg);} 13 | 14 | public TimeoutException() 15 | {super();} 16 | } 17 | -------------------------------------------------------------------------------- /test/conf-logging/logging.properties: -------------------------------------------------------------------------------- 1 | handlers=java.util.logging.ConsoleHandler 2 | .level=INFO 3 | #com.mchange.v2.resourcepool.level=FINER 4 | #.level=INFO 5 | com.mchange.v2.c3p0.impl.level=FINE 6 | #com.mchange.v2.c3p0.stmt.level=FINEST 7 | #com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.level=FINEST 8 | #com.mchange.v2.c3p0.impl.NewPooledConnection.level=FINEST 9 | #com.mchange.v2.c3p0.stmt.GooGooStatementCache.level=FINEST 10 | java.util.logging.ConsoleHandler.level=FINEST 11 | java.util.logging.ConsoleHandler.formatter=java.util.logging.SimpleFormatter 12 | java.util.logging.SimpleFormatter.format=%1$tF@%1$tT [%4$s] [%3$s] %5$s %6$s%n 13 | -------------------------------------------------------------------------------- /test/resources-local-rough/c3p0.properties: -------------------------------------------------------------------------------- 1 | # 2 | # This file is detritus from various testing attempts 3 | # the values below may change, and often do not represent 4 | # reasonable values for the parameters. 5 | # 6 | 7 | c3p0.testConnectionOnCheckout=true 8 | c3p0.testConnectionOnCheckin=true 9 | #c3p0.dataSourceName=poop 10 | c3p0.minPoolSize=10 11 | c3p0.maxPoolSize=40 12 | c3p0.checkoutTimeout=2000 13 | c3p0.connectionIsValidTimeout=1 14 | #c3p0.idleConnectionTestPeriod=30 15 | c3p0.idleConnectionTestPeriod=1 16 | c3p0.maxConnectionAge=1 17 | c3p0.maxIdleTime=2 18 | c3p0.maxIdleTimeExcessConnections=1 19 | c3p0.propertyCycle=1 20 | c3p0.numHelperThreads=10 21 | c3p0.unreturnedConnectionTimeout=15 22 | c3p0.debugUnreturnedConnectionStackTraces=true 23 | c3p0.forceSynchronousCheckins=true 24 | c3p0.maxStatements=20 25 | c3p0.maxStatementsPerConnection=5 26 | c3p0.maxAdministrativeTaskTime=1 27 | c3p0.cancelAutomaticallyClosedStatements=true 28 | #c3p0.preferredTestQuery=SELECT 1 29 | #c3p0.preferredTestQuery=SXLECT 1 30 | #c3p0.preferredTestQuery=SELECT a FROM emptyyukyuk WHERE a = 5 31 | #c3p0.preferredTestQuery=SELECT a FROM testpbds WHERE a = 5 32 | c3p0.statementCacheNumDeferredCloseThreads=1 33 | #c3p0.automaticTestTable=PoopyTestTable 34 | c3p0.acquireIncrement=10 35 | #c3p0.acquireRetryDelay=1000 36 | #c3p0.acquireRetryAttempts=60 37 | #c3p0.connectionTesterClassName=com.mchange.v2.c3p0.test.AlwaysFailConnectionTester 38 | #c3p0.connectionTesterClassName=com.mchange.v2.c3p0.test.Percent80FailConnectionTester 39 | c3p0.connectionTesterClassName=com.mchange.v2.c3p0.test.Percent20FailConnectionTester 40 | c3p0.initialPoolSize=15 41 | c3p0.attemptResurrectOnCheckin=true 42 | 43 | #c3p0.jdbcUrl= 44 | #c3p0.driverClass= 45 | #c3p0.user= 46 | #c3p0.password= 47 | 48 | #com.mchange.v2.c3p0.impl.DefaultConnectionTester.isValidTimeout=1 49 | 50 | com.mchange.v2.log.MLog=com.mchange.v2.log.jdk14logging.Jdk14MLog 51 | #com.mchange.v2.log.MLog=com.mchange.v2.log.log4j.Log4jMLog 52 | #com.mchange.v2.log.MLog=com.mchange.v2.log.FallbackMLog 53 | #com.mchange.v2.log.NameTransformer=com.mchange.v2.log.PackageNames 54 | #com.mchange.v2.log.FallbackMLog.DEFAULT_CUTOFF_LEVEL=ALL 55 | 56 | #com.mchange.v2.c3p0.VMID=poop 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | -------------------------------------------------------------------------------- /test/src/com/mchange/v2/c3p0/test/AlwaysFailConnectionTester.java: -------------------------------------------------------------------------------- 1 | package com.mchange.v2.c3p0.test; 2 | 3 | import java.sql.Connection; 4 | import com.mchange.v2.c3p0.QueryConnectionTester; 5 | import com.mchange.v2.log.MLevel; 6 | import com.mchange.v2.log.MLog; 7 | import com.mchange.v2.log.MLogger; 8 | 9 | public final class AlwaysFailConnectionTester implements QueryConnectionTester 10 | { 11 | final static MLogger logger = MLog.getLogger( AlwaysFailConnectionTester.class ); 12 | 13 | { 14 | logger.log(MLevel.WARNING, "Instantiated: " + this, new Exception("Instantiation Stack Trace.") ); 15 | } 16 | 17 | public int activeCheckConnection(Connection c) 18 | { 19 | logger.warning(this + ": activeCheckConnection(Connection c)"); 20 | return CONNECTION_IS_INVALID; 21 | } 22 | 23 | public int statusOnException(Connection c, Throwable t) 24 | { 25 | logger.warning(this + ": statusOnException(Connection c, Throwable t)"); 26 | return CONNECTION_IS_INVALID; 27 | } 28 | 29 | public int activeCheckConnection(Connection c, String preferredTestQuery) 30 | { 31 | logger.warning(this + ": activeCheckConnection(Connection c, String preferredTestQuery)"); 32 | return CONNECTION_IS_INVALID; 33 | } 34 | 35 | public boolean equals( Object o ) { return this.getClass().equals( o.getClass() ); } 36 | public int hashCode() { return this.getClass().getName().hashCode(); } 37 | } 38 | 39 | -------------------------------------------------------------------------------- /test/src/com/mchange/v2/c3p0/test/AlwaysFailDataSource.java: -------------------------------------------------------------------------------- 1 | package com.mchange.v2.c3p0.test; 2 | 3 | import java.sql.*; 4 | import javax.sql.*; 5 | 6 | public final class AlwaysFailDataSource implements DataSource 7 | { 8 | private static String MESSAGE = "AlwaysFailDataSource always fails."; 9 | 10 | private static SQLException failure() { return new SQLException( MESSAGE ); } 11 | public Connection getConnection() throws SQLException { throw failure(); } 12 | public Connection getConnection( String user, String password ) throws SQLException { throw failure(); } 13 | public java.io.PrintWriter getLogWriter() throws SQLException { throw failure(); } 14 | public void setLogWriter(java.io.PrintWriter pw) throws SQLException { throw failure(); } 15 | public void setLoginTimeout(int i) throws SQLException { throw failure(); } 16 | public int getLoginTimeout() throws SQLException { throw failure(); } 17 | public java.util.logging.Logger getParentLogger() throws SQLFeatureNotSupportedException 18 | { throw new SQLFeatureNotSupportedException( MESSAGE ); } 19 | public T unwrap(Class clz) throws SQLException { throw failure(); } 20 | public boolean isWrapperFor(java.lang.Class clz) throws SQLException { throw failure(); } 21 | } 22 | -------------------------------------------------------------------------------- /test/src/com/mchange/v2/c3p0/test/DynamicPreparedStatementTest.java: -------------------------------------------------------------------------------- 1 | package com.mchange.v2.c3p0.test; 2 | 3 | import java.sql.*; 4 | import java.util.Random; 5 | import com.mchange.v2.c3p0.*; 6 | 7 | // motivated by https://github.com/swaldman/c3p0/issues/61#issuecomment-1979715565 8 | // trying to reproduce a memory issue 9 | public final class DynamicPreparedStatementTest 10 | { 11 | final static String DYN_CREATE = "CREATE TABLE $tableName (a INTEGER)"; 12 | final static String DYN_SELECT = "SELECT * FROM $tableName"; 13 | final static String DYN_DROP = "DROP TABLE $tableName"; 14 | 15 | final static int NUM_TABLES = 1000; 16 | final static int NUM_ITERATIONS = 1000000; 17 | 18 | public static void main(String[] argv) throws Exception 19 | { 20 | Random r = new Random(); 21 | try (ComboPooledDataSource cpds = new ComboPooledDataSource();) 22 | { 23 | cpds.getConnection().close(); // force datasource initialization just to log config 24 | System.out.println("Pausing 30 seconds..."); // pause to sic visualvm on this puppy, to track heap size 25 | Thread.sleep(30000); 26 | 27 | try (Connection conn = cpds.getConnection()) 28 | { 29 | for (int i = 0; i < NUM_TABLES; ++i) 30 | { 31 | String create = DYN_CREATE.replace("$tableName","DYN"+i); 32 | try (PreparedStatement ps = conn.prepareStatement(create);) 33 | { ps.executeUpdate(); } 34 | System.out.println("Created DYN" + i); 35 | } 36 | } 37 | for (int i = 0; i < NUM_ITERATIONS; ++i) 38 | { 39 | int num = r.nextInt(NUM_TABLES); 40 | try (Connection conn = cpds.getConnection();) 41 | { 42 | try(PreparedStatement ps = conn.prepareStatement(DYN_SELECT.replace("$tableName", "DYN"+num));) 43 | { ps.executeQuery().close(); } 44 | System.out.println("Selected from DYN" + num + " (attempt " + i + ")"); 45 | } 46 | } 47 | try (Connection conn = cpds.getConnection()) 48 | { 49 | for (int i = 0; i < NUM_TABLES; ++i) 50 | { 51 | String drop = DYN_DROP.replace("$tableName","DYN"+i); 52 | try (PreparedStatement ps = conn.prepareStatement(drop);) 53 | { ps.executeUpdate(); } 54 | System.out.println("Dropped DYN" + i); 55 | } 56 | } 57 | } 58 | System.out.println("Done. (DynamicPreparedStatementTest)"); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /test/src/com/mchange/v2/c3p0/test/JavaBeanRefTest.java: -------------------------------------------------------------------------------- 1 | package com.mchange.v2.c3p0.test; 2 | 3 | import javax.naming.*; 4 | import com.mchange.v2.naming.*; 5 | import com.mchange.v2.c3p0.*; 6 | import com.mchange.v2.c3p0.impl.*; 7 | 8 | public final class JavaBeanRefTest 9 | { 10 | public static void main(String[] argv) 11 | { 12 | try 13 | { 14 | ComboPooledDataSource cpds = new ComboPooledDataSource(); 15 | Reference ref = cpds.getReference(); 16 | ComboPooledDataSource cpdsJBOF = (ComboPooledDataSource) (new JavaBeanObjectFactory()).getObjectInstance( ref, null, null, null ); 17 | ComboPooledDataSource cpdsCJBOF = (ComboPooledDataSource) (new C3P0JavaBeanObjectFactory()).getObjectInstance( ref, null, null, null ); 18 | System.err.println( "cpds: " + cpds ); 19 | System.err.println( "cpdsJBOF: " + cpdsJBOF ); 20 | System.err.println( "cpdsCJBOF: " + cpdsCJBOF ); 21 | } 22 | catch (Exception e) 23 | { e.printStackTrace(); } 24 | } 25 | 26 | private JavaBeanRefTest() 27 | {} 28 | } 29 | -------------------------------------------------------------------------------- /test/src/com/mchange/v2/c3p0/test/JndiBindTest.java: -------------------------------------------------------------------------------- 1 | package com.mchange.v2.c3p0.test; 2 | 3 | import javax.naming.*; 4 | import javax.sql.*; 5 | import com.mchange.v2.c3p0.*; 6 | 7 | public final class JndiBindTest 8 | { 9 | public static void main(String[] argv) 10 | { 11 | try 12 | { 13 | String driverClass = null; 14 | String jdbc_url = null; 15 | String username = null; 16 | String password = null; 17 | String dmds_name = null; 18 | String cpds_name = null; 19 | String pbds_name = null; 20 | 21 | if (argv.length == 7) 22 | { 23 | driverClass = argv[0]; 24 | jdbc_url = argv[1]; 25 | username = argv[2]; 26 | password = argv[3]; 27 | dmds_name = argv[4]; 28 | cpds_name = argv[5]; 29 | pbds_name = argv[6]; 30 | } 31 | else if (argv.length == 5) 32 | { 33 | driverClass = argv[0]; 34 | jdbc_url = argv[1]; 35 | username = null; 36 | password = null; 37 | dmds_name = argv[2]; 38 | cpds_name = argv[3]; 39 | pbds_name = argv[4]; 40 | } 41 | else 42 | usage(); 43 | 44 | if (! jdbc_url.startsWith("jdbc:") ) 45 | usage(); 46 | 47 | DataSource dmds = DriverManagerDataSourceFactory.create( driverClass, 48 | jdbc_url, 49 | username, 50 | password ); 51 | WrapperConnectionPoolDataSource cpds = new WrapperConnectionPoolDataSource(); 52 | cpds.setNestedDataSource(dmds); 53 | DataSource pbds = PoolBackedDataSourceFactory.create( driverClass, 54 | jdbc_url, 55 | username, 56 | password ); 57 | 58 | InitialContext ctx = new InitialContext(); 59 | ctx.rebind( dmds_name , dmds ); 60 | System.out.println( "DriverManagerDataSource bounds as " + dmds_name ); 61 | ctx.rebind( cpds_name , cpds ); 62 | System.out.println( "ConnectionPoolDataSource bounds as " + cpds_name ); 63 | ctx.rebind( pbds_name , pbds ); 64 | System.out.println( "PoolDataSource bounds as " + pbds_name ); 65 | } 66 | catch (Exception e) 67 | { e.printStackTrace(); } 68 | } 69 | 70 | private static void usage() 71 | { 72 | System.err.println("java " + JndiBindTest.class.getName() + " \\"); 73 | System.err.println("\t \\"); 74 | System.err.println("\t [ ] \\"); 75 | System.err.println("\t " ); 76 | System.exit(-1); 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /test/src/com/mchange/v2/c3p0/test/JndiLookupTest.java: -------------------------------------------------------------------------------- 1 | package com.mchange.v2.c3p0.test; 2 | 3 | import javax.naming.*; 4 | import javax.sql.*; 5 | import com.mchange.v2.c3p0.*; 6 | 7 | public final class JndiLookupTest 8 | { 9 | public static void main(String[] argv) 10 | { 11 | try 12 | { 13 | 14 | String dmds_name = null; 15 | String cpds_name = null; 16 | String pbds_name = null; 17 | 18 | if (argv.length == 3) 19 | { 20 | dmds_name = argv[0]; 21 | cpds_name = argv[1]; 22 | pbds_name = argv[2]; 23 | } 24 | else 25 | usage(); 26 | 27 | InitialContext ctx = new InitialContext(); 28 | DataSource dmds = (DataSource) ctx.lookup( dmds_name ); 29 | dmds.getConnection().close(); 30 | System.out.println( "DriverManagerDataSource " + dmds_name + 31 | " sucessfully looked up and checked."); 32 | ConnectionPoolDataSource cpds = (ConnectionPoolDataSource) ctx.lookup( cpds_name ); 33 | cpds.getPooledConnection().close(); 34 | System.out.println( "ConnectionPoolDataSource " + cpds_name + 35 | " sucessfully looked up and checked."); 36 | DataSource pbds = (DataSource) ctx.lookup( pbds_name ); 37 | pbds.getConnection().close(); 38 | System.out.println( "PoolBackedDataSource " + pbds_name + 39 | " sucessfully looked up and checked."); 40 | } 41 | catch (Exception e) 42 | { e.printStackTrace(); } 43 | } 44 | 45 | private static void usage() 46 | { 47 | System.err.println("java " + 48 | JndiLookupTest.class.getName() + " \\"); 49 | System.err.println("\t " ); 50 | System.exit(-1); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /test/src/com/mchange/v2/c3p0/test/ListTablesTest.java: -------------------------------------------------------------------------------- 1 | package com.mchange.v2.c3p0.test; 2 | 3 | import java.sql.*; 4 | import javax.sql.*; 5 | import javax.naming.*; 6 | import com.mchange.v1.db.sql.*; 7 | 8 | public final class ListTablesTest 9 | { 10 | public static void main(String[] argv) 11 | { 12 | try 13 | { 14 | InitialContext ctx = new InitialContext(); 15 | DataSource ds = (DataSource) ctx.lookup(argv[0]); 16 | System.err.println( ds.getClass() ); 17 | Connection con = null; 18 | ResultSet rs = null; 19 | try 20 | { 21 | con = ds.getConnection(); 22 | DatabaseMetaData md = con.getMetaData(); 23 | rs = md.getTables( null, null, "%", null); 24 | while (rs.next()) 25 | System.out.println(rs.getString(3)); 26 | } 27 | finally 28 | { 29 | ResultSetUtils.attemptClose( rs ); 30 | ConnectionUtils.attemptClose( con ); 31 | } 32 | } 33 | catch (Exception e) 34 | { e.printStackTrace(); } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /test/src/com/mchange/v2/c3p0/test/LogCreationTaskRunnerFactory.java: -------------------------------------------------------------------------------- 1 | package com.mchange.v2.c3p0.test; 2 | 3 | import java.util.Timer; 4 | import javax.sql.ConnectionPoolDataSource; 5 | import com.mchange.v2.async.ThreadPoolReportingAsynchronousRunner; 6 | import com.mchange.v2.c3p0.TaskRunnerFactory; 7 | import com.mchange.v2.c3p0.impl.DefaultTaskRunnerFactory; 8 | 9 | import com.mchange.v2.log.*; 10 | 11 | public final class LogCreationTaskRunnerFactory implements TaskRunnerFactory 12 | { 13 | //MT: thread-safe 14 | final static MLogger logger = MLog.getLogger( LogCreationTaskRunnerFactory.class ); 15 | 16 | public ThreadPoolReportingAsynchronousRunner createTaskRunner( 17 | int num_threads_if_supported, 18 | int max_administrative_task_time_if_supported, // in seconds! 19 | String contextClassLoaderSourceIfSupported, 20 | boolean privilege_spawned_threads_if_supported, 21 | String threadLabelIfSupported, 22 | ConnectionPoolDataSource cpds, 23 | Timer timer 24 | ) 25 | { 26 | TaskRunnerFactory inner = new DefaultTaskRunnerFactory(); 27 | ThreadPoolReportingAsynchronousRunner out = 28 | inner.createTaskRunner( 29 | num_threads_if_supported, 30 | max_administrative_task_time_if_supported, 31 | contextClassLoaderSourceIfSupported, 32 | privilege_spawned_threads_if_supported, 33 | threadLabelIfSupported, 34 | cpds, 35 | timer 36 | ); 37 | if (logger.isLoggable(MLevel.INFO)) 38 | logger.log(MLevel.INFO, "Created TaskRunner: " + out); 39 | return out; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /test/src/com/mchange/v2/c3p0/test/Percent20FailConnectionTester.java: -------------------------------------------------------------------------------- 1 | package com.mchange.v2.c3p0.test; 2 | 3 | import java.sql.Connection; 4 | import com.mchange.v2.c3p0.QueryConnectionTester; 5 | import com.mchange.v2.log.MLevel; 6 | import com.mchange.v2.log.MLog; 7 | import com.mchange.v2.log.MLogger; 8 | 9 | public final class Percent20FailConnectionTester extends PercentXXFailConnectionTester 10 | { 11 | public Percent20FailConnectionTester() 12 | { super(20); } 13 | } 14 | 15 | -------------------------------------------------------------------------------- /test/src/com/mchange/v2/c3p0/test/Percent80FailConnectionTester.java: -------------------------------------------------------------------------------- 1 | package com.mchange.v2.c3p0.test; 2 | 3 | import java.sql.Connection; 4 | import com.mchange.v2.c3p0.QueryConnectionTester; 5 | import com.mchange.v2.log.MLevel; 6 | import com.mchange.v2.log.MLog; 7 | import com.mchange.v2.log.MLogger; 8 | 9 | public final class Percent80FailConnectionTester extends PercentXXFailConnectionTester 10 | { 11 | public Percent80FailConnectionTester() 12 | { super(80); } 13 | } 14 | 15 | -------------------------------------------------------------------------------- /test/src/com/mchange/v2/c3p0/test/PercentXXFailConnectionTester.java: -------------------------------------------------------------------------------- 1 | package com.mchange.v2.c3p0.test; 2 | 3 | import java.sql.Connection; 4 | import com.mchange.v2.c3p0.QueryConnectionTester; 5 | import com.mchange.v2.log.MLevel; 6 | import com.mchange.v2.log.MLog; 7 | import com.mchange.v2.log.MLogger; 8 | 9 | public abstract class PercentXXFailConnectionTester implements QueryConnectionTester 10 | { 11 | //final static MLogger logger = MLog.getLogger( PercentXXFailConnectionTester.class ); 12 | 13 | double threshold; 14 | 15 | protected PercentXXFailConnectionTester(int pct) 16 | { 17 | if (pct < 0 || pct > 100) 18 | throw new IllegalArgumentException("Percentage must be between 0 and 100, found " + pct + "."); 19 | this.threshold = pct / 100d; 20 | //logger.log(MLevel.WARNING, "Instantiated: " + this, new Exception("Instantiation Stack Trace.") ); 21 | } 22 | 23 | private int roulette() 24 | { 25 | if (Math.random() < threshold) 26 | return CONNECTION_IS_INVALID; 27 | else 28 | return CONNECTION_IS_OKAY; 29 | } 30 | 31 | public int activeCheckConnection(Connection c) 32 | { 33 | //logger.warning(this + ": activeCheckConnection(Connection c)"); 34 | return roulette(); 35 | } 36 | 37 | public int statusOnException(Connection c, Throwable t) 38 | { 39 | //logger.warning(this + ": statusOnException(Connection c, Throwable t)"); 40 | return roulette(); 41 | } 42 | 43 | public int activeCheckConnection(Connection c, String preferredTestQuery) 44 | { 45 | //logger.warning(this + ": activeCheckConnection(Connection c, String preferredTestQuery)"); 46 | return roulette(); 47 | } 48 | 49 | public boolean equals( Object o ) { return this.getClass().equals( o.getClass() ); } 50 | public int hashCode() { return this.getClass().getName().hashCode(); } 51 | } 52 | 53 | -------------------------------------------------------------------------------- /test/src/com/mchange/v2/c3p0/test/ProxyWrappersTest.java: -------------------------------------------------------------------------------- 1 | package com.mchange.v2.c3p0.test; 2 | 3 | import java.util.*; 4 | import java.sql.*; 5 | import javax.sql.*; 6 | import com.mchange.v2.c3p0.*; 7 | import com.mchange.v1.db.sql.*; 8 | 9 | public final class ProxyWrappersTest 10 | { 11 | public static void main(String[] argv) 12 | { 13 | ComboPooledDataSource cpds = null; 14 | Connection c = null; 15 | try 16 | { 17 | cpds = new ComboPooledDataSource(); 18 | 19 | // let system properties or c3p0.properties set this stuff up 20 | // cpds.setDriverClass( "org.postgresql.Driver" ); 21 | // cpds.setJdbcUrl( "jdbc:postgresql://localhost/c3p0-test" ); 22 | // cpds.setUser("swaldman"); 23 | // cpds.setPassword("test"); 24 | 25 | cpds.setMinPoolSize(5); 26 | cpds.setAcquireIncrement(5); 27 | cpds.setMaxPoolSize(20); 28 | 29 | c = cpds.getConnection(); 30 | c.setAutoCommit( false ); 31 | Statement stmt = c.createStatement(); 32 | stmt.executeUpdate("CREATE TABLE pwtest_table (col1 char(5), col2 char(5))"); 33 | ResultSet rs = stmt.executeQuery("SELECT * FROM pwtest_table"); 34 | System.err.println("rs: " + rs); 35 | System.err.println("rs.getStatement(): " + rs.getStatement()); 36 | System.err.println("rs.getStatement().getConnection(): " + rs.getStatement().getConnection()); 37 | } 38 | catch( Exception e ) 39 | { e.printStackTrace(); } 40 | finally 41 | { 42 | try { if (c!= null) c.rollback(); } 43 | catch (Exception e) { e.printStackTrace(); } 44 | try { if (cpds!= null) cpds.close(); } 45 | catch (Exception e) { e.printStackTrace(); } 46 | } 47 | } 48 | } 49 | 50 | 51 | 52 | 53 | 54 | -------------------------------------------------------------------------------- /test/src/com/mchange/v2/c3p0/test/RawConnectionOpTest.java: -------------------------------------------------------------------------------- 1 | package com.mchange.v2.c3p0.test; 2 | 3 | import java.lang.reflect.Method; 4 | 5 | import com.mchange.v2.c3p0.ComboPooledDataSource; 6 | import com.mchange.v2.c3p0.C3P0ProxyConnection; 7 | import com.mchange.v2.c3p0.C3P0ProxyStatement; 8 | import com.mchange.v2.c3p0.util.TestUtils; 9 | 10 | public final class RawConnectionOpTest 11 | { 12 | public static void main(String[] argv) 13 | { 14 | ComboPooledDataSource cpds = null; 15 | try 16 | { 17 | /* 18 | String jdbc_url = null; 19 | String username = null; 20 | String password = null; 21 | 22 | if (argv.length == 3) 23 | { 24 | jdbc_url = argv[0]; 25 | username = argv[1]; 26 | password = argv[2]; 27 | } 28 | else if (argv.length == 1) 29 | { 30 | jdbc_url = argv[0]; 31 | username = null; 32 | password = null; 33 | } 34 | else 35 | usage(); 36 | 37 | if (! jdbc_url.startsWith("jdbc:") ) 38 | usage(); 39 | */ 40 | 41 | cpds = new ComboPooledDataSource(); 42 | 43 | // let system properties or c3p0.properties set this stuff up for now 44 | // cpds.setJdbcUrl( jdbc_url ); 45 | // cpds.setUser( username ); 46 | // cpds.setPassword( password ); 47 | cpds.setInitialPoolSize( 1 ); 48 | cpds.setMinPoolSize( 1 ); 49 | cpds.setMaxPoolSize( 1 ); 50 | 51 | C3P0ProxyConnection conn = (C3P0ProxyConnection) cpds.getConnection(); 52 | Method toStringMethod = Object.class.getMethod("toString", new Class[]{}); 53 | Method identityHashCodeMethod = System.class.getMethod("identityHashCode", new Class[] {Object.class}); 54 | System.out.println("rawConnection.toString() -> " + 55 | conn.rawConnectionOperation(toStringMethod, C3P0ProxyConnection.RAW_CONNECTION, new Object[]{})); 56 | Integer ihc = (Integer) conn.rawConnectionOperation(identityHashCodeMethod, null, new Object[]{C3P0ProxyConnection.RAW_CONNECTION}); 57 | System.out.println("System.identityHashCode( rawConnection ) -> " + Integer.toHexString( ihc.intValue() )); 58 | 59 | C3P0ProxyStatement stmt = (C3P0ProxyStatement) conn.createStatement(); 60 | System.out.println("rawStatement.toString() -> " + 61 | stmt.rawStatementOperation(toStringMethod, C3P0ProxyStatement.RAW_STATEMENT, new Object[]{})); 62 | Integer ihc2 = (Integer) stmt.rawStatementOperation(identityHashCodeMethod, null, new Object[]{C3P0ProxyStatement.RAW_STATEMENT}); 63 | System.out.println("System.identityHashCode( rawStatement ) -> " + Integer.toHexString( ihc2.intValue() )); 64 | 65 | conn.close(); 66 | 67 | for (int i = 0; i < 10; ++i) 68 | { 69 | C3P0ProxyConnection check = null; 70 | try 71 | { 72 | check = (C3P0ProxyConnection) cpds.getConnection(); 73 | //System.err.println( TestUtils.samePhysicalConnection( conn, check ) ); 74 | System.err.println( (TestUtils.physicalConnectionIdentityHashCode( check ) == ihc.intValue()) + " " + check.rawConnectionOperation(toStringMethod, C3P0ProxyConnection.RAW_CONNECTION, new Object[]{}) ); 75 | } 76 | finally 77 | { if (check != null) check.close(); } 78 | } 79 | } 80 | catch (Exception e) 81 | { e.printStackTrace(); } 82 | finally 83 | { if (cpds != null) cpds.close(); } 84 | } 85 | 86 | private static void usage() 87 | { 88 | System.err.println("java " + RawConnectionOpTest.class.getName() /* + " \\" */); 89 | //System.err.println("\t \\"); 90 | //System.err.println("\t [ ]"); 91 | System.exit(-1); 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /test/src/com/mchange/v2/c3p0/test/StatsTest.java: -------------------------------------------------------------------------------- 1 | package com.mchange.v2.c3p0.test; 2 | 3 | import java.util.*; 4 | import java.sql.*; 5 | import javax.sql.*; 6 | import com.mchange.v2.c3p0.*; 7 | import com.mchange.v1.db.sql.*; 8 | 9 | public final class StatsTest 10 | { 11 | static void display( ComboPooledDataSource cpds ) throws Exception 12 | { 13 | System.err.println("numConnections: " + cpds.getNumConnections()); 14 | System.err.println("numBusyConnections: " + cpds.getNumBusyConnections()); 15 | System.err.println("numIdleConnections: " + cpds.getNumIdleConnections()); 16 | System.err.println("numUnclosedOrphanedConnections: " + cpds.getNumUnclosedOrphanedConnections()); 17 | System.err.println(); 18 | } 19 | 20 | public static void main(String[] argv) 21 | { 22 | try 23 | { 24 | ComboPooledDataSource cpds = new ComboPooledDataSource(); 25 | 26 | //we'll let sysprops of c3p0.properties set-up this stuff for now 27 | //cpds.setJdbcUrl( argv[0] ); 28 | //cpds.setUser( argv[1] ); 29 | //cpds.setPassword( argv[2] ); 30 | 31 | cpds.setMinPoolSize(5); 32 | cpds.setAcquireIncrement(5); 33 | cpds.setMaxPoolSize(20); 34 | 35 | System.err.println("Initial..."); 36 | display( cpds ); 37 | Thread.sleep(2000); 38 | 39 | HashSet hs = new HashSet(); 40 | for (int i = 0; i < 20; ++i) 41 | { 42 | Connection c = cpds.getConnection(); 43 | hs.add( c ); 44 | System.err.println( "Adding (" + (i + 1) + ") " + c ); 45 | display( cpds ); 46 | Thread.sleep(1000); 47 | 48 | // if (i == 9) 49 | // { 50 | // //System.err.println("hardReset()ing"); 51 | // //cpds.hardReset(); 52 | // System.err.println("softReset()ing"); 53 | // cpds.softReset(); 54 | // } 55 | } 56 | 57 | int count = 0; 58 | for (Iterator ii = hs.iterator(); ii.hasNext(); ) 59 | { 60 | Connection c = ((Connection) ii.next()); 61 | System.err.println("Removing " + ++count); 62 | ii.remove(); 63 | try { c.getMetaData().getTables( null, null, "PROBABLYNOT", new String[] {"TABLE"} ); } 64 | catch (Exception e) 65 | { 66 | System.err.println( e ); 67 | System.err.println(); 68 | continue; 69 | } 70 | finally 71 | { c.close(); } 72 | Thread.sleep(2000); 73 | display( cpds ); 74 | } 75 | 76 | System.err.println("Closing data source, \"forcing\" garbage collection, and sleeping for 5 seconds..."); 77 | cpds.close(); 78 | System.gc(); 79 | System.err.println("Main Thread: Sleeping for five seconds!"); 80 | Thread.sleep(5000); 81 | // System.gc(); 82 | // Thread.sleep(5000); 83 | System.err.println("Bye!"); 84 | } 85 | catch( Exception e ) 86 | { e.printStackTrace(); } 87 | } 88 | } 89 | 90 | 91 | 92 | 93 | 94 | -------------------------------------------------------------------------------- /test/src/com/mchange/v2/c3p0/test/TestConnectionCustomizer.java: -------------------------------------------------------------------------------- 1 | package com.mchange.v2.c3p0.test; 2 | 3 | import com.mchange.v2.c3p0.*; 4 | import java.sql.Connection; 5 | 6 | public class TestConnectionCustomizer extends AbstractConnectionCustomizer 7 | { 8 | public void onAcquire( Connection c, String pdsIdt ) 9 | { System.err.println("Acquired " + c + " [" + pdsIdt + "]"); } 10 | 11 | public void onDestroy( Connection c, String pdsIdt ) 12 | { System.err.println("Destroying " + c + " [" + pdsIdt + "]"); } 13 | 14 | public void onCheckOut( Connection c, String pdsIdt ) 15 | { System.err.println("Checked out " + c + " [" + pdsIdt + "]"); } 16 | 17 | public void onCheckIn( Connection c, String pdsIdt ) 18 | { System.err.println("Checking in " + c + " [" + pdsIdt + "]"); } 19 | } 20 | -------------------------------------------------------------------------------- /test/src/com/mchange/v2/c3p0/test/junit/C3P0JUnitTestCaseBase.java: -------------------------------------------------------------------------------- 1 | package com.mchange.v2.c3p0.test.junit; 2 | 3 | import com.mchange.v2.c3p0.*; 4 | import junit.framework.TestCase; 5 | 6 | public abstract class C3P0JUnitTestCaseBase extends TestCase 7 | { 8 | protected ComboPooledDataSource cpds; 9 | 10 | protected void setUp() 11 | { 12 | //we let this stuff get setup in c3p0.properties now 13 | 14 | /* 15 | String url = System.getProperty("c3p0.test.jdbc.url"); 16 | String user = System.getProperty("c3p0.test.jdbc.user"); 17 | String password = System.getProperty("c3p0.test.jdbc.password"); 18 | */ 19 | 20 | //C3P0JUnitTestConfig.loadDrivers(); 21 | cpds = new ComboPooledDataSource(); 22 | 23 | /* 24 | cpds.setJdbcUrl( url ); 25 | cpds.setUser( user ); 26 | cpds.setPassword( password ); 27 | */ 28 | } 29 | 30 | protected void tearDown() 31 | { 32 | try { cpds.close(); } 33 | catch ( Exception e ) 34 | { 35 | System.err.println("Exception on DataSource close in JUnit test tearDown():"); 36 | e.printStackTrace(); 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /test/src/com/mchange/v2/c3p0/test/junit/ConnectionPropertiesResetJUnitTestCase.java: -------------------------------------------------------------------------------- 1 | package com.mchange.v2.c3p0.test.junit; 2 | 3 | import java.sql.*; 4 | import java.util.*; 5 | import junit.framework.*; 6 | 7 | public final class ConnectionPropertiesResetJUnitTestCase extends C3P0JUnitTestCaseBase 8 | { 9 | final static Map TM; 10 | 11 | static 12 | { 13 | Map tmp = new HashMap(); 14 | tmp.put("FAKE", SQLData.class); 15 | TM = Collections.unmodifiableMap( tmp ); 16 | } 17 | 18 | public void testAllConnectionDefaultsReset() 19 | { 20 | // System.err.println("XOXO err"); 21 | // System.out.println("XOXO out"); 22 | 23 | cpds.setInitialPoolSize(5); 24 | cpds.setMinPoolSize(5); 25 | cpds.setMaxPoolSize(5); 26 | cpds.setMaxIdleTime(0); 27 | cpds.setTestConnectionOnCheckout(false); 28 | cpds.setTestConnectionOnCheckin(false); 29 | cpds.setIdleConnectionTestPeriod(0); 30 | 31 | String dfltCat; 32 | int dflt_txn_isolation; 33 | 34 | try 35 | { 36 | Connection con = null; 37 | try 38 | { 39 | con = cpds.getConnection(); 40 | 41 | 42 | dfltCat = con.getCatalog(); 43 | dflt_txn_isolation = con.getTransactionIsolation(); 44 | 45 | try { con.setReadOnly(true); } catch (Exception e) { /* setReadOnly() not supported */ } 46 | try { con.setTypeMap(TM); } catch (Exception e) { /* setTypeMap() not supported */ } 47 | try { con.setCatalog("C3P0TestCatalogXXX"); } catch (Exception e) { /* setCatalog() not supported */ } 48 | try 49 | { 50 | con.setTransactionIsolation( dflt_txn_isolation == Connection.TRANSACTION_SERIALIZABLE ? 51 | Connection.TRANSACTION_READ_COMMITTED : 52 | Connection.TRANSACTION_SERIALIZABLE ); 53 | } 54 | catch (Exception e) { /* setTransactionIsolation() not fully supported */ } 55 | } 56 | finally 57 | { 58 | try { if (con != null) con.close(); } 59 | catch (Exception e) {} 60 | } 61 | 62 | Connection[] cons = new Connection[5]; 63 | for (int i = 0; i < 5; ++i) 64 | { 65 | cons[i] = cpds.getConnection(); 66 | assertFalse( "Connection from pool should not be readOnly!", cons[i].isReadOnly() ); 67 | 68 | // some drivers return null rather than an empty type map 69 | Map typeMap = cons[i].getTypeMap(); 70 | assertTrue( "Connection from pool should have an empty type map!", (typeMap == null ? true : typeMap.isEmpty() ) ); 71 | 72 | assertEquals( "Connection from pool should have default catalog set!", dfltCat, cons[i].getCatalog() ); 73 | assertEquals( "Connection from pool should have default txn isolation set!", dflt_txn_isolation, cons[i].getTransactionIsolation() ); 74 | cons[i].close(); 75 | } 76 | } 77 | catch (Exception e) 78 | { 79 | e.printStackTrace(); 80 | fail( e.getMessage() ); 81 | } 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /test/src/com/mchange/v2/c3p0/test/junit/MockDriver.java: -------------------------------------------------------------------------------- 1 | package com.mchange.v2.c3p0.test.junit; 2 | 3 | import java.sql.*; 4 | import java.util.*; 5 | import java.util.concurrent.atomic.AtomicInteger; 6 | import java.util.logging.Logger; 7 | import junit.framework.*; 8 | 9 | public class MockDriver implements Driver { 10 | public static final AtomicInteger beginRequestCount = new AtomicInteger(0); 11 | public static final AtomicInteger endRequestCount = new AtomicInteger(0); 12 | 13 | @Override 14 | public boolean acceptsURL(String url) throws SQLException { 15 | return true; 16 | } 17 | 18 | @Override 19 | public Connection connect(String url, Properties info) throws SQLException { 20 | if (url.contains("with-request-boundaries")) { 21 | return new MockConnectionWithBoundaries(); 22 | } else { 23 | return new MockConnectionWithoutBoundaries(); 24 | } 25 | } 26 | 27 | @Override 28 | public int getMajorVersion() { 29 | return 0; 30 | } 31 | 32 | @Override 33 | public int getMinorVersion() { 34 | return 0; 35 | } 36 | 37 | @Override 38 | public Logger getParentLogger() throws SQLFeatureNotSupportedException { 39 | return null; 40 | } 41 | 42 | @Override 43 | public DriverPropertyInfo[] getPropertyInfo(String url, Properties info) throws SQLException { 44 | return null; 45 | } 46 | 47 | @Override 48 | public boolean jdbcCompliant() { 49 | return true; 50 | } 51 | 52 | } -------------------------------------------------------------------------------- /unsupported/dbms/oracle-thin/.gitignore: -------------------------------------------------------------------------------- 1 | build/* 2 | dist/* 3 | -------------------------------------------------------------------------------- /unsupported/dbms/oracle-thin/build.properties: -------------------------------------------------------------------------------- 1 | # 2 | # You'll rarely (never) want to set these properties by hand... they 3 | # are set by the main c3p0 build script. They are listed here primarily 4 | # to document the dependencies of the dbms-specific build script. 5 | # 6 | 7 | c3p0-version= 8 | c3p0.jar.file= 9 | oracle-thin.jdbc.jar.file= 10 | 11 | -------------------------------------------------------------------------------- /unsupported/dbms/oracle-thin/build.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 43 | 44 | 45 | 46 | 47 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | -------------------------------------------------------------------------------- /unsupported/dbms/oracle-thin/src/classes/com/mchange/v2/c3p0/dbms/Debug.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Distributed as part of c3p0 v.0.9.1.3-pre2-transition 3 | * 4 | * Copyright (C) 2010 Machinery For Change, Inc. 5 | * 6 | * Author: Steve Waldman 7 | * 8 | * This library is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU Lesser General Public License version 2.1, as 10 | * published by the Free Software Foundation. 11 | * 12 | * This software is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License 18 | * along with this software; see the file LICENSE. If not, write to the 19 | * Free Software Foundation, Inc., 59 Temple Place, Suite 330, 20 | * Boston, MA 02111-1307, USA. 21 | */ 22 | 23 | 24 | /******************************************************************** 25 | * This class generated by com.mchange.v2.debug.DebugGen 26 | * and will probably be overwritten by the same! Edit at 27 | * YOUR PERIL!!! Hahahahaha. 28 | ********************************************************************/ 29 | 30 | package com.mchange.v2.c3p0.dbms; 31 | 32 | import com.mchange.v2.debug.DebugConstants; 33 | 34 | final class Debug implements DebugConstants 35 | { 36 | final static boolean DEBUG = true; 37 | final static int TRACE = TRACE_MED; 38 | 39 | private Debug() 40 | {} 41 | } 42 | 43 | -------------------------------------------------------------------------------- /unsupported/old-build/build.properties: -------------------------------------------------------------------------------- 1 | # >> BASICS << 2 | 3 | # 4 | # c3p0 depends on the mchange-commons-java library, with 5 | # which it is distributed. you must set the directory 6 | # in which that library's jar and sources-jar files can 7 | # be found 8 | # 9 | mchange-commons-java.dist.dir=lib 10 | 11 | # 12 | # the version and jar file name against which the present distribution 13 | # is intended to be built are shown below. usually you should leave 14 | # these alone. 15 | # 16 | mchange-commons-java.version=0.2.19 17 | mchange-commons-java.jar.file.name=mchange-commons-java-${mchange-commons-java.version}.jar 18 | mchange-commons-java.jar.file=${mchange-commons-java.dist.dir}/${mchange-commons-java.jar.file.name} 19 | mchange-commons-java.sources.jar.file=${mchange-commons-java.dist.dir}/mchange-commons-java-${mchange-commons-java.version}-sources.jar 20 | 21 | 22 | # we compile against jdk 1.8, but output jdk 1.6 compatible classfiles. 23 | jvm.target.version=1.6 24 | 25 | # >> DEBUGGING AND TRACING << 26 | 27 | # Set this to true if you want logging enabled for logging levels below INFO. 28 | # If debug is not set, logging code for these messages will be eliminated from 29 | # the compiled code by virtue of "if (false) { ... }" blocks. 30 | 31 | #c3p0-build.debug= 32 | 33 | # Set trace to an integer between 0 and 10 (inclusive) to control how the level 34 | # of detail of debug logging messages. Only makes a difference if c3p0.debug is 35 | # set to true above. Default to 5 if unset. 36 | 37 | #c3p0-build.trace= 38 | 39 | # NOTE: You must still configure your logging library to log or display these 40 | # debug level messages if you actually want to see any change! 41 | 42 | #---------------------------------------------------------------------------- 43 | 44 | # >> OPTIONAL LIBRARY SUPPRT << 45 | 46 | # 47 | # You'll only need this property if you want to 48 | # build the jar of utilities specific to the 49 | # oracle-thin jdbc driver / dbms 50 | # 51 | 52 | #oracle-thin.jdbc.jar.file= 53 | 54 | #---------------------------------------------------------------------------- 55 | 56 | # >> OPTIONAL TEST SUPPORT 57 | 58 | # 59 | # this stuff is only required if you want to run 60 | # the various tests. very optional 61 | # 62 | 63 | #test.jdbc.driver.jar.file= 64 | #test.jdbc.driver= 65 | #test.jdbc.url= 66 | #test.jdbc.user= 67 | #test.jdbc.password= 68 | 69 | # optional even for tests 70 | #extra.test.classpath= 71 | 72 | # 73 | # required if you want to run junit tests 74 | # 75 | 76 | #junit.jar.file 77 | 78 | # >> VERY VERY OPTIONAL DOCS-TO-WEB SUPPORT 79 | 80 | # 81 | # this stuff is only required if you want to deploy 82 | # an ear file containing c3p0's docs to a J2EE appserver. 83 | # via scp. Requires an available executable "scp". 84 | # 85 | # this is a convenience for c3p0's developer, not 86 | # really intended for other users. just leave blank 87 | # 88 | # note that virtual.host modifies a jboss-web.xml file, 89 | # will do nothing if you are deploying to some other 90 | # app server 91 | # 92 | 93 | #docwebapp.context.root= 94 | #docwebapp.virtual.host= 95 | #docwebear.deploy.user= 96 | #docwebear.deploy.host= 97 | #docwebear.deploy.path= 98 | 99 | -------------------------------------------------------------------------------- /unsupported/old-build/src/dist-static/LICENSE: -------------------------------------------------------------------------------- 1 | /* 2 | * This library is free software; you can redistribute it and/or modify 3 | * it under the terms of EITHER: 4 | * 5 | * 1) The GNU Lesser General Public License (LGPL), version 2.1, as 6 | * published by the Free Software Foundation 7 | * 8 | * OR 9 | * 10 | * 2) The Eclipse Public License (EPL), version 1.0 11 | * 12 | * You may choose which license to accept if you wish to redistribute 13 | * or modify this work. You may offer derivatives of this work 14 | * under the license you have chosen, or you may provide the same 15 | * choice of license which you have been offered here. 16 | * 17 | * This software is distributed in the hope that it will be useful, 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 20 | * 21 | * You should have received copies of both LGPL v2.1 and EPL v1.0 22 | * along with this software; see the files LICENSE-EPL and LICENSE-LGPL. 23 | * If not, the text of these licenses are currently available at 24 | * 25 | * LGPL v2.1: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html 26 | * EPL v1.0: http://www.eclipse.org/org/documents/epl-v10.php 27 | */ 28 | -------------------------------------------------------------------------------- /unsupported/old-build/src/dist-static/README: -------------------------------------------------------------------------------- 1 | _____________________________________ 2 | ................................. 3 | ..(c3p0)......................... 4 | ............a.........fresh...... 5 | ....coat.......of........stucco.. 6 | .........over.......that.....old. 7 | ...jdbc........driver............ 8 | ................................. 9 | ------------------------------------- 10 | versions 0.8.4 and above 11 | 23-Dec-2003 12 | 13 | -> Feedback to Steve Waldman <- 14 | -> Please! :) <- 15 | 16 | Hi. c3p0's docs have been HTML-ized, and moved to the "doc" 17 | directory of this distribution. Please check that out. 18 | 19 | Sorry all you plain text fans! 20 | 21 | -------------------------------------------------------------------------------- /unsupported/old-build/src/dist-static/RELEASE_NOTES-c3p0-0.9.2: -------------------------------------------------------------------------------- 1 | RELEASE NOTES, c3p0-0.9.2 2 | ========================= 3 | 4 | Some highlights: 5 | 6 | + Some JDBC drivers freeze up if cached Statements are close()ed while their parent 7 | Connections are in use. Previously users of these drivers (Oracle, JTDS) generally 8 | had to forego Statement caching to avoid deadlocks. C3P0's statement cache can now 9 | be set to cautiously close Statements only when the parent Connections are known 10 | to be idle. If you experience "APPARENT DEADLOCKS" due to StatementCloseTasks, set 11 | 12 | c3p0.statementCacheNumDeferredCloseThreads=1 13 | 14 | and they should go away! 15 | 16 | + There are some other minor improvements and fixes: 17 | 18 | -- the more granular and efficient "scattered" Connection acquisition algorithm that 19 | was "experimental" in the previous release is enabled by default 20 | 21 | -- unreturned Connections that are timed out (bad! bad!) are either rolled back (default) 22 | or committed before close(), respecting your unresolved transaction configuration. 23 | (see config parameter unresolvedConnectionTimeout in docs) 24 | 25 | -- c3p0 is now actively maintained for deployment as a managed dependency on 26 | Sonatype's central maven repository 27 | 28 | -- You can use the dataSourceName config parameter to create stable patterns in 29 | JMX mBeans, so that you can distinguish your DataSources and monitor then across 30 | application restarts. 31 | 32 | -- Miscellaneous fixes for bugs/deadlocks/resource-leaks, see CHANGELOG (and many thanks 33 | to users who've helped track these issues down!) 34 | 35 | + You must now include two jar files (c3p0 and mchange-commons-java) in your CLASSPATH 36 | rather than just one. Both can be found in the lib directory of the binary distribution. 37 | (Please provide feedback; if this is very inconvenient I can bundle it all up into 38 | a unified jar.) 39 | 40 | Some structural changes: 41 | 42 | + Development of c3p0 and mchange-commons-java have migrated to github: 43 | 44 | https://github.com/swaldman/c3p0 45 | https://github.com/swaldman/mchange-commons-java 46 | 47 | Note that c3p0 depends (heavily) on the mchange-commons library. 48 | 49 | I apologize very, very much for disappearing for a few of years. Your guess is as 50 | good as mine as to where I have been. 51 | 52 | As always, please give the library a very thorough beating. Your testing and feedback 53 | are very much appreciated, to Steve Waldman , please. 54 | 55 | -------------------------------------------------------------------------------- /unsupported/old-build/src/dist-static/RELEASE_NOTES-c3p0-0.9.5.1: -------------------------------------------------------------------------------- 1 | RELEASE NOTES, c3p0-0.9.5.1 2 | =========================== 3 | 4 | + Full JDBC4 support. 5 | 6 | + Support for logging the SLF4J / logback library 7 | 8 | + Support for configuration via HOCON / typesafe-config files 9 | 10 | + Support for dynamic configuration reloading (to support autorestarting appservers like playframework) 11 | 12 | + Support for predictable, reproducible JMX names (whose uniqueness users must ensure!) via config parmeter 13 | com.mchange.v2.c3p0.management.ExcludeIdentityToken 14 | 15 | + Configuration param 'forceUseNamedDriverClass' allows users to circumvent DriverManager resolution 16 | of JDBC-url appropriate Driver classes and use the class specified in the 'driverClass' config param 17 | unconditionally 18 | 19 | + Configuaration params 'privilegeSpawnedThreads' and 'contextClassLoaderSource' can be set to 20 | help avoid memory leaks following multiple hot redeploys (references to ClassLoaders from stale deployments) 21 | in some application servers (most prominently Tomcat). 22 | 23 | + Added support for easily deriving instrumented debug versions of ComboPooledDataSource, and implemented 24 | two of those: 25 | com.mchange.v2.c3p0.debug.AfterCloseLoggingComboPooledDataSource and 26 | com.mchange.v2.c3p0.debug.CloseLoggingComboPooledDataSource 27 | 28 | + Added support for a new configurataion parameter, forceSynchronousCheckins, which can offer significantly 29 | improved performance when no Connection tests are performed on check-in and no difficult work is performed 30 | in ConnectionCustomizer.onCheckIn(...) 31 | 32 | + Lots and lots of bug fixes, tweaks, etc. 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /unsupported/old-build/src/dist-static/RELEASE_NOTES-c3p0-0.9.5.2: -------------------------------------------------------------------------------- 1 | RELEASE NOTES, c3p0-0.9.5.2 2 | =========================== 3 | 4 | + This minor bugfix release fixed a bug that caused useless allocation of below-logging-threshold 5 | Strings, and added better debugging information on failed attempts to acquire database Connections. 6 | 7 | 8 | -------------------------------------------------------------------------------- /unsupported/old-build/src/dist-static/RELEASE_NOTES-c3p0-0.9.5.3: -------------------------------------------------------------------------------- 1 | RELEASE NOTES, c3p0-0.9.5.3 2 | =========================== 3 | 4 | + This minor bugfix release addresses a security issue: 5 | 6 | CVE-2018-20433, https://nvd.nist.gov/vuln/detail/CVE-2018-20433 7 | 8 | The c3p0 parsed XML config files liberally, including resolving external 9 | entity references. Incautious use of this feature could permit injection 10 | of malicious config. Now c3p0 does not resolve external entity references 11 | in its the XML config file. 12 | 13 | HOWEVER, in the EXCEEDINGLY RARE CASE that your configuration depends on 14 | the old behavior, if you have UNDERSTOOD the security concern, you may 15 | restore external entity resolution with the following config parameter 16 | (in c3p0.properties, as HOCON config, or as a System property): 17 | 18 | com.mchange.v2.c3p0.cfg.xml.expandEntityReferences=true 19 | 20 | Thanks to user zhutougg on GitHub for calling attention to and suggesting 21 | a fix for this issue. 22 | 23 | + c3p0 now supports logging to log4j2. (Logging to the old, original log4j 24 | library remains supported as well.) Thanks to user fireandfuel on GitHub 25 | for implementing this feature! (In the mchange-commons-java library.) 26 | -------------------------------------------------------------------------------- /unsupported/old-build/src/dist-static/RELEASE_NOTES-c3p0-0.9.5.4: -------------------------------------------------------------------------------- 1 | RELEASE NOTES, c3p0-0.9.5.4 2 | =========================== 3 | 4 | + This minor bugfix release continues to address security issues associated 5 | with parsing configuration in XML format. The solution provided in 0.9.5.3 6 | was not sufficiently general to address all "XXE" attacks. For more on 7 | those in general, see https://vsecurity.com//download/papers/XMLDTDEntityAttacks.pdf 8 | 9 | The current release includes implementing the suggestions offered here: 10 | https://github.com/OWASP/CheatSheetSeries/blob/31c94f233c40af4237432008106f42a9c4bff05e/cheatsheets/XML_External_Entity_Prevention_Cheat_Sheet.md 11 | 12 | Because more than entity reference expansion is implicated, the configuration 13 | key introduced in 0.9.5.3... 14 | 15 | com.mchange.v2.c3p0.cfg.xml.expandEntityReferences 16 | 17 | is now deprecated. Instead, if you wish to restore prior versions' permissive 18 | parsing of XML -- and if you strictly control your XML configuration and 19 | understand the security issues enabled by permissive parsing, you can set 20 | 21 | com.mchange.v2.c3p0.cfg.xml.usePermissiveParser=true 22 | 23 | (The deprecated key introduced in 0.9.5.3 will continue to work, but will 24 | provoke warnings.) 25 | 26 | Many thanks to Aaron Massey (amassey) at HackerOne and zhutougg on GitHub 27 | for calling attention to these issues. 28 | 29 | + The release also includes a change in how c3p0 handles the rare condition 30 | in which 31 | 32 | 1. A round of attempts to acquire Connections fails 33 | 2. c3p0 attempts to wake and throw Exceptions to client threads waiting for 34 | Connections to arrive, but a Thread interrupt or some unexpected Throwable 35 | occurs before that process has completed. 36 | 37 | Previously, a failure within "forceKillAcquires()" would leave the pool in a broken 38 | state, so that after database recovery clients might still fail to acquire Connections. 39 | Now c3p0 uses Thread.interrupt() to make a best-effort attempt to free the clients, 40 | logs a warning, then resets the pool to a recoverable state. 41 | 42 | This should be an extraordinarily rare occurrence, and c3p0 will emit warnings when 43 | it does occur. 44 | 45 | If by some hard-to-understand cause, waiting client Threads become somehow impossible 46 | to wake, despite use of notifyAll(), even after Thread.interrupt(), and even as new 47 | Connections become available to satisfy them, then recovery after the incomplete wake 48 | might lead to more aggressive tha intended (faster) pool growth (as Threads waiting 49 | for new Connections are taken into account when c3p0 calculates its target_pool_size. 50 | But it is very difficult to imagine any condition under which the semantics of the 51 | JVM threading model are respected and yet wait()ing Threads remain stuck despite 52 | notifyAll() and interrupt() calls. 53 | 54 | Many thanks to Stefan Cordes (rscadrde on github), Vipin Nair (swvist on github), and 55 | Łukasz Jąder (ljader on github) for their work on this issue. 56 | 57 | -------------------------------------------------------------------------------- /unsupported/old-build/src/dist-static/TODO: -------------------------------------------------------------------------------- 1 | -- in-use locking of NewPooledConnections ResourcePool.Manager tasks in C3P0PooledConnectionPool is 2 | unnecessary and hard to reason aboout in light of NewPooledConnection locks, pool semantics 3 | enforce exclusive use by maintenance tasks, there is no need to re-enforce exclusive access at all 4 | [???] 5 | 6 | -- ConnectionTesters should be coalesced on deserialization if possible. [0.9.6] 7 | 8 | -- MultipliedPoolBackedDataSources [0.9.6] 9 | 10 | -- Modify AbstractPoolBackedDataSource so that mere JMX inspection doesn't force initialization [0.9.6] 11 | implement withPoolManager( doitIfThere, defaultValue ) 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /unsupported/old-build/src/dist-static/old/KNOWN-ISSUES-0.9.0: -------------------------------------------------------------------------------- 1 | c3p0-0.9.0 2 | ---------- 3 | 4 | ******************************************************************* 5 | * --> All of these issues are rare, and we believe c3p0-0.9.0 <-- * 6 | * --> to be the most appropriate version of the library for <-- * 7 | * --> most users! <-- * 8 | ******************************************************************* 9 | 10 | As of release, the following issues have been reported, but have not been understood or resolved 11 | to the satisfaction of the developers. All of these are issues that the developers have not been 12 | able to reproduce, making them hard to fix. Any help in tracking down these problems would be 13 | greatly appreciated. 14 | 15 | Known Issues 16 | ============ 17 | 18 | RARE reports of InterruptedException on client threads, especially at database recovery 19 | 20 | + Two users have reported observing InterruptedExceptions on client threads, one upon 21 | database recovery after an outage and one upon trying to acquire a cached PreparedStatement. 22 | c3p0 does not call interrup() on client Threads, except for Threads wait()ing for 23 | Connections in a pool that is close()ing. The reported Exceptions do not involve a pool 24 | close(). It may be that some non-c3p0 is interruting() these Threads, and c3p0 is 25 | simply the first library to react to the interrupted state. [Thanks to Scott Russell and 26 | Pkumar for these reports.] 27 | 28 | RARE reports of retention of closed Connections: 29 | 30 | + One user has documented retention of Connections for some time after they have been 31 | closed. He tracked the problem down to a retained reference in the Thread Pool's 32 | deadlock detector. This reference is now nulled out early, and there have been no 33 | further reports of prolonged retention, but the cause of the original apparent retention 34 | has not been adequately explained. [Thanks to Venkatesh Seetharamaiah for this report.] 35 | 36 | RARE reports c3p0/jTDS deadlocks: 37 | 38 | + Although most c3p0/jTDS issues have been resolved as of this release of c3p0 and 39 | the latest release of jTDS (thanks guys!), there is at least one outstanding report 40 | of an unexplained deadlock when c3p0 attempts to close pooled jTDS Connnections. (These 41 | appear as occasional "APPARENT DEADLOCK" dumps at WARN level to whatever logger is 42 | in use. We believe that most c3p0/jTDS users do NOT experience this issue, and are 43 | eager for further reports or feedback of any sort that might shed light upon the 44 | problem. [Thanks to Guillaume Chevallier for this report.] 45 | 46 | (Users who experience this problem may resolve it by turning off statement caching, 47 | but we'd prefer you give us more information about what went wrong so we can resolve 48 | the problem if you experience this issue.) 49 | 50 | 51 | 52 | 53 | 54 | -------------------------------------------------------------------------------- /unsupported/old-build/src/dist-static/old/RELEASE-NOTES-0.8.5-pre4.txt: -------------------------------------------------------------------------------- 1 | RELEASE NOTES 2 | c3p0-0.8.5-pre4 3 | <-=-=-=-=-=-=-=-=-> 4 | 5 | Version 0.8.5-pre4 contains a major, relatively untested, restructuring of 6 | c3p0's codebase. This new implementation should be faster and more maintainable 7 | than the original, but it needs to have its tires kicked a good bit to be sure 8 | it is production ready... 9 | 10 | Please do try it out, and send feedback to Steve Waldman ! 11 | 12 | --> If you have problems, don't despair! You can revert to the traditional codebase 13 | --> by setting the parameter 'usesTraditionalReflectiveProxies' to true. 14 | 15 | See c3p0's documentation for information on how to set configuration parameters. 16 | 17 | Thanks for using c3p0, and thanks in advance for your feedback and bug reports! 18 | 19 | Steve Waldman 20 | Machinery For Change, Inc. 21 | 22 | -------------------------------------------------------------------------------- /unsupported/old-build/src/dist-static/old/RELEASE-NOTES-0.8.5-pre7.txt: -------------------------------------------------------------------------------- 1 | RELEASE NOTES 2 | c3p0-0.8.5-pre7 3 | <-=-=-=-=-=-=-=-=-> 4 | 5 | Lots of new features, and more than a few bug fixes. For more information, 6 | check out the docs relating to the following config params: 7 | 8 | + automaticTestTable 9 | (most convenient way to speed up connection testing) 10 | 11 | + preferredTestQuery 12 | (alternative way to speed up connection testing) 13 | 14 | + testConnectionOnCheckin 15 | (combine with idleConnectionTestPeriod to ensure frequent, 16 | but always asynchronous testing) 17 | 18 | + checkoutTimeout 19 | (control how long clients hang waiting for Connection acquisition 20 | or check-in to an empty pool) 21 | 22 | + maxStatementsPerConnection 23 | (more sensible way of specifying how many statements to cache) 24 | 25 | ...also previously added 0.8.5 params for configuring pool behavior 26 | when Conection acquisition for the database is unreliable: 27 | 28 | + acquireRetryAttempts 29 | (how many times should the pool try to acquire a Connection from 30 | the database?) 31 | 32 | + acquireRetryDelay 33 | (how long should the pool wait after a Connection acquisition failure 34 | before trying again?) 35 | 36 | + breakAfterAcquireFailure 37 | (if a pool can't acquire a Connection after acquireRetryAttempts, 38 | should the pool declare itself broken, or give up momentarily but 39 | try again in response to future client requests) 40 | 41 | ...and previously added features: 42 | + raw connection operations 43 | + Oracle large object utilities 44 | 45 | --- 46 | 47 | Version 0.8.5-pre4 and above contains a major, relatively untested, restructuring of 48 | c3p0's codebase. This new implementation should be faster and more maintainable 49 | than the original, but it needs to have its tires kicked a good bit to be sure 50 | it is production ready... 51 | 52 | Please do try it out, and send feedback to Steve Waldman ! 53 | 54 | --> If you have problems, don't despair! You can revert to the traditional codebase 55 | --> by setting the parameter 'usesTraditionalReflectiveProxies' to true. 56 | 57 | See c3p0's documentation for information on how to set configuration parameters. 58 | 59 | Thanks for using c3p0, and thanks in advance for your feedback and bug reports! 60 | 61 | Steve Waldman 62 | Machinery For Change, Inc. 63 | 64 | -------------------------------------------------------------------------------- /unsupported/old-build/src/dist-static/old/RELEASE_NOTES-c3p0-0.9.1-pre7: -------------------------------------------------------------------------------- 1 | RELEASE NOTES, c3p0-0.9.1-pre7 2 | 3 | This release contains a lot of changes and improvements for a minor 4 | release. Please give the library a very thorough beating. Your 5 | testing and feedback are very much appreciated, to 6 | Steve Waldman , please. 7 | 8 | Given the fairly large changes, I'd be cautious about using this 9 | release in production. 10 | 11 | The documentation has not yet been updated. Among the new features 12 | in this release are... 13 | 14 | + JDK 1.5 JMX instrumentation of both Connection 15 | and Thread pool data. 16 | 17 | + A ConnectionCustomizer interface that users can 18 | implement for setting up Connections, including 19 | Connection state properties (holdability, 20 | transactionIsolation, readOnly), prior to entry 21 | into the pool (or on check-out). (Use the 22 | connectionCustomizerClassName config parameter 23 | to attach your customizer to a PooledDataSource.) 24 | 25 | + maxIdleTimeExcessConnections lets users control 26 | how quickly pools shrink to their minimum size 27 | if unused. (This differs from maxIdleTime, which 28 | is intended to maintain the validity of Connections 29 | maxIdleTime will time-out old Connections regardless 30 | of pool size, sometimes forcing the pool to acquire 31 | new Connections. maxExcessConnectionIdleTime stops 32 | expiring Connections once minPoolSize has been 33 | achieve. minPoolSize should be set to a smaller value 34 | than maxIdleTime.) [For these params, 0 means 35 | do not enforce, times are in seconds, they default 36 | to 0.] 37 | 38 | + New parameters permit debugging and working 39 | around Connection leaks caused by sloppy client 40 | applications. After unreturnedConnectionTimeout 41 | seconds, checked-out Connections are destroyed 42 | by the pool. If debugUnreturnedConnectionStackTraces 43 | is set to "true", stack traces are captured at 44 | every Connection checkout, and printed for 45 | Connections that have to be cleaned up by the pool. 46 | [For unreturnedConnectionTimeout, 0 means 47 | do not enforce, time is in seconds, default is 0.] 48 | debugUnreturnedConnectionStackTraces defaults to 49 | false.] 50 | 51 | + maxConnectionAge lets pools time out pooled 52 | Connections based on then absolute age of the 53 | Connection, rather than idle time. [0 means do 54 | not enforce, times are in seconds, default is 55 | to 0.] 56 | 57 | + propertyCycle controls how frequently c3p0 checks 58 | resources against these various timeouts. The 59 | default is 0 (seconds), which means c3p0 will 60 | automatically set a reasonable rate given the 61 | timeout property values. (The effective 62 | propertyCycle, whether manually or automatically 63 | set, is exposed via JMX.) 64 | 65 | + Many other bugfixes and improvements, which should 66 | improve pool concurrency and performance, and will 67 | hopefully make thread pool deadlocks ("APPARENT 68 | DEADLOCK" messages) much more rare. 69 | 70 | c3p0-0.9.1-pre6 added other important features, including 71 | an optional XML config file, user-specific overrides 72 | of config parameters, and named configurations, so that 73 | multiple DataSources with distinct configurations can 74 | be specified without having to set DataSource properties 75 | in code. 76 | 77 | Please let me know how this stuff works for you! 78 | -------------------------------------------------------------------------------- /unsupported/old-build/src/dist-static/src/README: -------------------------------------------------------------------------------- 1 | The jar files here include c3p0's Java source code and source for the mchange-commons-java library. 2 | they may be helpful for debugging purposes. However, they mix handwritten and automatically generated code, 3 | and are not intended for standalone use in rebuilding the libraries. 4 | 5 | To modify or build c3p0, please download the full source distribution, now 6 | available on github at 7 | 8 | https://github.com/swaldman/c3p0 9 | 10 | You'll find the full mchange-commons-java source distrubution at 11 | 12 | https://github.com/swaldman/mchange-commons-java 13 | 14 | Thanks! 15 | 16 | 17 | -------------------------------------------------------------------------------- /unsupported/old-build/src/docweb/docwebapp/WEB-INF/jboss-web.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | 7 | 8 | @virtual.host@ 9 | 10 | -------------------------------------------------------------------------------- /unsupported/old-build/src/docweb/docwebapp/WEB-INF/web.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /unsupported/old-build/src/docweb/docwebear/META-INF/application.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | 7 | www.mchange.com 8 | 9 | 10 | @web.uri@ 11 | @context.root@ 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /unsupported/old-build/src/maven/pom.xml: -------------------------------------------------------------------------------- 1 | 5 | 6 | 4.0.0 7 | 8 | com.mchange 9 | c3p0 10 | jar 11 | @c3p0.version.maven@ 12 | 13 | c3p0 14 | a JDBC Connection pooling / Statement caching library 15 | https://github.com/swaldman/c3p0 16 | 17 | 18 | GNU Lesser General Public License, Version 2.1 19 | http://www.gnu.org/licenses/lgpl-2.1.html 20 | repo 21 | 22 | 23 | Eclipse Public License, Version 1.0 24 | http://www.eclipse.org/org/documents/epl-v10.php 25 | repo 26 | 27 | 28 | 29 | scm:git:git@github.com:swaldman/c3p0.git 30 | scm:git:git@github.com:swaldman/c3p0.git 31 | 32 | 33 | 34 | swaldman 35 | Steve Waldman 36 | swaldman@mchange.com 37 | 38 | 39 | 40 | 41 | com.mchange 42 | mchange-commons-java 43 | @mchange-commons-java.version.maven@ 44 | 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /unsupported/test-properties/META-INF/poop.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | specialPoop! 22 | 23 | 24 | 25 | 26 | 27 | 28 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /unsupported/test-properties/application.conf: -------------------------------------------------------------------------------- 1 | c3p0 { 2 | 3 | # dataSourceName=${resolvetest.name} 4 | # connectionCustomizerClassName=com.mchange.v2.c3p0.example.InitSqlConnectionCustomizer 5 | 6 | # extensions { 7 | # initSql=SET TIME ZONE 'PST8PDT' 8 | # } 9 | 10 | # named-configs { 11 | # kittycat { 12 | # maxPoolSize=35 13 | # } 14 | # } 15 | 16 | # user-overrides { 17 | # swaldman { 18 | # idleConnectionTestPeriod=300 19 | # } 20 | # } 21 | 22 | } 23 | 24 | -------------------------------------------------------------------------------- /unsupported/test-properties/application.properties: -------------------------------------------------------------------------------- 1 | resolvetest.name=hoconTest 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /unsupported/test-properties/c3p0-config.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 63 | 64 | 65 | -------------------------------------------------------------------------------- /unsupported/test-properties/c3p0.properties: -------------------------------------------------------------------------------- 1 | # 2 | # This file is detritus from various testing attempts 3 | # the values below may change, and often do not represent 4 | # reasonable values for the parameters. 5 | # 6 | 7 | #c3p0.testConnectionOnCheckout=true 8 | #c3p0.testConnectionOnCheckin=true 9 | #c3p0.dataSourceName=poop 10 | #c3p0.minPoolSize=10 11 | #c3p0.maxPoolSize=40 12 | #c3p0.checkoutTimeout=2000 13 | #c3p0.connectionIsValidTimeout=5 14 | #c3p0.idleConnectionTestPeriod=30 15 | #c3p0.idleConnectionTestPeriod=1 16 | #c3p0.maxConnectionAge=10 17 | #c3p0.maxIdleTime=2 18 | #c3p0.maxIdleTimeExcessConnections=1 19 | #c3p0.propertyCycle=1 20 | #c3p0.numHelperThreads=10 21 | #c3p0.unreturnedConnectionTimeout=15 22 | #c3p0.debugUnreturnedConnectionStackTraces=true 23 | #c3p0.forceSynchronousCheckins=true 24 | #c3p0.maxStatements=20 25 | #c3p0.maxStatementsPerConnection=5 26 | #c3p0.maxAdministrativeTaskTime=3 27 | #c3p0.preferredTestQuery=SELECT 1 28 | #c3p0.preferredTestQuery=SXLECT 1 29 | #c3p0.preferredTestQuery=SELECT a FROM emptyyukyuk WHERE a = 5 30 | #c3p0.preferredTestQuery=SELECT a FROM testpbds WHERE a = 5 31 | #c3p0.statementCacheNumDeferredCloseThreads=1 32 | #c3p0.automaticTestTable=PoopyTestTable 33 | #c3p0.acquireIncrement=3 34 | #c3p0.acquireRetryDelay=1000 35 | #c3p0.acquireRetryAttempts=60 36 | #c3p0.connectionTesterClassName=com.mchange.v2.c3p0.test.AlwaysFailConnectionTester 37 | #c3p0.initialPoolSize=15 38 | #c3p0.contextClassLoaderSource=library 39 | #c3p0.markSessionBoundaries=always 40 | #c3p0.privilegeSpawnedThreads=true 41 | #c3p0.connectionTesterClassName=com.mchange.v2.c3p0.example.IsValidOnlyConnectionTester30 42 | #c3p0.attemptResurrectOnCheckin=false 43 | 44 | c3p0.jdbcUrl=@c3p0.jdbcUrl@ 45 | c3p0.driverClass=@c3p0.driverClass@ 46 | c3p0.user=@c3p0.user@ 47 | c3p0.password=@c3p0.password@ 48 | 49 | #c3p0.forceUseNamedDriverClass=true 50 | 51 | #com.mchange.v2.c3p0.cfg.xml=classloader:META-INF/poop.xml 52 | #com.mchange.v2.c3p0.cfg.xml=/data/home/swaldman/development/gitproj/c3p0/src/test-properties/META-INF/poop.xml 53 | 54 | com.mchange.v2.log.MLog=slf4j 55 | #com.mchange.v2.log.MLog=log4j 56 | #com.mchange.v2.log.MLog=com.mchange.v2.log.log4j.Log4jMLog 57 | #com.mchange.v2.log.MLog=com.mchange.v2.log.jdk14logging.Jdk14MLog 58 | #com.mchange.v2.log.MLog=com.mchange.v2.log.FallbackMLog 59 | #com.mchange.v2.log.NameTransformer=com.mchange.v2.log.PackageNames 60 | #com.mchange.v2.log.FallbackMLog.DEFAULT_CUTOFF_LEVEL=ALL 61 | #com.mchange.v2.log.jdk14logging.suppressStackWalk=true 62 | 63 | #com.mchange.v2.c3p0.cfg.xml.usePermissiveParser=true 64 | #com.mchange.v2.c3p0.cfg.xml.expandEntityReferences=true 65 | 66 | #com.mchange.v2.c3p0.VMID=poop 67 | 68 | #com.mchange.v2.resourcepool.experimental.useScatteredAcquireTask=false 69 | 70 | # make sure we warn on unknown config 71 | #c3p0.poop=stinky 72 | 73 | #prop-style named config 74 | #c3p0.named-configs.kittycat.maxPoolSize=10 75 | 76 | #a user-defined config param 77 | #c3p0.extensions.myKey=myVal 78 | 79 | #resolvetest.name=thisIsSomeName 80 | 81 | #com.mchange.v2.c3p0.impl.DefaultConnectionTester.isValidTimeout=5 82 | 83 | #com.mchange.v2.c3p0.impl.DefaultConnectionTester.querylessTestRunner=METADATA_TABLESEARCH 84 | #com.mchange.v2.c3p0.impl.DefaultConnectionTester.querylessTestRunner=IS_VALID 85 | #com.mchange.v2.c3p0.impl.DefaultConnectionTester.querylessTestRunner=SWITCH 86 | #com.mchange.v2.c3p0.impl.DefaultConnectionTester.querylessTestRunner=THREAD_LOCAL 87 | 88 | -------------------------------------------------------------------------------- /unsupported/test-properties/c3p0.properties.rough: -------------------------------------------------------------------------------- 1 | # 2 | # This file is detritus from various testing attempts 3 | # the values below may change, and often do not represent 4 | # reasonable values for the parameters. 5 | # 6 | 7 | c3p0.testConnectionOnCheckout=true 8 | c3p0.testConnectionOnCheckin=true 9 | #c3p0.dataSourceName=poop 10 | c3p0.minPoolSize=10 11 | c3p0.maxPoolSize=40 12 | c3p0.checkoutTimeout=2000 13 | c3p0.connectionIsValidTimeout=1 14 | c3p0.idleConnectionTestPeriod=30 15 | c3p0.idleConnectionTestPeriod=1 16 | c3p0.maxConnectionAge=1 17 | c3p0.maxIdleTime=2 18 | c3p0.maxIdleTimeExcessConnections=1 19 | c3p0.propertyCycle=1 20 | c3p0.numHelperThreads=10 21 | c3p0.unreturnedConnectionTimeout=15 22 | c3p0.debugUnreturnedConnectionStackTraces=true 23 | c3p0.forceSynchronousCheckins=true 24 | c3p0.maxStatements=20 25 | c3p0.maxStatementsPerConnection=5 26 | c3p0.maxAdministrativeTaskTime=3 27 | c3p0.preferredTestQuery=SELECT 1 28 | #c3p0.preferredTestQuery=SXLECT 1 29 | #c3p0.preferredTestQuery=SELECT a FROM emptyyukyuk WHERE a = 5 30 | #c3p0.preferredTestQuery=SELECT a FROM testpbds WHERE a = 5 31 | c3p0.statementCacheNumDeferredCloseThreads=1 32 | #c3p0.automaticTestTable=PoopyTestTable 33 | c3p0.acquireIncrement=10 34 | #c3p0.acquireRetryDelay=1000 35 | #c3p0.acquireRetryAttempts=60 36 | #c3p0.connectionTesterClassName=com.mchange.v2.c3p0.test.AlwaysFailConnectionTester 37 | c3p0.initialPoolSize=15 38 | #c3p0.attemptResurrectOnCheckin=true 39 | 40 | c3p0.jdbcUrl=@c3p0.jdbcUrl@ 41 | c3p0.driverClass=@c3p0.driverClass@ 42 | c3p0.user=@c3p0.user@ 43 | c3p0.password=@c3p0.password@ 44 | 45 | com.mchange.v2.c3p0.impl.DefaultConnectionTester.isValidTimeout=1 46 | 47 | #com.mchange.v2.log.MLog=com.mchange.v2.log.log4j.Log4jMLog 48 | com.mchange.v2.log.MLog=com.mchange.v2.log.jdk14logging.Jdk14MLog 49 | #com.mchange.v2.log.MLog=com.mchange.v2.log.FallbackMLog 50 | #com.mchange.v2.log.NameTransformer=com.mchange.v2.log.PackageNames 51 | #com.mchange.v2.log.FallbackMLog.DEFAULT_CUTOFF_LEVEL=ALL 52 | 53 | #com.mchange.v2.c3p0.VMID=poop 54 | 55 | #com.mchange.v2.resourcepool.experimental.useScatteredAcquireTask=false 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | -------------------------------------------------------------------------------- /unsupported/test-properties/log4j.properties: -------------------------------------------------------------------------------- 1 | 2 | #log4j.rootLogger=ALL,A1 3 | log4j.rootLogger=INFO,A1 4 | #log4j.logger.com.mchange.v2.resourcepool=ALL,A1 5 | #log4j.logger.com.mchange.v2.c3p0.stmt=ALL 6 | #log4j.logger.com.mchange.v2.c3p0.impl=ALL 7 | #log4j.logger.com.mchange.v2.c3p0.management=ALL 8 | #log4j.logger.com.mchange.v2.resourcepool=ALL 9 | #log4j.logger.com.mchange.v2.async=ALL 10 | #log4j.logger.com.mchange.v2.c3p0.impl.NewPooledConnection=ALL 11 | #log4j.logger.com.mchange.v2.resourcepool.BasicResourcePool=ALL 12 | #log4j.logger.com.mchange.v2.c3p0.DriverManagerDataSource=ALL 13 | 14 | log4j.appender.A1=org.apache.log4j.ConsoleAppender 15 | 16 | log4j.appender.A1.layout=org.apache.log4j.SimpleLayout 17 | #log4j.appender.A1.layout=org.apache.log4j.PatternLayout 18 | 19 | #log4j.appender.A1.layout.ConversionPattern=%r [%t] %-5p %c %x - %m\n 20 | #log4j.appender.A1.layout.ConversionPattern=%d %-5p %c [%t] %C %M --> %m%n 21 | #log4j.appender.A1.layout.ConversionPattern=%-5p %c %C.%M() --> %m%n 22 | -------------------------------------------------------------------------------- /unsupported/test-properties/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 7 | 8 | %-5level %logger{36} - %msg%n%ex{full} --> 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /unsupported/test-properties/logging.properties: -------------------------------------------------------------------------------- 1 | ############################################################ 2 | # Default Logging Configuration File 3 | # 4 | # For example java -Djava.util.logging.config.file=myfile 5 | ############################################################ 6 | 7 | ############################################################ 8 | # Global properties 9 | ############################################################ 10 | 11 | # "handlers" specifies a comma separated list of log Handler 12 | # classes. These handlers will be installed during VM startup. 13 | # Note that these classes must be on the system classpath. 14 | # By default we only configure a ConsoleHandler, which will only 15 | # show messages at the INFO and above levels. 16 | handlers=java.util.logging.ConsoleHandler 17 | 18 | # To also add the FileHandler, use the following line instead. 19 | #handlers= java.util.logging.FileHandler, java.util.logging.ConsoleHandler 20 | 21 | # Default global logging level. 22 | # This specifies which kinds of events are logged across 23 | # all loggers. For any given facility this global level 24 | # can be overriden by a facility specific level 25 | # Note that the ConsoleHandler also has a separate level 26 | # setting to limit messages printed to the console. 27 | 28 | #.level=ALL 29 | #.level=FINER 30 | #.level=OFF 31 | .level=INFO 32 | 33 | ############################################################ 34 | # Handler specific properties. 35 | # Describes specific configuration info for Handlers. 36 | ############################################################ 37 | 38 | # default file output is in user's home directory. 39 | java.util.logging.FileHandler.pattern=%h/java%u.log 40 | java.util.logging.FileHandler.limit=50000 41 | java.util.logging.FileHandler.count=1 42 | java.util.logging.FileHandler.formatter=java.util.logging.XMLFormatter 43 | 44 | # Limit the message that are printed on the console to INFO and above. 45 | java.util.logging.ConsoleHandler.level=ALL 46 | java.util.logging.ConsoleHandler.formatter=java.util.logging.SimpleFormatter 47 | 48 | 49 | ############################################################ 50 | # Facility specific properties. 51 | # Provides extra control for each logger. 52 | ############################################################ 53 | 54 | # For example, set the com.xyz.foo logger to only log SEVERE 55 | # messages: 56 | 57 | #com.xyz.foo.level = SEVERE 58 | #com.mchange.v2.resourcepool.level=INFO 59 | #com.mchange.v2.resourcepool.level=FINER 60 | #com.mchange.v2.resourcepool.level=ALL 61 | #com.mchange.v2.async.level=ALL 62 | #com.mchange.v2.async.level=FINER 63 | #com.mchange.v2.c3p0.impl.level=ALL 64 | #com.mchange.level=FINE 65 | #com.mchange.level=ALL 66 | #com.mchange.v2.c3p0.impl.level=ALL 67 | #com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.level=ALL 68 | #com.mchange.v2.c3p0.debug.level=ALL 69 | #com.mchange.v2.c3p0.example.level=ALL 70 | 71 | #com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.level=ALL 72 | #com.mchange.v2.c3p0.impl.NewProxyStatement.level=ALL 73 | #com.mchange.v2.c3p0.stmt.GooGooStatementCache.level=ALL 74 | #com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.level=ALL 75 | #com.mchange.v2.c3p0.impl.NewPooledConnection.level=ALL 76 | 77 | #com.mchange.v2.c3p0.impl.C3P0PooledConnectionPoolManager.level=FINE 78 | 79 | #com.mchange.v2.cfg.level=ALL 80 | #com.mchange.v3.hocon.level=ALL 81 | #com.mchange.v2.log.level=ALL 82 | #com.mchange.v2.naming.level=ALL 83 | -------------------------------------------------------------------------------- /unsupported/test-properties/other.json: -------------------------------------------------------------------------------- 1 | { 2 | "c3p0" : { 3 | "maxPoolSize" : 500 4 | } 5 | } 6 | --------------------------------------------------------------------------------