📄 c3p0pooledconnectionpoolmanager.java
字号:
String out; try { c = throwawayPooledConnection.getConnection(); DatabaseMetaData dmd = c.getMetaData(); String q = dmd.getIdentifierQuoteString(); String quotedTableName = q + automaticTestTable + q; out = "SELECT * FROM " + quotedTableName; mdrs = dmd.getTables( null, null, automaticTestTable, new String[] {"TABLE"} ); exists = mdrs.next(); //System.err.println("Table " + automaticTestTable + " exists? " + exists); if (exists) { testStmt = c.prepareStatement( out ); rs = testStmt.executeQuery(); has_rows = rs.next(); if (has_rows) throw new SQLException("automatic test table '" + automaticTestTable + "' contains rows, and it should not! Please set this " + "parameter to the name of a table c3p0 can create on its own, " + "that is not used elsewhere in the database!"); } else { String createSql = "CREATE TABLE " + quotedTableName + " ( a CHAR(1) )"; try { createStmt = c.prepareStatement( createSql ); createStmt.executeUpdate(); } catch (SQLException e) { if (logger.isLoggable( MLevel.WARNING )) logger.log(MLevel.WARNING, "An attempt to create an automatic test table failed. Create SQL: " + createSql, e ); throw e; } } return out; } finally { ResultSetUtils.attemptClose( mdrs ); ResultSetUtils.attemptClose( rs ); StatementUtils.attemptClose( testStmt ); StatementUtils.attemptClose( createStmt ); ConnectionUtils.attemptClose( c ); try{ if (throwawayPooledConnection != null) throwawayPooledConnection.close(); } catch ( Exception e ) { //e.printStackTrace(); logger.log(MLevel.WARNING, "A PooledConnection failed to close.", e); } } }}// public static find(ConnectionPoolDataSource cpds,// DbAuth defaultAuth, //may be null// int maxStatements,// int minPoolSize,// int maxPoolSize,// int idleConnectionTestPeriod,// int maxIdleTime,// int acquireIncrement,// boolean testConnectionOnCheckout,// boolean autoCommitOnClose,// boolean forceIgnoreUnresolvedTransactions,// ConnectionTester connectionTester)// {// C3P0PooledConnectionPoolManager nascent = new C3P0PooledConnectionPoolManager( cpds,// defaultAuth, // maxStatements,// minPoolSize,// maxPoolSize,// idleConnectionTestPeriod,// maxIdleTime,// acquireIncrement,// testConnectionOnCheckout,// autoCommitOnClose,// forceIgnoreUnresolvedTransactions,// connectionTester);// C3P0PooledConnectionPoolManager out = (C3P0PooledConnectionPoolManager) coalescer.coalesce( nascent );// if ( out == nascent ) //the new guy is the ONE// out.poolInit();// return out;// }// private C3P0PooledConnectionPoolManager(ConnectionPoolDataSource cpds,// DbAuth defaultAuth, //may be null// int maxStatements,// int minPoolSize,// int maxPoolSize,// int idleConnectionTestPeriod,// int maxIdleTime,// int acquireIncrement,// boolean testConnectionOnCheckout,// boolean autoCommitOnClose,// boolean forceIgnoreUnresolvedTransactions,// ConnectionTester connectionTester)// {// this.cpds = cpds;// this.defaultAuth = (defaultAuth == null ? C3P0ImplUtils.NULL_AUTH : defaultAuth);// this.maxStatements = maxStatements;// this.minPoolSize = minPoolSize;// this.maxPoolSize = maxPoolSize;// this.idleConnectionTestPeriod = idleConnectionTestPeriod;// this.maxIdleTime = maxIdleTime;// this.acquireIncrement = acquireIncrement;// this.testConnectionOnCheckout = testConnectionOnCheckout;// this.autoCommitOnClose = autoCommitOnClose;// this.testConnectionOnCheckout = testConnectionOnCheckout;// this.forceIgnoreUnresolvedTransactions = forceIgnoreUnresolvedTransactions;// } // private final static CoalesceChecker COALESCE_CHECKER = new CoalesceChecker()// {// // note that we expect all ConnectionTesters of a single class to be effectively// // equivalent, since they are to be constructed via a no-arg ctor and no// // extra initialization is performed. thus we only compare the classes of ConnectionTesters.// public boolean checkCoalesce( Object a, Object b )// {// C3P0PooledConnectionPoolManager aa = (C3P0PooledConnectionPoolManager) a;// C3P0PooledConnectionPoolManager bb = (C3P0PooledConnectionPoolManager) b;// return// aa.poolOwnerIdentityToken.equals( bb.poolOwnerIdentityToken ) &&// (aa.preferredTestQuery == null ? (bb.preferredTestQuery == null ) : (aa.preferredTestQuery.equals( bb.preferredTestQuery ))) &&// (aa.automaticTestTable == null ? (bb.automaticTestTable == null ) : (aa.automaticTestTable.equals( bb.automaticTestTable ))) &&// aa.sourceCpdsIdentityToken.equals( bb.sourceCpdsIdentityToken ) &&// aa.num_task_threads == bb.num_task_threads &&// aa.maxStatements == bb.maxStatements &&// aa.maxStatementsPerConnection == bb.maxStatementsPerConnection &&// aa.minPoolSize == bb.minPoolSize &&// aa.idleConnectionTestPeriod == bb.idleConnectionTestPeriod &&// aa.maxIdleTime == bb.maxIdleTime &&// aa.checkoutTimeout == bb.checkoutTimeout &&// aa.acquireIncrement == bb.acquireIncrement &&// aa.acquireRetryAttempts == bb.acquireRetryAttempts &&// aa.acquireRetryDelay == bb.acquireRetryDelay &&// aa.breakAfterAcquireFailure == bb.breakAfterAcquireFailure &&// aa.testConnectionOnCheckout == bb.testConnectionOnCheckout &&// aa.testConnectionOnCheckin == bb.testConnectionOnCheckin &&// aa.autoCommitOnClose == bb.autoCommitOnClose &&// aa.forceIgnoreUnresolvedTransactions == bb.forceIgnoreUnresolvedTransactions &&// aa.defaultAuth.equals( bb.defaultAuth ) &&// aa.connectionTester.getClass().equals( bb.connectionTester.getClass() );// };// public int coalesceHash( Object a )// {// C3P0PooledConnectionPoolManager aa = (C3P0PooledConnectionPoolManager) a;// int out =// aa.poolOwnerIdentityToken.hashCode() ^// (aa.preferredTestQuery == null ? 0 : aa.preferredTestQuery.hashCode()) ^// (aa.automaticTestTable == null ? 0 : aa.automaticTestTable.hashCode()) ^// aa.sourceCpdsIdentityToken.hashCode() ^// aa.num_task_threads ^// aa.maxStatements ^// aa.maxStatementsPerConnection ^// aa.minPoolSize ^// aa.idleConnectionTestPeriod ^// aa.maxIdleTime ^// aa.checkoutTimeout ^// aa.acquireIncrement ^// aa.acquireRetryAttempts ^// aa.acquireRetryDelay ^// (aa.testConnectionOnCheckout ? 1<<0 : 0) ^// (aa.testConnectionOnCheckin ? 1<<1 : 0) ^// (aa.autoCommitOnClose ? 1<<2 : 0) ^// (aa.forceIgnoreUnresolvedTransactions ? 1<<3 : 0) ^// (aa.breakAfterAcquireFailure ? 1<<4 : 0) ^// aa.defaultAuth.hashCode() ^// aa.connectionTester.getClass().hashCode(); // //System.err.println("coalesceHash() --> " + out);// return out;// };// };// int maxStatements = PoolConfig.defaultMaxStatements(); // int maxStatementsPerConnection = PoolConfig.defaultMaxStatementsPerConnection(); // int minPoolSize = PoolConfig.defaultMinPoolSize(); // int maxPoolSize = PoolConfig.defaultMaxPoolSize(); // int idleConnectionTestPeriod = PoolConfig.defaultIdleConnectionTestPeriod();// int maxIdleTime = PoolConfig.defaultMaxIdleTime(); // int checkoutTimeout = PoolConfig.defaultCheckoutTimeout(); // int acquireIncrement = PoolConfig.defaultAcquireIncrement(); // int acquireRetryAttempts = PoolConfig.defaultAcquireRetryAttempts(); // int acquireRetryDelay = PoolConfig.defaultAcquireRetryDelay(); // boolean breakAfterAcquireFailure = PoolConfig.defaultBreakAfterAcquireFailure(); // boolean testConnectionOnCheckout = PoolConfig.defaultTestConnectionOnCheckout(); // boolean testConnectionOnCheckin = PoolConfig.defaultTestConnectionOnCheckin(); // boolean autoCommitOnClose = PoolConfig.defaultAutoCommitOnClose(); // boolean forceIgnoreUnresolvedTransactions = PoolConfig.defaultForceIgnoreUnresolvedTransactions(); // String preferredTestQuery = PoolConfig.defaultPreferredTestQuery(); // String automaticTestTable = PoolConfig.defaultAutomaticTestTable(); // DbAuth defaultAuth = C3P0ImplUtils.NULL_AUTH; // ConnectionTester connectionTester = C3P0ImplUtils.defaultConnectionTester();;// // we look for non-standard props user and// // password, available as read-only props on// // our implementation of ConnectionPoolDataSource.// //// // If other implementations are used, the only// // hazard is the possibility that there will be // // two pools for the same real authorization credentials// // one for when the credentials are explicitly specified,// // and one for when the defaults are used.// this.defaultAuth = C3P0ImplUtils.findAuth( cpds );// BeanInfo bi = Introspector.getBeanInfo( cpds.getClass() );// PropertyDescriptor[] pds = bi.getPropertyDescriptors();// for (int i = 0, len = pds.length; i < len; ++i)// {// PropertyDescriptor pd = pds[i];// Class propCl = pd.getPropertyType();// String propName = pd.getName();// Method readMethod = pd.getReadMethod();// Object propVal;// if (propCl == int.class)// {// propVal = readMethod.invoke( cpds, C3P0ImplUtils.NOARGS );// int value = ((Integer) propVal).intValue();// if ("maxStatements".equals(propName))// this.maxStatements = value;// else if ("maxStatementsPerConnection".equals(propName))// this.maxStatementsPerConnection = value;// else if ("minPoolSize".equals(propName))// this.minPoolSize = value;// else if ("maxPoolSize".equals(propName))// this.maxPoolSize = value;// else if ("idleConnectionTestPeriod".equals(propName))// this.idleConnectionTestPeriod = value;// else if ("maxIdleTime".equals(propName))// this.maxIdleTime = value;// else if ("checkoutTimeout".equals(propName))// this.checkoutTimeout = value;// else if ("acquireIncrement".equals(propName))// this.acquireIncrement = value;// else if ("acquireRetryAttempts".equals(propName))// this.acquireRetryAttempts = value;// else if ("acquireRetryDelay".equals(propName))// this.acquireRetryDelay = value;// // System.err.println( propName + " -> " + propVal );// }// else if (propCl == String.class)// {// propVal = readMethod.invoke( cpds, C3P0ImplUtils.NOARGS );// String value = (String) propVal;// if ("connectionTesterClassName".equals(propName))// this.connectionTester =// (ConnectionTester) Class.forName( value ).newInstance();// else if ("preferredTestQuery".equals(propName))// this.preferredTestQuery = value;// else if ("automaticTestTable".equals(propName))// this.automaticTestTable = value;// // System.err.println( propName + " -> " + propVal );// }// else if (propCl == boolean.class)// {// propVal = readMethod.invoke( cpds, C3P0ImplUtils.NOARGS );// boolean value = ((Boolean) propVal).booleanValue();// if ("testConnectionOnCheckout".equals(propName))// this.testConnectionOnCheckout = value;// else if ("testConnectionOnCheckin".equals(propName))// this.testConnectionOnCheckin = value;// else if ("autoCommitOnClose".equals(propName))// this.autoCommitOnClose = value;// else if ("forceIgnoreUnresolvedTransactions".equals(propName))// this.forceIgnoreUnresolvedTransactions = value;// else if ("breakAfterAcquireFailure".equals(propName))// this.breakAfterAcquireFailure = value;// // System.err.println( propName + " -> " + propVal );// }// }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -