本文整理汇总了Java中com.mchange.v2.c3p0.DataSources类的典型用法代码示例。如果您正苦于以下问题:Java DataSources类的具体用法?Java DataSources怎么用?Java DataSources使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DataSources类属于com.mchange.v2.c3p0包,在下文中一共展示了DataSources类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testOpenPooledDataSource
import com.mchange.v2.c3p0.DataSources; //导入依赖的package包/类
/**
* Test openPoolesDataSource(...) method.
*
* @throws Exception
*/
@Test
public void testOpenPooledDataSource() throws Exception {
PowerMockito.mockStatic(DataSources.class);
DataSource unPooledDSMock = mock(DataSource.class);
DataSource retPooledDSMock = mock(DataSource.class);
PowerMockito.doReturn(unPooledDSMock).when(DataSources.class, "unpooledDataSource"
, anyString(), anyString(), anyString());
PowerMockito.doReturn(retPooledDSMock).when(DataSources.class, "pooledDataSource"
, any(DataSource.class), anyMap());
assertEquals(retPooledDSMock, provider.openPooledDataSource(DBConnectionManager.DBType.MYSQL
, "url", USERNAME, "password"));
//Call PowerMockito.verifyStatic() to start verifying behavior
PowerMockito.verifyStatic();
//Use EasyMock-like semantic to verify behavior:
DataSources.unpooledDataSource(anyString(), anyString(), anyString());
DataSources.pooledDataSource(any(DataSource.class), anyMap());
}
示例2: closePolledDataSources
import com.mchange.v2.c3p0.DataSources; //导入依赖的package包/类
/**
* Close all pooled datasources created by C3P0.
*/
public static void closePolledDataSources() {
for (PooledDataSource dataSource:(Set<PooledDataSource>)C3P0Registry.allPooledDataSources()) {
try {
dataSource.close();
DataSources.destroy(dataSource);
} catch (SQLException e) {
e.printStackTrace();
}
}
}
示例3: createDataSource
import com.mchange.v2.c3p0.DataSources; //导入依赖的package包/类
public static DataSource createDataSource(Properties poolProperties) throws SQLException {
assertNotNull(poolProperties);
if (poolProperties.containsKey(PROP_URL) == false) {
throw new SQLException("Could not find field: " + PROP_URL);
}
DataSource ds = null;
String jdbcUrl = (String) poolProperties.get(PROP_URL);
try {
ds = DataSources.unpooledDataSource(jdbcUrl, poolProperties);
return DataSources.pooledDataSource(ds);
} catch (Exception e) {
throw new SQLException(e);
}
}
示例4: testCreateDataSourceProperties
import com.mchange.v2.c3p0.DataSources; //导入依赖的package包/类
@Test
public void testCreateDataSourceProperties() throws SQLException {
DataSource dataSource = MjdbcFactory.createDataSource(this.poolProperties);
assertNotNull(dataSource);
assertNotNull(dataSource.getConnection());
testDataSource(dataSource);
DataSources.destroy(dataSource);
}
示例5: testCreateDataSourceAll
import com.mchange.v2.c3p0.DataSources; //导入依赖的package包/类
@Test
public void testCreateDataSourceAll() throws SQLException {
DataSource dataSource = MjdbcFactory.createDataSource(this.poolProperties.getProperty(PROP_DRIVERCLASSNAME),
this.poolProperties.getProperty(PROP_URL),
this.poolProperties.getProperty(PROP_USERNAME),
this.poolProperties.getProperty(PROP_PASSWORD),
Integer.parseInt(this.poolProperties.getProperty(PROP_INITIALSIZE)),
Integer.parseInt(this.poolProperties.getProperty(PROP_MAXACTIVE)));
assertNotNull(dataSource);
assertNotNull(dataSource.getConnection());
testDataSource(dataSource);
DataSources.destroy(dataSource);
}
示例6: DatabaseHelper
import com.mchange.v2.c3p0.DataSources; //导入依赖的package包/类
/**
* @param rawProperties
* @throws SQLException
*/
public DatabaseHelper(final Properties rawProperties) throws SQLException {
final Properties database = new Properties(rawProperties);
try {
Class.forName(database.getProperty("driver"));
} catch (final ClassNotFoundException e) {
throw new SQLException("Database driver is not available", e);
}
final String url = database.getProperty("url");
final String username = database.getProperty("user");
final String password = database.getProperty("password");
final DataSource source = DataSources.unpooledDataSource(url, username, password);
final DataSource polled = DataSources.pooledDataSource(source);
polled.getConnection().close();
this.connectionProvider = polled;
}
示例7: configure
import com.mchange.v2.c3p0.DataSources; //导入依赖的package包/类
/**
* Initializes and configures {@link DataSource} by properties
*
* @return {@link DataSource} initialized and configured
* @throws PropertyVetoException
* @throws SQLException
* @throws IOException
*/
private DataSource configure() throws PropertyVetoException, SQLException, IOException {
DataSource dataSource;
if (poolConfig.isPooledDataSource()) {
ComboPooledDataSource comboPooledDataSource = new ComboPooledDataSource();
comboPooledDataSource.setDriverClass(driver);
comboPooledDataSource.setJdbcUrl(url);
comboPooledDataSource.setUser(user);
comboPooledDataSource.setPassword(password);
dataSource = comboPooledDataSource;
} else {
// Initializes and loads data base driver class by name
Initializer.initializeDriver(driver);
dataSource = DataSources.unpooledDataSource(url, user, password);
}
return dataSource;
}
示例8: contextDestroyed
import com.mchange.v2.c3p0.DataSources; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public void contextDestroyed(ServletContextEvent sce) {
ComboPooledDataSource cpds = (ComboPooledDataSource) sce
.getServletContext().getAttribute("hr.fer.zemris.dbpool");
if (cpds != null) {
try {
DataSources.destroy(cpds);
} catch (SQLException e) {
e.printStackTrace();
}
}
}
示例9: close
import com.mchange.v2.c3p0.DataSources; //导入依赖的package包/类
public void close() {
try {
DataSources.destroy(ds);
}
catch (SQLException sqle) {
log.warn("could not destroy C3P0 connection pool", sqle);
}
}
示例10: getDataSource
import com.mchange.v2.c3p0.DataSources; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
// 2.1.0
// protected DataSource getDataSource() {
public DataSource getDataSource() {
////
// 2.1.0
// // url
// String url = properties.getProperty("url");
// if (url == null)
// logger.error("C3p0.<init>: property url == null");
////
try {
// 2.1.0
// DataSource unpooledDataSource = DataSources.unpooledDataSource(url, properties);
// logger.debug(() -> "C3p0.getDataSource: unpooledDataSource = " + unpooledDataSource);
DataSource unpooledDataSource = DataSources.unpooledDataSource(jdbcProperties.getProperty("url"), jdbcProperties);
DataSource dataSource = DataSources.pooledDataSource(unpooledDataSource);
// 2.1.0
// logger.debug(() -> "C3p0.getDataSource: dataSource = " + dataSource);
////
return dataSource;
}
catch (SQLException e) {
// 2.1.0
// logger.error("C3p0.<init>: " + e, e);
throw new RuntimeException("jdbcProperties: " + jdbcProperties, e);
}
// 2.1.0
// return null;
////
}
示例11: destroy
import com.mchange.v2.c3p0.DataSources; //导入依赖的package包/类
@Override
public void destroy() {
try {
DataSources.destroy(cpds);
} catch (SQLException e) {
e.printStackTrace();
}
}
示例12: close
import com.mchange.v2.c3p0.DataSources; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
public void close() {
try {
DataSources.destroy( ds );
}
catch ( SQLException sqle ) {
log.warn( "could not destroy C3P0 connection pool", sqle );
}
}
示例13: destroy
import com.mchange.v2.c3p0.DataSources; //导入依赖的package包/类
public void destroy() {
try {
DataSources.destroy(ds);
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
示例14: closePooledDataSource
import com.mchange.v2.c3p0.DataSources; //导入依赖的package包/类
/**
* close the pooled data source
*
* @param aPooledDataSource a pooled datasource
* @throws SQLException
*/
public void closePooledDataSource(DataSource aPooledDataSource) throws SQLException {
if (aPooledDataSource == null) {
return;
}
DataSources.destroy(aPooledDataSource);
}
示例15: prepareTestInstance
import com.mchange.v2.c3p0.DataSources; //导入依赖的package包/类
@Override
public void prepareTestInstance(final TestContext testContext) throws Exception {
System.err.println(String.format("TemporaryDatabaseExecutionListener.prepareTestInstance(%s)", testContext));
final JUnitTemporaryDatabase jtd = findAnnotation(testContext);
if (jtd == null) {
return;
}
m_database = m_databases.remove();
final PooledDataSource pooledDataSource = (PooledDataSource)DataSources.pooledDataSource(m_database);
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
try { pooledDataSource.close(); }
catch (final Throwable t) { LogUtils.debugf(this, t, "failed to close pooled data source"); }
}
});
final LazyConnectionDataSourceProxy proxy = new LazyConnectionDataSourceProxy(pooledDataSource);
DataSourceFactory.setInstance(proxy);
testContext.setAttribute("org.opennms.netmgt.dao.db.TemporaryDatabaseExecutionListener.pooledDataSource", pooledDataSource);
System.err.println(String.format("TemporaryDatabaseExecutionListener.prepareTestInstance(%s) prepared db %s", testContext, m_database.toString()));
System.err.println("Temporary Database Name: " + m_database.getTestDatabase());
}