Java Code Examples for com.mchange.v2.c3p0.ComboPooledDataSource#setJdbcUrl()

The following examples show how to use com.mchange.v2.c3p0.ComboPooledDataSource#setJdbcUrl() . 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 File: ConnectionPool.java    From streamx with Apache License 2.0 6 votes vote down vote up
public static synchronized ComboPooledDataSource getDatasource(String connectionUrl, String user, String password) {
  if(dataSources.containsKey(connectionUrl)) {
    return dataSources.get(connectionUrl);
  }
  else {
    try {
      ComboPooledDataSource cpds = new ComboPooledDataSource();
      cpds.setDriverClass("com.mysql.jdbc.Driver"); //loads the jdbc driver
      cpds.setJdbcUrl(connectionUrl);
      cpds.setUser(user);
      cpds.setPassword(password);
      cpds.setMaxConnectionAge(18000);//5 hours
      dataSources.put(connectionUrl, cpds);
      return cpds;
    } catch (PropertyVetoException e) {
      log.error("Error while creating c3p0 ComboPooledDataSource" + e);
      throw new ConnectException(e);
    }
  }
}
 
Example 2
Source File: MysqlLoaderTest.java    From nd4j with Apache License 2.0 6 votes vote down vote up
@Test
@Ignore
public void testMysqlLoader() throws Exception {
    ComboPooledDataSource ds = new ComboPooledDataSource();
    ds.setJdbcUrl("jdbc:mysql://localhost:3306/nd4j?user=nd4j&password=nd4j");
    MysqlLoader loader = new MysqlLoader(ds, "jdbc:mysql://localhost:3306/nd4j?user=nd4j&password=nd4j", "ndarrays",
                    "array");
    loader.delete("1");
    INDArray load = loader.load(loader.loadForID("1"));
    if (load != null) {
        loader.delete("1");
    }
    loader.save(Nd4j.create(new float[] {1, 2, 3}), "1");
    Blob b = loader.loadForID("1");
    INDArray loaded = loader.load(b);
    assertEquals((Nd4j.create(new float[] {1, 2, 3})), loaded);
}
 
Example 3
Source File: DataSourceFactory.java    From copper-engine with Apache License 2.0 6 votes vote down vote up
public static ComboPooledDataSource createDataSource(Properties props) {
    try {
        final String jdbcUrl = trim(props.getProperty(ConfigParameter.DS_JDBC_URL.getKey()));
        final String user = trim(props.getProperty(ConfigParameter.DS_USER.getKey()));
        final String password = trim(props.getProperty(ConfigParameter.DS_PASSWORD.getKey()));
        final String driverClass = trim(props.getProperty(ConfigParameter.DS_DRIVER_CLASS.getKey()));
        final int minPoolSize = Integer.valueOf(props.getProperty(ConfigParameter.DS_MIN_POOL_SIZE.getKey(), Integer.toString(Runtime.getRuntime().availableProcessors())));
        final int maxPoolSize = Integer.valueOf(props.getProperty(ConfigParameter.DS_MAX_POOL_SIZE.getKey(), Integer.toString(2 * Runtime.getRuntime().availableProcessors())));
        ComboPooledDataSource ds = new ComboPooledDataSource();
        ds.setJdbcUrl(jdbcUrl.replace("${NOW}", Long.toString(System.currentTimeMillis())));
        if (!isNullOrEmpty(user))
            ds.setUser(user);
        if (!isNullOrEmpty(password))
            ds.setPassword(password);
        if (!isNullOrEmpty(driverClass))
            ds.setDriverClass(driverClass);
        ds.setMinPoolSize(minPoolSize);
        ds.setInitialPoolSize(minPoolSize);
        ds.setMaxPoolSize(maxPoolSize);
        return ds;
    } catch (Exception e) {
        throw new RuntimeException("Unable to create datasource", e);
    }
}
 
Example 4
Source File: C3P0DataSourceFactoryBean.java    From cloud-config with MIT License 6 votes vote down vote up
private ComboPooledDataSource createNewDataSource() throws Exception {
    ComboPooledDataSource c3p0DataSource = new ComboPooledDataSource();

    c3p0DataSource.setDriverClass(config.getDriverClassName()); //loads the jdbc driver
    c3p0DataSource.setJdbcUrl(config.getJdbcUrl());
    c3p0DataSource.setUser(config.getUserName());
    c3p0DataSource.setPassword(config.getPassword());

    // the settings below are optional -- c3p0 can work with defaults
    c3p0DataSource.setMinPoolSize(config.getMinPoolSize());
    c3p0DataSource.setMaxPoolSize(config.getMaxPoolSize());
    c3p0DataSource.setAcquireIncrement(config.getAcquireIncrement());
    c3p0DataSource.setMaxStatements(config.getMaxStatements());
    c3p0DataSource.setIdleConnectionTestPeriod(config.getIdleTestPeriod());
    c3p0DataSource.setMaxIdleTime(config.getMaxIdleTime());

    return c3p0DataSource;
}
 
Example 5
Source File: C3P0DataSource.java    From maven-framework-project with MIT License 6 votes vote down vote up
private C3P0DataSource() throws IOException, SQLException,
		PropertyVetoException {
	cpds = new ComboPooledDataSource();
	cpds.setDriverClass("org.h2.Driver"); // loads the jdbc driver
	cpds.setJdbcUrl("jdbc:h2:./target/test;AUTO_SERVER=TRUE");
	cpds.setUser("sa");
	cpds.setPassword("");

	// the settings below are optional -- c3p0 can work with defaults
	cpds.setMinPoolSize(5);
	cpds.setAcquireIncrement(5);
	cpds.setMaxPoolSize(20);
	cpds.setMaxStatements(180);

	this.setDataSource(cpds);

}
 
Example 6
Source File: C3P0Factory.java    From rapidoid with Apache License 2.0 6 votes vote down vote up
public static DataSource createDataSourceFor(JdbcClient jdbc) {
	ComboPooledDataSource pool = new ComboPooledDataSource();

	pool.setJdbcUrl(jdbc.url());
	pool.setUser(jdbc.username());
	pool.setPassword(jdbc.password());

	try {
		pool.setDriverClass(jdbc.driver());
	} catch (PropertyVetoException e) {
		throw U.rte("Cannot load JDBC driver!", e);
	}

	Conf.section("c3p0").applyTo(pool);

	return pool;
}
 
Example 7
Source File: C3P0PoolSlaveManager.java    From wind-im with Apache License 2.0 5 votes vote down vote up
public static void initPool(Properties pro) throws Exception {
	List<String> jdbcUrlList = getSlaveJdbcUrl(pro);

	String userName = trimToNull(pro, JdbcConst.MYSQL_SLAVE_USER_NAME);
	String password = trimToNull(pro, JdbcConst.MYSQL_SLAVE_PASSWORD);

	if (jdbcUrlList == null || jdbcUrlList.size() == 0 || StringUtils.isAnyEmpty(userName, password)) {
		SqlLog.warn(
				"load database slave for mysql fail, system will user mysql master connection pool.urls={} user={} passwd={}",
				jdbcUrlList, userName, password);
		return;
	}

	cpdsList = new ArrayList<ComboPooledDataSource>();

	for (String jdbcUrl : jdbcUrlList) {
		ComboPooledDataSource cpds = new ComboPooledDataSource();
		cpds.setDriverClass(MYSQL_JDBC_DRIVER); // loads the jdbc driver
		cpds.setJdbcUrl(jdbcUrl);
		cpds.setUser(userName);
		cpds.setPassword(password);
		int inititalSize = Integer.valueOf(trimToNull(pro, JdbcConst.MYSQL_SLAVE_INITIAL_SIZE, "10"));
		int maxSize = Integer.valueOf(trimToNull(pro, JdbcConst.MYSQL_SLAVE_MAX_SIZE, "100"));
		cpds.setInitialPoolSize(inititalSize);// 初始创建默认10个连接
		cpds.setMaxPoolSize(maxSize);// 最大默认100个
		int inc = (maxSize - inititalSize) / 5;
		cpds.setAcquireIncrement(Integer.max(1, inc));// 每次创建个数

		int maxIdle = Integer.valueOf(trimToNull(pro, JdbcConst.MYSQL_SLAVE_MAX_IDLE, "60"));
		cpds.setMaxIdleTime(maxIdle);// 最大空闲时间

		cpdsList.add(cpds);

		SqlLog.info("windchat init mysql slave connection pool cpds={}", cpds.toString());
	}
}
 
Example 8
Source File: MainConfigofProfile.java    From code with Apache License 2.0 5 votes vote down vote up
@Profile("test")
@Bean("testDataSource")
public DataSource dataSourceTest(@Value("${db.password}") String pwd) throws PropertyVetoException {
    ComboPooledDataSource dataSource = new ComboPooledDataSource();
    dataSource.setUser(user);
    dataSource.setPassword(pwd);
    dataSource.setDriverClass(driverClass);
    dataSource.setJdbcUrl("jdbc:mysql://localhost:3306/test");
    return dataSource;
}
 
Example 9
Source File: MainConfigofProfile.java    From code with Apache License 2.0 5 votes vote down vote up
@Profile("dev")
@Bean("devDataSource")
public DataSource dataSourceDev(@Value("${db.password}") String pwd) throws PropertyVetoException {
    ComboPooledDataSource dataSource = new ComboPooledDataSource();
    dataSource.setUser(user);
    dataSource.setPassword(pwd);
    dataSource.setDriverClass(driverClass);
    dataSource.setJdbcUrl("jdbc:mysql://localhost:3306/dev");
    return dataSource;
}
 
Example 10
Source File: DAOFactory.java    From uavstack with Apache License 2.0 5 votes vote down vote up
protected DAOFactory(String facName, String driverClassName, String jdbcURL, String userName, String userPassword,
        int initPoolSize, int MinPoolSize, int MaxPoolSize, int maxIdleTime, int idleConnectionTestPeriod,
        String testQuerySQL) {

    this.facName = facName;

    ds = new ComboPooledDataSource();
    // 设置JDBC的Driver类
    try {
        ds.setDriverClass(driverClassName);
    }
    catch (PropertyVetoException e) {
        throw new RuntimeException(e);
    }
    // 设置JDBC的URL
    ds.setJdbcUrl(jdbcURL);
    // 设置数据库的登录用户名
    ds.setUser(userName);
    // 设置数据库的登录用户密码
    ds.setPassword(userPassword);
    // 设置连接池的最大连接数
    ds.setMaxPoolSize(MaxPoolSize);
    // 设置连接池的最小连接数
    ds.setMinPoolSize(MinPoolSize);
    // 设置初始化连接数
    ds.setInitialPoolSize(initPoolSize);
    // 设置最大闲置时间
    ds.setMaxIdleTime(maxIdleTime);
    // 设置测试SQL
    ds.setPreferredTestQuery(testQuerySQL);
    // 设置闲置测试周期
    ds.setIdleConnectionTestPeriod(idleConnectionTestPeriod);
    // 增加单个连接的Statements数量
    ds.setMaxStatements(0);
    // 连接池内单个连接所拥有的最大缓存statements数
    ds.setMaxStatementsPerConnection(200);
    // 获取空闲连接超时时间
    ds.setCheckoutTimeout(10 * 1000);
}
 
Example 11
Source File: SqlConnectionPool.java    From mxisd with GNU Affero General Public License v3.0 5 votes vote down vote up
public SqlConnectionPool(SqlConfig cfg) {
    Drivers.load(cfg.getType());

    ds = new ComboPooledDataSource();
    ds.setJdbcUrl("jdbc:" + cfg.getType() + ":" + cfg.getConnection());
    ds.setMinPoolSize(1);
    ds.setMaxPoolSize(10);
    ds.setAcquireIncrement(2);
    ds.setAcquireRetryAttempts(10);
    ds.setAcquireRetryDelay(1000);
}
 
Example 12
Source File: C3P0DataSource.java    From sqlg with MIT License 5 votes vote down vote up
public static C3P0DataSource create(final Configuration configuration) throws Exception {
    Preconditions.checkState(configuration.containsKey(SqlgGraph.JDBC_URL));
    Preconditions.checkState(configuration.containsKey("jdbc.username"));
    Preconditions.checkState(configuration.containsKey("jdbc.password"));

    String jdbcUrl = configuration.getString(SqlgGraph.JDBC_URL);
    SqlgPlugin sqlgPlugin = SqlgPlugin.load(jdbcUrl);
    SqlDialect sqlDialect = sqlgPlugin.instantiateDialect();

    String driver = sqlgPlugin.getDriverFor(jdbcUrl);
    String username = configuration.getString("jdbc.username");
    String password = configuration.getString("jdbc.password");

    ComboPooledDataSource comboPooledDataSource = new ComboPooledDataSource();
    comboPooledDataSource.setDriverClass(driver);
    comboPooledDataSource.setJdbcUrl(jdbcUrl);
    comboPooledDataSource.setMaxPoolSize(configuration.getInt("maxPoolSize", 100));
    comboPooledDataSource.setMaxIdleTime(configuration.getInt("maxIdleTime", 3600));
    comboPooledDataSource.setAcquireRetryAttempts(configuration.getInt("jdbc.acquireRetryAttempts", 30));
    comboPooledDataSource.setForceUseNamedDriverClass(true);
    if (!StringUtils.isEmpty(username)) {
        comboPooledDataSource.setUser(username);
    }

    if (!StringUtils.isEmpty(password)) {
        comboPooledDataSource.setPassword(password);
    }

    return new C3P0DataSource(jdbcUrl, comboPooledDataSource, sqlDialect);
}
 
Example 13
Source File: C3P0Pool.java    From MtgDesktopCompanion with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void init(String url, String user, String pass, boolean enable) {
	datasource = new ComboPooledDataSource();
	datasource.setProperties(props);
	datasource.setUser(user);
	datasource.setPassword(pass);
	datasource.setJdbcUrl(url);
	
}
 
Example 14
Source File: C3P0DataSourceAdapter.java    From ymate-platform-v2 with Apache License 2.0 5 votes vote down vote up
@Override
protected void __doInit() throws Exception {
    __ds = new ComboPooledDataSource();
    __ds.setDriverClass(__cfgMeta.getDriverClass());
    __ds.setJdbcUrl(__cfgMeta.getConnectionUrl());
    __ds.setUser(__cfgMeta.getUsername());
    __ds.setPassword(__doGetPasswordDecryptIfNeed());
}
 
Example 15
Source File: ConnectionPoolingTester.java    From spanner-jdbc with MIT License 4 votes vote down vote up
public void testPooling(CloudSpannerConnection original)
    throws SQLException, PropertyVetoException, InterruptedException {
  log.info("Starting connection pooling tests");
  ComboPooledDataSource cpds = new ComboPooledDataSource();
  cpds.setDriverClass("nl.topicus.jdbc.CloudSpannerDriver");
  cpds.setJdbcUrl(original.getUrl());
  cpds.setProperties(original.getSuppliedProperties());

  cpds.setInitialPoolSize(5);
  cpds.setMinPoolSize(5);
  cpds.setAcquireIncrement(5);
  cpds.setMaxPoolSize(20);
  cpds.setCheckoutTimeout(1000);

  log.info("Connection pool created and configured. Acquiring connection from pool");
  Assert.assertEquals(0, cpds.getNumBusyConnectionsDefaultUser());
  Connection connection = cpds.getConnection();
  Assert.assertNotNull(connection);
  Assert.assertEquals(1, cpds.getNumBusyConnectionsDefaultUser());
  connection.close();
  while (cpds.getNumBusyConnections() == 1) {
    TimeUnit.MILLISECONDS.sleep(100L);
  }
  Assert.assertEquals(0, cpds.getNumBusyConnectionsDefaultUser());

  log.info("About to acquire 10 connections");
  Connection[] connections = new Connection[10];
  for (int i = 0; i < connections.length; i++) {
    connections[i] = cpds.getConnection();
    Assert.assertEquals(i + 1, cpds.getNumBusyConnectionsDefaultUser());
  }
  log.info("10 connections acquired, closing connections...");
  for (int i = 0; i < connections.length; i++) {
    connections[i].close();
  }
  log.info("10 connections closed");
  log.info("Acquiring 20 connections");
  // Check that we can get 20 connections
  connections = new Connection[20];
  for (int i = 0; i < connections.length; i++) {
    connections[i] = cpds.getConnection();
    connections[i].prepareStatement("SELECT 1").executeQuery();
  }
  log.info("20 connections acquired, trying to get one more");
  // Verify that we can't get a connection now
  connection = null;
  try {
    connection = cpds.getConnection();
  } catch (SQLException e) {
    // timeout exception
    log.info("Exception when trying to get one more connection (this is expected)");
  }
  log.info("Closing 20 connections");
  Assert.assertNull(connection);
  for (int i = 0; i < connections.length; i++) {
    connections[i].close();
  }
  log.info("Closing connection pool");
  cpds.close();
  log.info("Finished tests");
}
 
Example 16
Source File: DataSourceIT.java    From apm-agent-java with Apache License 2.0 4 votes vote down vote up
private static DataSource getC3p0DataSource() {
    ComboPooledDataSource comboPooledDataSource = new ComboPooledDataSource();
    comboPooledDataSource.setJdbcUrl(URL);
    return comboPooledDataSource;
}
 
Example 17
Source File: DefaultDataSourceManager.java    From dhis2-core with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private List<DataSource> getReadOnlyDataSources()
{
    String mainUser = config.getProperty( ConfigurationKey.CONNECTION_USERNAME );
    String mainPassword = config.getProperty( ConfigurationKey.CONNECTION_PASSWORD );
    String driverClass = config.getProperty( CONNECTION_DRIVER_CLASS );
    String maxPoolSize = config.getPropertyOrDefault( CONNECTION_POOL_MAX_SIZE, DEFAULT_POOL_SIZE );

    Properties props = config.getProperties();

    List<DataSource> dataSources = new ArrayList<>();

    for ( int i = 1; i <= MAX_READ_REPLICAS; i++ )
    {
        String jdbcUrl = props.getProperty( String.format( FORMAT_CONNECTION_URL, i ) );
        String user = props.getProperty( String.format( FORMAT_CONNECTION_USERNAME, i ) );
        String password = props.getProperty( String.format( FORMAT_CONNECTION_PASSWORD, i ) );

        user = StringUtils.defaultIfEmpty( user, mainUser );
        password = StringUtils.defaultIfEmpty( password, mainPassword );

        if ( ObjectUtils.allNonNull( jdbcUrl, user, password ) )
        {
            try
            {
                ComboPooledDataSource ds = new ComboPooledDataSource();

                ds.setDriverClass( driverClass );
                ds.setJdbcUrl( jdbcUrl );
                ds.setUser( user );
                ds.setPassword( password );
                ds.setMaxPoolSize( Integer.parseInt( maxPoolSize ) );
                ds.setAcquireIncrement( VAL_ACQUIRE_INCREMENT );
                ds.setMaxIdleTime( VAL_MAX_IDLE_TIME );

                dataSources.add( ds );

                log.info( String.format( "Found read replica, index: '%d', connection URL: '%s''", i, jdbcUrl ) );

                testConnection( ds );
            }
            catch ( PropertyVetoException ex )
            {
                throw new IllegalArgumentException( "Invalid configuration of read replica: " + jdbcUrl, ex );
            }
        }
    }

    log.info( "Read only configuration initialized, read replicas found: " + dataSources.size() );

    return dataSources;
}
 
Example 18
Source File: C3P0DataSourceProvider.java    From vertx-jdbc-client with Apache License 2.0 4 votes vote down vote up
@Override
public DataSource getDataSource(JsonObject config) throws SQLException {
  String url = config.getString("url");
  if (url == null) throw new NullPointerException("url cannot be null");
  String driverClass = config.getString("driver_class");
  String user = config.getString("user");
  String password = config.getString("password");
  Integer maxPoolSize = config.getInteger("max_pool_size");
  Integer initialPoolSize = config.getInteger("initial_pool_size");
  Integer minPoolSize = config.getInteger("min_pool_size");
  Integer maxStatements = config.getInteger("max_statements");
  Integer maxStatementsPerConnection = config.getInteger("max_statements_per_connection");
  Integer maxIdleTime = config.getInteger("max_idle_time");
  Integer acquireRetryAttempts = config.getInteger("acquire_retry_attempts");
  Integer acquireRetryDelay = config.getInteger("acquire_retry_delay");
  Boolean breakAfterAcquireFailure = config.getBoolean("break_after_acquire_failure");

  // If you want to configure any other C3P0 properties you can add a file c3p0.properties to the classpath
  ComboPooledDataSource cpds = new ComboPooledDataSource();
  cpds.setJdbcUrl(url);
  if (driverClass != null) {
    try {
      cpds.setDriverClass(driverClass);
    } catch (PropertyVetoException e) {
      throw new IllegalArgumentException(e);
    }
  }
  if (user != null) {
    cpds.setUser(user);
  }
  if (password != null) {
    cpds.setPassword(password);
  }
  if (maxPoolSize != null) {
    cpds.setMaxPoolSize(maxPoolSize);
  }
  if (minPoolSize != null) {
    cpds.setMinPoolSize(minPoolSize);
  }
  if (initialPoolSize != null) {
    cpds.setInitialPoolSize(initialPoolSize);
  }
  if (maxStatements != null) {
    cpds.setMaxStatements(maxStatements);
  }
  if (maxStatementsPerConnection != null) {
    cpds.setMaxStatementsPerConnection(maxStatementsPerConnection);
  }
  if (maxIdleTime != null) {
    cpds.setMaxIdleTime(maxIdleTime);
  }
  if(acquireRetryAttempts != null){
    cpds.setAcquireRetryAttempts(acquireRetryAttempts);
  }
  if(acquireRetryDelay != null){
    cpds.setAcquireRetryDelay(acquireRetryDelay);
  }
  if(breakAfterAcquireFailure != null){
    cpds.setBreakAfterAcquireFailure(breakAfterAcquireFailure);
  }
  return cpds;
}
 
Example 19
Source File: H2Db.java    From hortonmachine with GNU General Public License v3.0 4 votes vote down vote up
public boolean open( String dbPath ) throws Exception {
    this.mDbPath = dbPath;

    connectionData = new ConnectionData();
    connectionData.connectionLabel = dbPath;
    connectionData.connectionUrl = new String(dbPath);
    connectionData.user = user;
    connectionData.password = password;
    connectionData.dbType = getType().getCode();

    boolean dbExists = false;
    if (dbPath != null) {
        File dbFile = new File(dbPath + "." + EDb.H2.getExtension());
        if (dbFile.exists()) {
            if (mPrintInfos)
                Logger.INSTANCE.insertInfo(null, "Database exists");
            dbExists = true;
        }
        if (dbPath.toLowerCase().startsWith("tcp")) {
            // no way to check, assume it exists
            dbExists = true;

            // also cleanup path
            int first = dbPath.indexOf('/');
            int second = dbPath.indexOf('/', first + 1);
            int third = dbPath.indexOf('/', second + 1);
            int lastSlash = dbPath.indexOf('/', third + 1);
            if (lastSlash != -1) {
                mDbPath = dbPath.substring(lastSlash, dbPath.length());
            }
        }
    } else {
        dbPath = "mem:syntax";
        dbExists = false;
    }

    String jdbcUrl = EDb.H2.getJdbcPrefix() + dbPath;

    if (makePooled) {
        Properties p = new Properties(System.getProperties());
        p.put("com.mchange.v2.log.MLog", "com.mchange.v2.log.FallbackMLog");
        p.put("com.mchange.v2.log.FallbackMLog.DEFAULT_CUTOFF_LEVEL", "OFF");
        System.setProperties(p);

        comboPooledDataSource = new ComboPooledDataSource();
        comboPooledDataSource.setDriverClass(DRIVER_CLASS);
        comboPooledDataSource.setJdbcUrl(jdbcUrl);
        if (user != null && password != null) {
            comboPooledDataSource.setUser(user);
            comboPooledDataSource.setPassword(password);
        }
        comboPooledDataSource.setInitialPoolSize(10);
        comboPooledDataSource.setMinPoolSize(5);
        comboPooledDataSource.setAcquireIncrement(5);
        comboPooledDataSource.setMaxPoolSize(30);
        comboPooledDataSource.setMaxStatements(100);
        comboPooledDataSource.setMaxIdleTime(14400); // 4 hours by default

        // comboPooledDataSource.setCheckoutTimeout(2000);
        comboPooledDataSource.setAcquireRetryAttempts(1);
        // comboPooledDataSource.setBreakAfterAcquireFailure(false);
        // TODO remove after debug
        // comboPooledDataSource.setUnreturnedConnectionTimeout(180);

    } else {
        if (user != null && password != null) {
            singleJdbcConn = DriverManager.getConnection(jdbcUrl, user, password);
        } else {
            singleJdbcConn = DriverManager.getConnection(jdbcUrl);
        }
    }
    if (mPrintInfos) {
        String[] dbInfo = getDbInfo();
        Logger.INSTANCE.insertDebug(null, "H2 Version: " + dbInfo[0] + "(" + dbPath + ")");
    }
    return dbExists;
}
 
Example 20
Source File: PooledConnectionC3P0.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
private static void setupDataSource(Isolation isolation) {
  ds = new ComboPooledDataSource();
  Endpoint locatorEndPoint = (Endpoint) (NetworkServerHelper.getNetworkLocatorEndpoints()).get(0);
  String hostname = getHostNameFromEndpoint(locatorEndPoint);
  int port = getPortFromEndpoint(locatorEndPoint); 
  
  connProp.putAll(getExtraConnProp()); //singlehop conn properties and any additional prop
  
  try {
    ds.setProperties(connProp); 
    ds.setDriverClass(driver);
    ds.setJdbcUrl(protocol + hostname+ ":" + port);
    
    ds.setMinPoolSize(5);
    ds.setAcquireIncrement(5);
    ds.setMaxPoolSize(numOfWorkers + 100);
    ds.setMaxStatementsPerConnection(10);
    
    if (isolation == Isolation.NONE) {
      ds.setConnectionCustomizerClassName( "sql.sqlutil.MyConnectionCustomizer");
    } else if (isolation == Isolation.READ_COMMITTED) {
      ds.setConnectionCustomizerClassName("sql.sqlutil.IsolationRCConnectionCustomizer");
    } else {
      ds.setConnectionCustomizerClassName("sql.sqlutil.IsolationRRConnectionCustomizer");
    }
    
    Log.getLogWriter().info("Pooled data source url is set as " + ds.getJdbcUrl());
    
    StringBuilder sb = new StringBuilder();
    
    for (Iterator iter = connProp.entrySet().iterator(); iter.hasNext(); ) {
      Map.Entry<String, String> entry = (Map.Entry<String, String>) iter.next();
      
      sb.append(entry.getKey() + " is set to " + entry.getValue() +"\n");
    }
    
    Log.getLogWriter().info("Pooled data source setting the following connection prop: " + sb.toString());
    
  } catch (Exception e) {
    throw new TestException("could not set data source" + TestHelper.getStackTrace(e));
  }
}