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


Java TransactionSystemException类代码示例

本文整理汇总了Java中org.springframework.transaction.TransactionSystemException的典型用法代码示例。如果您正苦于以下问题:Java TransactionSystemException类的具体用法?Java TransactionSystemException怎么用?Java TransactionSystemException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: doRollback

import org.springframework.transaction.TransactionSystemException; //导入依赖的package包/类
@Override
protected void doRollback(DefaultTransactionStatus status) {
	JpaTransactionObject txObject = (JpaTransactionObject) status.getTransaction();
	if (status.isDebug()) {
		logger.debug("Rolling back JPA transaction on EntityManager [" +
				txObject.getEntityManagerHolder().getEntityManager() + "]");
	}
	try {
		EntityTransaction tx = txObject.getEntityManagerHolder().getEntityManager().getTransaction();
		if (tx.isActive()) {
			tx.rollback();
		}
	}
	catch (PersistenceException ex) {
		throw new TransactionSystemException("Could not roll back JPA transaction", ex);
	}
	finally {
		if (!txObject.isNewEntityManagerHolder()) {
			// Clear all pending inserts/updates/deletes in the EntityManager.
			// Necessary for pre-bound EntityManagers, to avoid inconsistent state.
			txObject.getEntityManagerHolder().getEntityManager().clear();
		}
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:25,代码来源:JpaTransactionManager.java

示例2: doRollback

import org.springframework.transaction.TransactionSystemException; //导入依赖的package包/类
@Override
protected void doRollback(DefaultTransactionStatus status) {
	JdoTransactionObject txObject = (JdoTransactionObject) status.getTransaction();
	if (status.isDebug()) {
		logger.debug("Rolling back JDO transaction on PersistenceManager [" +
				txObject.getPersistenceManagerHolder().getPersistenceManager() + "]");
	}
	try {
		Transaction tx = txObject.getPersistenceManagerHolder().getPersistenceManager().currentTransaction();
		if (tx.isActive()) {
			tx.rollback();
		}
	}
	catch (JDOException ex) {
		throw new TransactionSystemException("Could not roll back JDO transaction", ex);
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:18,代码来源:JdoTransactionManager.java

示例3: testTransactionWithExceptionOnCommit

import org.springframework.transaction.TransactionSystemException; //导入依赖的package包/类
@Test
public void testTransactionWithExceptionOnCommit() throws Exception {
	willThrow(new SQLException("Cannot commit")).given(con).commit();

	TransactionTemplate tt = new TransactionTemplate(tm);
	try {
		tt.execute(new TransactionCallbackWithoutResult() {
			@Override
			protected void doInTransactionWithoutResult(TransactionStatus status) {
				// something transactional
			}
		});
		fail("Should have thrown TransactionSystemException");
	}
	catch (TransactionSystemException ex) {
		// expected
	}

	assertTrue("Hasn't thread connection", !TransactionSynchronizationManager.hasResource(ds));
	verify(con).close();
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:22,代码来源:DataSourceTransactionManagerTests.java

示例4: testTransactionWithExceptionOnCommitAndRollbackOnCommitFailure

import org.springframework.transaction.TransactionSystemException; //导入依赖的package包/类
@Test
public void testTransactionWithExceptionOnCommitAndRollbackOnCommitFailure() throws Exception {
	willThrow(new SQLException("Cannot commit")).given(con).commit();

	tm.setRollbackOnCommitFailure(true);
	TransactionTemplate tt = new TransactionTemplate(tm);
	try {
		tt.execute(new TransactionCallbackWithoutResult() {
			@Override
			protected void doInTransactionWithoutResult(TransactionStatus status) {
				// something transactional
			}
		});
		fail("Should have thrown TransactionSystemException");
	}
	catch (TransactionSystemException ex) {
		// expected
	}

	assertTrue("Hasn't thread connection", !TransactionSynchronizationManager.hasResource(ds));
	verify(con).rollback();
	verify(con).close();
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:24,代码来源:DataSourceTransactionManagerTests.java

示例5: testTransactionWithExceptionOnRollback

import org.springframework.transaction.TransactionSystemException; //导入依赖的package包/类
@Test
public void testTransactionWithExceptionOnRollback() throws Exception {
	given(con.getAutoCommit()).willReturn(true);
	willThrow(new SQLException("Cannot rollback")).given(con).rollback();

	TransactionTemplate tt = new TransactionTemplate(tm);
	try {
		tt.execute(new TransactionCallbackWithoutResult() {
			@Override
			protected void doInTransactionWithoutResult(TransactionStatus status) throws RuntimeException {
				status.setRollbackOnly();
			}
		});
		fail("Should have thrown TransactionSystemException");
	}
	catch (TransactionSystemException ex) {
		// expected
	}

	assertTrue("Hasn't thread connection", !TransactionSynchronizationManager.hasResource(ds));
	InOrder ordered = inOrder(con);
	ordered.verify(con).setAutoCommit(false);
	ordered.verify(con).rollback();
	ordered.verify(con).setAutoCommit(true);
	verify(con).close();
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:27,代码来源:DataSourceTransactionManagerTests.java

示例6: doCommit

import org.springframework.transaction.TransactionSystemException; //导入依赖的package包/类
@Override
protected void doCommit(DefaultTransactionStatus status) {
	DataSourceTransactionObject txObject = (DataSourceTransactionObject) status.getTransaction();
	Connection con = txObject.getConnectionHolder().getConnection();
	if (status.isDebug()) {
		logger.debug("Committing JDBC transaction on Connection [" + con + "]");
	}
	try {
		con.commit();
	}
	catch (SQLException ex) {
		throw new TransactionSystemException("Could not commit JDBC transaction", ex);
	}
	
	/**modify by guosg 这里提交ldtm事务*/
	SynchronizationManager.getCurrentUserTransation().commit();
}
 
开发者ID:gsgsdtc,项目名称:ldtm,代码行数:18,代码来源:LdtmDataSourceTransactionManager.java

示例7: doRollback

import org.springframework.transaction.TransactionSystemException; //导入依赖的package包/类
@Override
protected void doRollback(DefaultTransactionStatus status) {
	DataSourceTransactionObject txObject = (DataSourceTransactionObject) status.getTransaction();
	Connection con = txObject.getConnectionHolder().getConnection();
	if (status.isDebug()) {
		logger.debug("Rolling back JDBC transaction on Connection [" + con + "]");
	}
	try {
		con.rollback();
	}
	catch (SQLException ex) {
		throw new TransactionSystemException("Could not roll back JDBC transaction", ex);
	}
	
	/**modify by guosg 这里提交回滚事务*/
	SynchronizationManager.getCurrentUserTransation().rollback();
}
 
开发者ID:gsgsdtc,项目名称:ldtm,代码行数:18,代码来源:LdtmDataSourceTransactionManager.java

示例8: lookupTransactionSynchronizationRegistry

import org.springframework.transaction.TransactionSystemException; //导入依赖的package包/类
/**
 * Look up the JTA 1.1 TransactionSynchronizationRegistry in JNDI via the configured name.
 * <p>Can be overridden in subclasses to provide a different TransactionManager object.
 * @param registryName the JNDI name of the
 * TransactionSynchronizationRegistry
 * @return the TransactionSynchronizationRegistry object
 * @throws TransactionSystemException if the JNDI lookup failed
 * @see #setJndiTemplate
 * @see #setTransactionSynchronizationRegistryName
 */
protected Object lookupTransactionSynchronizationRegistry(String registryName) throws TransactionSystemException {
	if (transactionSynchronizationRegistryClass == null) {
		throw new TransactionSystemException(
				"JTA 1.1 [" + TRANSACTION_SYNCHRONIZATION_REGISTRY_CLASS_NAME + "] API not available");
	}
	try {
		if (logger.isDebugEnabled()) {
			logger.debug("Retrieving JTA TransactionSynchronizationRegistry from JNDI location [" + registryName + "]");
		}
		return getJndiTemplate().lookup(registryName, transactionSynchronizationRegistryClass);
	}
	catch (NamingException ex) {
		throw new TransactionSystemException(
				"JTA TransactionSynchronizationRegistry is not available at JNDI location [" + registryName + "]", ex);
	}
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:27,代码来源:JtaTransactionManager.java

示例9: process

import org.springframework.transaction.TransactionSystemException; //导入依赖的package包/类
/**
 * Define how message exchanges are processed.
 *
 * @param exchange the InOut message exchange
 * @throws FcrepoOperationFailedException when the underlying HTTP request results in an error
 */
@Override
public void process(final Exchange exchange) throws FcrepoOperationFailedException {
    if (exchange.isTransacted()) {
        transactionTemplate.execute(new TransactionCallbackWithoutResult() {
            protected void doInTransactionWithoutResult(final TransactionStatus status) {
                final DefaultTransactionStatus st = (DefaultTransactionStatus)status;
                final FcrepoTransactionObject tx = (FcrepoTransactionObject)st.getTransaction();
                try {
                    doRequest(exchange, tx.getSessionId());
                } catch (FcrepoOperationFailedException ex) {
                    throw new TransactionSystemException(
                        "Error executing fcrepo request in transaction: ", ex);
                }
            }
        });
    } else {
        doRequest(exchange, null);
    }
}
 
开发者ID:fcrepo4-exts,项目名称:fcrepo-camel,代码行数:26,代码来源:FcrepoProducer.java

示例10: doCommit

import org.springframework.transaction.TransactionSystemException; //导入依赖的package包/类
@Override
protected void doCommit(final DefaultTransactionStatus status) {
    final FcrepoTransactionObject tx = (FcrepoTransactionObject)status.getTransaction();
    final InputStream is = null;
    final String contentType = null;

    try {
        getClient().post(URI.create(baseUrl + "/" + tx.getSessionId() + COMMIT))
            .body(is, contentType).perform();
    } catch (final FcrepoOperationFailedException ex) {
        LOGGER.debug("Transaction commit failed: ", ex);
        throw new TransactionSystemException("Could not commit fcrepo transaction");
    } finally {
        tx.setSessionId(null);
    }
}
 
开发者ID:fcrepo4-exts,项目名称:fcrepo-camel,代码行数:17,代码来源:FcrepoTransactionManager.java

示例11: doCommit

import org.springframework.transaction.TransactionSystemException; //导入依赖的package包/类
@Override
protected void doCommit(DefaultTransactionStatus status) {
	JcrTransactionObject txObject = (JcrTransactionObject) status
			.getTransaction();
	if (status.isDebug()) {
		LOG.debug("Committing JCR transaction on session ["
				+ txObject.getSessionHolder().getSession() + "]");
	}
	try {
		txObject.getSessionHolder().getTransaction().commit();
	} catch (Exception ex) {
		// assumably from commit call to the underlying JCR repository
		throw new TransactionSystemException(
				"Could not commit JCR transaction", ex);
	}
}
 
开发者ID:MyCollab,项目名称:mycollab,代码行数:17,代码来源:LocalTransactionManager.java

示例12: doRollback

import org.springframework.transaction.TransactionSystemException; //导入依赖的package包/类
@Override
protected void doRollback(DefaultTransactionStatus status) {
	JcrTransactionObject txObject = (JcrTransactionObject) status
			.getTransaction();
	if (status.isDebug()) {
		LOG.debug("Rolling back JCR transaction on session ["
				+ txObject.getSessionHolder().getSession() + "]");
	}
	try {
		txObject.getSessionHolder().getTransaction().rollback();
	} catch (Exception ex) {
		throw new TransactionSystemException(
				"Could not roll back JCR transaction", ex);
	} finally {
		if (!txObject.isNewSessionHolder()) {
			// Clear all pending inserts/updates/deletes in the Session.
			// Necessary for pre-bound Sessions, to avoid inconsistent
			// state.
			try {
				txObject.getSessionHolder().getSession().refresh(false);
			} catch (RepositoryException e) {
				// we already throw an exception (hold back this one).
			}
		}
	}
}
 
开发者ID:MyCollab,项目名称:mycollab,代码行数:27,代码来源:LocalTransactionManager.java

示例13: loadWebLogicTransactionClasses

import org.springframework.transaction.TransactionSystemException; //导入依赖的package包/类
private void loadWebLogicTransactionClasses() throws TransactionSystemException {
	try {
		Class<?> userTransactionClass = getClass().getClassLoader().loadClass(USER_TRANSACTION_CLASS_NAME);
		this.weblogicUserTransactionAvailable = userTransactionClass.isInstance(getUserTransaction());
		if (this.weblogicUserTransactionAvailable) {
			this.beginWithNameMethod = userTransactionClass.getMethod("begin", String.class);
			this.beginWithNameAndTimeoutMethod = userTransactionClass.getMethod("begin", String.class, int.class);
			logger.info("Support for WebLogic transaction names available");
		}
		else {
			logger.info("Support for WebLogic transaction names not available");
		}

		// Obtain WebLogic ClientTransactionManager interface.
		Class<?> transactionManagerClass =
				getClass().getClassLoader().loadClass(CLIENT_TRANSACTION_MANAGER_CLASS_NAME);
		logger.debug("WebLogic ClientTransactionManager found");

		this.weblogicTransactionManagerAvailable = transactionManagerClass.isInstance(getTransactionManager());
		if (this.weblogicTransactionManagerAvailable) {
			Class<?> transactionClass = getClass().getClassLoader().loadClass(TRANSACTION_CLASS_NAME);
			this.forceResumeMethod = transactionManagerClass.getMethod("forceResume", Transaction.class);
			this.setPropertyMethod = transactionClass.getMethod("setProperty", String.class, Serializable.class);
			logger.debug("Support for WebLogic forceResume available");
		}
		else {
			logger.warn("Support for WebLogic forceResume not available");
		}
	}
	catch (Exception ex) {
		throw new TransactionSystemException(
				"Could not initialize WebLogicJtaTransactionManager because WebLogic API classes are not available",
				ex);
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:36,代码来源:WebLogicJtaTransactionManager.java

示例14: afterPropertiesSet

import org.springframework.transaction.TransactionSystemException; //导入依赖的package包/类
/**
 * Initialize the UserTransaction as well as the TransactionManager handle.
 * @see #initUserTransactionAndTransactionManager()
 */
@Override
public void afterPropertiesSet() throws TransactionSystemException {
	initUserTransactionAndTransactionManager();
	checkUserTransactionAndTransactionManager();
	initTransactionSynchronizationRegistry();
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:11,代码来源:JtaTransactionManager.java

示例15: initUserTransactionAndTransactionManager

import org.springframework.transaction.TransactionSystemException; //导入依赖的package包/类
/**
 * Initialize the UserTransaction as well as the TransactionManager handle.
 * @throws TransactionSystemException if initialization failed
 */
protected void initUserTransactionAndTransactionManager() throws TransactionSystemException {
	if (this.userTransaction == null) {
		// Fetch JTA UserTransaction from JNDI, if necessary.
		if (StringUtils.hasLength(this.userTransactionName)) {
			this.userTransaction = lookupUserTransaction(this.userTransactionName);
			this.userTransactionObtainedFromJndi = true;
		}
		else {
			this.userTransaction = retrieveUserTransaction();
			if (this.userTransaction == null && this.autodetectUserTransaction) {
				// Autodetect UserTransaction at its default JNDI location.
				this.userTransaction = findUserTransaction();
			}
		}
	}

	if (this.transactionManager == null) {
		// Fetch JTA TransactionManager from JNDI, if necessary.
		if (StringUtils.hasLength(this.transactionManagerName)) {
			this.transactionManager = lookupTransactionManager(this.transactionManagerName);
		}
		else {
			this.transactionManager = retrieveTransactionManager();
			if (this.transactionManager == null && this.autodetectTransactionManager) {
				// Autodetect UserTransaction object that implements TransactionManager,
				// and check fallback JNDI locations otherwise.
				this.transactionManager = findTransactionManager(this.userTransaction);
			}
		}
	}

	// If only JTA TransactionManager specified, create UserTransaction handle for it.
	if (this.userTransaction == null && this.transactionManager != null) {
		this.userTransaction = buildUserTransaction(this.transactionManager);
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:41,代码来源:JtaTransactionManager.java


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