use of com.mchange.v2.c3p0.jacksonTest.ComboPooledDataSource in project opencast by opencast.
the class Activator method start.
@Override
public void start(BundleContext bundleContext) throws Exception {
// Use the configured storage directory
rootDir = bundleContext.getProperty("org.opencastproject.storage.dir") + File.separator + "db";
// Register the data source, defaulting to an embedded H2 database if DB configurations are not specified
String jdbcDriver = getConfigProperty(bundleContext.getProperty("org.opencastproject.db.jdbc.driver"), "org.h2.Driver");
String jdbcUrl = getConfigProperty(bundleContext.getProperty("org.opencastproject.db.jdbc.url"), "jdbc:h2:" + rootDir);
String jdbcUser = getConfigProperty(bundleContext.getProperty("org.opencastproject.db.jdbc.user"), "sa");
String jdbcPass = getConfigProperty(bundleContext.getProperty("org.opencastproject.db.jdbc.pass"), "sa");
Integer maxPoolSize = getConfigProperty(bundleContext.getProperty("org.opencastproject.db.jdbc.pool.max.size"));
Integer minPoolSize = getConfigProperty(bundleContext.getProperty("org.opencastproject.db.jdbc.pool.min.size"));
Integer acquireIncrement = getConfigProperty(bundleContext.getProperty("org.opencastproject.db.jdbc.pool.acquire.increment"));
Integer maxStatements = getConfigProperty(bundleContext.getProperty("org.opencastproject.db.jdbc.pool.max.statements"));
Integer loginTimeout = getConfigProperty(bundleContext.getProperty("org.opencastproject.db.jdbc.pool.login.timeout"));
Integer maxIdleTime = getConfigProperty(bundleContext.getProperty("org.opencastproject.db.jdbc.pool.max.idle.time"));
Integer maxConnectionAge = getConfigProperty(bundleContext.getProperty("org.opencastproject.db.jdbc.pool.max.connection.age"));
pooledDataSource = new ComboPooledDataSource();
pooledDataSource.setDriverClass(jdbcDriver);
pooledDataSource.setJdbcUrl(jdbcUrl);
pooledDataSource.setUser(jdbcUser);
pooledDataSource.setPassword(jdbcPass);
if (minPoolSize != null)
pooledDataSource.setMinPoolSize(minPoolSize);
if (maxPoolSize != null)
pooledDataSource.setMaxPoolSize(maxPoolSize);
if (acquireIncrement != null)
pooledDataSource.setAcquireIncrement(acquireIncrement);
if (maxStatements != null)
pooledDataSource.setMaxStatements(maxStatements);
if (loginTimeout != null)
pooledDataSource.setLoginTimeout(loginTimeout);
// that have been closed by the database.
if (maxIdleTime != null)
pooledDataSource.setMaxIdleTime(maxIdleTime);
else if (pooledDataSource.getMaxIdleTime() == 0) {
logger.debug("Setting database connection pool max.idle.time to default of {}", DEFAULT_MAX_IDLE_TIME);
pooledDataSource.setMaxIdleTime(DEFAULT_MAX_IDLE_TIME);
}
if (maxConnectionAge != null)
pooledDataSource.setMaxConnectionAge(maxConnectionAge);
Connection connection = null;
try {
logger.info("Testing connectivity to database at {}", jdbcUrl);
connection = pooledDataSource.getConnection();
Hashtable<String, String> dsProps = new Hashtable<>();
dsProps.put("osgi.jndi.service.name", "jdbc/opencast");
datasourceRegistration = bundleContext.registerService(DataSource.class.getName(), pooledDataSource, dsProps);
} catch (SQLException e) {
logger.error("Connection attempt to {} failed", jdbcUrl);
logger.error("Exception: ", e);
throw e;
} finally {
if (connection != null)
connection.close();
}
logger.info("Database connection pool established at {}", jdbcUrl);
logger.info("Database connection pool parameters: max.size={}, min.size={}, max.idle.time={}", pooledDataSource.getMaxPoolSize(), pooledDataSource.getMinPoolSize(), pooledDataSource.getMaxIdleTime());
}
use of com.mchange.v2.c3p0.jacksonTest.ComboPooledDataSource in project Mybatis-PageHelper by pagehelper.
the class DataSourceNegotiationAutoDialectTest method getC3P0.
private ComboPooledDataSource getC3P0() {
ComboPooledDataSource dataSource = new ComboPooledDataSource();
dataSource.setJdbcUrl(C3P0);
dataSource.setUser("root");
dataSource.setPassword("password");
return dataSource;
}
use of com.mchange.v2.c3p0.jacksonTest.ComboPooledDataSource in project leopard by tanhaichao.
the class OracleProxyDataSource method createDataSource.
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);
}
use of com.mchange.v2.c3p0.jacksonTest.ComboPooledDataSource in project hutool by looly.
the class C3p0DSFactory method createDataSource.
@Override
protected DataSource createDataSource(String jdbcUrl, String driver, String user, String pass, Setting poolSetting) {
final ComboPooledDataSource ds = new ComboPooledDataSource();
// remarks等特殊配置,since 5.3.8
final Props connProps = new Props();
String connValue;
for (String key : KEY_CONN_PROPS) {
connValue = poolSetting.getAndRemoveStr(key);
if (StrUtil.isNotBlank(connValue)) {
connProps.setProperty(key, connValue);
}
}
if (MapUtil.isNotEmpty(connProps)) {
ds.setProperties(connProps);
}
ds.setJdbcUrl(jdbcUrl);
try {
ds.setDriverClass(driver);
} catch (PropertyVetoException e) {
throw new DbRuntimeException(e);
}
ds.setUser(user);
ds.setPassword(pass);
// 注入属性
poolSetting.toBean(ds);
return ds;
}
use of com.mchange.v2.c3p0.jacksonTest.ComboPooledDataSource in project crawler4j by yasserg.
the class SampleLauncher method main.
public static void main(String[] args) throws Exception {
String crawlStorageFolder = Files.createTempDir().getAbsolutePath();
final int numberOfCrawlers = Integer.valueOf(args[2]);
CrawlConfig config = new CrawlConfig();
config.setPolitenessDelay(100);
config.setCrawlStorageFolder(crawlStorageFolder);
config.setMaxPagesToFetch(Integer.valueOf(args[0]));
/*
* Instantiate the controller for this crawl.
*/
PageFetcher pageFetcher = new PageFetcher(config);
RobotstxtConfig robotstxtConfig = new RobotstxtConfig();
RobotstxtServer robotstxtServer = new RobotstxtServer(robotstxtConfig, pageFetcher);
CrawlController controller = new CrawlController(config, pageFetcher, robotstxtServer);
/*
* For each crawl, you need to add some seed urls. These are the first
* URLs that are fetched and then the crawler starts following links
* which are found in these pages
*/
controller.addSeed("https://de.wikipedia.org/wiki/Java_Database_Connectivity");
controller.addSeed("https://de.wikipedia.org/wiki/Relationale_Datenbank");
controller.addSeed("https://pt.wikipedia.org/wiki/JDBC");
controller.addSeed("https://pt.wikipedia.org/wiki/Protocolo");
controller.addSeed("https://de.wikipedia.org/wiki/Datenbank");
Flyway flyway = new Flyway();
flyway.setDataSource(args[1], "crawler4j", "crawler4j");
flyway.migrate();
ComboPooledDataSource pool = new ComboPooledDataSource();
pool.setDriverClass("org.postgresql.Driver");
pool.setJdbcUrl(args[1]);
pool.setUser("crawler4j");
pool.setPassword("crawler4j");
pool.setMaxPoolSize(numberOfCrawlers);
pool.setMinPoolSize(numberOfCrawlers);
pool.setInitialPoolSize(numberOfCrawlers);
/*
* Start the crawl. This is a blocking operation, meaning that your code
* will reach the line after this only when crawling is finished.
*/
controller.start(new PostgresCrawlerFactory(pool), numberOfCrawlers);
pool.close();
}
Aggregations