Java Code Examples for org.apache.tomcat.jdbc.pool.PoolProperties#setInitSQL()
The following examples show how to use
org.apache.tomcat.jdbc.pool.PoolProperties#setInitSQL() .
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 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 2
Source File: Bug54225.java From Tomcat8-Source-Read with MIT License | 5 votes |
@Test public void testPool() throws SQLException { PoolProperties poolProperties = new DefaultProperties(); poolProperties.setMinIdle(0); poolProperties.setInitialSize(0); poolProperties.setMaxWait(5000); poolProperties.setRemoveAbandoned(true); poolProperties.setRemoveAbandonedTimeout(300); poolProperties.setRollbackOnReturn(true); poolProperties.setInitSQL(initSQL); final DataSource ds = new DataSource(poolProperties); ds.getConnection().close(); Assert.assertNull(poolProperties.getInitSQL()); }
Example 3
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 4
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 5
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; }
Example 6
Source File: TomcatJdbcDataSourcePool.java From Zebra with Apache License 2.0 | 4 votes |
@Override public DataSource build(DataSourceConfig config, boolean withDefaultValue) { PoolProperties properties = new PoolProperties(); properties.setUrl(config.getJdbcUrl()); properties.setUsername(config.getUsername()); properties.setPassword(config.getPassword()); properties.setDriverClassName(JdbcDriverClassHelper.getDriverClassNameByJdbcUrl(config.getJdbcUrl())); if (withDefaultValue) { properties.setInitialSize(getIntProperty(config, "initialPoolSize", 5)); properties.setMaxActive(getIntProperty(config, "maxPoolSize", 30)); properties.setMinIdle(getIntProperty(config, "minPoolSize", 5)); properties.setMaxIdle(getIntProperty(config, "maxPoolSize", 20)); properties.setMaxWait(getIntProperty(config, "checkoutTimeout", 1000)); properties.setValidationQuery(getStringProperty(config, "preferredTestQuery", "SELECT 1")); properties.setMinEvictableIdleTimeMillis(getIntProperty(config, "minEvictableIdleTimeMillis", 300000));// 5min properties.setTimeBetweenEvictionRunsMillis(getIntProperty(config, "timeBetweenEvictionRunsMillis", 30000)); // 30s properties.setNumTestsPerEvictionRun(getIntProperty(config, "numTestsPerEvictionRun", 6)); properties.setValidationQueryTimeout(getIntProperty(config, "validationQueryTimeout", 0)); properties.setValidationInterval(getIntProperty(config, "validationInterval", 30000));// 30s properties.setRemoveAbandonedTimeout(getIntProperty(config, "removeAbandonedTimeout", 300)); if (StringUtils.isNotBlank(getStringProperty(config, "connectionInitSql", null))) { properties.setInitSQL(getStringProperty(config, "connectionInitSql", null)); } properties.setTestWhileIdle(true); properties.setTestOnBorrow(false); properties.setTestOnReturn(false); properties.setRemoveAbandoned(true); } else { try { PropertiesInit<PoolProperties> propertiesInit = new PropertiesInit<PoolProperties>(properties); propertiesInit.initPoolProperties(config); } catch (Exception e) { throw new ZebraConfigException( String.format("tomcat-jdbc dataSource [%s] created error : ", config.getId()), e); } } org.apache.tomcat.jdbc.pool.DataSource datasource = new org.apache.tomcat.jdbc.pool.DataSource(); datasource.setPoolProperties(properties); this.pool = datasource; LOGGER.info(String.format("New dataSource [%s] created.", config.getId())); return this.pool; }