use of org.apache.tomcat.jdbc.pool.PoolProperties in project tomcat by apache.
the class Bug54978 method testIllegalValidationQueryWithLegalInit.
@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();
}
use of org.apache.tomcat.jdbc.pool.PoolProperties in project tomcat by apache.
the class Bug54978 method testIllegalValidationQuery.
@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();
fail("Validation should have failed.");
} catch (SQLException x) {
}
}
use of org.apache.tomcat.jdbc.pool.PoolProperties in project tomcat by apache.
the class SimplePOJOAsyncExample method main.
public static void main(String[] args) throws Exception {
PoolConfiguration p = new PoolProperties();
p.setFairQueue(true);
p.setUrl("jdbc:mysql://localhost:3306/mysql?autoReconnect=true");
p.setDriverClassName("com.mysql.jdbc.Driver");
p.setUsername("root");
p.setPassword("password");
p.setJmxEnabled(true);
p.setTestWhileIdle(false);
p.setTestOnBorrow(true);
p.setValidationQuery("SELECT 1");
p.setTestOnReturn(false);
p.setValidationInterval(30000);
p.setTimeBetweenEvictionRunsMillis(30000);
p.setMaxActive(100);
p.setInitialSize(10);
p.setMaxWait(10000);
p.setRemoveAbandonedTimeout(60);
p.setMinEvictableIdleTimeMillis(30000);
p.setMinIdle(10);
p.setLogAbandoned(true);
p.setRemoveAbandoned(true);
p.setJdbcInterceptors("org.apache.tomcat.jdbc.pool.interceptor.ConnectionState;org.apache.tomcat.jdbc.pool.interceptor.StatementFinalizer");
DataSource datasource = new DataSource();
datasource.setPoolProperties(p);
Connection con = null;
try {
Future<Connection> future = datasource.getConnectionAsync();
while (!future.isDone()) {
System.out.println("Connection is not yet available. Do some background work");
try {
//simulate work
Thread.sleep(100);
} catch (InterruptedException x) {
Thread.interrupted();
}
}
//should return instantly
con = future.get();
Statement st = con.createStatement();
ResultSet rs = st.executeQuery("select * from user");
int cnt = 1;
while (rs.next()) {
System.out.println((cnt++) + ". Host:" + rs.getString("Host") + " User:" + rs.getString("User") + " Password:" + rs.getString("Password"));
}
rs.close();
st.close();
} finally {
if (con != null) {
try {
con.close();
} catch (Exception ignore) {
// Ignore
}
}
}
}
use of org.apache.tomcat.jdbc.pool.PoolProperties in project platformlayer by platformlayer.
the class TomcatJdbcPoolDataSourceBuilder method buildDataSource.
@Override
public DataSource buildDataSource(String key, JdbcConfiguration jdbcConfig) {
PoolProperties p = new PoolProperties();
if (jdbcConfig.driverClassName != null) {
p.setDriverClassName(jdbcConfig.driverClassName);
}
log.warn("Building data source for " + jdbcConfig.jdbcUrl);
p.setUrl(jdbcConfig.jdbcUrl);
p.setUsername(jdbcConfig.username);
p.setPassword(jdbcConfig.password);
String sqlDebug = null;
if (jdbcConfig.extraProperties != null) {
sqlDebug = jdbcConfig.extraProperties.get("sql.debug");
}
Properties jdbcProperties = buildDbProperties(jdbcConfig);
if (!jdbcProperties.isEmpty()) {
try {
p.setDbProperties(jdbcProperties);
} catch (Exception e) {
throw new IllegalStateException("Unable to set JDBC properties", e);
}
}
if (!Strings.isNullOrEmpty(sqlDebug)) {
throw new UnsupportedOperationException();
// pooledDataSource.setLogStatementsEnabled(Boolean.parseBoolean(sqlDebug));
}
p.setMinIdle(1);
p.setInitialSize(1);
List<String> interceptors = Lists.newArrayList();
interceptors.add("org.apache.tomcat.jdbc.pool.interceptor.StatementCache");
if (!interceptors.isEmpty()) {
p.setJdbcInterceptors(Joiner.on(';').join(interceptors));
}
// p.setJmxEnabled(true);
// p.setTestWhileIdle(false);
// p.setTestOnBorrow(true);
// p.setValidationQuery("SELECT 1");
// p.setTestOnReturn(true);
// p.setValidationInterval(30000);
// p.setTimeBetweenEvictionRunsMillis(30000);
// p.setMaxActive(100);
// p.setInitialSize(10);
// p.setMaxWait(10000);
// p.setRemoveAbandonedTimeout(60);
// p.setMinEvictableIdleTimeMillis(30000);
// p.setMinIdle(10);
// p.setLogAbandoned(true);
// p.setRemoveAbandoned(true);
// p.setJdbcInterceptors("org.apache.tomcat.jdbc.pool.interceptor.ConnectionState;"
// + "org.apache.tomcat.jdbc.pool.interceptor.StatementFinalizer");
org.apache.tomcat.jdbc.pool.DataSource pooledDataSource = new org.apache.tomcat.jdbc.pool.DataSource();
pooledDataSource.setPoolProperties(p);
databaseStatistics.register(key, pooledDataSource, new TomcatJdbcPoolMetricsReporter(databaseStatistics.getMetricKey(key), pooledDataSource));
return pooledDataSource;
}
use of org.apache.tomcat.jdbc.pool.PoolProperties in project sling by apache.
the class DataSourceFactory method createPoolConfig.
private PoolConfiguration createPoolConfig(Map<String, ?> config) {
Properties props = new Properties();
//Copy the other properties first
Map<String, String> otherProps = PropertiesUtil.toMap(config.get(PROP_DATASOURCE_SVC_PROPS), new String[0]);
for (Map.Entry<String, String> e : otherProps.entrySet()) {
set(e.getKey(), e.getValue(), props);
}
props.setProperty(org.apache.tomcat.jdbc.pool.DataSourceFactory.OBJECT_NAME, name);
for (String propName : DummyDataSourceFactory.getPropertyNames()) {
String value = PropertiesUtil.toString(config.get(propName), null);
set(propName, value, props);
}
//Specify the DataSource such that connection creation logic is handled
//by us where we take care of OSGi env
PoolConfiguration poolProperties = org.apache.tomcat.jdbc.pool.DataSourceFactory.parsePoolProperties(props);
poolProperties.setDataSource(createDriverDataSource(poolProperties));
return poolProperties;
}
Aggregations