Examples of PooledDataSource


Examples of com.mchange.v2.c3p0.PooledDataSource

   public void testGetConnection() throws Exception
   {
      cf = new C3p0ConnectionFactory();
      cf.setConfig(config);
      cf.start();
      PooledDataSource internalDs = (PooledDataSource) cf.getDataSource();

      Connection c1 = cf.getConnection();
      Connection c2 = cf.getConnection();
      assertEquals("There should be two connections checked out", 2, internalDs.getNumBusyConnectionsDefaultUser());

      cf.close(c1);
      Thread.sleep(100);
      assertEquals("There should be one connection checked out", 1, internalDs.getNumBusyConnectionsDefaultUser());

      cf.close(c2);
      Thread.sleep(100);
      assertEquals("There should be no connections checked out", 0, internalDs.getNumBusyConnectionsDefaultUser());
   }
View Full Code Here

Examples of com.mchange.v2.c3p0.PooledDataSource

   public void testGetConnection() throws Exception
   {
      cf = new C3p0ConnectionFactory();
      cf.setConfig(config);
      cf.start();
      PooledDataSource internalDs = (PooledDataSource) cf.getDataSource();

      Connection c1 = cf.getConnection();
      Connection c2 = cf.getConnection();
      assertEquals("There should be two connections checked out", 2, internalDs.getNumBusyConnectionsDefaultUser());

      cf.close(c1);
      Thread.sleep(100);
      assertEquals("There should be one connection checked out", 1, internalDs.getNumBusyConnectionsDefaultUser());

      cf.close(c2);
      Thread.sleep(100);
      assertEquals("There should be no connections checked out", 0, internalDs.getNumBusyConnectionsDefaultUser());
   }
View Full Code Here

Examples of com.mchange.v2.c3p0.PooledDataSource

                ds = (DataSource) DatabaseConfig.getInstance().getPooledDataSource(connectionName);
            }

            // make sure it's a c3p0 PooledDataSource
            if (ds != null && (ds instanceof PooledDataSource)) {
                PooledDataSource pds = (PooledDataSource) ds;
                log.debug("displayDS for " + where + " -      num_connections: " + pds.getNumConnectionsDefaultUser());
                log.debug("displayDS for " + where + " - num_busy_connections: " + pds.getNumBusyConnectionsDefaultUser());
                log.debug("displayDS for " + where + " - num_idle_connections: " + pds.getNumIdleConnectionsDefaultUser());
            }
        } catch(Exception ex) {
            log.debug("displayDS for " + where + " - ERROR: " + ex.getMessage());
        }
    }
View Full Code Here

Examples of com.mchange.v2.c3p0.PooledDataSource

   public void testGetConnection() throws Exception
   {
      cf = new C3p0ConnectionFactory();
      cf.setConfig(config);
      cf.start();
      PooledDataSource internalDs = (PooledDataSource) cf.getDataSource();

      Connection c1 = cf.getConnection();
      Connection c2 = cf.getConnection();
      assertEquals("There should be two connections checked out", 2, internalDs.getNumBusyConnectionsDefaultUser());

      cf.close(c1);
      Thread.sleep(100);
      assertEquals("There should be one connection checked out", 1, internalDs.getNumBusyConnectionsDefaultUser());

      cf.close(c2);
      Thread.sleep(100);
      assertEquals("There should be no connections checked out", 0, internalDs.getNumBusyConnectionsDefaultUser());
   }
View Full Code Here

Examples of org.apache.ibatis.datasource.pooled.PooledDataSource

   
    // Verify that these properties are correctly set in the MyBatis datasource
    DataSource datasource = config.getDbSqlSessionFactory().getSqlSessionFactory().getConfiguration().getEnvironment().getDataSource();
    assertTrue(datasource instanceof PooledDataSource);
   
    PooledDataSource pooledDataSource = (PooledDataSource) datasource;
    assertEquals(maxActive, pooledDataSource.getPoolMaximumActiveConnections());
    assertEquals(maxIdle, pooledDataSource.getPoolMaximumIdleConnections());
    assertEquals(maxCheckoutTime, pooledDataSource.getPoolMaximumCheckoutTime());
    assertEquals(maxWaitTime, pooledDataSource.getPoolTimeToWait());
   
    engine.close();
  }
View Full Code Here

Examples of org.apache.ibatis.datasource.pooled.PooledDataSource

public class DatabaseTablePrefixTest extends TestCase {

  public void testPerformDatabaseSchemaOperationCreate() throws Exception{
   
    // both process engines will be using this datasource.
    PooledDataSource pooledDataSource = new PooledDataSource(ReflectUtil.getClassLoader(),
            "org.h2.Driver",
            "jdbc:h2:mem:DatabaseTablePrefixTest;DB_CLOSE_DELAY=1000",
            "sa",
            "" );
         
    // create two schemas is the database
    Connection connection = pooledDataSource.getConnection();
    connection.createStatement().execute("drop schema if exists SCHEMA1");
    connection.createStatement().execute("drop schema if exists SCHEMA2");
    connection.createStatement().execute("create schema SCHEMA1");
    connection.createStatement().execute("create schema SCHEMA2");   
    connection.close();

    // configure & build two different process engines, each having a separate table prefix
    ProcessEngineConfigurationImpl config1 = createCustomProcessEngineConfiguration()
            .setProcessEngineName("DatabaseTablePrefixTest-engine1")
            .setDataSource(pooledDataSource)
            .setDatabaseSchemaUpdate("NO_CHECK"); // disable auto create/drop schema
    config1.setDatabaseTablePrefix("SCHEMA1.");
    ProcessEngine engine1 = config1.buildProcessEngine();
   
    ProcessEngineConfigurationImpl config2 = createCustomProcessEngineConfiguration()
            .setProcessEngineName("DatabaseTablePrefixTest-engine2")
            .setDataSource(pooledDataSource)
            .setDatabaseSchemaUpdate("NO_CHECK"); // disable auto create/drop schema       
    config2.setDatabaseTablePrefix("SCHEMA2.");
    ProcessEngine engine2 = config2.buildProcessEngine();
   
    // create the tables in SCHEMA1
    connection = pooledDataSource.getConnection();
    connection.createStatement().execute("set schema SCHEMA1");   
    engine1.getManagementService().databaseSchemaUpgrade(connection, "", "SCHEMA1");
    connection.close();

    // create the tables in SCHEMA2
    connection = pooledDataSource.getConnection();
    connection.createStatement().execute("set schema SCHEMA2");   
    engine2.getManagementService().databaseSchemaUpgrade(connection, "", "SCHEMA2");
    connection.close();

    // if I deploy a process to one engine, it is not visible to the other
View Full Code Here

Examples of org.apache.ibatis.datasource.pooled.PooledDataSource

          throw new ProcessEngineException("DataSource or JDBC properties have to be specified in a process engine configuration");
        }

        log.fine("initializing datasource to db: "+jdbcUrl);

        PooledDataSource pooledDataSource =
          new PooledDataSource(ReflectUtil.getClassLoader(), jdbcDriver, jdbcUrl, jdbcUsername, jdbcPassword );

        if (jdbcMaxActiveConnections > 0) {
          pooledDataSource.setPoolMaximumActiveConnections(jdbcMaxActiveConnections);
        }
        if (jdbcMaxIdleConnections > 0) {
          pooledDataSource.setPoolMaximumIdleConnections(jdbcMaxIdleConnections);
        }
        if (jdbcMaxCheckoutTime > 0) {
          pooledDataSource.setPoolMaximumCheckoutTime(jdbcMaxCheckoutTime);
        }
        if (jdbcMaxWaitTime > 0) {
          pooledDataSource.setPoolTimeToWait(jdbcMaxWaitTime);
        }
        if (jdbcPingEnabled == true) {
          pooledDataSource.setPoolPingEnabled(true);
          if (jdbcPingQuery != null) {
            pooledDataSource.setPoolPingQuery(jdbcPingQuery);
          }
          pooledDataSource.setPoolPingConnectionsNotUsedFor(jdbcPingConnectionNotUsedFor);
        }
        dataSource = pooledDataSource;
      }

      if (dataSource instanceof PooledDataSource) {
View Full Code Here

Examples of org.apache.ibatis.datasource.pooled.PooledDataSource

    return ds;
  }

  public static PooledDataSource createPooledDataSource(String resource) throws IOException {
    Properties props = Resources.getResourceAsProperties(resource);
    PooledDataSource ds = new PooledDataSource();
    ds.setDriver(props.getProperty("driver"));
    ds.setUrl(props.getProperty("url"));
    ds.setUsername(props.getProperty("username"));
    ds.setPassword(props.getProperty("password"));
    return ds;
  }
View Full Code Here

Examples of org.apache.ibatis.datasource.pooled.PooledDataSource

    runScript(runner, JPETSTORE_DDL);
    runScript(runner, JPETSTORE_DATA);
  }

  private void assertProductsTableExistsAndLoaded() throws IOException, SQLException {
    PooledDataSource ds = createPooledDataSource(JPETSTORE_PROPERTIES);
    try {
      Connection conn = ds.getConnection();
      SqlRunner executor = new SqlRunner(conn);
      List<Map<String, Object>> products = executor.selectAll("SELECT * FROM PRODUCT");
      assertEquals(16, products.size());
    } finally {
      ds.forceCloseAll();
    }
  }
View Full Code Here

Examples of org.apache.ibatis.datasource.pooled.PooledDataSource

public class PooledDataSourceTest extends BaseDataTest {

  @Test
  public void shouldProperlyMaintainPoolOf3ActiveAnd2IdleConnections() throws Exception {
    PooledDataSource ds = createPooledDataSource(JPETSTORE_PROPERTIES);
    try {
      runScript(ds, JPETSTORE_DDL);
      ds.setDefaultAutoCommit(false);
      ds.setDriverProperties(new Properties() {
        {
          setProperty("username", "sa");
          setProperty("password", "");
        }
      });
      ds.setPoolMaximumActiveConnections(3);
      ds.setPoolMaximumIdleConnections(2);
      ds.setPoolMaximumCheckoutTime(10000);
      ds.setPoolPingConnectionsNotUsedFor(1);
      ds.setPoolPingEnabled(true);
      ds.setPoolPingQuery("SELECT * FROM PRODUCT");
      ds.setPoolTimeToWait(10000);
      ds.setLogWriter(null);
      List<Connection> connections = new ArrayList<Connection>();
      for (int i = 0; i < 3; i++) {
        connections.add(ds.getConnection());
      }
      assertEquals(3, ds.getPoolState().getActiveConnectionCount());
      for (Connection c : connections) {
        c.close();
      }
      assertEquals(2, ds.getPoolState().getIdleConnectionCount());
      assertEquals(4, ds.getPoolState().getRequestCount());
      assertEquals(0, ds.getPoolState().getBadConnectionCount());
      assertEquals(0, ds.getPoolState().getHadToWaitCount());
      assertEquals(0, ds.getPoolState().getAverageOverdueCheckoutTime());
      assertEquals(0, ds.getPoolState().getClaimedOverdueConnectionCount());
      assertEquals(0, ds.getPoolState().getAverageWaitTime());
      assertNotNull(ds.getPoolState().toString());
    } finally {
      ds.forceCloseAll();
    }
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.