當前位置: 首頁>>代碼示例>>Java>>正文


Java ComboPooledDataSource類代碼示例

本文整理匯總了Java中com.mchange.v2.c3p0.ComboPooledDataSource的典型用法代碼示例。如果您正苦於以下問題:Java ComboPooledDataSource類的具體用法?Java ComboPooledDataSource怎麽用?Java ComboPooledDataSource使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


ComboPooledDataSource類屬於com.mchange.v2.c3p0包,在下文中一共展示了ComboPooledDataSource類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: pooled

import com.mchange.v2.c3p0.ComboPooledDataSource; //導入依賴的package包/類
private static PooledDataSource pooled(String hostname, int port, String username, String password, String database, String driver, int maxPoolsize) {
    ComboPooledDataSource dataSource = new ComboPooledDataSource();
    dataSource.setJdbcUrl(format("jdbc:mysql://%s:%d/%s?rewriteBatchedStatements=true",
            hostname,
            port,
            database));
    dataSource.setUser(username);
    dataSource.setPassword(password);
    dataSource.setIdleConnectionTestPeriod(60 * 5);
    dataSource.setMinPoolSize(3);
    dataSource.setInitialPoolSize(3);
    dataSource.setAcquireIncrement(1);
    dataSource.setMaxPoolSize(maxPoolsize);

    try {
        Class.forName(driver);
    } catch (ClassNotFoundException e) {
        throw new RuntimeException(e);
    }
    return dataSource;
}
 
開發者ID:tim-group,項目名稱:tg-eventstore,代碼行數:22,代碼來源:StacksConfiguredDataSource.java

示例2: getConfig

import com.mchange.v2.c3p0.ComboPooledDataSource; //導入依賴的package包/類
/**
 * DESC: 獲取XLS的配置
 * @return
 */
private Config getConfig(){
    Config config = new Config();
    config.setConfigFile("classpath:bean2xls.xml");

    List<String> handlers = new ArrayList<>();
    handlers.add("site.oaksharks.xlsutils.typecovent.DateHandler");
    config.setHandleList(handlers);
    config.setStyleFactoryClass("site.oaksharks.xlsutils.style.DefaultStyleFactory");
    config.load();
    // 生成文件的臨時目錄
    config.setTempDir("D:\\xlstmp");
    DataSource dataSource=new ComboPooledDataSource("xlsutils");
    config.setDataSource(dataSource);
    return config ;
}
 
開發者ID:oaksharks,項目名稱:XLSUtils,代碼行數:20,代碼來源:GenerateTest.java

示例3: get

import com.mchange.v2.c3p0.ComboPooledDataSource; //導入依賴的package包/類
@Override
public DataSource get() throws PropertyVetoException {
    if (cpds != null) {
        return cpds;
    }

    this.cpds = new com.mchange.v2.c3p0.ComboPooledDataSource();

    cpds.setDriverClass("com.mysql.cj.jdbc.Driver");
    cpds.setJdbcUrl("jdbc:mysql://localhost:3306/db_example");
    cpds.setUser("tully");
    cpds.setPassword("tully");

    cpds.setInitialPoolSize(3);
    cpds.setMinPoolSize(1);
    cpds.setAcquireIncrement(1);
    cpds.setMaxPoolSize(5);

    return cpds;
}
 
開發者ID:vitaly-chibrikov,項目名稱:otus_java_2017_06,代碼行數:21,代碼來源:C3P0DataSourceFactory.java

示例4: defualtDataSource

import com.mchange.v2.c3p0.ComboPooledDataSource; //導入依賴的package包/類
@Bean
public DataSource defualtDataSource() {
    ComboPooledDataSource defualtDatasource = new ComboPooledDataSource();
    try {
        defualtDatasource.setJdbcUrl(environment.getProperty("db.url"));
        defualtDatasource.setUser(environment.getProperty("db.user"));
        defualtDatasource.setPassword(environment.getProperty("db.pass"));
        defualtDatasource.setDriverClass(environment.getProperty("db.driver"));

        defualtDatasource.setInitialPoolSize(Integer.valueOf("1"));
        defualtDatasource.setMaxPoolSize(Integer.parseInt("5"));
        defualtDatasource.setMinPoolSize(Integer.parseInt("5"));
        defualtDatasource.setMaxConnectionAge(Integer.parseInt("100"));
    } catch (PropertyVetoException e) {
        e.printStackTrace();
    }
    return defualtDatasource;
}
 
開發者ID:mojtaba-sharif,項目名稱:boot-rest-mysql,代碼行數:19,代碼來源:DefualtDataBaseConfig.java

示例5: defualtDataSource

import com.mchange.v2.c3p0.ComboPooledDataSource; //導入依賴的package包/類
@Bean
public DataSource defualtDataSource() {
    ComboPooledDataSource defualtDatasource = new ComboPooledDataSource();
    defualtDatasource.setJdbcUrl(properties.getUrl());
    defualtDatasource.setUser(properties.getUsername());
    defualtDatasource.setPassword(properties.getPassword());
    try {
        defualtDatasource.setDriverClass(properties.getDriver());
    } catch (PropertyVetoException e) {
        e.printStackTrace();
    }
    defualtDatasource.setInitialPoolSize(Integer.valueOf(defultPoolProp.getInitialPoolSize()));
    defualtDatasource.setMaxPoolSize(Integer.parseInt(defultPoolProp.getMaxPoolSize()));
    defualtDatasource.setMinPoolSize(Integer.parseInt(defultPoolProp.getMinPoolSize()));
    defualtDatasource.setMaxConnectionAge(Integer.parseInt(defultPoolProp.getPoolMaxConnectionAge()));
    return defualtDatasource;
}
 
開發者ID:mojtaba-sharif,項目名稱:multi-tenancy,代碼行數:18,代碼來源:DefualtDataBaseConfig.java

示例6: get

import com.mchange.v2.c3p0.ComboPooledDataSource; //導入依賴的package包/類
@Override
public DataSource get() throws PropertyVetoException {
    if (cpds != null) {
        return cpds;
    }

    this.cpds = new com.mchange.v2.c3p0.ComboPooledDataSource();

    cpds.setDriverClass("org.h2.Driver");
    cpds.setJdbcUrl("jdbc:h2:~/test");
    cpds.setUser("sa");
    cpds.setPassword("");

    cpds.setInitialPoolSize(1);
    cpds.setMinPoolSize(1);
    cpds.setAcquireIncrement(1);
    cpds.setMaxPoolSize(1);

    return cpds;
}
 
開發者ID:vitaly-chibrikov,項目名稱:otus_java_2017_10,代碼行數:21,代碼來源:C3P0DataSourceFactory.java

示例7: connect

import com.mchange.v2.c3p0.ComboPooledDataSource; //導入依賴的package包/類
/**
 * Method load properties and get connection pool to database.
 * Use c3p0 library.
 */
public void connect() {
    pool = new ComboPooledDataSource();
    try {
        pool.setDriverClass(dbPROP.getProperty("driver"));
    } catch (PropertyVetoException ex) {
        ex.printStackTrace();
    }
    pool.setJdbcUrl(dbPROP.getProperty("url"));
    pool.setUser(dbPROP.getProperty("username"));
    pool.setPassword(dbPROP.getProperty("password"));
    pool.setMinPoolSize(2);
    pool.setAcquireIncrement(1);
    pool.setMaxPoolSize(5);
    pool.setMaxStatements(50);
    pool.setMaxStatementsPerConnection(10);
}
 
開發者ID:CkimiHoK,項目名稱:JavaWork,代碼行數:21,代碼來源:DataBaseController.java

示例8: getDatasource

import com.mchange.v2.c3p0.ComboPooledDataSource; //導入依賴的package包/類
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);
    }
  }
}
 
開發者ID:qubole,項目名稱:streamx,代碼行數:21,代碼來源:ConnectionPool.java

示例9: createC3P0DataSource

import com.mchange.v2.c3p0.ComboPooledDataSource; //導入依賴的package包/類
private DataSource createC3P0DataSource() throws PropertyVetoException {
    ComboPooledDataSource ds = new ComboPooledDataSource();
    ds.setDriverClass(configuration.getDriverClassName());
    ds.setJdbcUrl(configuration.getJdbcUrl());
    ds.setUser(configuration.getJdbcUsername());
    ds.setPassword(configuration.getJdbcPassword());

    ds.setAcquireIncrement(3);
    ds.setMinPoolSize(configuration.getMinPoolSize());
    ds.setMaxPoolSize(configuration.getMaxPoolSize());
    ds.setIdleConnectionTestPeriod(1800);
    ds.setConnectionTesterClassName(MidPointConnectionTester.class.getName());
    ds.setConnectionCustomizerClassName(MidPointConnectionCustomizer.class.getName());

    return ds;
}
 
開發者ID:Pardus-Engerek,項目名稱:engerek,代碼行數:17,代碼來源:DataSourceFactory.java

示例10: getDataSource

import com.mchange.v2.c3p0.ComboPooledDataSource; //導入依賴的package包/類
private DataSource getDataSource(String datasourceName, PersistenceOptions config) {
  try {

    DataSource ds = new ComboPooledDataSource();
    ((ComboPooledDataSource) ds).setDataSourceName(datasourceName);
    ((ComboPooledDataSource) ds).setDriverClass(config.getDriverClass());
    ((ComboPooledDataSource) ds).setJdbcUrl(config.getUrl());
    ((ComboPooledDataSource) ds).setUser(config.getUsername());
    ((ComboPooledDataSource) ds).setPassword(config.getPassword());
    ((ComboPooledDataSource) ds).setInitialPoolSize(config.getInitialPool());
    ((ComboPooledDataSource) ds).setMinPoolSize(config.getMinPool());
    ((ComboPooledDataSource) ds).setMaxPoolSize(config.getMaxPool());
    ((ComboPooledDataSource) ds).setMaxIdleTime(config.getMaxIdleTime());
    ((ComboPooledDataSource) ds).setMaxStatementsPerConnection(config.getMaxStatementsPerConnection());
    return ds;
  } catch (Exception e) {

    throw new RuntimeException(e);
  }
}
 
開發者ID:jspare-projects,項目名稱:jspare-container,代碼行數:21,代碼來源:PersistenceUnitProviderImpl.java

示例11: registerC3P0DataSource

import com.mchange.v2.c3p0.ComboPooledDataSource; //導入依賴的package包/類
@Test
public void registerC3P0DataSource() throws Exception {
    MetricCollector metricCollector = MonitoringCenter.getMetricCollector(MonitoringCenterTest.class);

    ComboPooledDataSource cpds = new ComboPooledDataSource();
    cpds.setDriverClass("com.mysql.jdbc.Driver");

    cpds.setMinPoolSize(2);
    cpds.setAcquireIncrement(5);
    cpds.setMaxPoolSize(20);
    cpds.setMaxStatements(180);
    cpds.setBreakAfterAcquireFailure(true);

    metricCollector.registerC3P0DataSource(cpds, "testDB");

    C3P0PooledDataSourceMetricSet c3P0PooledDataSourceMetricSet = new C3P0PooledDataSourceMetricSet(cpds);

    String[] startsWithFilters = {"MonitoringCenterTest."};

    Assert.assertEquals(c3P0PooledDataSourceMetricSet.getMetrics().size(), MonitoringCenter.getMetricsByNames(false, startsWithFilters).size());
}
 
開發者ID:centro,項目名稱:monitoring-center,代碼行數:22,代碼來源:MetricCollectorImplTest.java

示例12: initialize

import com.mchange.v2.c3p0.ComboPooledDataSource; //導入依賴的package包/類
public static boolean initialize(String url, String user, String password, int minPoolSize, int maxPoolSize,
		int poolIncrement) {
	try {
		cpds = new ComboPooledDataSource();
		cpds.setDriverClass("com.mysql.cj.jdbc.Driver");
		cpds.setJdbcUrl(url);
		cpds.setUser(user);
		cpds.setPassword(password);

		cpds.setInitialPoolSize(minPoolSize);
		cpds.setMinPoolSize(minPoolSize);
		cpds.setAcquireIncrement(poolIncrement);
		cpds.setMaxPoolSize(maxPoolSize);

		cpds.setNumHelperThreads(Nomad.DB_WORKERS);

		cpds.setTestConnectionOnCheckout(true);
	} catch (Exception e) {
		logger.error("Failed to initialize DB.", e);
		return false;
	}
	logger.debug("Initialized DB.");
	return true;
}
 
開發者ID:GHzGangster,項目名稱:Nomad,代碼行數:25,代碼來源:DB.java

示例13: getSpecificDataSource

import com.mchange.v2.c3p0.ComboPooledDataSource; //導入依賴的package包/類
@ConfigurationProperties(prefix="system.datasource")
private DataSource getSpecificDataSource(String dbname) {
	try {
		System.out.println("CONNECTING TO DB ---------------> " + dbname.replaceAll("discoursedb_ext", ""));

		ComboPooledDataSource ds = new ComboPooledDataSource();
		ds.setDriverClass(environment.getRequiredProperty("jdbc.driverClassName"));
		String host = environment.getRequiredProperty("jdbc.host");
		String port = environment.getRequiredProperty("jdbc.port");
		String database = "discoursedb_ext_" + dbname.replaceAll("discoursedb_ext_", "");
		ds.setJdbcUrl("jdbc:mysql://" + host + ":" + port + "/" + database+ "?createDatabaseIfNotExist=true&useUnicode=true&characterEncoding=UTF-8&characterSetResults=UTF-8&useSSL=false");
		ds.setUser(environment.getRequiredProperty("jdbc.username"));
		ds.setPassword(environment.getRequiredProperty("jdbc.password"));
		ds.setAcquireIncrement(Integer.parseInt(environment.getRequiredProperty("c3p0.acquireIncrement").trim()));
		ds.setIdleConnectionTestPeriod(
				Integer.parseInt(environment.getRequiredProperty("c3p0.idleConnectionTestPeriod").trim()));
		ds.setMaxStatements(Integer.parseInt(environment.getRequiredProperty("c3p0.maxStatements").trim()));
		ds.setMinPoolSize(Integer.parseInt(environment.getRequiredProperty("c3p0.minPoolSize").trim()));
		ds.setMaxPoolSize(Integer.parseInt(environment.getRequiredProperty("c3p0.maxPoolSize").trim()));
		return ds;
	} catch (Exception e) {
		throw new RuntimeException(e);
	}
}
 
開發者ID:DiscourseDB,項目名稱:discoursedb-core,代碼行數:25,代碼來源:DatabaseSelector.java

示例14: systemDataSource

import com.mchange.v2.c3p0.ComboPooledDataSource; //導入依賴的package包/類
@Bean(name = "systemDataSource")
   @ConfigurationProperties(prefix="system.datasource")
  public DataSource systemDataSource() {
	try {
		ComboPooledDataSource ds = new ComboPooledDataSource();
		ds.setDriverClass(environment.getRequiredProperty("jdbc.driverClassName"));
		String host = environment.getRequiredProperty("jdbc.host");
		String port = environment.getRequiredProperty("jdbc.port");
		String database = environment.getRequiredProperty("jdbc.system_database").replaceAll("discoursedb_ext_", "");
		ds.setJdbcUrl("jdbc:mysql://" + host + ":" + port + "/discoursedb_ext_" + database+ "?createDatabaseIfNotExist=true&useUnicode=true&characterEncoding=UTF-8&characterSetResults=UTF-8&useSSL=false");
		ds.setUser(environment.getRequiredProperty("jdbc.username"));
		ds.setPassword(environment.getRequiredProperty("jdbc.password"));
		ds.setAcquireIncrement(Integer.parseInt(environment.getRequiredProperty("c3p0.acquireIncrement").trim()));
		ds.setIdleConnectionTestPeriod(
				Integer.parseInt(environment.getRequiredProperty("c3p0.idleConnectionTestPeriod").trim()));
		ds.setMaxStatements(Integer.parseInt(environment.getRequiredProperty("c3p0.maxStatements").trim()));
		ds.setMinPoolSize(Integer.parseInt(environment.getRequiredProperty("c3p0.minPoolSize").trim()));
		ds.setMaxPoolSize(Integer.parseInt(environment.getRequiredProperty("c3p0.maxPoolSize").trim()));
		return ds;
	} catch (Exception e) {
		throw new RuntimeException(e);
	}
}
 
開發者ID:DiscourseDB,項目名稱:discoursedb-core,代碼行數:24,代碼來源:SystemDbConfiguration.java

示例15: start

import com.mchange.v2.c3p0.ComboPooledDataSource; //導入依賴的package包/類
public boolean start() {
    if (isStarted)
        return true;

    dataSource = new ComboPooledDataSource();
    dataSource.setJdbcUrl(jdbcUrl);
    dataSource.setUser(user);
    dataSource.setPassword(password);
    try {
        dataSource.setDriverClass(driverClass);
    } catch (PropertyVetoException e) {
        dataSource = null;
        logger.error("C3p0Plugin start error");
        throw new RuntimeException(e);
    }
    dataSource.setMaxPoolSize(maxPoolSize);
    dataSource.setMinPoolSize(minPoolSize);
    dataSource.setInitialPoolSize(initialPoolSize);
    dataSource.setMaxIdleTime(maxIdleTime);
    dataSource.setAcquireIncrement(acquireIncrement);

    isStarted = true;
    return true;
}
 
開發者ID:T-baby,項目名稱:ICERest-plugin,代碼行數:25,代碼來源:C3p0Plugin.java


注:本文中的com.mchange.v2.c3p0.ComboPooledDataSource類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。