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


Java ComboPooledDataSource.setTestConnectionOnCheckout方法代碼示例

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


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

示例1: 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

示例2: wrap

import com.mchange.v2.c3p0.ComboPooledDataSource; //導入方法依賴的package包/類
@Override
public DataSource wrap(ReportDataSource rptDs) {
    try {
        ComboPooledDataSource dataSource = new ComboPooledDataSource();
        dataSource.setDriverClass(rptDs.getDriverClass());
        dataSource.setJdbcUrl(rptDs.getJdbcUrl());
        dataSource.setUser(rptDs.getUser());
        dataSource.setPassword(rptDs.getPassword());
        dataSource.setInitialPoolSize(MapUtils.getInteger(rptDs.getOptions(), "initialPoolSize", 3));
        dataSource.setMinPoolSize(MapUtils.getInteger(rptDs.getOptions(), "minPoolSize", 1));
        dataSource.setMaxPoolSize(MapUtils.getInteger(rptDs.getOptions(), "maxPoolSize", 20));
        dataSource.setMaxStatements(MapUtils.getInteger(rptDs.getOptions(), "maxStatements", 50));
        dataSource.setMaxIdleTime(MapUtils.getInteger(rptDs.getOptions(), "maxIdleTime", 1800));
        dataSource.setAcquireIncrement(MapUtils.getInteger(rptDs.getOptions(), "acquireIncrement", 3));
        dataSource.setAcquireRetryAttempts(MapUtils.getInteger(rptDs.getOptions(), "acquireRetryAttempts", 30));
        dataSource.setIdleConnectionTestPeriod(
            MapUtils.getInteger(rptDs.getOptions(), "idleConnectionTestPeriod", 60));
        dataSource.setBreakAfterAcquireFailure(
            MapUtils.getBoolean(rptDs.getOptions(), "breakAfterAcquireFailure", false));
        dataSource.setTestConnectionOnCheckout(
            MapUtils.getBoolean(rptDs.getOptions(), "testConnectionOnCheckout", false));
        return dataSource;
    } catch (Exception ex) {
        throw new RuntimeException("C3p0DataSourcePool Create Error", ex);
    }
}
 
開發者ID:xianrendzw,項目名稱:EasyReport,代碼行數:27,代碼來源:C3p0DataSourcePool.java

示例3: Initialize

import com.mchange.v2.c3p0.ComboPooledDataSource; //導入方法依賴的package包/類
/**
 * Initializes the pool.
 *DriverClass - The JDBC driver class.
 *JdbcUrl - JDBC connection url.
 *User / Password - Connection credentials.
 */
public void Initialize(String DriverClass, String JdbcUrl, String User, String Password) throws PropertyVetoException {
	final ComboPooledDataSource pool = new ComboPooledDataSource();
	setObject(pool);
	pool.setDriverClass(DriverClass);
	pool.setJdbcUrl(JdbcUrl);
	pool.setUser(User);
	pool.setPassword(Password);
	pool.setMaxStatements(150);
	pool.setMaxIdleTime(1800);
	pool.setIdleConnectionTestPeriod(600);
	pool.setCheckoutTimeout(20000);
	pool.setTestConnectionOnCheckout(true);
}
 
開發者ID:AnywhereSoftware,項目名稱:B4J_Server,代碼行數:20,代碼來源:ConnectionPool.java

示例4: createDataSource

import com.mchange.v2.c3p0.ComboPooledDataSource; //導入方法依賴的package包/類
public static ProxyDataSource createDataSource(String driverClass, String jdbcUrl, String user, String password, int maxPoolSize) {
	if (StringUtils.isEmpty(driverClass)) {
		// System.err.println("驅動程序沒有設置.");
		driverClass = "oracle.jdbc.driver.OracleDriver";
	}

	logger.info("createDataSource jdbcUrl:" + jdbcUrl);
	// ComboPooledDataSource dataSource = new ComboPooledDataSource();
	ComboPooledDataSource dataSource = new ComboPooledDataSource();
	try {
		// dataSource.setDriverClass("org.mariadb.jdbc.Driver");
		// dataSource.setDriverClass("org.gjt.mm.mysql.Driver");
		dataSource.setDriverClass(driverClass);
	}
	catch (PropertyVetoException e) {
		throw new RuntimeException(e.getMessage(), e);
	}
	dataSource.setJdbcUrl(jdbcUrl);
	dataSource.setUser(user);
	dataSource.setPassword(password);
	dataSource.setTestConnectionOnCheckout(false);
	dataSource.setInitialPoolSize(1);
	dataSource.setMinPoolSize(1);
	dataSource.setMaxPoolSize(maxPoolSize);
	dataSource.setAcquireIncrement(1);
	dataSource.setAcquireRetryAttempts(1);
	dataSource.setMaxIdleTime(7200);
	dataSource.setMaxStatements(0);
	return new OracleProxyDataSource(dataSource);
}
 
開發者ID:tanhaichao,項目名稱:leopard,代碼行數:31,代碼來源:OracleProxyDataSource.java

示例5: init

import com.mchange.v2.c3p0.ComboPooledDataSource; //導入方法依賴的package包/類
@Override
public void init(String configurationName, Map<String, String> properties) {
    this.configurationName = configurationName;
    this.properties = new HashMap<>(properties);

    String connectionKey = getConnectionKey();

    try {
        String driver = property("driver");

        String userName = property("user");
        String password = property("pass");

        cpds = new ComboPooledDataSource();
        cpds.setDriverClass(driver);
        cpds.setJdbcUrl(getJdbcUrl());
        cpds.setUser(userName);
        cpds.setPassword(password);

        int minPoolSize = Integer.parseInt(property("pool_min_size"));
        int aquireIncrement = Integer.parseInt(property("pool_increment_by"));
        int maxPoolSize = Integer.parseInt(property("pool_max_size"));

        cpds.setMinPoolSize(minPoolSize);
        cpds.setAcquireIncrement(aquireIncrement);
        cpds.setMaxPoolSize(maxPoolSize);
        cpds.setIdleConnectionTestPeriod(300);
        cpds.setPreferredTestQuery("SELECT 1");
        cpds.setTestConnectionOnCheckin(false);
        cpds.setTestConnectionOnCheckout(false);
    } catch (Throwable t) {
        throw new RuntimeException("Unable to establich SQL connection for JDBC-key: " + connectionKey, t);
    }
}
 
開發者ID:geetools,項目名稱:geeCommerce-Java-Shop-Software-and-PIM,代碼行數:35,代碼來源:MySqlDatabaseConnection.java

示例6: createDelegate

import com.mchange.v2.c3p0.ComboPooledDataSource; //導入方法依賴的package包/類
@Override
protected DataSource createDelegate() {
    final ComboPooledDataSource ds = new ComboPooledDataSource();
    try {
        ds.setDriverClass(context.getConnectionDriver());
    } catch (final PropertyVetoException e1) {
        throw Err.process(e1);
    }
    ds.setJdbcUrl(context.getConnectionUrl());
    ds.setUser(context.getConnectionUser());
    ds.setPassword(context.getConnectionPassword());

    ds.setMaxStatements(5000);
    ds.setMaxStatementsPerConnection(50);
    ds.setStatementCacheNumDeferredCloseThreads(1); //fix apparent deadlocks

    ds.setMaxPoolSize(100);
    ds.setMinPoolSize(1);
    ds.setMaxIdleTime(new Duration(1, FTimeUnit.MINUTES).intValue(FTimeUnit.SECONDS));
    ds.setTestConnectionOnCheckout(true);

    ds.setAutoCommitOnClose(true);

    Assertions.assertThat(this.closeableDs).isNull();
    this.closeableDs = ds;

    if (logging) {
        try {
            final ConnectionPoolDataSourceProxy proxy = new ConnectionPoolDataSourceProxy();
            proxy.setTargetDSDirect(ds);
            return proxy;
        } catch (final JdbcDsLogRuntimeException e) {
            throw new RuntimeException(e);
        }
    } else {
        return ds;
    }
}
 
開發者ID:subes,項目名稱:invesdwin-context-persistence,代碼行數:39,代碼來源:ConfiguredCPDataSource.java

示例7: createDataSource

import com.mchange.v2.c3p0.ComboPooledDataSource; //導入方法依賴的package包/類
public static ProxyDataSource createDataSource(String driverClass, String jdbcUrl, String user, String password, int maxPoolSize) {
	if (StringUtils.isEmpty(driverClass)) {
		// System.err.println("驅動程序沒有設置.");
		driverClass = "org.gjt.mm.mysql.Driver";
	}

	System.err.println("createDataSource jdbcUrl:" + jdbcUrl);
	// ComboPooledDataSource dataSource = new ComboPooledDataSource();
	ComboPooledDataSource dataSource = new ComboPooledDataSource();
	try {
		// dataSource.setDriverClass("org.mariadb.jdbc.Driver");
		// dataSource.setDriverClass("org.gjt.mm.mysql.Driver");
		dataSource.setDriverClass(driverClass);
	}
	catch (PropertyVetoException e) {
		throw new RuntimeException(e.getMessage(), e);
	}
	dataSource.setJdbcUrl(jdbcUrl);
	dataSource.setUser(user);
	dataSource.setPassword(password);
	dataSource.setTestConnectionOnCheckout(false);
	dataSource.setInitialPoolSize(1);
	dataSource.setMinPoolSize(1);
	dataSource.setMaxPoolSize(maxPoolSize);
	dataSource.setAcquireIncrement(1);
	dataSource.setAcquireRetryAttempts(1);
	dataSource.setMaxIdleTime(7200);
	dataSource.setMaxStatements(0);
	return new ProxyDataSource(dataSource);
}
 
開發者ID:tanhaichao,項目名稱:leopard-data,代碼行數:31,代碼來源:ProxyDataSource.java

示例8: start

import com.mchange.v2.c3p0.ComboPooledDataSource; //導入方法依賴的package包/類
@Override
public void start() {
    cpds = new ComboPooledDataSource();
    cpds.setJdbcUrl(getServerURL());
    cpds.setUser(getUsername());
    cpds.setPassword(getPassword());
    cpds.setMinPoolSize(getMinConnections());
    cpds.setMaxPoolSize(getMaxConnections());
    cpds.setIdleConnectionTestPeriod(getIdleTestInterval());
    cpds.setTestConnectionOnCheckout(getTestBeforeUse());
    cpds.setTestConnectionOnCheckin(getTestAfterUse());
    cpds.setPreferredTestQuery(getTestSQL());
    cpds.setMaxConnectionAge(getConnectionTimeout());
}
 
開發者ID:MoneyBeets,項目名稱:Narvaro,代碼行數:15,代碼來源:AbstractConnectionProvider.java

示例9: createDataSource

import com.mchange.v2.c3p0.ComboPooledDataSource; //導入方法依賴的package包/類
public DataSource createDataSource(String url, String username, String password, int initialSize, int maxPoolSize) throws PropertyVetoException {
    ComboPooledDataSource dataSource = new ComboPooledDataSource();
    dataSource.setDriverClass("com.mysql.jdbc.Driver");
    dataSource.setJdbcUrl(url);
    dataSource.setUser(username);
    dataSource.setPassword(password);
    dataSource.setInitialPoolSize(initialSize);
    dataSource.setMaxPoolSize(maxPoolSize);
    dataSource.setTestConnectionOnCheckout(true);
    return dataSource;
}
 
開發者ID:CrawlScript,項目名稱:WebCollector,代碼行數:12,代碼來源:MysqlHelper.java

示例10: initialize

import com.mchange.v2.c3p0.ComboPooledDataSource; //導入方法依賴的package包/類
/**
 * Create the underlying C3PO ComboPooledDataSource with the 
 * default supported properties.
 * @throws SchedulerException 
 */
private void initialize(
    String dbDriver, 
    String dbURL, 
    String dbUser,
    String dbPassword, 
    int maxConnections, 
    int maxStatementsPerConnection, 
    String dbValidationQuery,
    boolean validateOnCheckout,
    int idleValidationSeconds,
    int maxIdleSeconds) throws SQLException, SchedulerException {
    if (dbURL == null) {
        throw new SQLException(
            "DBPool could not be created: DB URL cannot be null");
    }
    
    if (dbDriver == null) {
        throw new SQLException(
            "DBPool '" + dbURL + "' could not be created: " +
            "DB driver class name cannot be null!");
    }
    
    if (maxConnections < 0) {
        throw new SQLException(
            "DBPool '" + dbURL + "' could not be created: " + 
            "Max connections must be greater than zero!");
    }

    
    datasource = new ComboPooledDataSource(); 
    try {
        datasource.setDriverClass(dbDriver);
    } catch (PropertyVetoException e) {
        throw new SchedulerException("Problem setting driver class name on datasource: " + e.getMessage(), e);
    }  
    datasource.setJdbcUrl(dbURL); 
    datasource.setUser(dbUser); 
    datasource.setPassword(dbPassword);
    datasource.setMaxPoolSize(maxConnections);
    datasource.setMinPoolSize(1);
    datasource.setMaxIdleTime(maxIdleSeconds);
    datasource.setMaxStatementsPerConnection(maxStatementsPerConnection);
    
    if (dbValidationQuery != null) {
        datasource.setPreferredTestQuery(dbValidationQuery);
        if(!validateOnCheckout)
            datasource.setTestConnectionOnCheckin(true);
        else
            datasource.setTestConnectionOnCheckout(true);
        datasource.setIdleConnectionTestPeriod(idleValidationSeconds);
    }
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:58,代碼來源:PoolingConnectionProvider.java

示例11: createDataSource

import com.mchange.v2.c3p0.ComboPooledDataSource; //導入方法依賴的package包/類
public static ProxyDataSource createDataSource(String driverClass, String jdbcUrl, String user, String password, int maxPoolSize, int idleConnectionTestPeriod) {
	if (StringUtils.isEmpty(driverClass)) {
		// System.err.println("驅動程序沒有設置.");
		driverClass = "org.gjt.mm.mysql.Driver";
	}

	logger.info("createDataSource jdbcUrl:" + jdbcUrl);
	// ComboPooledDataSource dataSource = new ComboPooledDataSource();
	ComboPooledDataSource dataSource = new ComboPooledDataSource();
	try {
		// dataSource.setDriverClass("org.mariadb.jdbc.Driver");
		// dataSource.setDriverClass("org.gjt.mm.mysql.Driver");
		dataSource.setDriverClass(driverClass);
	}
	catch (PropertyVetoException e) {
		throw new RuntimeException(e.getMessage(), e);
	}
	dataSource.setJdbcUrl(jdbcUrl);
	dataSource.setUser(user);
	dataSource.setPassword(password);
	dataSource.setTestConnectionOnCheckout(false);

	// testConnectionOnCheckout
	// 如果設置為true,每次從池中取一個連接,將做一下測試,使用automaticTestTable 或者 preferredTestQuery,
	// 做一條查詢語句.看看連接好不好用,不好用,就關閉它,重新從池中拿一個.
	// idleConnectionTestPeriod
	// 設置在池中的沒有被使用的連接,是否定時做測試,看看這個連接還可以用嗎?

	// <!--每60秒檢查所有連接池中的空閑連接。Default: 0 -->
	// <property name="idleConnectionTestPeriod" value="60" />
	dataSource.setIdleConnectionTestPeriod(idleConnectionTestPeriod);

	dataSource.setInitialPoolSize(1);
	dataSource.setMinPoolSize(1);
	dataSource.setMaxPoolSize(maxPoolSize);
	dataSource.setAcquireIncrement(1);
	dataSource.setAcquireRetryAttempts(1);
	dataSource.setMaxIdleTime(7200);
	dataSource.setMaxStatements(0);
	return new ProxyDataSource(dataSource);
}
 
開發者ID:tanhaichao,項目名稱:leopard,代碼行數:42,代碼來源:ProxyDataSource.java

示例12: init

import com.mchange.v2.c3p0.ComboPooledDataSource; //導入方法依賴的package包/類
public void init(Map<String, String> configuration) {
    try {
        Class.forName("com.mysql.jdbc.Driver");
        String connectURI = "jdbc:mysql://" + MYSQL_SERVER + ":"
                + MYSQL_PORT + "/" + MYSQL_DATABASE + "?"
          + "user=" + MYSQL_USER + "&password=" + MYSQL_PASSWORD;

        datasource = new ComboPooledDataSource();
        datasource.setJdbcUrl(connectURI);
        datasource.setMaxPoolSize(16);
        datasource.setMinPoolSize(4);
        datasource.setInitialPoolSize(4);
        datasource.setNumHelperThreads(6);
        datasource.setTestConnectionOnCheckin(true);
        datasource.setTestConnectionOnCheckout(true);

        connection = datasource.getConnection();

        preparedLookupStatement = connection
                .prepareStatement("SELECT value FROM " + MYSQL_TABLE
                        + " WHERE `key` = ?");
        preparedDeleteStatement = connection
                .prepareStatement("DELETE FROM " + MYSQL_TABLE
                        + " WHERE `key` = ?");
        preparedDeleteAllStatement = connection
                .prepareStatement("DELETE FROM " + MYSQL_TABLE);
        preparedInsertStatement = connection
                .prepareStatement("INSERT INTO " + MYSQL_TABLE
                        + " (`key`, value) VALUES (?, ?)");
        preparedCreateTableStatement = connection
                .prepareStatement("CREATE TABLE "
                        + MYSQL_TABLE
                        + " (`key` VARCHAR(255) NOT NULL, value BLOB NOT NULL, PRIMARY KEY (`key`))"
                        + "ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci");

        preparedCreateDatabaseStatement = connection
                .prepareStatement("CREATE DATABASE IF NOT EXISTS "
                        + MYSQL_DATABASE);

        // Check if database exist, on fail, create it
        //
        preparedCreateDatabaseStatement.executeUpdate();

        // Check if table exist, on fail, create it
        //

        DatabaseMetaData dbm = connection.getMetaData();

        resultSet = dbm.getTables(null, null, MYSQL_TABLE, null);
        if (!resultSet.next()) {
            preparedCreateTableStatement.executeUpdate();
        }

    } catch (Exception e) {
        throw new RuntimeException(e);
    }

}
 
開發者ID:ManuelB,項目名稱:key-value-benchmark,代碼行數:59,代碼來源:MySQLKeyValueLookup.java


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