本文整理汇总了Java中com.mchange.v2.c3p0.DataSources.unpooledDataSource方法的典型用法代码示例。如果您正苦于以下问题:Java DataSources.unpooledDataSource方法的具体用法?Java DataSources.unpooledDataSource怎么用?Java DataSources.unpooledDataSource使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.mchange.v2.c3p0.DataSources
的用法示例。
在下文中一共展示了DataSources.unpooledDataSource方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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);
}
}
示例3: 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;
}
示例4: 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;
}
示例5: 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;
////
}
示例6: shouldUseConnectionFromPool
import com.mchange.v2.c3p0.DataSources; //导入方法依赖的package包/类
@Test
public void shouldUseConnectionFromPool() throws PropertyVetoException, SQLException, ClassNotFoundException {
Class.forName(driver());
DataSource dataSourceUnpooled = DataSources.unpooledDataSource(url(), user(), password());
DataSource dataSourcePooled = DataSources.pooledDataSource(dataSourceUnpooled); //init the connection pool
Base.open(dataSourcePooled); //get connection from pool
Person.deleteAll(); //clean DB before test
Person.createIt("name", "Matt", "last_name", "Diamont", "dob", "1962-01-01");
a(Person.findAll().size()).shouldBeEqual(1);
Person.deleteAll();//clean DB after test
Base.close();// really connection goes back to pool
DataSources.destroy(dataSourcePooled);//shut down the pool
}
示例7: configure
import com.mchange.v2.c3p0.DataSources; //导入方法依赖的package包/类
public void configure(Properties props) throws HibernateException {
String jdbcDriverClass = props.getProperty(Environment.DRIVER);
String jdbcUrl = props.getProperty(Environment.URL);
Properties connectionProps = ConnectionProviderFactory.getConnectionProperties(props);
log.info("C3P0 using driver: " + jdbcDriverClass + " at URL: " + jdbcUrl);
log.info("Connection properties: " + connectionProps);
if (jdbcDriverClass==null) {
log.warn("No JDBC Driver class was specified by property " + Environment.DRIVER);
}
else {
try {
Class.forName(jdbcDriverClass);
}
catch (ClassNotFoundException cnfe) {
String msg = "JDBC Driver class not found: " + jdbcDriverClass;
log.fatal(msg);
throw new HibernateException(msg);
}
}
try {
int minPoolSize = PropertiesHelper.getInt(Environment.C3P0_MIN_SIZE, props, 1);
int maxPoolSize = PropertiesHelper.getInt(Environment.C3P0_MAX_SIZE, props, 100);
int maxIdleTime = PropertiesHelper.getInt(Environment.C3P0_TIMEOUT, props, 0);
int maxStatements = PropertiesHelper.getInt(Environment.C3P0_MAX_STATEMENTS, props, 0);
int acquireIncrement = PropertiesHelper.getInt(Environment.C3P0_ACQUIRE_INCREMENT, props, 1);
int idleTestPeriod = PropertiesHelper.getInt(Environment.C3P0_IDLE_TEST_PERIOD, props, 0);
boolean validateConnection = PropertiesHelper.getBoolean(Environment.C3P0_VALIDATE_CONNECTION, props);
PoolConfig pcfg = new PoolConfig();
pcfg.setInitialPoolSize(minPoolSize);
pcfg.setMinPoolSize(minPoolSize);
pcfg.setMaxPoolSize(maxPoolSize);
pcfg.setAcquireIncrement(acquireIncrement);
pcfg.setMaxIdleTime(maxIdleTime);
pcfg.setMaxStatements(maxStatements);
pcfg.setTestConnectionOnCheckout(validateConnection);
pcfg.setIdleConnectionTestPeriod(idleTestPeriod);
/*DataSource unpooled = DataSources.unpooledDataSource(
jdbcUrl, props.getProperty(Environment.USER), props.getProperty(Environment.PASS)
);*/
DataSource unpooled = DataSources.unpooledDataSource(jdbcUrl, connectionProps);
ds = DataSources.pooledDataSource(unpooled, pcfg);
}
catch (Exception e) {
log.fatal("could not instantiate C3P0 connection pool", e);
throw new HibernateException("Could not instantiate C3P0 connection pool", e);
}
String i = props.getProperty(Environment.ISOLATION);
if (i==null) {
isolation=null;
}
else {
isolation = new Integer(i);
log.info( "JDBC isolation level: " + Environment.isolationLevelToString( isolation.intValue() ) );
}
}
示例8: openPooledDataSource
import com.mchange.v2.c3p0.DataSources; //导入方法依赖的package包/类
/**
* get the pooled datasource from c3p0 pool
*
* @param aDbType a supported database type.
* @param aDbUrl a connection url
* @param aUsername a username for the database
* @param aPassword a password for the database connection
* @return a DataSource a pooled data source
* @throws SQLException
*/
public DataSource openPooledDataSource(DBType aDbType, String aDbUrl, String aUsername, String aPassword) throws SQLException {
final DataSource unPooledDS = DataSources.unpooledDataSource(aDbUrl, aUsername, aPassword);
//override the default properties with ours
final Map<String, String> props = this.getPoolingProperties(aDbType);
return DataSources.pooledDataSource(unPooledDS, props);
}