當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。