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


Java BasicDataSource.close方法代码示例

本文整理汇总了Java中org.apache.commons.dbcp2.BasicDataSource.close方法的典型用法代码示例。如果您正苦于以下问题:Java BasicDataSource.close方法的具体用法?Java BasicDataSource.close怎么用?Java BasicDataSource.close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.commons.dbcp2.BasicDataSource的用法示例。


在下文中一共展示了BasicDataSource.close方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: test

import org.apache.commons.dbcp2.BasicDataSource; //导入方法依赖的package包/类
@Test
public void test() throws SQLException {
  BasicDataSource dataSource = getDataSource("");

  JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
  jdbcTemplate.execute("CREATE TABLE employee (id INTEGER)");

  dataSource.close();

  List<MockSpan> finishedSpans = mockTracer.finishedSpans();
  assertEquals(1, finishedSpans.size());
  checkTags(finishedSpans, "myservice", "jdbc:hsqldb:mem:spring");
  checkSameTrace(finishedSpans);

  assertNull(mockTracer.scopeManager().active());
}
 
开发者ID:opentracing-contrib,项目名称:java-p6spy,代码行数:17,代码来源:SpringTest.java

示例2: testWithSpanOnlyWithParent

import org.apache.commons.dbcp2.BasicDataSource; //导入方法依赖的package包/类
@Test
public void testWithSpanOnlyWithParent() throws SQLException {
  try (Scope activeSpan = mockTracer.buildSpan("parent").startActive(true)) {
    BasicDataSource dataSource = getDataSource(";traceWithActiveSpanOnly=true");

    JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
    jdbcTemplate.execute("CREATE TABLE with_parent_skip (id INTEGER)");

    dataSource.close();
  }

  List<MockSpan> finishedSpans = mockTracer.finishedSpans();
  assertEquals(2, finishedSpans.size());
  checkSameTrace(finishedSpans);
  assertNull(mockTracer.scopeManager().active());
}
 
开发者ID:opentracing-contrib,项目名称:java-p6spy,代码行数:17,代码来源:SpringTest.java

示例3: spring

import org.apache.commons.dbcp2.BasicDataSource; //导入方法依赖的package包/类
@Test
public void spring() throws SQLException {
  BasicDataSource dataSource = getDataSource(false);

  JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
  jdbcTemplate.execute("CREATE TABLE employee (id INTEGER)");

  dataSource.close();

  List<MockSpan> finishedSpans = mockTracer.finishedSpans();
  assertEquals(1, finishedSpans.size());
  MockSpan mockSpan = finishedSpans.get(0);

  assertEquals(Tags.SPAN_KIND_CLIENT, mockSpan.tags().get(Tags.SPAN_KIND.getKey()));
  assertEquals(JdbcTracingUtils.COMPONENT_NAME, mockSpan.tags().get(Tags.COMPONENT.getKey()));
  assertThat(mockSpan.tags().get(Tags.DB_STATEMENT.getKey()).toString()).isNotEmpty();
  assertEquals("h2", mockSpan.tags().get(Tags.DB_TYPE.getKey()));
  assertEquals("sa", mockSpan.tags().get(Tags.DB_USER.getKey()));
  assertEquals(0, mockSpan.generatedErrors().size());

  assertNull(mockTracer.activeSpan());
}
 
开发者ID:opentracing-contrib,项目名称:java-jdbc,代码行数:23,代码来源:SpringTest.java

示例4: spring_with_parent

import org.apache.commons.dbcp2.BasicDataSource; //导入方法依赖的package包/类
@Test
public void spring_with_parent() throws Exception {
  try (Scope ignored = mockTracer.buildSpan("parent").startActive(true)) {
    BasicDataSource dataSource = getDataSource(false);

    JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
    jdbcTemplate.execute("CREATE TABLE with_parent_1 (id INTEGER)");
    jdbcTemplate.execute("CREATE TABLE with_parent_2 (id INTEGER)");

    dataSource.close();
  }

  List<MockSpan> spans = mockTracer.finishedSpans();
  assertEquals(3, spans.size());

  checkSameTrace(spans);
}
 
开发者ID:opentracing-contrib,项目名称:java-jdbc,代码行数:18,代码来源:SpringTest.java

示例5: spring_with_parent_and_active_span_only

import org.apache.commons.dbcp2.BasicDataSource; //导入方法依赖的package包/类
@Test
public void spring_with_parent_and_active_span_only() throws Exception {
  try (Scope ignored = mockTracer.buildSpan("parent").startActive(true)) {
    BasicDataSource dataSource = getDataSource(true);

    JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
    jdbcTemplate.execute("CREATE TABLE with_parent_skip_1 (id INTEGER)");
    jdbcTemplate.execute("CREATE TABLE with_parent_skip_2 (id INTEGER)");

    dataSource.close();
  }

  List<MockSpan> spans = mockTracer.finishedSpans();
  assertEquals(3, spans.size());

  checkSameTrace(spans);
}
 
开发者ID:opentracing-contrib,项目名称:java-jdbc,代码行数:18,代码来源:SpringTest.java

示例6: shutdownBasicDataSources

import org.apache.commons.dbcp2.BasicDataSource; //导入方法依赖的package包/类
/**
 * 關閉
 *
 * @return
 */
protected BasicDataSource[] shutdownBasicDataSources() throws Exception {
	try {
		if (this.basicDataSources != null) {
			for (int i = 0; i < this.basicDataSources.length; i++) {
				BasicDataSource oldInstance = this.basicDataSources[i];
				oldInstance.close();
				this.basicDataSources[i] = null;
			}
			//
			this.basicDataSources = null;
		}
	} catch (Exception e) {
		LOGGER.error(new StringBuilder("Exception encountered during shutdownBasicDataSources()").toString(), e);
		throw e;
	}
	return this.basicDataSources;
}
 
开发者ID:mixaceh,项目名称:openyu-commons,代码行数:23,代码来源:BasicDataSourceGroupFactoryBean.java

示例7: testWithSpanOnlyNoParent

import org.apache.commons.dbcp2.BasicDataSource; //导入方法依赖的package包/类
@Test
public void testWithSpanOnlyNoParent() throws SQLException {
  BasicDataSource dataSource = getDataSource(";traceWithActiveSpanOnly=true");

  JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
  jdbcTemplate.execute("CREATE TABLE skip_new_spans (id INTEGER)");

  dataSource.close();

  List<MockSpan> finishedSpans = mockTracer.finishedSpans();
  assertEquals(0, finishedSpans.size());

  assertNull(mockTracer.scopeManager().active());
}
 
开发者ID:opentracing-contrib,项目名称:java-p6spy,代码行数:15,代码来源:SpringTest.java

示例8: batch

import org.apache.commons.dbcp2.BasicDataSource; //导入方法依赖的package包/类
@Test
public void batch() throws SQLException {
  BasicDataSource dataSource = getDataSource(false);

  JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
  jdbcTemplate.execute("CREATE TABLE batch (id INTEGER)");

  final List<Integer> ids = Arrays.asList(1, 2, 3, 4, 5);
  jdbcTemplate.batchUpdate("INSERT INTO batch (id) VALUES (?)",
      new BatchPreparedStatementSetter() {
        @Override
        public void setValues(PreparedStatement preparedStatement, int i) throws SQLException {
          preparedStatement.setInt(1, ids.get(i));
        }

        @Override
        public int getBatchSize() {
          return ids.size();
        }
      }
  );

  dataSource.close();

  List<MockSpan> spans = mockTracer.finishedSpans();
  assertEquals(2, spans.size());

  for (MockSpan span : spans) {
    assertEquals(Tags.SPAN_KIND_CLIENT, span.tags().get(Tags.SPAN_KIND.getKey()));
    assertEquals(JdbcTracingUtils.COMPONENT_NAME, span.tags().get(Tags.COMPONENT.getKey()));
    assertThat(span.tags().get(Tags.DB_STATEMENT.getKey()).toString()).isNotEmpty();
    assertEquals("h2", span.tags().get(Tags.DB_TYPE.getKey()));
    assertEquals("sa", span.tags().get(Tags.DB_USER.getKey()));
    assertEquals(0, span.generatedErrors().size());
  }

  assertNull(mockTracer.activeSpan());
}
 
开发者ID:opentracing-contrib,项目名称:java-jdbc,代码行数:39,代码来源:SpringTest.java

示例9: spring_active_span_only

import org.apache.commons.dbcp2.BasicDataSource; //导入方法依赖的package包/类
@Test
public void spring_active_span_only() throws Exception {
  BasicDataSource dataSource = getDataSource(true);

  JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
  jdbcTemplate.execute("CREATE TABLE skip_new_spans (id INTEGER)");

  dataSource.close();

  List<MockSpan> finishedSpans = mockTracer.finishedSpans();
  assertEquals(0, finishedSpans.size());
}
 
开发者ID:opentracing-contrib,项目名称:java-jdbc,代码行数:13,代码来源:SpringTest.java

示例10: afterAll

import org.apache.commons.dbcp2.BasicDataSource; //导入方法依赖的package包/类
@Override
public void afterAll(final TestInvocation invocation) throws Exception {
    final ExecutionContext context = invocation.getContext();
    final BasicDataSource ds = (BasicDataSource) context.getData(Constants.KEY_DATA_SOURCE);
    ds.close();
    context.storeData(Constants.KEY_DATA_SOURCE, null);
}
 
开发者ID:dadrus,项目名称:jpa-unit,代码行数:8,代码来源:DataSourceDecorator.java

示例11: closeAll

import org.apache.commons.dbcp2.BasicDataSource; //导入方法依赖的package包/类
public void closeAll() throws SQLException {
    for (BasicDataSource datasource : cache.asMap().values()) {
        LOG.info("close DataSource:" + datasource);
        datasource.close();
    }
    cache.invalidateAll();
}
 
开发者ID:bitnine-oss,项目名称:octopus,代码行数:8,代码来源:JdbcUtils.java

示例12: shutdownBasicDataSource

import org.apache.commons.dbcp2.BasicDataSource; //导入方法依赖的package包/类
/**
 * 關閉
 *
 * @return
 */
protected BasicDataSource shutdownBasicDataSource() throws Exception {
	try {
		if (this.basicDataSource != null) {
			BasicDataSource oldInstance = this.basicDataSource;
			oldInstance.close();
			this.basicDataSource = null;
		}
	} catch (Exception e) {
		LOGGER.error(new StringBuilder("Exception encountered during shutdownBasicDataSource()").toString(), e);
		throw e;
	}
	return this.basicDataSource;
}
 
开发者ID:mixaceh,项目名称:openyu-commons,代码行数:19,代码来源:BasicDataSourceFactoryBean.java

示例13: shutdownDataSource

import org.apache.commons.dbcp2.BasicDataSource; //导入方法依赖的package包/类
public static void shutdownDataSource(DataSource ds) throws SQLException {
    BasicDataSource bds = (BasicDataSource) ds;
    bds.close();
}
 
开发者ID:apache,项目名称:commons-dbcp,代码行数:5,代码来源:BasicDataSourceExample.java

示例14: passivateDataSourcePool

import org.apache.commons.dbcp2.BasicDataSource; //导入方法依赖的package包/类
@Override
protected void passivateDataSourcePool( BasicDataSource dataSourcePool )
        throws Exception
{
    dataSourcePool.close();
}
 
开发者ID:apache,项目名称:polygene-java,代码行数:7,代码来源:DBCPDataSourceServiceImporter.java


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