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


Java PooledDataSource类代码示例

本文整理汇总了Java中org.apache.ibatis.datasource.pooled.PooledDataSource的典型用法代码示例。如果您正苦于以下问题:Java PooledDataSource类的具体用法?Java PooledDataSource怎么用?Java PooledDataSource使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


PooledDataSource类属于org.apache.ibatis.datasource.pooled包,在下文中一共展示了PooledDataSource类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createDefaultDataSource

import org.apache.ibatis.datasource.pooled.PooledDataSource; //导入依赖的package包/类
/**
     * create Default Datasource for in-memory database.
     * @return
     */
    private static DataSource createDefaultDataSource() {
//        JdbcDataSource ds = new JdbcDataSource();
//        ds.setURL("jdbc:h2:mem:taskana");
//        ds.setPassword("sa");
//        ds.setUser("sa");

        String jdbcDriver = "org.h2.Driver";
        String jdbcUrl = "jdbc:h2:mem:taskana";
        String dbUserName = "sa";
        String dbPassword = "sa";
        DataSource ds = new PooledDataSource(Thread.currentThread().getContextClassLoader(), jdbcDriver,
                jdbcUrl, dbUserName, dbPassword);
        ((PooledDataSource) ds).setPoolTimeToWait(POOL_TIME_TO_WAIT);
        ((PooledDataSource) ds).forceCloseAll();  // otherwise the MyBatis pool is not initialized correctly

        return ds;
    }
 
开发者ID:Taskana,项目名称:taskana,代码行数:22,代码来源:TaskanaEngineConfigurationTest.java

示例2: DBManager

import org.apache.ibatis.datasource.pooled.PooledDataSource; //导入依赖的package包/类
public DBManager(AppConfiguration appConfig) {

        this.appConfig = appConfig;

        boolean isDev = appConfig.getBool(CONFIG_KEY_APP_DEV_MODE, true);

        String dbHost = appConfig.get(CONFIG_KEY_MYSQL_HOST, DEFAULT_MYSQL_HOST);
        int dbPort = appConfig.getInt(CONFIG_KEY_MYSQL_PORT, DEFAULT_MYSQL_PORT);
        String dbName = appConfig.get(CONFIG_KEY_MYSQL_DBNAME, DEFAULT_MEYSQL_DBNAME);
        String dbUser = appConfig.get(CONFIG_KEY_MYSQL_USER, "");
        String dbPass = appConfig.get(CONFIG_KEY_MYSQL_PASS, "");
        String dbDriver = "com.mysql.cj.jdbc.Driver";
        String connString = "jdbc:mysql://" + dbHost + ":" + dbPort + "/" + dbName + "?autoReconnect=true&useSSL=false&useUnicode=true";

        DataSource dataSource = new PooledDataSource(dbDriver, connString, dbUser, dbPass);
        TransactionFactory transactionFactory = new JdbcTransactionFactory();
        Environment environment = new Environment(isDev ? "development" : "production", transactionFactory, dataSource);
        configuration = new Configuration(environment);

        configuration.addMappers("com.elune.dao");

        sqlSessionFactory = new SqlSessionFactoryBuilder().build(configuration);
    }
 
开发者ID:thundernet8,项目名称:Elune,代码行数:24,代码来源:DBManager.java

示例3: createPoolMetrics

import org.apache.ibatis.datasource.pooled.PooledDataSource; //导入依赖的package包/类
private void createPoolMetrics() {
  DataSource dataSource = sessionFactory.getConfiguration().getEnvironment().getDataSource();
  // Should not fail because we specify a PoolDataSource in DbModule
  PoolState poolState = ((PooledDataSource) dataSource).getPoolState();

  createPoolGauge("requests", poolState::getRequestCount);
  createPoolGauge("average_request_time_ms", poolState::getAverageRequestTime);
  createPoolGauge("average_wait_time_ms", poolState::getAverageWaitTime);
  createPoolGauge("connections_had_to_wait", poolState::getHadToWaitCount);
  createPoolGauge("bad_connections", poolState::getBadConnectionCount);
  createPoolGauge("claimed_overdue_connections", poolState::getClaimedOverdueConnectionCount);
  createPoolGauge("average_overdue_checkout_time_ms", poolState::getAverageOverdueCheckoutTime);
  createPoolGauge("average_checkout_time_ms", poolState::getAverageCheckoutTime);
  createPoolGauge("idle_connections", poolState::getIdleConnectionCount);
  createPoolGauge("active_connections", poolState::getActiveConnectionCount);
}
 
开发者ID:PacktPublishing,项目名称:Mastering-Mesos,代码行数:17,代码来源:DbStorage.java

示例4: testForceCloseMybatisConnectionPoolTrue

import org.apache.ibatis.datasource.pooled.PooledDataSource; //导入依赖的package包/类
@Test
public void testForceCloseMybatisConnectionPoolTrue() {

  // given
  // that the process engine is configured with forceCloseMybatisConnectionPool = true
  ProcessEngineConfigurationImpl configurationImpl = new StandaloneInMemProcessEngineConfiguration()
   .setJdbcUrl("jdbc:h2:mem:camunda-forceclose")
   .setProcessEngineName("engine-forceclose")
   .setForceCloseMybatisConnectionPool(true);

  ProcessEngine processEngine = configurationImpl
   .buildProcessEngine();

  PooledDataSource pooledDataSource = (PooledDataSource) configurationImpl.getDataSource();
  PoolState state = pooledDataSource.getPoolState();


  // then
  // if the process engine is closed
  processEngine.close();

  // the idle connections are closed
  Assert.assertTrue(state.getIdleConnectionCount() == 0);

}
 
开发者ID:camunda,项目名称:camunda-bpm-platform,代码行数:26,代码来源:ForceCloseMybatisConnectionPoolTest.java

示例5: getMySQLDataSource

import org.apache.ibatis.datasource.pooled.PooledDataSource; //导入依赖的package包/类
private DataSource getMySQLDataSource() {
    PooledDataSource ds = new PooledDataSource();

    ds.setDriver("com.mysql.cj.jdbc.Driver");
    ds.setUrl("jdbc:mysql://localhost:3306/db_example");
    ds.setUsername("tully");
    ds.setPassword("tully");

    return ds;
}
 
开发者ID:vitaly-chibrikov,项目名称:otus_java_2017_06,代码行数:11,代码来源:MainAnnotationsExample.java

示例6: getH2DataSource

import org.apache.ibatis.datasource.pooled.PooledDataSource; //导入依赖的package包/类
private DataSource getH2DataSource() {
    PooledDataSource ds = new PooledDataSource();

    ds.setDriver("org.h2.Driver");
    ds.setUrl("jdbc:h2:mem:test");

    return ds;
}
 
开发者ID:vitaly-chibrikov,项目名称:otus_java_2017_06,代码行数:9,代码来源:MainAnnotationsExample.java

示例7: getH2DataSource

import org.apache.ibatis.datasource.pooled.PooledDataSource; //导入依赖的package包/类
private DataSource getH2DataSource() {
    PooledDataSource ds = new PooledDataSource();

    ds.setDriver("org.h2.Driver");
    ds.setUrl("jdbc:h2:mem:test");
    ds.setUsername("sa");

    return ds;
}
 
开发者ID:vitaly-chibrikov,项目名称:otus_java_2017_10,代码行数:10,代码来源:MainAnnotationsExample.java

示例8: shouldProperlyMaintainPoolOf3ActiveAnd2IdleConnections

import org.apache.ibatis.datasource.pooled.PooledDataSource; //导入依赖的package包/类
@Test
public void shouldProperlyMaintainPoolOf3ActiveAnd2IdleConnections() throws Exception {
  PooledDataSource ds = createPooledDataSource(JPETSTORE_PROPERTIES);
  try {
    runScript(ds, JPETSTORE_DDL);
    ds.setDefaultAutoCommit(false);
    ds.setDriverProperties(new Properties() {
      {
        setProperty("username", "sa");
        setProperty("password", "");
      }
    });
    ds.setPoolMaximumActiveConnections(3);
    ds.setPoolMaximumIdleConnections(2);
    ds.setPoolMaximumCheckoutTime(10000);
    ds.setPoolPingConnectionsNotUsedFor(1);
    ds.setPoolPingEnabled(true);
    ds.setPoolPingQuery("SELECT * FROM PRODUCT");
    ds.setPoolTimeToWait(10000);
    ds.setLogWriter(null);
    List<Connection> connections = new ArrayList<Connection>();
    for (int i = 0; i < 3; i++) {
      connections.add(ds.getConnection());
    }
    assertEquals(3, ds.getPoolState().getActiveConnectionCount());
    for (Connection c : connections) {
      c.close();
    }
    assertEquals(2, ds.getPoolState().getIdleConnectionCount());
    assertEquals(4, ds.getPoolState().getRequestCount());
    assertEquals(0, ds.getPoolState().getBadConnectionCount());
    assertEquals(0, ds.getPoolState().getHadToWaitCount());
    assertEquals(0, ds.getPoolState().getAverageOverdueCheckoutTime());
    assertEquals(0, ds.getPoolState().getClaimedOverdueConnectionCount());
    assertEquals(0, ds.getPoolState().getAverageWaitTime());
    assertNotNull(ds.getPoolState().toString());
  } finally {
    ds.forceCloseAll();
  }
}
 
开发者ID:yuexiahandao,项目名称:MybatisCode,代码行数:41,代码来源:PooledDataSourceTest.java

示例9: shouldNotFailCallingToStringOverAnInvalidConnection

import org.apache.ibatis.datasource.pooled.PooledDataSource; //导入依赖的package包/类
@Test
public void shouldNotFailCallingToStringOverAnInvalidConnection() throws Exception {
  PooledDataSource ds = createPooledDataSource(JPETSTORE_PROPERTIES);
  Connection c = ds.getConnection();
  c.close();
  c.toString();
}
 
开发者ID:yuexiahandao,项目名称:MybatisCode,代码行数:8,代码来源:PooledDataSourceTest.java

示例10: assertProductsTableExistsAndLoaded

import org.apache.ibatis.datasource.pooled.PooledDataSource; //导入依赖的package包/类
private void assertProductsTableExistsAndLoaded() throws IOException, SQLException {
  PooledDataSource ds = createPooledDataSource(JPETSTORE_PROPERTIES);
  try {
    Connection conn = ds.getConnection();
    SqlRunner executor = new SqlRunner(conn);
    List<Map<String, Object>> products = executor.selectAll("SELECT * FROM PRODUCT");
    assertEquals(16, products.size());
  } finally {
    ds.forceCloseAll();
  }
}
 
开发者ID:yuexiahandao,项目名称:MybatisCode,代码行数:12,代码来源:ScriptRunnerTest.java

示例11: createPooledDataSource

import org.apache.ibatis.datasource.pooled.PooledDataSource; //导入依赖的package包/类
public static PooledDataSource createPooledDataSource(String resource) throws IOException {
  Properties props = Resources.getResourceAsProperties(resource);
  PooledDataSource ds = new PooledDataSource();
  ds.setDriver(props.getProperty("driver"));
  ds.setUrl(props.getProperty("url"));
  ds.setUsername(props.getProperty("username"));
  ds.setPassword(props.getProperty("password"));
  return ds;
}
 
开发者ID:yuexiahandao,项目名称:MybatisCode,代码行数:10,代码来源:BaseDataTest.java

示例12: doLoad

import org.apache.ibatis.datasource.pooled.PooledDataSource; //导入依赖的package包/类
@Override
protected boolean doLoad() throws ModuleException {
	Properties driverProperties = new Properties();
	driverProperties.setProperty("driver.encoding", "UTF-8");
	//******* driverProperties *****
	//poolMaximumActiveConnections
	//poolMaximumIdleConnections
	//poolMaximumCheckoutTime
	//poolTimeToWait
	//poolPingQuery
	//poolPingEnabled
	//poolPingConnectionsNotUsedFor
	//////////////////////////////////
	
	PooledDataSource dataSource = new PooledDataSource(derbyEmbeddedDriver, dbPath, driverProperties);
	org.apache.ibatis.mapping.Environment environment = new org.apache.ibatis.mapping.Environment("ID", new JdbcTransactionFactory(), dataSource);
	Configuration configuration = new Configuration(environment);
	
	if(mapperFileList != null){
		for(URL mapperFile : mapperFileList){
			addSqlMappings(configuration, mapperFile);
		}
	}
	
	sqlSessionFactory = new SqlSessionFactoryBuilder().build(configuration);
	logger.info("DBModule[{}] Loaded! with {}", dbPath, mapperFileList);
	return true;
}
 
开发者ID:gncloud,项目名称:fastcatsearch3,代码行数:29,代码来源:InternalDBModule.java

示例13: testSessionCloseAndOpen

import org.apache.ibatis.datasource.pooled.PooledDataSource; //导入依赖的package包/类
@Test
public void testSessionCloseAndOpen() throws InterruptedException, IOException {
	
	String url = "jdbc:derby:/Users/swsong/TEST_HOME/fastcatsearch2_shard/node1/db/plugin";
	PooledDataSource dataSource = new PooledDataSource("org.apache.derby.jdbc.EmbeddedDriver", url, "", "");
	Environment environment = new Environment("ID", new JdbcTransactionFactory(), dataSource);
	Configuration configuration = new Configuration(environment);
	addSqlMappings(configuration, "org/fastcatsearch/db/TestMapper.xml");
	
	SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(configuration);
	
	long lap = System.nanoTime();
	for(int k =0;k <10; k++){
		System.out.println("Open session....");
		SqlSession session = sqlSessionFactory.openSession();
		System.out.println("Open session....Done");
		TestMapper setDictionaryMapper = session.getMapper(TestMapper.class);
		System.out.println("Got mapper!");
		
		//SetDictionaryVO vo = (SetDictionaryVO) session.selectOne("org.fastcatsearch.db.SetDictionaryMapper.selectWord", i);
		List<Map<String, Object>> list = setDictionaryMapper.selectList(0, 15, null);
		if(list != null){
			for(int i=0;i<list.size(); i++){
				Map<String, Object> vo = list.get(i);
//				System.out.println("------------");
				for(Map.Entry<String, Object> entry : vo.entrySet()){
//					System.out.println(entry.getKey() + "= " + entry.getValue());
				}
			}
		}
		session.close();
		
		System.out.println("lap time = "+(System.nanoTime() - lap)/1000000);
		lap = System.nanoTime();
	}
		
}
 
开发者ID:gncloud,项目名称:fastcatsearch3,代码行数:38,代码来源:MyBatisTest.java

示例14: testOpenTwice

import org.apache.ibatis.datasource.pooled.PooledDataSource; //导入依赖的package包/类
@Test
public void testOpenTwice() throws InterruptedException, IOException, SQLException {
	
	String url = "jdbc:derby:/Users/swsong/TEST_HOME/fastcatsearch2_shard/node1/db/plugin";
	PooledDataSource dataSource = new PooledDataSource("org.apache.derby.jdbc.EmbeddedDriver", url, "", "");
	Environment environment = new Environment("ID", new JdbcTransactionFactory(), dataSource);
	Configuration configuration = new Configuration(environment);
	addSqlMappings(configuration, "org/fastcatsearch/db/TestMapper.xml");
	
	System.out.println("----1----");
	SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(configuration);
	SqlSession session = sqlSessionFactory.openSession();
	TestMapper setDictionaryMapper = session.getMapper(TestMapper.class);
	Map<String, Object> vo = setDictionaryMapper.selectWord(1);
	System.out.println(vo);
	session.close();
	System.out.println(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource().getConnection());
	
	
	System.out.println("----2----");
	sqlSessionFactory = new SqlSessionFactoryBuilder().build(configuration);
	session = sqlSessionFactory.openSession();
	setDictionaryMapper = session.getMapper(TestMapper.class);
	vo = setDictionaryMapper.selectWord(1);
	System.out.println(vo);
	session.close();
		
}
 
开发者ID:gncloud,项目名称:fastcatsearch3,代码行数:29,代码来源:MyBatisTest.java

示例15: testMyBatisConnectionPoolProperlyConfigured

import org.apache.ibatis.datasource.pooled.PooledDataSource; //导入依赖的package包/类
public void testMyBatisConnectionPoolProperlyConfigured() {
    ProcessEngineConfigurationImpl config = (ProcessEngineConfigurationImpl) ProcessEngineConfiguration
            .createProcessEngineConfigurationFromResource("org/activiti/engine/test/db/connection-pool.flowable.cfg.xml");

    config.buildProcessEngine();

    // Expected values
    int maxActive = 25;
    int maxIdle = 10;
    int maxCheckoutTime = 30000;
    int maxWaitTime = 25000;

    assertEquals(maxActive, config.getJdbcMaxActiveConnections());
    assertEquals(maxIdle, config.getJdbcMaxIdleConnections());
    assertEquals(maxCheckoutTime, config.getJdbcMaxCheckoutTime());
    assertEquals(maxWaitTime, config.getJdbcMaxWaitTime());

    // Verify that these properties are correctly set in the MyBatis datasource
    DataSource datasource = config.getDbSqlSessionFactory().getSqlSessionFactory().getConfiguration().getEnvironment().getDataSource();
    assertTrue(datasource instanceof PooledDataSource);

    PooledDataSource pooledDataSource = (PooledDataSource) datasource;
    assertEquals(maxActive, pooledDataSource.getPoolMaximumActiveConnections());
    assertEquals(maxIdle, pooledDataSource.getPoolMaximumIdleConnections());
    assertEquals(maxCheckoutTime, pooledDataSource.getPoolMaximumCheckoutTime());
    assertEquals(maxWaitTime, pooledDataSource.getPoolTimeToWait());
}
 
开发者ID:flowable,项目名称:flowable-engine,代码行数:28,代码来源:ConnectionPoolTest.java


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