本文整理汇总了Java中javax.resource.cci.ConnectionFactory.getConnection方法的典型用法代码示例。如果您正苦于以下问题:Java ConnectionFactory.getConnection方法的具体用法?Java ConnectionFactory.getConnection怎么用?Java ConnectionFactory.getConnection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.resource.cci.ConnectionFactory
的用法示例。
在下文中一共展示了ConnectionFactory.getConnection方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doGetConnection
import javax.resource.cci.ConnectionFactory; //导入方法依赖的package包/类
/**
* Actually obtain a CCI Connection from the given ConnectionFactory.
* Same as {@link #getConnection}, but throwing the original ResourceException.
* <p>Is aware of a corresponding Connection bound to the current thread, for example
* when using {@link CciLocalTransactionManager}. Will bind a Connection to the thread
* if transaction synchronization is active (e.g. if in a JTA transaction).
* <p>Directly accessed by {@link TransactionAwareConnectionFactoryProxy}.
* @param cf the ConnectionFactory to obtain Connection from
* @return a CCI Connection from the given ConnectionFactory
* @throws ResourceException if thrown by CCI API methods
* @see #doReleaseConnection
*/
public static Connection doGetConnection(ConnectionFactory cf) throws ResourceException {
Assert.notNull(cf, "No ConnectionFactory specified");
ConnectionHolder conHolder = (ConnectionHolder) TransactionSynchronizationManager.getResource(cf);
if (conHolder != null) {
return conHolder.getConnection();
}
logger.debug("Opening CCI Connection");
Connection con = cf.getConnection();
if (TransactionSynchronizationManager.isSynchronizationActive()) {
logger.debug("Registering transaction synchronization for CCI Connection");
conHolder = new ConnectionHolder(con);
conHolder.setSynchronizedWithTransaction(true);
TransactionSynchronizationManager.registerSynchronization(new ConnectionSynchronization(conHolder, cf));
TransactionSynchronizationManager.bindResource(cf, conHolder);
}
return con;
}
示例2: testRMERRInOnePCToTransactionRolledbackException
import javax.resource.cci.ConnectionFactory; //导入方法依赖的package包/类
/**
* Describe <code>testXAException</code> method here.
* @ejb.interface-method
*/
public void testRMERRInOnePCToTransactionRolledbackException()
{
try
{
InitialContext ctx = new InitialContext();
ConnectionFactory cf1 = (ConnectionFactory) ctx.lookup("java:/JBossTestCF");
TestConnection c1 = (TestConnection) cf1.getConnection();
try
{
c1.setFailInCommit(true, XAException.XAER_RMERR);
}
finally
{
c1.close();
}
}
catch (Exception e)
{
log.warn("Unexpected: ", e);
throw new EJBException("unexpected exception: " + e);
}
}
示例3: testXAExceptionToTransactionRolledbackException
import javax.resource.cci.ConnectionFactory; //导入方法依赖的package包/类
/**
* Describe <code>testXAException</code> method here.
* @ejb.interface-method
*/
public void testXAExceptionToTransactionRolledbackException()
{
try
{
InitialContext ctx = new InitialContext();
ConnectionFactory cf1 = (ConnectionFactory) ctx.lookup("java:/JBossTestCF");
ConnectionFactory cf2 = (ConnectionFactory) ctx.lookup("java:/JBossTestCF2");
Connection c1 = cf1.getConnection();
try
{
TestConnection c2 = (TestConnection) cf2.getConnection();
try
{
c2.setFailInPrepare(true, XAException.XA_RBROLLBACK);
}
finally
{
c2.close();
}
}
finally
{
c1.close();
}
}
catch (Exception e)
{
log.warn("Unexpected: ", e);
throw new EJBException("unexpected exception: " + e);
}
}
示例4: simulateConnectionError
import javax.resource.cci.ConnectionFactory; //导入方法依赖的package包/类
/**
* Similate a connection failure
*
* @ejb.interface-method
*/
public void simulateConnectionError()
{
log.info("Simulating connection error");
try
{
InitialContext ctx = new InitialContext();
ConnectionFactory cf = (ConnectionFactory) ctx.lookup("java:/JBossTestCF");
TestConnection c = (TestConnection) cf.getConnection();
try
{
c.simulateConnectionError();
}
finally
{
c.close();
}
}
catch (Exception e)
{
if (e.getMessage().equals("Simulated exception") == false)
{
log.warn("Unexpected: ", e);
throw new EJBException(e.getMessage());
}
else
{
sessionContext.setRollbackOnly();
}
}
}
示例5: getConnection
import javax.resource.cci.ConnectionFactory; //导入方法依赖的package包/类
/**
* Obtain a Connection from the given ConnectionFactory. Translates ResourceExceptions
* into the Spring hierarchy of unchecked generic data access exceptions, simplifying
* calling code and making any exception that is thrown more meaningful.
* <p>Is aware of a corresponding Connection bound to the current thread, for example
* when using {@link CciLocalTransactionManager}. Will bind a Connection to the thread
* if transaction synchronization is active (e.g. if in a JTA transaction).
* @param cf the ConnectionFactory to obtain Connection from
* @param spec the ConnectionSpec for the desired Connection (may be {@code null}).
* Note: If this is specified, a new Connection will be obtained for every call,
* without participating in a shared transactional Connection.
* @return a CCI Connection from the given ConnectionFactory
* @throws org.springframework.jca.cci.CannotGetCciConnectionException
* if the attempt to get a Connection failed
* @see #releaseConnection
*/
public static Connection getConnection(ConnectionFactory cf, ConnectionSpec spec)
throws CannotGetCciConnectionException {
try {
if (spec != null) {
Assert.notNull(cf, "No ConnectionFactory specified");
return cf.getConnection(spec);
}
else {
return doGetConnection(cf);
}
}
catch (ResourceException ex) {
throw new CannotGetCciConnectionException("Could not get CCI Connection", ex);
}
}