当前位置: 首页>>代码示例>>Java>>正文


Java DataSources类代码示例

本文整理汇总了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());
}
 
开发者ID:CloudSlang,项目名称:cs-actions,代码行数:25,代码来源:C3P0PooledDataSourceProviderTest.java

示例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();
		}
	}
}
 
开发者ID:javalover123,项目名称:full-hibernate-plugin-for-struts2,代码行数:14,代码来源:C3P0Util.java

示例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);
    }
}
 
开发者ID:pryzach,项目名称:midao,代码行数:18,代码来源:MjdbcPoolBinder.java

示例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);
}
 
开发者ID:pryzach,项目名称:midao,代码行数:12,代码来源:MjdbcPoolBinderTest.java

示例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);
}
 
开发者ID:pryzach,项目名称:midao,代码行数:17,代码来源:MjdbcPoolBinderTest.java

示例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;
}
 
开发者ID:MuOnlineRepositories,项目名称:MuOnline,代码行数:24,代码来源:DatabaseHelper.java

示例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;
   }
 
开发者ID:levants,项目名称:lightmare,代码行数:28,代码来源:InitC3p0.java

示例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();
        }
    }
}
 
开发者ID:fgulan,项目名称:java-course,代码行数:16,代码来源:ContextListener.java

示例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);
	}
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:9,代码来源:C3P0ConnectionProvider.java

示例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;
	////
	}
 
开发者ID:MasatoKokubo,项目名称:Lightsleep,代码行数:35,代码来源:C3p0.java

示例11: destroy

import com.mchange.v2.c3p0.DataSources; //导入依赖的package包/类
@Override
public void destroy() {
    try {
        DataSources.destroy(cpds);
    } catch (SQLException e) {
        e.printStackTrace();
    }
}
 
开发者ID:geetools,项目名称:geeCommerce-Java-Shop-Software-and-PIM,代码行数:9,代码来源:MySqlDatabaseConnection.java

示例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 );
	}
}
 
开发者ID:cacheonix,项目名称:cacheonix-core,代码行数:12,代码来源:C3P0ConnectionProvider.java

示例13: destroy

import com.mchange.v2.c3p0.DataSources; //导入依赖的package包/类
public void destroy() {
  try {
    DataSources.destroy(ds);
  } catch (SQLException e) {
    throw new RuntimeException(e);
  }
}
 
开发者ID:creichlin,项目名称:hops-db,代码行数:8,代码来源:Db.java

示例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);
}
 
开发者ID:CloudSlang,项目名称:cs-actions,代码行数:13,代码来源:C3P0PooledDataSourceProvider.java

示例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());
}
 
开发者ID:qoswork,项目名称:opennmszh,代码行数:28,代码来源:TemporaryDatabaseExecutionListener.java


注:本文中的com.mchange.v2.c3p0.DataSources类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。