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


Java PoolingDataSource.close方法代码示例

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


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

示例1: actualDataSource

import bitronix.tm.resource.jdbc.PoolingDataSource; //导入方法依赖的package包/类
@Override
public DataSource actualDataSource() {
    final PoolingDataSource poolingDataSource = (PoolingDataSource) super.actualDataSource();
    com.vladmihalcea.flexypool.config.Configuration<PoolingDataSource> configuration = new com.vladmihalcea.flexypool.config.Configuration.Builder<>(
        getClass().getSimpleName(), poolingDataSource, BitronixPoolAdapter.FACTORY).build();

    FlexyPoolDataSource<PoolingDataSource> flexyPoolDataSource = new FlexyPoolDataSource<PoolingDataSource>(configuration) {
        @Override
        public void start() {
            poolingDataSource.init();
            super.start();
        }

        @Override
        public void stop() {
            super.stop();
            poolingDataSource.close();
        }
    };
    return flexyPoolDataSource;
}
 
开发者ID:vladmihalcea,项目名称:high-performance-java-persistence,代码行数:22,代码来源:JTAFlexyPoolTestConfiguration.java

示例2: testDefaultUserTransactionAndResources

import bitronix.tm.resource.jdbc.PoolingDataSource; //导入方法依赖的package包/类
public void testDefaultUserTransactionAndResources() throws Exception {
    PoolingDataSource pds = new PoolingDataSource();
    pds.setMaxPoolSize(1);
    pds.setClassName(MockitoXADataSource.class.getName());
    pds.setUniqueName("jdbc/pds");
    pds.init();

    Hashtable<String, String> env = new Hashtable<String, String>();
    env.put(Context.INITIAL_CONTEXT_FACTORY, BitronixInitialContextFactory.class.getName());
    Context ctx = new InitialContext(env);

    assertTrue(transactionManager == ctx.lookup("java:comp/UserTransaction"));

    try {
        ctx.lookup("aaa");
        fail("expected NameNotFoundException");
    } catch (NameNotFoundException ex) {
        assertEquals("unable to find a bound object at name 'aaa'", ex.getMessage());
    }

    assertTrue(pds == ctx.lookup("jdbc/pds"));

    ctx.close();

    pds.close();
}
 
开发者ID:bitronix,项目名称:btm,代码行数:27,代码来源:JndiTest.java

示例3: testAcquiringConnectionAfterRecoveryDoesNotMarkAsFailed

import bitronix.tm.resource.jdbc.PoolingDataSource; //导入方法依赖的package包/类
public void testAcquiringConnectionAfterRecoveryDoesNotMarkAsFailed() throws Exception {
    PoolingDataSource poolingDataSource = new PoolingDataSource();
    poolingDataSource.setClassName(MockitoXADataSource.class.getName());
    poolingDataSource.setUniqueName("ds1");
    poolingDataSource.setMaxPoolSize(1);
    poolingDataSource.setMaxIdleTime(1); // set low shrink timeout
    poolingDataSource.init();

    IncrementalRecoverer.recover(poolingDataSource);

    MockitoXADataSource.setStaticGetXAConnectionException(new SQLException("creating a new connection does not work"));
    Thread.sleep(2000); // wait for shrink

    // should not work but should not mark the pool as failed as it could recover
    try {
        poolingDataSource.getConnection();
        fail("expected SQLException");
    } catch (SQLException ex) {
        assertEquals("unable to get a connection from pool of a PoolingDataSource containing an XAPool of resource ds1 with 0 connection(s) (0 still available)", ex.getMessage());
    }

    poolingDataSource.close();
}
 
开发者ID:bitronix,项目名称:btm,代码行数:24,代码来源:JdbcFailedPoolTest.java

示例4: testFailingRecoveryMarksAsFailed

import bitronix.tm.resource.jdbc.PoolingDataSource; //导入方法依赖的package包/类
public void testFailingRecoveryMarksAsFailed() throws Exception {
    MockitoXADataSource.setStaticGetXAConnectionException(new SQLException("creating a new connection does not work"));

    PoolingDataSource poolingDataSource = new PoolingDataSource();
    poolingDataSource.setClassName(MockitoXADataSource.class.getName());
    poolingDataSource.setUniqueName("ds1");
    poolingDataSource.setMaxPoolSize(1);
    poolingDataSource.init();

    Recoverer recoverer = new Recoverer();
    recoverer.run();
    assertEquals("a PoolingDataSource containing an XAPool of resource ds1 with 0 connection(s) (0 still available) -failed-", poolingDataSource.toString());
    // recoverer must not unregister the resource
    assertSame(poolingDataSource, ResourceRegistrar.get("ds1"));

    MockitoXADataSource.setStaticGetXAConnectionException(null);

    recoverer.run();
    assertEquals("a PoolingDataSource containing an XAPool of resource ds1 with 1 connection(s) (1 still available)", poolingDataSource.toString());
    // recoverer must not unregister the resource
    assertSame(poolingDataSource, ResourceRegistrar.get("ds1"));

    poolingDataSource.close();
}
 
开发者ID:bitronix,项目名称:btm,代码行数:25,代码来源:JdbcFailedPoolTest.java

示例5: testRestartWithoutLoaderNoReuseResource

import bitronix.tm.resource.jdbc.PoolingDataSource; //导入方法依赖的package包/类
public void testRestartWithoutLoaderNoReuseResource() throws Exception {
    for (int i=0; i<3 ;i++) {
        PoolingDataSource pds = new PoolingDataSource();
        pds.setClassName(MockitoXADataSource.class.getName());
        pds.setUniqueName("ds");
        pds.setMaxPoolSize(1);
        pds.init();

        try {
            ResourceRegistrar.register(pds);
            fail("expected IllegalStateException");
        } catch (IllegalStateException ex) {
            String expected = "A resource with uniqueName 'ds' has already been registered";
            assertEquals(expected, ex.getMessage().substring(0, expected.length()));
        }

        BitronixTransactionManager tm = TransactionManagerServices.getTransactionManager();
        tm.shutdown();
        assertEquals(1, ResourceRegistrar.getResourcesUniqueNames().size());

        pds.close();
    }
}
 
开发者ID:bitronix,项目名称:btm,代码行数:24,代码来源:RestartTest.java

示例6: testRestartWithoutLoaderReuseResource

import bitronix.tm.resource.jdbc.PoolingDataSource; //导入方法依赖的package包/类
public void testRestartWithoutLoaderReuseResource() throws Exception {
    PoolingDataSource pds = new PoolingDataSource();
    pds.setClassName(MockitoXADataSource.class.getName());
    pds.setUniqueName("ds");
    pds.setMaxPoolSize(1);
    pds.init();

    for (int i=0; i<3 ;i++) {
        try {
            ResourceRegistrar.register(pds);
            fail("expected IllegalStateException");
        } catch (IllegalStateException ex) {
            String expected = "A resource with uniqueName 'ds' has already been registered";
            assertEquals(expected, ex.getMessage().substring(0, expected.length()));
        }

        BitronixTransactionManager tm = TransactionManagerServices.getTransactionManager();
        tm.shutdown();
        assertEquals(1, ResourceRegistrar.getResourcesUniqueNames().size());
    }

    pds.close();
}
 
开发者ID:bitronix,项目名称:btm,代码行数:24,代码来源:RestartTest.java

示例7: testPoolNotStartingTransactionManager

import bitronix.tm.resource.jdbc.PoolingDataSource; //导入方法依赖的package包/类
public void testPoolNotStartingTransactionManager() throws Exception {
    if (log.isDebugEnabled()) { log.debug("*** Starting testPoolNotStartingTransactionManager"); }
    // make sure TM is not running
    TransactionManagerServices.getTransactionManager().shutdown();

    PoolingDataSource pds = new PoolingDataSource();
    pds.setMinPoolSize(1);
    pds.setMaxPoolSize(2);
    pds.setMaxIdleTime(1);
    pds.setClassName(MockitoXADataSource.class.getName());
    pds.setUniqueName("pds2");
    pds.setAllowLocalTransactions(true);
    pds.setAcquisitionTimeout(1);
    pds.init();

    assertFalse(TransactionManagerServices.isTransactionManagerRunning());

    Connection c = pds.getConnection();
    Statement stmt = c.createStatement();
    stmt.close();
    c.close();

    assertFalse(TransactionManagerServices.isTransactionManagerRunning());

    pds.close();

    assertFalse(TransactionManagerServices.isTransactionManagerRunning());
}
 
开发者ID:bitronix,项目名称:btm,代码行数:29,代码来源:JdbcPoolTest.java

示例8: testCustomizerCall

import bitronix.tm.resource.jdbc.PoolingDataSource; //导入方法依赖的package包/类
@Test public void testCustomizerCall() throws Exception{
    String name = "pds";
    PoolingDataSource pds = new PoolingDataSource();
    pds.setUniqueName(name);
    pds.setXaDataSource(new MockitoXADataSource());
    pds.setMinPoolSize(1);
    pds.setMaxPoolSize(1);
    pds.setXaDataSource(new MockitoXADataSource());
    pds.addConnectionCustomizer(customizer);
    pds.init();

    Connection connection = pds.getConnection(); // onAcquire, onLease
    connection.close(); // onRelease

    connection = pds.getConnection(); // onLease
    connection.close(); // onRelease

    pds.close(); // onDestroy

    InOrder callOrder = inOrder(customizer);
    callOrder.verify(customizer).onAcquire(any(Connection.class), eq(name));
    callOrder.verify(customizer).onLease(any(Connection.class), eq(name));
    callOrder.verify(customizer).onRelease(any(Connection.class), eq(name));
    callOrder.verify(customizer).onLease(any(Connection.class), eq(name));
    callOrder.verify(customizer).onRelease(any(Connection.class), eq(name));
    callOrder.verify(customizer).onDestroy(any(Connection.class), eq(name));
}
 
开发者ID:bitronix,项目名称:btm,代码行数:28,代码来源:ConnectionCustomizerTest.java

示例9: testNoRestartOfTaskSchedulerDuringClose

import bitronix.tm.resource.jdbc.PoolingDataSource; //导入方法依赖的package包/类
public void testNoRestartOfTaskSchedulerDuringClose() throws Exception {
    PoolingDataSource pds = new PoolingDataSource();
    pds.setClassName(MockitoXADataSource.class.getName());
    pds.setMaxPoolSize(1);
    pds.setUniqueName("mock");
    pds.init();

    BitronixTransactionManager btm = TransactionManagerServices.getTransactionManager();
    btm.shutdown();

    pds.close();

    assertFalse(TransactionManagerServices.isTaskSchedulerRunning());
}
 
开发者ID:bitronix,项目名称:btm,代码行数:15,代码来源:XAPoolTest.java

示例10: testRecycleAfterSuspend

import bitronix.tm.resource.jdbc.PoolingDataSource; //导入方法依赖的package包/类
public void testRecycleAfterSuspend() throws Exception {
    PoolingDataSource pds = new PoolingDataSource();
    pds.setClassName(LrcXADataSource.class.getName());
    pds.setUniqueName("lrc-pds");
    pds.setMaxPoolSize(2);
    pds.getDriverProperties().setProperty("driverClassName", MockDriver.class.getName());
    pds.init();

    btm.begin();

    Connection c1 = pds.getConnection();
    c1.createStatement();
    c1.close();

    Transaction tx = btm.suspend();

        btm.begin();

        Connection c11 = pds.getConnection();
        c11.createStatement();
        c11.close();

        btm.commit();


    btm.resume(tx);

    Connection c2 = pds.getConnection();
    c2.createStatement();
    c2.close();

    btm.commit();

    pds.close();
}
 
开发者ID:bitronix,项目名称:btm,代码行数:36,代码来源:JtaTest.java

示例11: testSuccessfulRecoveryMarksAsNotFailed

import bitronix.tm.resource.jdbc.PoolingDataSource; //导入方法依赖的package包/类
public void testSuccessfulRecoveryMarksAsNotFailed() throws Exception {
    MockitoXADataSource.setStaticGetXAConnectionException(new SQLException("creating a new connection does not work"));

    PoolingDataSource poolingDataSource = new PoolingDataSource();
    poolingDataSource.setClassName(MockitoXADataSource.class.getName());
    poolingDataSource.setUniqueName("ds1");
    poolingDataSource.setMaxPoolSize(1);
    poolingDataSource.init();

    try {
        IncrementalRecoverer.recover(poolingDataSource);
        fail("expected RecoveryException");
    } catch (RecoveryException ex) {
        assertEquals("cannot start recovery on a PoolingDataSource containing an XAPool of resource ds1 with 0 connection(s) (0 still available)", ex.getMessage());
    }

    assertEquals("a PoolingDataSource containing an XAPool of resource ds1 with 0 connection(s) (0 still available) -failed-", poolingDataSource.toString());

    MockitoXADataSource.setStaticGetXAConnectionException(null);

    Recoverer recoverer = new Recoverer();
    recoverer.run();
    assertEquals("a PoolingDataSource containing an XAPool of resource ds1 with 1 connection(s) (1 still available)", poolingDataSource.toString());
    // recoverer must not unregister the resource
    assertSame(poolingDataSource, ResourceRegistrar.get("ds1"));

    poolingDataSource.close();
}
 
开发者ID:bitronix,项目名称:btm,代码行数:29,代码来源:JdbcFailedPoolTest.java

示例12: testRegisterTwoLrc

import bitronix.tm.resource.jdbc.PoolingDataSource; //导入方法依赖的package包/类
public void testRegisterTwoLrc() throws Exception {
    BitronixTransactionManager tm = TransactionManagerServices.getTransactionManager();

    PoolingDataSource lrcDs1 = new PoolingDataSource();
    lrcDs1.setClassName(LrcXADataSource.class.getName());
    lrcDs1.setUniqueName(DATASOURCE1_NAME + "_lrc");
    lrcDs1.setMinPoolSize(POOL_SIZE);
    lrcDs1.setMaxPoolSize(POOL_SIZE);
    lrcDs1.setAllowLocalTransactions(true);
    lrcDs1.getDriverProperties().setProperty("driverClassName", MockDriver.class.getName());
    lrcDs1.getDriverProperties().setProperty("url", "");
    lrcDs1.init();

    PoolingDataSource lrcDs2 = new PoolingDataSource();
    lrcDs2.setClassName(LrcXADataSource.class.getName());
    lrcDs2.setUniqueName(DATASOURCE2_NAME + "_lrc");
    lrcDs2.setMinPoolSize(POOL_SIZE);
    lrcDs2.setMaxPoolSize(POOL_SIZE);
    lrcDs2.setAllowLocalTransactions(true);
    lrcDs2.getDriverProperties().setProperty("driverClassName", MockDriver.class.getName());
    lrcDs2.getDriverProperties().setProperty("url", "");
    lrcDs2.init();

    tm.begin();

    Connection c1 = lrcDs1.getConnection();
    c1.createStatement();
    c1.close();

    Connection c2 = lrcDs2.getConnection();
    try {
        c2.createStatement();
        fail("expected SQLException");
    } catch (SQLException ex) {
   	 assertTrue(ex.getMessage().startsWith("error enlisting a ConnectionJavaProxy of a JdbcPooledConnection from datasource pds2_lrc in state ACCESSIBLE with usage count 1 wrapping a JDBC LrcXAConnection on a JDBC LrcConnectionJavaProxy on Mock"));
        assertTrue(ex.getCause().getMessage().matches("cannot enlist more than one non-XA resource, tried enlisting an XAResourceHolderState with uniqueName=pds2_lrc XAResource=a JDBC LrcXAResource in state NO_TX with XID null, already enlisted: an XAResourceHolderState with uniqueName=pds1_lrc XAResource=a JDBC LrcXAResource in state STARTED \\(started\\) with XID a Bitronix XID .*"));
    }
    c2.close();

    tm.commit();

    lrcDs2.close();
    lrcDs1.close();
}
 
开发者ID:bitronix,项目名称:btm,代码行数:45,代码来源:NewJdbcWrongUsageMockTest.java

示例13: testRegisterTwoLrcJms

import bitronix.tm.resource.jdbc.PoolingDataSource; //导入方法依赖的package包/类
public void testRegisterTwoLrcJms() throws Exception {
    BitronixTransactionManager tm = TransactionManagerServices.getTransactionManager();

    PoolingConnectionFactory pcf = new PoolingConnectionFactory();
    pcf.setClassName(LrcXAConnectionFactory.class.getName());
    pcf.setUniqueName("pcf_lrc");
    pcf.setMaxPoolSize(1);
    pcf.getDriverProperties().setProperty("connectionFactoryClassName", MockConnectionFactory.class.getName());
    pcf.init();

    PoolingDataSource lrcDs2 = new PoolingDataSource();
    lrcDs2.setClassName(LrcXADataSource.class.getName());
    lrcDs2.setUniqueName(DATASOURCE2_NAME + "_lrc");
    lrcDs2.setMinPoolSize(POOL_SIZE);
    lrcDs2.setMaxPoolSize(POOL_SIZE);
    lrcDs2.setAllowLocalTransactions(true);
    lrcDs2.getDriverProperties().setProperty("driverClassName", MockDriver.class.getName());
    lrcDs2.getDriverProperties().setProperty("url", "");
    lrcDs2.init();

    tm.begin();

    javax.jms.Connection c = pcf.createConnection();
    javax.jms.Session s = c.createSession(true, 0);
    javax.jms.MessageProducer p = s.createProducer(null);
    p.send(null);
    c.close();

    Connection c2 = lrcDs2.getConnection();
    try {
        c2.createStatement();
        fail("expected SQLException");
    } catch (SQLException ex) {
   	 assertTrue(ex.getMessage().startsWith("error enlisting a ConnectionJavaProxy of a JdbcPooledConnection from datasource pds2_lrc in state ACCESSIBLE with usage count 1 wrapping a JDBC LrcXAConnection on a JDBC LrcConnectionJavaProxy on Mock"));
        assertTrue(ex.getCause().getMessage().startsWith("cannot enlist more than one non-XA resource, tried enlisting an XAResourceHolderState with uniqueName=pds2_lrc XAResource=a JDBC LrcXAResource in state NO_TX with XID null, already enlisted: an XAResourceHolderState with uniqueName=pcf_lrc XAResource=a JMS LrcXAResource in state STARTED of session Mock for Session"));
    }
    c2.close();

    tm.commit();

    lrcDs2.close();
    pcf.close();
}
 
开发者ID:bitronix,项目名称:btm,代码行数:44,代码来源:NewJdbcWrongUsageMockTest.java


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