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

The following examples show how to use org.apache.tomcat.jdbc.pool.DataSource. 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: Bug54978.java    License: MIT License 6 votes vote down vote up
@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 Project: Tomcat8-Source-Read   Source File: Bug54978.java    License: MIT License 6 votes vote down vote up
@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 Project: Tomcat8-Source-Read   Source File: PoolCleanerTest.java    License: MIT License 6 votes vote down vote up
@Test
public void test2PoolCleaners() throws Exception {
    datasource.getPoolProperties().setTimeBetweenEvictionRunsMillis(2000);
    datasource.getPoolProperties().setTestWhileIdle(true);

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

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

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

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

    ds2.close();
    Assert.assertEquals("Pool shutdown, no cleaners should be present.",0,ConnectionPool.getPoolCleaners().size() );
    Assert.assertNull("Pool timer should be null after shutdown", ConnectionPool.getPoolTimer());
    Assert.assertEquals("Pool cleaner threads should not be present after close.",0, countPoolCleanerThreads());
}
 
Example 4
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 5
Source Project: micro-integrator   Source File: JDBCPoolSQLConfig.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public DataSource getDataSource() throws DataServiceFault {
	if (this.dataSource == null) {
	    synchronized (this) {
	    	/* this second check is necessary, in case another thread already initialized it */
		    if (this.dataSource == null) {
		        try {
			        RDBMSDataSource rdbmsDS = new RDBMSDataSource(
					        this.createConfigFromProps(this.getProperties()));
			        this.dataSource = rdbmsDS.getDataSource();
		        } catch (Exception e) {
			        throw new DataServiceFault(e,
                                                  "Error creating JDBC Pool SQL Config: "	+ e.getMessage());
		        }
		    }
	    }
	}
	return dataSource;
}
 
Example 6
Source Project: radman   Source File: Utils.java    License: MIT License 6 votes vote down vote up
static LocalContainerEntityManagerFactoryBean buildEntityManager(DataSource dataSource,
                                                                 JpaProperties jpaProperties,
                                                                 String entitiesPackage,
                                                                 String persistenceUnitName) {
    LocalContainerEntityManagerFactoryBean entityManager = new LocalContainerEntityManagerFactoryBean();
    entityManager.setDataSource(dataSource);
    entityManager.setPackagesToScan(entitiesPackage);
    entityManager.setPersistenceUnitName(persistenceUnitName);
    entityManager.setJpaVendorAdapter(new HibernateJpaVendorAdapter());

    HashMap<String, Object> properties = new HashMap<>();
    properties.put("hibernate.hbm2ddl.auto", jpaProperties.getHibernate().getDdlAuto());
    properties.put("hibernate.dialect", jpaProperties.getHibernate().getDialect());
    properties.put("show-sql", jpaProperties.getShowSql());

    entityManager.setJpaPropertyMap(properties);
    return entityManager;
}
 
Example 7
Source Project: Tomcat7.0.67   Source File: PoolCleanerTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void test2PoolCleaners() throws Exception {
    datasource.getPoolProperties().setTimeBetweenEvictionRunsMillis(2000);
    datasource.getPoolProperties().setTestWhileIdle(true);

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

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

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

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

    ds2.close();
    Assert.assertEquals("Pool shutdown, no cleaners should be present.",0,ConnectionPool.getPoolCleaners().size() );
    Assert.assertNull("Pool timer should be null after shutdown", ConnectionPool.getPoolTimer());
    Assert.assertEquals("Pool cleaner threads should not be present after close.",0, countPoolCleanerThreads());
}
 
Example 8
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 9
Source Project: gemfirexd-oss   Source File: PooledConnectionTomcat.java    License: Apache License 2.0 6 votes vote down vote up
private static void setupDataSource(Isolation isolation) {
  ds = new DataSource();

  try {    
    ds.setPoolProperties(getPoolProperties()); //set earlier to avoid overriding the isolation setting
    
    ds.setMaxActive(100);
    
    if (isolation == Isolation.NONE) {
      ds.setDefaultTransactionIsolation(Connection.TRANSACTION_NONE);
    } else if (isolation == Isolation.READ_COMMITTED) {
      ds.setDefaultTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
      ds.setDefaultAutoCommit(false);
    } else {
      ds.setDefaultTransactionIsolation(Connection.TRANSACTION_REPEATABLE_READ);
      ds.setDefaultAutoCommit(false);
    }
    
    dsSet = true;
    Log.getLogWriter().info("tomcat data source url is set as " + ds.getUrl());
    Log.getLogWriter().info("tomcat data source DefaultTransactionIsolation is set to " + ds.getDefaultTransactionIsolation());
    Log.getLogWriter().info("tomcat data source DefaultAutoCommit is set to " + ds.getDefaultAutoCommit());
  } catch (Exception e) {
    throw new TestException("could not set data source" + TestHelper.getStackTrace(e));
  }
}
 
Example 10
Source Project: tomcatsrc   Source File: PoolCleanerTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void test2PoolCleaners() throws Exception {
    datasource.getPoolProperties().setTimeBetweenEvictionRunsMillis(2000);
    datasource.getPoolProperties().setTestWhileIdle(true);

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

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

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

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

    ds2.close();
    Assert.assertEquals("Pool shutdown, no cleaners should be present.",0,ConnectionPool.getPoolCleaners().size() );
    Assert.assertNull("Pool timer should be null after shutdown", ConnectionPool.getPoolTimer());
    Assert.assertEquals("Pool cleaner threads should not be present after close.",0, countPoolCleanerThreads());
}
 
Example 11
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 12
Source Project: gemfirexd-oss   Source File: PooledConnectionTomcat.java    License: Apache License 2.0 6 votes vote down vote up
private static void setupDataSource(Isolation isolation) {
  ds = new DataSource();

  try {    
    ds.setPoolProperties(getPoolProperties()); //set earlier to avoid overriding the isolation setting
    
    ds.setMaxActive(100);
    
    if (isolation == Isolation.NONE) {
      ds.setDefaultTransactionIsolation(Connection.TRANSACTION_NONE);
    } else if (isolation == Isolation.READ_COMMITTED) {
      ds.setDefaultTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
      ds.setDefaultAutoCommit(false);
    } else {
      ds.setDefaultTransactionIsolation(Connection.TRANSACTION_REPEATABLE_READ);
      ds.setDefaultAutoCommit(false);
    }
    
    dsSet = true;
    Log.getLogWriter().info("tomcat data source url is set as " + ds.getUrl());
    Log.getLogWriter().info("tomcat data source DefaultTransactionIsolation is set to " + ds.getDefaultTransactionIsolation());
    Log.getLogWriter().info("tomcat data source DefaultAutoCommit is set to " + ds.getDefaultAutoCommit());
  } catch (Exception e) {
    throw new TestException("could not set data source" + TestHelper.getStackTrace(e));
  }
}
 
Example 13
@Test
void testCloseDataSource() throws Exception {
	TomcatJdbcDataSourceFactory tomcatJdbcDataSourceFactory = new TomcatJdbcDataSourceFactory();
	tomcatJdbcDataSourceFactory.setInitialSize(0);

	DataSourceInformation dataSourceInformation = new DataSourceInformation(
			DatabaseType.MYSQL, "localhost", 3306, "test", "user", "password");
	DataSource dataSource = tomcatJdbcDataSourceFactory
			.createDataSource(dataSourceInformation);
	assertThat(dataSource).isNotNull();

	ConnectionPool pool = dataSource.createPool();
	assertThat(pool.isClosed()).isFalse();
	tomcatJdbcDataSourceFactory.closeDataSource(dataSource);
	assertThat(pool.isClosed()).isTrue();
}
 
Example 14
Source Project: incubator-pinot   Source File: SqlResponseCacheLoader.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * This method gets the dimension filters for the given dataset from the presto data source,
 * and returns them as map of dimension name to values
 * @param dataset
 * @return dimension filters map
 */
public Map<String, List<String>> getDimensionFilters(String dataset) throws Exception {
  LOG.info("Getting dimension filters for " + dataset);
  DatasetConfigDTO datasetConfig = ThirdEyeUtils.getDatasetConfigFromName(dataset);

  String sourceName = dataset.split("\\.")[0];
  String tableName = SqlUtils.computeSqlTableName(dataset);
  DataSource dataSource = getDataSourceFromDataset(dataset);

  Map<String, List<String>> dimensionFilters = new HashMap<>();

  for (String dimension: datasetConfig.getDimensions()) {
    dimensionFilters.put(dimension, new ArrayList<>());
    try (Connection conn = dataSource.getConnection();
        Statement stmt = conn.createStatement();
        ResultSet rs = stmt.executeQuery(SqlUtils.getDimensionFiltersSQL(dimension, tableName, sourceName));) {
      while (rs.next()) {
        dimensionFilters.get(dimension).add(rs.getString(1));
      }
    }
    catch (Exception e) {
        throw e;
    }
  }
  return dimensionFilters;
}
 
Example 15
Source Project: incubator-pinot   Source File: SqlResponseCacheLoader.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Helper method that return a DataSource object corresponding to the dataset
 *
 * @param dataset name of dataset
 * @return DataSource object: datasource for the dataset
 */
private DataSource getDataSourceFromDataset(String dataset) {
  String[] tableComponents = dataset.split("\\.");
  String sourceName = tableComponents[0];
  String dbName = tableComponents[1];

  if (sourceName.equals(PRESTO)) {
    return prestoDBNameToDataSourceMap.get(dbName);
  } else if (sourceName.equals(MYSQL)) {
    return mysqlDBNameToDataSourceMap.get(dbName);
  } else if (sourceName.equals(VERTICA)) {
    return verticaDBNameToDataSourceMap.get(dbName);
  } else {
    return h2DataSource;
  }
}
 
Example 16
Source Project: incubator-pinot   Source File: SqlUtils.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Insert a table to SQL database, currently only used by H2, that can be read by ThirdEye
 *
 * @param ds DataSource object
 * @param tableName table name
 * @param timeColumn time column name
 * @param metrics list of metrics
 * @param dimensions list of dimensions
 * @throws SQLException SQL exception if SQL failed
 */
public static void createTableOverride(DataSource ds, String tableName,
    String timeColumn, List<String> metrics, List<String> dimensions) throws SQLException {
  StringBuilder sb = new StringBuilder();
  sb.append("drop table if exists ").append(tableName).append(";");
  sb.append("create table ").append(tableName).append(" (");

  for (String metric: metrics) {
    sb.append(metric).append(" decimal(50,3), ");
  }
  for (String dimension: dimensions) {
    sb.append(dimension).append(" varchar(50), ");
  }
  sb.append(timeColumn).append(" varchar(50) ) ENGINE=InnoDB;");

  String sql = sb.toString();

  LOG.info("Creating H2 table: " + sql);

  try (Connection connection = ds.getConnection();
      Statement statement = connection.createStatement()){
    statement.execute(sql);
  }
}
 
Example 17
Source Project: incubator-pinot   Source File: SqlUtils.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Run SQL query to insert a row in a CSV file to a datasource, for now only used by H2 initialization
 *
 * @param tableName table name
 * @param columnNames column names in CSV, separated by ,
 * @param items row items
 * @throws SQLException
 */
public static void insertCSVRow(DataSource ds, String tableName, String columnNames, String[] items) throws SQLException {
  // Put quotes around values that contains spaces
  StringBuilder sb = new StringBuilder();
  String prefix = "";
  for (String item: items) {
    sb.append(prefix);
    prefix = ",";
    if (!StringUtils.isNumeric(item)) {
      sb.append('\'').append(item).append('\'');
    } else {
      sb.append(item);
    }
  }

  String sql = String.format("INSERT INTO %s(%s) VALUES(%s)", tableName, columnNames, sb.toString());
  try (Connection connection = ds.getConnection();
      Statement statement = connection.createStatement()){
    statement.execute(sql);
  }
}
 
Example 18
protected static javax.sql.DataSource createDatasource(Properties properties) {

    PoolProperties p = new PoolProperties();
    p.setUrl(properties.getProperty("databaseUrl"));
    p.setDriverClassName(properties.getProperty("databaseDriver"));
    p.setUsername(properties.getProperty("databaseUser"));
    p.setPassword(properties.getProperty("databasePassword"));

    p.setJmxEnabled(false);

    p.setMaxActive(100);
    p.setInitialSize(10);

    DataSource datasource = new DataSource();
    datasource.setPoolProperties(p);

    return datasource;
  }
 
Example 19
Source Project: Tomcat8-Source-Read   Source File: Bug54225.java    License: MIT License 5 votes vote down vote up
@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 20
Source Project: Tomcat8-Source-Read   Source File: Bug54227.java    License: MIT License 5 votes vote down vote up
@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 21
Source Project: micro-integrator   Source File: RDBMSDataSource.java    License: Apache License 2.0 5 votes vote down vote up
public DataSource getDataSource() {
	if (this.dataSource == null) {
		this.dataSource = new DataSource(poolProperties);
	}
               if (poolProperties.isJmxEnabled()) {
                       this.registerMBean();
               }
	return this.dataSource;
}
 
Example 22
Source Project: radman   Source File: Utils.java    License: MIT License 5 votes vote down vote up
static SpringLiquibase buildLiquibase(DataSource dataSource, LiquibaseProperties properties) {
    SpringLiquibase liquibase = new SpringLiquibase();
    liquibase.setDataSource(dataSource);
    liquibase.setChangeLog(properties.getChangeLog());
    liquibase.setContexts(properties.getContexts());
    liquibase.setDefaultSchema(properties.getDefaultSchema());
    liquibase.setDropFirst(properties.isDropFirst());
    liquibase.setShouldRun(properties.isEnabled());
    liquibase.setLabels(properties.getLabels());
    liquibase.setChangeLogParameters(properties.getParameters());
    liquibase.setRollbackFile(properties.getRollbackFile());
    return liquibase;
}
 
Example 23
Source Project: dfactor   Source File: DFDbUtil.java    License: MIT License 5 votes vote down vote up
public static DataSource createMysqlDbSource(String url, String user, String pwd, 
		int initSize, int maxActive, int maxWait, int maxIdle, int minIdle){
	PoolProperties p = new PoolProperties();
	p.setDriverClassName("com.mysql.jdbc.Driver");
    p.setUrl(url);
    p.setUsername(user);
    p.setPassword(pwd);
    p.setJmxEnabled(true);
    p.setTestWhileIdle(true);
    p.setTestOnBorrow(false);
    p.setTestOnReturn(false);
    p.setValidationQuery("SELECT 1");
    p.setValidationInterval(30000);
    p.setTimeBetweenEvictionRunsMillis(30000);
    p.setMaxActive(maxActive);
    p.setInitialSize(initSize);
    p.setMaxWait(maxWait);   //conn timeout 
    p.setRemoveAbandonedTimeout(60);
    p.setMinEvictableIdleTimeMillis(30000);
    p.setMaxIdle(maxIdle);
    p.setMinIdle(minIdle);
    p.setLogAbandoned(true);
    p.setRemoveAbandoned(true);
    p.setJdbcInterceptors("org.apache.tomcat.jdbc.pool.interceptor.ConnectionState;"+
      "org.apache.tomcat.jdbc.pool.interceptor.StatementFinalizer");
    final DataSource dbSrc = new DataSource();
    dbSrc.setPoolProperties(p);
    return dbSrc;
}
 
Example 24
Source Project: easy-sync   Source File: DatabaseService.java    License: Apache License 2.0 5 votes vote down vote up
protected DataSource createDataSource(Mysql mysql) {

        DataSource dataSource = new org.apache.tomcat.jdbc.pool.DataSource();
        dataSource.setDriverClassName(driverClassName);
        dataSource.setUrl(mysql.getUrl());
        dataSource.setUsername(mysql.getUser());
        dataSource.setPassword(mysql.getPassword());
        dataSource.setValidationQuery("select 1");
        dataSource.setTestWhileIdle(true);
        dataSource.setTimeBetweenEvictionRunsMillis(30*1000);
        return dataSource;
    }
 
Example 25
public static void createPool() throws Exception {
// Modify this code in order to extract a Connection from your
// connection pooling system:

// Driver parameters to use:
String driverClassName = "org.postgresql.Driver";
String url = "jdbc:postgresql://localhost:5432/sampledb";
String username = "user1";
String password = "password1";

// Creating the DataSource bean and populating the values:
// Mandatory values to set
PoolProperties p = new PoolProperties();
p.setDriverClassName(driverClassName);
p.setUrl(url);
p.setUsername(username);
p.setPassword(password);

// Other possible values to set
p.setTestOnBorrow(true);
p.setValidationQuery("SELECT 1");
p.setTestOnReturn(false);
p.setValidationInterval(30000);
p.setTimeBetweenEvictionRunsMillis(30000);
p.setMaxActive(2);
p.setInitialSize(2);
p.setMaxWait(10000);
p.setRemoveAbandonedTimeout(60);
p.setMinEvictableIdleTimeMillis(30000);
p.setMinIdle(2);
p.setMaxIdle(2);
p.setLogAbandoned(true);
p.setRemoveAbandoned(true);
p.setJdbcInterceptors("ConnectionState;StatementFinalizer");

dataSource = new DataSource();
dataSource.setPoolProperties(p);

   }
 
Example 26
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 27
Source Project: gemfirexd-oss   Source File: PooledConnectionTomcat.java    License: Apache License 2.0 5 votes vote down vote up
public static DataSource getDataSource(Isolation isolation) {
  if (ds == null) {
    setupDataSource(isolation);
    MasterController.sleepForMs(1000);
    Log.getLogWriter().info("max active is " + ds.getMaxActive());
  }

  return ds;
}
 
Example 28
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 29
Source Project: gemfirexd-oss   Source File: PooledConnectionTomcat.java    License: Apache License 2.0 5 votes vote down vote up
public static DataSource getDataSource(Isolation isolation) {
  if (ds == null) {
    setupDataSource(isolation);
    MasterController.sleepForMs(1000);
    Log.getLogWriter().info("max active is " + ds.getMaxActive());
  }

  return ds;
}
 
Example 30
Source Project: flexy-pool   Source File: FlexyPoolConfiguration.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
public Configuration<DataSource> configuration() {
    return new Configuration.Builder<DataSource>(
            uniqueId,
            poolingDataSource,
            TomcatCPPoolAdapter.FACTORY
    ).build();
}