本文整理汇总了Java中com.mchange.v2.c3p0.ComboPooledDataSource.setDataSourceName方法的典型用法代码示例。如果您正苦于以下问题:Java ComboPooledDataSource.setDataSourceName方法的具体用法?Java ComboPooledDataSource.setDataSourceName怎么用?Java ComboPooledDataSource.setDataSourceName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.mchange.v2.c3p0.ComboPooledDataSource
的用法示例。
在下文中一共展示了ComboPooledDataSource.setDataSourceName方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getDataSource
import com.mchange.v2.c3p0.ComboPooledDataSource; //导入方法依赖的package包/类
private DataSource getDataSource(C3P0 c3p0) throws Exception {
ComboPooledDataSource ds = new ComboPooledDataSource(true);
ds.setDataSourceName("C3PO");
ds.setJdbcUrl(c3p0.jdbcUrl);
ds.setDriverClass(c3p0.driverClass);
ds.setUser(c3p0.user);
ds.setPassword(c3p0.password);
ds.setMaxIdleTime(c3p0.maxIdleTime);
ds.setMaxPoolSize((c3p0.maxPoolSize));
ds.setMinPoolSize(c3p0.minPoolSize);
return ds;
}
示例2: createFromConfig
import com.mchange.v2.c3p0.ComboPooledDataSource; //导入方法依赖的package包/类
private TransactionAwareDataSource createFromConfig(String instanceName, rapture.common.ConnectionInfo info) throws PropertyVetoException {
String url = PostgresConnectionInfoConfigurer.getUrl(info);
String user = info.getUsername();
validateConfig(url, user);
log.info("Host is " + url);
ComboPooledDataSource dataSource = new ComboPooledDataSource();
dataSource.setDataSourceName(createDataSourceName(instanceName));
dataSource.setDriverClass(DRIVER_CLASS); // loads the jdbc driver
dataSource.setJdbcUrl(url);
dataSource.setUser(user);
dataSource.setCheckoutTimeout(DEFAULT_CHECKOUT_TIMEOUT);
String password = info.getPassword();
if (!StringUtils.isBlank(password)) {
dataSource.setPassword(password);
} else {
throw RaptureExceptionFactory.create("Password cannot be null!");
}
// pool size configuration
dataSource.setInitialPoolSize(getOptionAsInt(info, "initialPoolSize"));
dataSource.setMinPoolSize(getOptionAsInt(info, "minPoolSize"));
dataSource.setMaxPoolSize(getOptionAsInt(info, "maxPoolSize"));
dataSource.setMaxIdleTimeExcessConnections(getOptionAsInt(info, "maxIdleTimeExcessConnections"));
// statement size configuration
dataSource.setMaxStatements(getOptionAsInt(info, "maxStatements"));
dataSource.setStatementCacheNumDeferredCloseThreads(getOptionAsInt(info, "statementCacheNumDeferredCloseThreads"));
// connection testing
dataSource.setIdleConnectionTestPeriod(getOptionAsInt(info, "idleConnectionTestPeriod"));
boolean testConnectionOnCheckin = true;
if(info.getOption("testConnectionOnCheckin") != null) {
testConnectionOnCheckin = (boolean) info.getOption("testConnectionOnCheckin");
}
dataSource.setTestConnectionOnCheckin(testConnectionOnCheckin);
monitor.monitor(dataSource);
try {
Connection connection = DriverManager.getConnection(url, user, password);
connection.close();
} catch (SQLException e) {
throw RaptureExceptionFactory.create(ExceptionToString.format(e));
}
return new TransactionAwareDataSource(dataSource);
}
示例3: createDataSource
import com.mchange.v2.c3p0.ComboPooledDataSource; //导入方法依赖的package包/类
/**
* Creates {@link DataSource} based on {@link CConnection} properties.
*
* NOTE: this method never throws exception but just logs it.
*
* @param connection
* @return {@link DataSource} or <code>null</code> if it cannot be created
*/
private ComboPooledDataSource createDataSource(final CConnection connection)
{
try
{
System.setProperty("com.mchange.v2.log.MLog", com.mchange.v2.log.slf4j.Slf4jMLog.class.getName());
// System.setProperty("com.mchange.v2.log.FallbackMLog.DEFAULT_CUTOFF_LEVEL", "ALL");
final ComboPooledDataSource cpds = new ComboPooledDataSource();
cpds.setDataSourceName("AdempiereDS");
cpds.setDriverClass(DRIVER);
// loads the jdbc driver
cpds.setJdbcUrl(getConnectionURL(connection));
cpds.setUser(connection.getDbUid());
cpds.setPassword(connection.getDbPwd());
cpds.setPreferredTestQuery(DEFAULT_CONN_TEST_SQL);
cpds.setIdleConnectionTestPeriod(1200);
// cpds.setTestConnectionOnCheckin(true);
// cpds.setTestConnectionOnCheckout(true);
cpds.setAcquireRetryAttempts(2);
// Set checkout timeout to avoid forever locking when trying to connect to a not existing host.
cpds.setCheckoutTimeout(SystemUtils.getSystemProperty(CONFIG_CheckoutTimeout, 20 * 1000));
if (Ini.isClient())
{
cpds.setInitialPoolSize(1);
cpds.setMinPoolSize(1);
cpds.setMaxPoolSize(20);
cpds.setMaxIdleTimeExcessConnections(1200);
cpds.setMaxIdleTime(900);
m_maxbusyconnectionsThreshold = 15;
}
else
{
cpds.setInitialPoolSize(10);
cpds.setMinPoolSize(5);
cpds.setMaxPoolSize(150);
cpds.setMaxIdleTimeExcessConnections(1200);
cpds.setMaxIdleTime(1200);
m_maxbusyconnectionsThreshold = 120;
}
// the following sometimes kill active connection!
// cpds.setUnreturnedConnectionTimeout(1200);
// cpds.setDebugUnreturnedConnectionStackTraces(true);
// 04006: add a customizer to set the log level for message that are send to the client
// background: if there are too many messages sent (e.g. from a verbose and long-running DB function)
// then the whole JVM might suffer an OutOfMemoryError
cpds.setConnectionCustomizerClassName(DB_PostgreSQL_ConnectionCustomizer.class.getName());
return cpds;
}
catch (Exception ex)
{
throw new DBNoConnectionException("Could not initialise C3P0 Datasource", ex);
}
}