Java Code Examples for org.apache.tomcat.jdbc.pool.PoolConfiguration

The following examples show how to use org.apache.tomcat.jdbc.pool.PoolConfiguration. These examples are extracted from open source projects. 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 Project: Tomcat8-Source-Read   Source File: DefaultTestCase.java    License: MIT License 6 votes vote down vote up
public org.apache.tomcat.jdbc.pool.DataSource createDefaultDataSource() {
    org.apache.tomcat.jdbc.pool.DataSource datasource = null;
    PoolConfiguration p = new DefaultProperties();
    p.setFairQueue(false);
    p.setJmxEnabled(false);
    p.setTestWhileIdle(false);
    p.setTestOnBorrow(false);
    p.setTestOnReturn(false);
    p.setValidationInterval(30000);
    p.setTimeBetweenEvictionRunsMillis(30000);
    p.setMaxActive(threadcount);
    p.setInitialSize(threadcount);
    p.setMaxWait(10000);
    p.setRemoveAbandonedTimeout(10);
    p.setMinEvictableIdleTimeMillis(10000);
    p.setMinIdle(threadcount);
    p.setLogAbandoned(false);
    p.setRemoveAbandoned(false);
    datasource = new org.apache.tomcat.jdbc.pool.DataSource();
    datasource.setPoolProperties(p);
    return datasource;
}
 
Example 2
Source Project: Tomcat8-Source-Read   Source File: TestSizePreservation.java    License: MIT License 6 votes vote down vote up
private void initSimplePoolProperties() {
    PoolConfiguration p = new DefaultProperties();
    ds = new org.apache.tomcat.jdbc.pool.DataSource();
    ds.setPoolProperties(p);

    ds.getPoolProperties().setDriverClassName(Driver.class.getName());
    ds.getPoolProperties().setUrl(Driver.url);
    ds.getPoolProperties().setFairQueue(true);
    ds.getPoolProperties().setJmxEnabled(false);
    ds.getPoolProperties().setTestWhileIdle(true);
    ds.getPoolProperties().setTestOnBorrow(false);
    ds.getPoolProperties().setTestOnReturn(false);
    ds.getPoolProperties().setValidationInterval(30000);
    ds.getPoolProperties().setTimeBetweenEvictionRunsMillis(30000);
    ds.getPoolProperties().setInitialSize(100);
    ds.getPoolProperties().setMaxActive(100);
    ds.getPoolProperties().setMinIdle(0);
    ds.getPoolProperties().setMaxIdle(0);
    ds.getPoolProperties().setMaxWait(10000);
    ds.getPoolProperties().setRemoveAbandonedTimeout(10);
    ds.getPoolProperties().setMinEvictableIdleTimeMillis(10000);
    ds.getPoolProperties().setLogAbandoned(false);
    ds.getPoolProperties().setRemoveAbandoned(false);
    ds.getPoolProperties().setUseLock(true);
}
 
Example 3
Source Project: micro-integrator   Source File: DBPropertiesTestCase.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void modifyDataSourceConfig() throws Exception {
    String fileName = this.getClass().getClassLoader().getResource("master-datasources.xml").getPath();
    try (BufferedReader br = new BufferedReader(new FileReader(fileName))) {
        StringBuilder sb = new StringBuilder();
        String line = br.readLine();

        while (line != null) {
            sb.append(line);
            sb.append(System.lineSeparator());
            line = br.readLine();
        }
        String everything = sb.toString();
        RDBMSConfiguration configuration = RDBMSDataSourceReader.loadConfig(everything);
        PoolConfiguration poolConfiguration = RDBMSDataSourceUtils.createPoolConfiguration(configuration);
        Assert.assertEquals("true", poolConfiguration.getDbProperties().getProperty("SetFloatAndDoubleUseBinary"));
    }
}
 
Example 4
Source Project: qmq   Source File: TomcatDataSourceService.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public DataSource makeDataSource(String url, String driverClassName, String username, String pwd) {
    PoolConfiguration p = new PoolProperties();
    p.setMinIdle(0);
    p.setMaxActive(2);
    p.setMaxIdle(0);
    p.setInitialSize(0);
    p.setMaxWait(10000);
    p.setDriverClassName(driverClassName);
    p.setUrl(url);
    p.setUsername(username);
    p.setPassword(pwd);
    p.setValidationQuery("select 1");
    p.setTestOnBorrow(true);

    org.apache.tomcat.jdbc.pool.DataSource datasource = new org.apache.tomcat.jdbc.pool.DataSource();
    datasource.setPoolProperties(p);
    return datasource;
}
 
Example 5
Source Project: Tomcat7.0.67   Source File: DefaultTestCase.java    License: Apache License 2.0 6 votes vote down vote up
public org.apache.tomcat.jdbc.pool.DataSource createDefaultDataSource() {
    org.apache.tomcat.jdbc.pool.DataSource datasource = null;
    PoolConfiguration p = new DefaultProperties();
    p.setFairQueue(false);
    p.setJmxEnabled(false);
    p.setTestWhileIdle(false);
    p.setTestOnBorrow(false);
    p.setTestOnReturn(false);
    p.setValidationInterval(30000);
    p.setTimeBetweenEvictionRunsMillis(30000);
    p.setMaxActive(threadcount);
    p.setInitialSize(threadcount);
    p.setMaxWait(10000);
    p.setRemoveAbandonedTimeout(10);
    p.setMinEvictableIdleTimeMillis(10000);
    p.setMinIdle(threadcount);
    p.setLogAbandoned(false);
    p.setRemoveAbandoned(false);
    datasource = new org.apache.tomcat.jdbc.pool.DataSource();
    datasource.setPoolProperties(p);
    return datasource;
}
 
Example 6
Source Project: Tomcat7.0.67   Source File: TestSizePreservation.java    License: Apache License 2.0 6 votes vote down vote up
private void initSimplePoolProperties() {
    PoolConfiguration p = new DefaultProperties();
    ds = new org.apache.tomcat.jdbc.pool.DataSource();
    ds.setPoolProperties(p);

    ds.getPoolProperties().setDriverClassName(Driver.class.getName());
    ds.getPoolProperties().setUrl(Driver.url);
    ds.getPoolProperties().setFairQueue(true);
    ds.getPoolProperties().setJmxEnabled(false);
    ds.getPoolProperties().setTestWhileIdle(true);
    ds.getPoolProperties().setTestOnBorrow(false);
    ds.getPoolProperties().setTestOnReturn(false);
    ds.getPoolProperties().setValidationInterval(30000);
    ds.getPoolProperties().setTimeBetweenEvictionRunsMillis(30000);
    ds.getPoolProperties().setInitialSize(100);
    ds.getPoolProperties().setMaxActive(100);
    ds.getPoolProperties().setMinIdle(0);
    ds.getPoolProperties().setMaxIdle(0);
    ds.getPoolProperties().setMaxWait(10000);
    ds.getPoolProperties().setRemoveAbandonedTimeout(10);
    ds.getPoolProperties().setMinEvictableIdleTimeMillis(10000);
    ds.getPoolProperties().setLogAbandoned(false);
    ds.getPoolProperties().setRemoveAbandoned(false);
    ds.getPoolProperties().setUseLock(true);
}
 
Example 7
Source Project: tomcatsrc   Source File: DefaultTestCase.java    License: Apache License 2.0 6 votes vote down vote up
public org.apache.tomcat.jdbc.pool.DataSource createDefaultDataSource() {
    org.apache.tomcat.jdbc.pool.DataSource datasource = null;
    PoolConfiguration p = new DefaultProperties();
    p.setFairQueue(false);
    p.setJmxEnabled(false);
    p.setTestWhileIdle(false);
    p.setTestOnBorrow(false);
    p.setTestOnReturn(false);
    p.setValidationInterval(30000);
    p.setTimeBetweenEvictionRunsMillis(30000);
    p.setMaxActive(threadcount);
    p.setInitialSize(threadcount);
    p.setMaxWait(10000);
    p.setRemoveAbandonedTimeout(10);
    p.setMinEvictableIdleTimeMillis(10000);
    p.setMinIdle(threadcount);
    p.setLogAbandoned(false);
    p.setRemoveAbandoned(false);
    datasource = new org.apache.tomcat.jdbc.pool.DataSource();
    datasource.setPoolProperties(p);
    return datasource;
}
 
Example 8
Source Project: tomcatsrc   Source File: TestSizePreservation.java    License: Apache License 2.0 6 votes vote down vote up
private void initSimplePoolProperties() {
    PoolConfiguration p = new DefaultProperties();
    ds = new org.apache.tomcat.jdbc.pool.DataSource();
    ds.setPoolProperties(p);

    ds.getPoolProperties().setDriverClassName(Driver.class.getName());
    ds.getPoolProperties().setUrl(Driver.url);
    ds.getPoolProperties().setFairQueue(true);
    ds.getPoolProperties().setJmxEnabled(false);
    ds.getPoolProperties().setTestWhileIdle(true);
    ds.getPoolProperties().setTestOnBorrow(false);
    ds.getPoolProperties().setTestOnReturn(false);
    ds.getPoolProperties().setValidationInterval(30000);
    ds.getPoolProperties().setTimeBetweenEvictionRunsMillis(30000);
    ds.getPoolProperties().setInitialSize(100);
    ds.getPoolProperties().setMaxActive(100);
    ds.getPoolProperties().setMinIdle(0);
    ds.getPoolProperties().setMaxIdle(0);
    ds.getPoolProperties().setMaxWait(10000);
    ds.getPoolProperties().setRemoveAbandonedTimeout(10);
    ds.getPoolProperties().setMinEvictableIdleTimeMillis(10000);
    ds.getPoolProperties().setLogAbandoned(false);
    ds.getPoolProperties().setRemoveAbandoned(false);
    ds.getPoolProperties().setUseLock(true);
}
 
Example 9
@Override
public org.apache.tomcat.jdbc.pool.DataSource createDataSource(
		DataSourceInformation dataSourceInformation) {
	// create a method scoped instance
	PoolConfiguration configurationToUse = new PoolProperties();

	// copy all general properties
	BeanUtils.copyProperties(this, configurationToUse);

	configurationToUse.setDriverClassName(this.databasePlatformSupport
			.getDriverClassNameForDatabase(dataSourceInformation.getDatabaseType()));
	configurationToUse.setUrl(this.databasePlatformSupport.getDatabaseUrlForDatabase(
			dataSourceInformation.getDatabaseType(),
			dataSourceInformation.getHostName(), dataSourceInformation.getPort(),
			dataSourceInformation.getDatabaseName()));
	configurationToUse.setUsername(dataSourceInformation.getUserName());
	configurationToUse.setPassword(dataSourceInformation.getPassword());

	return new org.apache.tomcat.jdbc.pool.DataSource(configurationToUse);
}
 
Example 10
Source Project: micro-integrator   Source File: DBPropertiesTestCase.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void modifyDBConfig() throws DataSourceException {
    RDBMSConfiguration configuration = new RDBMSConfiguration();
    List<RDBMSConfiguration.DataSourceProperty> propertyList = new ArrayList<>();
    RDBMSConfiguration.DataSourceProperty property = new RDBMSConfiguration.DataSourceProperty();
    property.setName("SetFloatAndDoubleUseBinary");
    property.setValue("true");
    propertyList.add(property);
    configuration.setDatabaseProps(propertyList);
    PoolConfiguration poolConfiguration = RDBMSDataSourceUtils.createPoolConfiguration(configuration);
    Assert.assertEquals("true", poolConfiguration.getDbProperties().getProperty("SetFloatAndDoubleUseBinary"));
}
 
Example 11
Source Project: Tomcat7.0.67   Source File: SimplePOJOExample.java    License: Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    PoolConfiguration p = new PoolProperties();
    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.setJdbcInterceptors("org.apache.tomcat.jdbc.pool.interceptor.ConnectionState;org.apache.tomcat.jdbc.pool.interceptor.StatementFinalizer");
    p.setLogAbandoned(true);
    p.setRemoveAbandoned(true);
    DataSource datasource = new DataSource();
    datasource.setPoolProperties(p);

    Connection con = null;
    try {
      con = datasource.getConnection();
      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) {}
    }
}
 
Example 12
Source Project: tomcatsrc   Source File: SimplePOJOExample.java    License: Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    PoolConfiguration p = new PoolProperties();
    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.setJdbcInterceptors("org.apache.tomcat.jdbc.pool.interceptor.ConnectionState;org.apache.tomcat.jdbc.pool.interceptor.StatementFinalizer");
    p.setLogAbandoned(true);
    p.setRemoveAbandoned(true);
    DataSource datasource = new DataSource();
    datasource.setPoolProperties(p);

    Connection con = null;
    try {
      con = datasource.getConnection();
      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) {}
    }
}
 
Example 13
Source Project: tomee   Source File: TomEEDataSourceCreator.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public CommonDataSource pool(final String name, final String driver, final Properties properties) {
    final PoolConfiguration config = build(TomEEPoolProperties.class, createProperties(name, properties));
    final TomEEDataSource ds = new TomEEDataSource(config, name);
    recipes.put(ds, recipes.remove(config));
    return ds;
}
 
Example 14
Source Project: tomee   Source File: TomEEDataSourceCreator.java    License: Apache License 2.0 5 votes vote down vote up
public TomEEDataSource(final PoolConfiguration poolConfiguration, final String name) {
    super(readOnly(poolConfiguration));
    try { // just to force the pool to be created and be able to register the mbean
        createPool();
        initJmx(name);
    } catch (final Throwable e) {
        LOGGER.error("Can't create DataSource", e);
    }
    this.name = name;
}
 
Example 15
Source Project: tomee   Source File: TomEEDataSourceCreator.java    License: Apache License 2.0 5 votes vote down vote up
private static PoolConfiguration readOnly(final PoolConfiguration pool) {
    try {
        return (PoolConfiguration) Proxy.newProxyInstance(TomEEDataSourceCreator.class.getClassLoader(), CONNECTION_POOL_CLASS, new ReadOnlyConnectionpool(pool));
    } catch (final Throwable e) {
        return (PoolConfiguration) Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(), CONNECTION_POOL_CLASS, new ReadOnlyConnectionpool(pool));
    }
}
 
Example 16
Source Project: Tomcat8-Source-Read   Source File: ConnectionPool.java    License: MIT License 4 votes vote down vote up
public PoolConfiguration getPoolProperties() {
    return pool.getPoolProperties();
}
 
Example 17
Source Project: Tomcat8-Source-Read   Source File: SimplePOJOExample.java    License: MIT License 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    PoolConfiguration p = new PoolProperties();
    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.setJdbcInterceptors("org.apache.tomcat.jdbc.pool.interceptor.ConnectionState;org.apache.tomcat.jdbc.pool.interceptor.StatementFinalizer");
    p.setLogAbandoned(true);
    p.setRemoveAbandoned(true);
    DataSource datasource = new DataSource();
    datasource.setPoolProperties(p);

    Connection con = null;
    try {
        con = datasource.getConnection();
        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
            }
        }
    }
}
 
Example 18
Source Project: Tomcat8-Source-Read   Source File: SimplePOJOAsyncExample.java    License: MIT License 4 votes vote down vote up
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 {
            Thread.sleep(100); //simulate work
            } catch (InterruptedException x) {
                Thread.interrupted();
            }
        }
        con = future.get(); //should return instantly
        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
            }
        }
    }
}
 
Example 19
Source Project: das   Source File: DalTomcatDataSource.java    License: Apache License 2.0 4 votes vote down vote up
public DalTomcatDataSource(PoolConfiguration poolProperties) {
    super(poolProperties);
}
 
Example 20
Source Project: das   Source File: DalConnectionPool.java    License: Apache License 2.0 4 votes vote down vote up
public DalConnectionPool(PoolConfiguration prop) throws SQLException {
    super(prop);
}
 
Example 21
Source Project: Tomcat7.0.67   Source File: ConnectionPool.java    License: Apache License 2.0 4 votes vote down vote up
public PoolConfiguration getPoolProperties() {
    return pool.getPoolProperties();
}
 
Example 22
Source Project: Tomcat7.0.67   Source File: SimplePOJOAsyncExample.java    License: Apache License 2.0 4 votes vote down vote up
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 {
              Thread.sleep(100); //simulate work
          }catch (InterruptedException x) {
              Thread.interrupted();
          }
      }
      con = future.get(); //should return instantly
      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) {}
    }
}
 
Example 23
Source Project: dal   Source File: DalTomcatDataSource.java    License: Apache License 2.0 4 votes vote down vote up
public DalTomcatDataSource(PoolConfiguration poolProperties) {
    super(poolProperties);
}
 
Example 24
Source Project: dal   Source File: DalConnectionPool.java    License: Apache License 2.0 4 votes vote down vote up
public DalConnectionPool(PoolConfiguration prop) throws SQLException {
    super(prop);
}
 
Example 25
Source Project: tomcatsrc   Source File: ConnectionPool.java    License: Apache License 2.0 4 votes vote down vote up
public PoolConfiguration getPoolProperties() {
    return pool.getPoolProperties();
}
 
Example 26
Source Project: tomcatsrc   Source File: SimplePOJOAsyncExample.java    License: Apache License 2.0 4 votes vote down vote up
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 {
              Thread.sleep(100); //simulate work
          }catch (InterruptedException x) {
              Thread.interrupted();
          }
      }
      con = future.get(); //should return instantly
      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) {}
    }
}
 
Example 27
Source Project: tomee   Source File: TomEEDataSourceCreator.java    License: Apache License 2.0 4 votes vote down vote up
public TomEEDataSource(final PoolConfiguration properties, final ConnectionPool pool, final String name) {
    super(readOnly(properties));
    this.pool = pool;
    initJmx(name);
    this.name = name;
}
 
Example 28
Source Project: tomee   Source File: TomEEDataSourceCreator.java    License: Apache License 2.0 4 votes vote down vote up
public ReadOnlyConnectionpool(final PoolConfiguration pool) {
    this.delegate = pool;
}
 
Example 29
Source Project: tomee   Source File: TomEEDataSourceCreator.java    License: Apache License 2.0 4 votes vote down vote up
public TomEEConnectionPool(final PoolConfiguration poolProperties, final ClassLoader creationLoader) throws SQLException {
    super(poolProperties);
    this.creationLoader = creationLoader;
}