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


Java ConnectionFactory.getConnection方法代码示例

本文整理汇总了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;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:34,代码来源:ConnectionFactoryUtils.java

示例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);
    }
}
 
开发者ID:windup,项目名称:windup-rulesets,代码行数:30,代码来源:XAExceptionSessionBean.java

示例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);
    }
}
 
开发者ID:windup,项目名称:windup-rulesets,代码行数:37,代码来源:XAExceptionSessionBean.java

示例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();
        }
    }
}
 
开发者ID:windup,项目名称:windup-rulesets,代码行数:36,代码来源:XAExceptionSessionBean.java

示例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);
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:32,代码来源:ConnectionFactoryUtils.java


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