📄 c3p0pooledconnectionpoolmanager.java
字号:
{ try { Method m = (Method) propNamesToReadMethods.get( propName ); if (m != null) { Object readProp = m.invoke( cpds, null ); if (readProp != null) out = readProp.toString(); } } catch (Exception e) { if (logger.isLoggable( MLevel.WARNING )) logger.log(MLevel.WARNING, "An exception occurred while trying to read property '" + propName + "' from ConnectionPoolDataSource: " + cpds + ". Default config value will be used.", e ); } } //if the ConnectionPoolDataSource DID NOT have config parameter defined as a property //(and there was no user-specific or force override) //use config-defined default if (out == null) out = C3P0Config.getUnspecifiedUserProperty( propName, null ); return out; } private String getString(String propName, String userName) { Object o = getObject( propName, userName); return (o == null ? null : o.toString()); } private int getInt(String propName, String userName) throws Exception { Object o = getObject( propName, userName); if (o instanceof Integer) return ((Integer) o).intValue(); else if (o instanceof String) return Integer.parseInt( (String) o ); else throw new Exception("Unexpected object found for putative int property '" + propName +"': " + o); } private boolean getBoolean(String propName, String userName) throws Exception { Object o = getObject( propName, userName); if (o instanceof Boolean) return ((Boolean) o).booleanValue(); else if (o instanceof String) return BooleanUtils.parseBoolean( (String) o ); else throw new Exception("Unexpected object found for putative boolean property '" + propName +"': " + o); } public String getAutomaticTestTable(String userName) { return getString("automaticTestTable", userName ); } public String getPreferredTestQuery(String userName) { return getString("preferredTestQuery", userName ); } public int getMinPoolSize(String userName) { try { return getInt("minPoolSize", userName ); } catch (Exception e) { if ( logger.isLoggable( MLevel.FINE ) ) logger.log( MLevel.FINE, "Could not fetch int property", e); return C3P0Defaults.minPoolSize(); } } private int getMaxPoolSize(String userName) { try { return getInt("maxPoolSize", userName ); } catch (Exception e) { if ( logger.isLoggable( MLevel.FINE ) ) logger.log( MLevel.FINE, "Could not fetch int property", e); return C3P0Defaults.maxPoolSize(); } } private int getMaxStatements(String userName) { try { return getInt("maxStatements", userName ); } catch (Exception e) { if ( logger.isLoggable( MLevel.FINE ) ) logger.log( MLevel.FINE, "Could not fetch int property", e); return C3P0Defaults.maxStatements(); } } private int getMaxStatementsPerConnection(String userName) { try { return getInt("maxStatementsPerConnection", userName ); } catch (Exception e) { if ( logger.isLoggable( MLevel.FINE ) ) logger.log( MLevel.FINE, "Could not fetch int property", e); return C3P0Defaults.maxStatementsPerConnection(); } } private int getAcquireIncrement(String userName) { try { return getInt("acquireIncrement", userName ); } catch (Exception e) { if ( logger.isLoggable( MLevel.FINE ) ) logger.log( MLevel.FINE, "Could not fetch int property", e); return C3P0Defaults.acquireIncrement(); } } private int getAcquireRetryAttempts(String userName) { try { return getInt("acquireRetryAttempts", userName ); } catch (Exception e) { if ( logger.isLoggable( MLevel.FINE ) ) logger.log( MLevel.FINE, "Could not fetch int property", e); return C3P0Defaults.acquireRetryAttempts(); } } private int getAcquireRetryDelay(String userName) { try { return getInt("acquireRetryDelay", userName ); } catch (Exception e) { if ( logger.isLoggable( MLevel.FINE ) ) logger.log( MLevel.FINE, "Could not fetch int property", e); return C3P0Defaults.acquireRetryDelay(); } } private boolean getBreakAfterAcquireFailure(String userName) { try { return getBoolean("breakAfterAcquireFailure", userName ); } catch (Exception e) { if ( logger.isLoggable( MLevel.FINE ) ) logger.log( MLevel.FINE, "Could not fetch boolean property", e); return C3P0Defaults.breakAfterAcquireFailure(); } } private int getCheckoutTimeout(String userName) { try { return getInt("checkoutTimeout", userName ); } catch (Exception e) { if ( logger.isLoggable( MLevel.FINE ) ) logger.log( MLevel.FINE, "Could not fetch int property", e); return C3P0Defaults.checkoutTimeout(); } } private int getIdleConnectionTestPeriod(String userName) { try { return getInt("idleConnectionTestPeriod", userName ); } catch (Exception e) { if ( logger.isLoggable( MLevel.FINE ) ) logger.log( MLevel.FINE, "Could not fetch int property", e); return C3P0Defaults.idleConnectionTestPeriod(); } } private int getMaxIdleTime(String userName) { try { return getInt("maxIdleTime", userName ); } catch (Exception e) { if ( logger.isLoggable( MLevel.FINE ) ) logger.log( MLevel.FINE, "Could not fetch int property", e); return C3P0Defaults.maxIdleTime(); } } private boolean getTestConnectionOnCheckout(String userName) { try { return getBoolean("testConnectionOnCheckout", userName ); } catch (Exception e) { if ( logger.isLoggable( MLevel.FINE ) ) logger.log( MLevel.FINE, "Could not fetch boolean property", e); return C3P0Defaults.testConnectionOnCheckout(); } } private boolean getTestConnectionOnCheckin(String userName) { try { return getBoolean("testConnectionOnCheckin", userName ); } catch (Exception e) { if ( logger.isLoggable( MLevel.FINE ) ) logger.log( MLevel.FINE, "Could not fetch boolean property", e); return C3P0Defaults.testConnectionOnCheckin(); } } public String getConnectionTesterClassName(String userName) { return getString("connectionTesterClassName", userName ); } private ConnectionTester getConnectionTester(String userName) { return C3P0Registry.getConnectionTester( getConnectionTesterClassName( userName ) ); } // called only from sync'ed methods private C3P0PooledConnectionPool createPooledConnectionPool(DbAuth auth) throws SQLException { String userName = auth.getUser(); String automaticTestTable = getAutomaticTestTable( userName ); String realTestQuery; if (automaticTestTable != null) { realTestQuery = initializeAutomaticTestTable( automaticTestTable ); if (this.getPreferredTestQuery( userName ) != null) { if ( logger.isLoggable( MLevel.WARNING ) ) { logger.logp(MLevel.WARNING, C3P0PooledConnectionPoolManager.class.getName(), "createPooledConnectionPool", "[c3p0] Both automaticTestTable and preferredTestQuery have been set! " + "Using automaticTestTable, and ignoring preferredTestQuery. Real test query is ''{0}''.", realTestQuery ); } } } else realTestQuery = this.getPreferredTestQuery( userName ); C3P0PooledConnectionPool out = new C3P0PooledConnectionPool( cpds, auth, this.getMinPoolSize( userName ), this.getMaxPoolSize( userName ), this.getAcquireIncrement( userName ), this.getAcquireRetryAttempts( userName ), this.getAcquireRetryDelay( userName ), this.getBreakAfterAcquireFailure( userName ), this.getCheckoutTimeout( userName ), this.getIdleConnectionTestPeriod( userName ), this.getMaxIdleTime( userName ), this.getTestConnectionOnCheckout( userName ), this.getTestConnectionOnCheckin( userName ), this.getMaxStatements( userName ), this.getMaxStatementsPerConnection( userName ), this.getConnectionTester( userName ), realTestQuery, rpfact, taskRunner ); return out; } // only called from sync'ed methods private String initializeAutomaticTestTable(String automaticTestTable) throws SQLException { PooledConnection throwawayPooledConnection = cpds.getPooledConnection(); Connection c = null; PreparedStatement testStmt = null; PreparedStatement createStmt = null; ResultSet mdrs = null; ResultSet rs = null; boolean exists; boolean has_rows;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -