Package org.apache.tomcat.jdbc.pool

Examples of org.apache.tomcat.jdbc.pool.DataSource


    public void test2PoolCleaners() throws Exception {
        datasource.getPoolProperties().setTimeBetweenEvictionRunsMillis(2000);
        datasource.getPoolProperties().setTestWhileIdle(true);

        DataSource ds2 = new DataSource(datasource.getPoolProperties());

        assertEquals("Pool cleaner should not be started yet.",0,ConnectionPool.getPoolCleaners().size() );
        assertNull("Pool timer should be null", ConnectionPool.getPoolTimer());

        datasource.getConnection().close();
        ds2.getConnection().close();
        assertEquals("Pool cleaner should have 2 cleaner.",2,ConnectionPool.getPoolCleaners().size() );
        assertNotNull("Pool timer should not be null", ConnectionPool.getPoolTimer());

        datasource.close();
        assertEquals("Pool cleaner should have 1 cleaner.",1,ConnectionPool.getPoolCleaners().size() );
        assertNotNull("Pool timer should not be null", ConnectionPool.getPoolTimer());

        ds2.close();
        assertEquals("Pool shutdown, no cleaners should be present.",0,ConnectionPool.getPoolCleaners().size() );
        assertNull("Pool timer should be null after shutdown", ConnectionPool.getPoolTimer());
    }
View Full Code Here


        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) {
View Full Code Here

        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"));
View Full Code Here

*/
public class DataSourceJsonSerializationTests {

  @Test
  public void serializerFactory() throws Exception {
    DataSource dataSource = new DataSource();
    SerializerFactory factory = BeanSerializerFactory.instance
        .withSerializerModifier(new GenericSerializerModifier());
    ObjectMapper mapper = new ObjectMapper();
    mapper.setSerializerFactory(factory);
    String value = mapper.writeValueAsString(dataSource);
View Full Code Here

    assertTrue(value.contains("\"url\":"));
  }

  @Test
  public void serializerWithMixin() throws Exception {
    DataSource dataSource = new DataSource();
    ObjectMapper mapper = new ObjectMapper();
    mapper.addMixInAnnotations(DataSource.class, DataSourceJson.class);
    String value = mapper.writeValueAsString(dataSource);
    assertTrue(value.contains("\"url\":"));
    assertEquals(1, StringUtils.countOccurrencesOf(value, "\"url\""));
View Full Code Here

    return this.dataSourceMetadata;
  }

  @Override
  public void getValidationQuery() {
    DataSource dataSource = createDataSource(0, 4);
    dataSource.setValidationQuery("SELECT FROM FOO");
    assertEquals("SELECT FROM FOO",
        new TomcatDataSourcePoolMetadata(dataSource).getValidationQuery());
  }
View Full Code Here

    assertEquals("SELECT FROM FOO",
        new TomcatDataSourcePoolMetadata(dataSource).getValidationQuery());
  }

  private DataSource createDataSource(int minSize, int maxSize) {
    DataSource dataSource = (DataSource) initializeBuilder().type(DataSource.class)
        .build();
    dataSource.setMinIdle(minSize);
    dataSource.setMaxActive(maxSize);

    // Avoid warnings
    dataSource.setInitialSize(minSize);
    dataSource.setMaxIdle(maxSize);
    return dataSource;
  }
View Full Code Here

public class UpdateReporter extends ServiceBase
{
    public boolean process(List<Entry<String, Change>> entries, Storage storage)
    {
        // Insert changes into database.
        DataSource datasource = Application.getDB().getDataSource();
        QueryRunner run = new QueryRunner(datasource);
        try {
            run.update("BEGIN");
            for(Entry<String, Change> entry: entries) {
                Change change = entry.getValue();
View Full Code Here

TOP

Related Classes of org.apache.tomcat.jdbc.pool.DataSource

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.