本文整理汇总了Java中bitronix.tm.resource.jdbc.PoolingDataSource.getConnection方法的典型用法代码示例。如果您正苦于以下问题:Java PoolingDataSource.getConnection方法的具体用法?Java PoolingDataSource.getConnection怎么用?Java PoolingDataSource.getConnection使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类bitronix.tm.resource.jdbc.PoolingDataSource
的用法示例。
在下文中一共展示了PoolingDataSource.getConnection方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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();
}
示例2: 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());
}
示例3: 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));
}
示例4: 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();
}
示例5: setUp
import bitronix.tm.resource.jdbc.PoolingDataSource; //导入方法依赖的package包/类
@Override
protected void setUp() throws Exception {
Iterator<String> it = ResourceRegistrar.getResourcesUniqueNames().iterator();
while (it.hasNext()) {
String name = it.next();
ResourceRegistrar.unregister(ResourceRegistrar.get(name));
}
pds = new PoolingDataSource();
pds.setClassName(MockitoXADataSource.class.getName());
pds.setUniqueName("mock-xads");
pds.setMinPoolSize(1);
pds.setMaxPoolSize(1);
pds.init();
new File(TransactionManagerServices.getConfiguration().getLogPart1Filename()).delete();
new File(TransactionManagerServices.getConfiguration().getLogPart2Filename()).delete();
EventRecorder.clear();
Connection connection1 = pds.getConnection();
PooledConnectionProxy handle = (PooledConnectionProxy) connection1;
xaResource = (MockXAResource) handle.getPooledConnection().getXAResource();
connection1.close();
// test the clustered recovery as its logic is more complex and covers the non-clustered logic
TransactionManagerServices.getConfiguration().setCurrentNodeOnlyRecovery(true);
// recoverer needs the journal to be open to be run manually
journal = TransactionManagerServices.getJournal();
journal.open();
}
示例6: 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();
}
示例7: 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();
}
示例8: testLrc
import bitronix.tm.resource.jdbc.PoolingDataSource; //导入方法依赖的package包/类
public void testLrc() throws Exception {
Thread.currentThread().setName("testLrc");
PoolingDataSource poolingDataSource2 = new PoolingDataSource();
poolingDataSource2.setClassName(LrcXADataSource.class.getName());
poolingDataSource2.setUniqueName(DATASOURCE2_NAME + "_lrc");
poolingDataSource2.setMinPoolSize(POOL_SIZE);
poolingDataSource2.setMaxPoolSize(POOL_SIZE);
poolingDataSource2.setAllowLocalTransactions(true);
poolingDataSource2.getDriverProperties().setProperty("driverClassName", MockDriver.class.getName());
poolingDataSource2.getDriverProperties().setProperty("user", "user");
poolingDataSource2.getDriverProperties().setProperty("password", "password");
poolingDataSource2.init();
if (log.isDebugEnabled()) { log.debug("*** getting TM"); }
BitronixTransactionManager tm = TransactionManagerServices.getTransactionManager();
if (log.isDebugEnabled()) { log.debug("*** before begin"); }
tm.setTransactionTimeout(10);
tm.begin();
if (log.isDebugEnabled()) { log.debug("*** after begin"); }
if (log.isDebugEnabled()) { log.debug("*** getting connection from DS2"); }
Connection connection2 = poolingDataSource2.getConnection();
if (log.isDebugEnabled()) { log.debug("*** creating statement 1 on connection 2"); }
connection2.createStatement();
if (log.isDebugEnabled()) { log.debug("*** creating statement 2 on connection 2"); }
connection2.createStatement();
if (log.isDebugEnabled()) { log.debug("*** getting connection from DS1"); }
Connection connection1 = poolingDataSource1.getConnection();
if (log.isDebugEnabled()) { log.debug("*** creating statement 1 on connection 1"); }
connection1.createStatement();
if (log.isDebugEnabled()) { log.debug("*** creating statement 2 on connection 1"); }
connection1.createStatement();
if (log.isDebugEnabled()) { log.debug("*** closing connection 2"); }
connection2.close();
if (log.isDebugEnabled()) { log.debug("*** closing connection 1"); }
connection1.close();
if (log.isDebugEnabled()) { log.debug("*** committing"); }
tm.commit();
if (log.isDebugEnabled()) { log.debug("*** TX is done"); }
// check flow
List orderedEvents = EventRecorder.getOrderedEvents();
log.info(EventRecorder.dumpToString());
assertEquals(12, orderedEvents.size());
int i=0;
assertEquals(Status.STATUS_ACTIVE, ((JournalLogEvent) orderedEvents.get(i++)).getStatus());
assertEquals(DATASOURCE1_NAME, ((ConnectionDequeuedEvent) orderedEvents.get(i++)).getPooledConnectionImpl().getPoolingDataSource().getUniqueName());
assertEquals(XAResource.TMNOFLAGS, ((XAResourceStartEvent) orderedEvents.get(i++)).getFlag());
assertEquals(XAResource.TMSUCCESS, ((XAResourceEndEvent) orderedEvents.get(i++)).getFlag());
assertEquals(Status.STATUS_PREPARING, ((JournalLogEvent) orderedEvents.get(i++)).getStatus());
assertEquals(XAResource.XA_OK, ((XAResourcePrepareEvent) orderedEvents.get(i++)).getReturnCode());
assertEquals(LocalCommitEvent.class, orderedEvents.get(i++).getClass());
assertEquals(Status.STATUS_PREPARED, ((JournalLogEvent) orderedEvents.get(i++)).getStatus());
assertEquals(Status.STATUS_COMMITTING, ((JournalLogEvent) orderedEvents.get(i++)).getStatus());
assertEquals(false, ((XAResourceCommitEvent) orderedEvents.get(i++)).isOnePhase());
assertEquals(Status.STATUS_COMMITTED, ((JournalLogEvent) orderedEvents.get(i++)).getStatus());
assertEquals(DATASOURCE1_NAME, ((ConnectionQueuedEvent) orderedEvents.get(i++)).getPooledConnectionImpl().getPoolingDataSource().getUniqueName());
}