Java Code Examples for org.apache.tomcat.jdbc.pool.PoolProperties#setMaxAge()
The following examples show how to use
org.apache.tomcat.jdbc.pool.PoolProperties#setMaxAge() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Bug54978.java From Tomcat8-Source-Read with MIT License | 6 votes |
@Test public void testIllegalValidationQuery() { PoolProperties poolProperties = new DefaultProperties(); poolProperties.setMinIdle(0); poolProperties.setInitialSize(1); poolProperties.setMaxActive(1); poolProperties.setMaxWait(5000); poolProperties.setMaxAge(100); poolProperties.setRemoveAbandoned(false); poolProperties.setTestOnBorrow(true); poolProperties.setTestOnConnect(false); poolProperties.setValidationQuery("sdadsada"); final DataSource ds = new DataSource(poolProperties); try { ds.getConnection().close(); Assert.fail("Validation should have failed."); }catch (SQLException x) { } }
Example 2
Source File: Bug54978.java From Tomcat8-Source-Read with MIT License | 6 votes |
@Test public void testIllegalValidationQueryWithLegalInit() throws SQLException { PoolProperties poolProperties = new DefaultProperties(); poolProperties.setMinIdle(0); poolProperties.setInitialSize(1); poolProperties.setMaxActive(1); poolProperties.setMaxWait(5000); poolProperties.setMaxAge(100); poolProperties.setRemoveAbandoned(false); poolProperties.setTestOnBorrow(true); poolProperties.setTestOnConnect(false); poolProperties.setValidationQuery("sdadsada"); poolProperties.setInitSQL("SELECT 1"); final DataSource ds = new DataSource(poolProperties); ds.getConnection().close(); }
Example 3
Source File: Bug54227.java From Tomcat8-Source-Read with MIT License | 5 votes |
@Test public void testPool() throws SQLException, InterruptedException { PoolProperties poolProperties = new DefaultProperties(); poolProperties.setMinIdle(0); poolProperties.setInitialSize(0); poolProperties.setMaxActive(1); poolProperties.setMaxWait(5000); poolProperties.setMaxAge(100); poolProperties.setRemoveAbandoned(false); final DataSource ds = new DataSource(poolProperties); Connection con; Connection actual1; Connection actual2; con = ds.getConnection(); actual1 = ((PooledConnection)con).getConnection(); con.close(); con = ds.getConnection(); actual2 = ((PooledConnection)con).getConnection(); Assert.assertSame(actual1, actual2); con.close(); Thread.sleep(150); con = ds.getConnection(); actual2 = ((PooledConnection)con).getConnection(); Assert.assertNotSame(actual1, actual2); con.close(); }
Example 4
Source File: DataSourceUtil.java From das with Apache License 2.0 | 5 votes |
private static DataSource createDataSource(String url, String userName, String password, String driverClass) throws Exception { PoolProperties p = new PoolProperties(); //System.out.println(url); p.setUrl(url); p.setUsername(userName); p.setPassword(password); p.setDriverClassName(driverClass); p.setJmxEnabled(false); p.setTestWhileIdle(false); p.setTestOnBorrow(true); p.setTestOnReturn(false); p.setValidationQuery("SELECT 1"); p.setValidationQueryTimeout(5); p.setValidationInterval(30000L); p.setTimeBetweenEvictionRunsMillis(300000); p.setNumTestsPerEvictionRun(50); p.setMaxActive(100); p.setMinIdle(0); p.setMaxWait(10000); p.setMaxAge(0L); p.setInitialSize(1); p.setRemoveAbandonedTimeout(60); p.setRemoveAbandoned(true); p.setLogAbandoned(true); p.setMinEvictableIdleTimeMillis(3600000); p.setJdbcInterceptors("org.apache.tomcat.jdbc.pool.interceptor.ConnectionState;" + "org.apache.tomcat.jdbc.pool.interceptor.StatementFinalizer"); org.apache.tomcat.jdbc.pool.DataSource ds = new org.apache.tomcat.jdbc.pool.DataSource(p); ds.createPool(); return ds; }
Example 5
Source File: DataSourceUtil.java From das with Apache License 2.0 | 5 votes |
private static DataSource createDataSource(String url, String userName, String password, String driverClass) throws Exception { PoolProperties p = new PoolProperties(); p.setUrl(url); p.setUsername(userName); p.setPassword(password); p.setDriverClassName(driverClass); p.setJmxEnabled(false); p.setTestWhileIdle(false); p.setTestOnBorrow(true); p.setTestOnReturn(false); p.setValidationQuery("SELECT 1"); p.setValidationQueryTimeout(5); p.setValidationInterval(30000L); p.setTimeBetweenEvictionRunsMillis(5000); p.setMaxActive(100); p.setMinIdle(0); p.setMaxWait(10000); p.setMaxAge(0L); p.setInitialSize(1); p.setRemoveAbandonedTimeout(60); p.setRemoveAbandoned(true); p.setLogAbandoned(true); p.setMinEvictableIdleTimeMillis(30000); p.setJdbcInterceptors("org.apache.tomcat.jdbc.pool.interceptor.ConnectionState;" + "org.apache.tomcat.jdbc.pool.interceptor.StatementFinalizer"); org.apache.tomcat.jdbc.pool.DataSource ds = new org.apache.tomcat.jdbc.pool.DataSource(p); ds.createPool(); return ds; }
Example 6
Source File: PoolPropertiesHelper.java From das with Apache License 2.0 | 5 votes |
public PoolProperties copy(PoolProperties from) { PoolProperties properties = new PoolProperties(); properties.setUrl(from.getUrl()); properties.setUsername(from.getUsername()); properties.setPassword(from.getPassword()); properties.setDriverClassName(from.getDriverClassName()); properties.setTestWhileIdle(from.isTestWhileIdle()); properties.setTestOnBorrow(from.isTestOnBorrow()); properties.setTestOnReturn(from.isTestOnReturn()); properties.setValidationQuery(from.getValidationQuery()); properties.setValidationQueryTimeout(from.getValidationQueryTimeout()); properties.setValidationInterval(from.getValidationInterval()); properties.setTimeBetweenEvictionRunsMillis(from.getTimeBetweenEvictionRunsMillis()); properties.setMinEvictableIdleTimeMillis(from.getMinEvictableIdleTimeMillis()); properties.setMaxAge(from.getMaxAge()); properties.setMaxActive(from.getMaxActive()); properties.setMinIdle(from.getMinIdle()); properties.setMaxWait(from.getMaxWait()); properties.setInitialSize(from.getInitialSize()); properties.setRemoveAbandonedTimeout(from.getRemoveAbandonedTimeout()); properties.setRemoveAbandoned(from.isRemoveAbandoned()); properties.setLogAbandoned(from.isLogAbandoned()); properties.setConnectionProperties(from.getConnectionProperties()); properties.setValidatorClassName(from.getValidatorClassName()); properties.setInitSQL(from.getInitSQL()); properties.setJmxEnabled(from.isJmxEnabled()); properties.setJdbcInterceptors(from.getJdbcInterceptors()); return properties; }
Example 7
Source File: DatabasePoolConfigParser.java From dal with Apache License 2.0 | 5 votes |
public DatabasePoolConfig getDatabasePoolConfig(String name) { DataSourceConfigure configure = DataSourceConfigureLocatorManager.getInstance().getDataSourceConfigure(name); PoolProperties poolProperties = new PoolProperties(); poolProperties.setTestWhileIdle(configure.getBooleanProperty(TESTWHILEIDLE, DEFAULT_TESTWHILEIDLE)); poolProperties.setTestOnBorrow(configure.getBooleanProperty(TESTONBORROW, DEFAULT_TESTONBORROW)); poolProperties.setTestOnReturn(configure.getBooleanProperty(TESTONRETURN, DEFAULT_TESTONRETURN)); poolProperties.setValidationQuery(configure.getProperty(VALIDATIONQUERY, DEFAULT_VALIDATIONQUERY)); poolProperties.setValidationQueryTimeout( configure.getIntProperty(VALIDATIONQUERYTIMEOUT, DEFAULT_VALIDATIONQUERYTIMEOUT)); poolProperties.setValidationInterval(configure.getLongProperty(VALIDATIONINTERVAL, DEFAULT_VALIDATIONINTERVAL)); poolProperties.setTimeBetweenEvictionRunsMillis( configure.getIntProperty(TIMEBETWEENEVICTIONRUNSMILLIS, DEFAULT_TIMEBETWEENEVICTIONRUNSMILLIS)); poolProperties.setMinEvictableIdleTimeMillis(DEFAULT_MINEVICTABLEIDLETIMEMILLIS); poolProperties.setMaxAge(configure.getIntProperty(MAX_AGE, DEFAULT_MAXAGE)); poolProperties.setMaxActive(configure.getIntProperty(MAXACTIVE, DEFAULT_MAXACTIVE)); poolProperties.setMinIdle(configure.getIntProperty(MINIDLE, DEFAULT_MINIDLE)); poolProperties.setMaxWait(configure.getIntProperty(MAXWAIT, DEFAULT_MAXWAIT)); poolProperties.setInitialSize(configure.getIntProperty(INITIALSIZE, DEFAULT_INITIALSIZE)); poolProperties.setRemoveAbandonedTimeout( configure.getIntProperty(REMOVEABANDONEDTIMEOUT, DEFAULT_REMOVEABANDONEDTIMEOUT)); poolProperties.setRemoveAbandoned(configure.getBooleanProperty(REMOVEABANDONED, DEFAULT_REMOVEABANDONED)); poolProperties.setLogAbandoned(configure.getBooleanProperty(LOGABANDONED, DEFAULT_LOGABANDONED)); poolProperties .setConnectionProperties(configure.getProperty(CONNECTIONPROPERTIES, DEFAULT_CONNECTIONPROPERTIES)); poolProperties.setValidatorClassName(configure.getProperty(VALIDATORCLASSNAME, DEFAULT_VALIDATORCLASSNAME)); poolProperties.setJmxEnabled(DEFAULT_JMXENABLED); poolProperties.setJdbcInterceptors(configure.getProperty(JDBC_INTERCEPTORS, DEFAULT_JDBCINTERCEPTORS)); return new DatabasePoolConfig(poolProperties); }
Example 8
Source File: DataSourceUtil.java From dal with Apache License 2.0 | 5 votes |
private static DataSource createDataSource(String url, String userName, String password, String driverClass) throws Exception { PoolProperties p = new PoolProperties(); p.setUrl(url); p.setUsername(userName); p.setPassword(password); p.setDriverClassName(driverClass); p.setJmxEnabled(false); p.setTestWhileIdle(false); p.setTestOnBorrow(true); p.setTestOnReturn(false); p.setValidationQuery("SELECT 1"); p.setValidationQueryTimeout(5); p.setValidationInterval(30000L); p.setTimeBetweenEvictionRunsMillis(5000); p.setMaxActive(100); p.setMinIdle(0); p.setMaxWait(10000); p.setMaxAge(0L); p.setInitialSize(1); p.setRemoveAbandonedTimeout(60); p.setRemoveAbandoned(true); p.setLogAbandoned(true); p.setMinEvictableIdleTimeMillis(30000); p.setJdbcInterceptors("org.apache.tomcat.jdbc.pool.interceptor.ConnectionState;" + "org.apache.tomcat.jdbc.pool.interceptor.StatementFinalizer"); org.apache.tomcat.jdbc.pool.DataSource ds = new org.apache.tomcat.jdbc.pool.DataSource(p); ds.createPool(); return ds; }
Example 9
Source File: MGRConfigReader.java From das with Apache License 2.0 | 4 votes |
/** * Merge existing data source and special configurations for MGR */ private PoolProperties mergePoolProperties(PoolProperties p) { PoolProperties merged = PoolPropertiesHelper.getInstance().copy(p); merged.setMinIdle(0); //don't cache connection merged.setMinEvictableIdleTimeMillis(1000); if(poolProperties == null) {//re-use data source configuration return merged; } String testWhileIdle = poolProperties.getProperty(DataSourceConfigureConstants.TESTWHILEIDLE); if(testWhileIdle != null){ merged.setTestWhileIdle(Boolean.valueOf(testWhileIdle)); } String testOnBorrow = poolProperties.getProperty(DataSourceConfigureConstants.TESTONBORROW); if(testOnBorrow != null){ merged.setTestOnBorrow(Boolean.valueOf(testOnBorrow)); } String validationInterval = poolProperties.getProperty(DataSourceConfigureConstants.VALIDATIONINTERVAL); if(validationInterval != null){ merged.setValidationInterval(Long.parseLong(validationInterval)); } String maxAge = poolProperties.getProperty(DataSourceConfigureConstants.MAX_AGE); if(maxAge != null){ merged.setMaxAge(Long.parseLong(maxAge)); } String validationQueryTimeout = poolProperties.getProperty(DataSourceConfigureConstants.VALIDATIONQUERYTIMEOUT); if(validationQueryTimeout != null){ merged.setValidationInterval(Long.parseLong(validationQueryTimeout)); } String validationQuery = poolProperties.getProperty(DataSourceConfigureConstants.VALIDATIONQUERY); if(validationQuery != null){ merged.setValidationQuery(validationQuery); } return merged; }
Example 10
Source File: PoolPropertiesHelper.java From das with Apache License 2.0 | 4 votes |
public PoolProperties convert(DataSourceConfigure config) { PoolProperties properties = new PoolProperties(); /** * It is assumed that user name/password/url/driver class name are provided in pool config If not, it should be * provided by the config provider */ properties.setUrl(config.getConnectionUrl()); properties.setUsername(config.getUserName()); properties.setPassword(config.getPassword()); properties.setDriverClassName(config.getDriverClass()); properties.setTestWhileIdle(config.getBooleanProperty(TESTWHILEIDLE, DEFAULT_TESTWHILEIDLE)); properties.setTestOnBorrow(config.getBooleanProperty(TESTONBORROW, DEFAULT_TESTONBORROW)); properties.setTestOnReturn(config.getBooleanProperty(TESTONRETURN, DEFAULT_TESTONRETURN)); properties.setValidationQuery(config.getProperty(VALIDATIONQUERY, DEFAULT_VALIDATIONQUERY)); properties.setValidationQueryTimeout( config.getIntProperty(VALIDATIONQUERYTIMEOUT, DEFAULT_VALIDATIONQUERYTIMEOUT)); properties.setValidationInterval(config.getLongProperty(VALIDATIONINTERVAL, DEFAULT_VALIDATIONINTERVAL)); properties.setTimeBetweenEvictionRunsMillis( config.getIntProperty(TIMEBETWEENEVICTIONRUNSMILLIS, DEFAULT_TIMEBETWEENEVICTIONRUNSMILLIS)); properties.setMinEvictableIdleTimeMillis( config.getIntProperty(MINEVICTABLEIDLETIMEMILLIS, DEFAULT_MINEVICTABLEIDLETIMEMILLIS)); properties.setMaxAge(config.getIntProperty(MAX_AGE, DEFAULT_MAXAGE)); properties.setMaxActive(config.getIntProperty(MAXACTIVE, DEFAULT_MAXACTIVE)); properties.setMinIdle(config.getIntProperty(MINIDLE, DEFAULT_MINIDLE)); properties.setMaxWait(config.getIntProperty(MAXWAIT, DEFAULT_MAXWAIT)); properties.setInitialSize(config.getIntProperty(INITIALSIZE, DEFAULT_INITIALSIZE)); properties.setRemoveAbandonedTimeout( config.getIntProperty(REMOVEABANDONEDTIMEOUT, DEFAULT_REMOVEABANDONEDTIMEOUT)); properties.setRemoveAbandoned(config.getBooleanProperty(REMOVEABANDONED, DEFAULT_REMOVEABANDONED)); properties.setLogAbandoned(config.getBooleanProperty(LOGABANDONED, DEFAULT_LOGABANDONED)); properties.setConnectionProperties(config.getProperty(CONNECTIONPROPERTIES, DEFAULT_CONNECTIONPROPERTIES)); properties.setValidatorClassName(config.getProperty(VALIDATORCLASSNAME, DEFAULT_VALIDATORCLASSNAME)); String initSQL = config.getProperty(INIT_SQL); if (initSQL != null && !initSQL.isEmpty()) { properties.setInitSQL(initSQL); } String initSQL2 = config.getProperty(INIT_SQL2); if (initSQL2 != null && !initSQL2.isEmpty()) { properties.setInitSQL(initSQL2); } // This are current hard coded as default value properties.setJmxEnabled(DEFAULT_JMXENABLED); properties.setJdbcInterceptors(config.getProperty(JDBC_INTERCEPTORS, DEFAULT_JDBCINTERCEPTORS)); return properties; }
Example 11
Source File: PoolPropertiesHelper.java From dal with Apache License 2.0 | 4 votes |
public PoolProperties convert(DataSourceConfigure config) { PoolProperties properties = new PoolProperties(); /** * It is assumed that user name/password/url/driver class name are provided in pool config If not, it should be * provided by the config provider */ properties.setUrl(config.getConnectionUrl()); properties.setUsername(config.getUserName()); properties.setPassword(config.getPassword()); properties.setDriverClassName(config.getDriverClass()); properties.setTestWhileIdle(config.getBooleanProperty(TESTWHILEIDLE, DEFAULT_TESTWHILEIDLE)); properties.setTestOnBorrow(config.getBooleanProperty(TESTONBORROW, DEFAULT_TESTONBORROW)); properties.setTestOnReturn(config.getBooleanProperty(TESTONRETURN, DEFAULT_TESTONRETURN)); properties.setValidationQuery(config.getProperty(VALIDATIONQUERY, DEFAULT_VALIDATIONQUERY)); properties.setValidationQueryTimeout( config.getIntProperty(VALIDATIONQUERYTIMEOUT, DEFAULT_VALIDATIONQUERYTIMEOUT)); properties.setValidationInterval(config.getLongProperty(VALIDATIONINTERVAL, DEFAULT_VALIDATIONINTERVAL)); properties.setTimeBetweenEvictionRunsMillis( config.getIntProperty(TIMEBETWEENEVICTIONRUNSMILLIS, DEFAULT_TIMEBETWEENEVICTIONRUNSMILLIS)); properties.setMinEvictableIdleTimeMillis( config.getIntProperty(MINEVICTABLEIDLETIMEMILLIS, DEFAULT_MINEVICTABLEIDLETIMEMILLIS)); properties.setMaxAge(config.getIntProperty(MAX_AGE, DEFAULT_MAXAGE)); properties.setMaxActive(config.getIntProperty(MAXACTIVE, DEFAULT_MAXACTIVE)); properties.setMinIdle(config.getIntProperty(MINIDLE, DEFAULT_MINIDLE)); properties.setMaxWait(config.getIntProperty(MAXWAIT, DEFAULT_MAXWAIT)); properties.setInitialSize(config.getIntProperty(INITIALSIZE, DEFAULT_INITIALSIZE)); properties.setRemoveAbandonedTimeout( config.getIntProperty(REMOVEABANDONEDTIMEOUT, DEFAULT_REMOVEABANDONEDTIMEOUT)); properties.setRemoveAbandoned(config.getBooleanProperty(REMOVEABANDONED, DEFAULT_REMOVEABANDONED)); properties.setLogAbandoned(config.getBooleanProperty(LOGABANDONED, DEFAULT_LOGABANDONED)); properties.setConnectionProperties(config.getProperty(CONNECTIONPROPERTIES, DEFAULT_CONNECTIONPROPERTIES)); properties.setValidatorClassName(config.getProperty(VALIDATORCLASSNAME, DEFAULT_VALIDATORCLASSNAME)); String initSQL = config.getProperty(INIT_SQL); if (initSQL != null && !initSQL.isEmpty()) properties.setInitSQL(initSQL); String initSQL2 = config.getProperty(INIT_SQL2); if (initSQL2 != null && !initSQL2.isEmpty()) properties.setInitSQL(initSQL2); // This are current hard coded as default value properties.setJmxEnabled(DEFAULT_JMXENABLED); properties.setJdbcInterceptors(config.getProperty(JDBC_INTERCEPTORS, DEFAULT_JDBCINTERCEPTORS)); return properties; }