Java Code Examples for org.springframework.transaction.TransactionSystemException

The following examples show how to use org.springframework.transaction.TransactionSystemException. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: spring-analysis-note   Source File: JpaTransactionManager.java    License: MIT License 6 votes vote down vote up
@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();
		}
	}
}
 
Example 2
@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);
	}
}
 
Example 3
@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();
}
 
Example 4
@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();
}
 
Example 5
@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();
}
 
Example 6
Source Project: spring-analysis-note   Source File: JmsTransactionManager.java    License: MIT License 6 votes vote down vote up
@Override
protected void doRollback(DefaultTransactionStatus status) {
	JmsTransactionObject txObject = (JmsTransactionObject) status.getTransaction();
	Session session = txObject.getResourceHolder().getOriginalSession();
	if (session != null) {
		try {
			if (status.isDebug()) {
				logger.debug("Rolling back JMS transaction on Session [" + session + "]");
			}
			session.rollback();
		}
		catch (JMSException ex) {
			throw new TransactionSystemException("Could not roll back JMS transaction", ex);
		}
	}
}
 
Example 7
Source Project: java-technology-stack   Source File: JpaTransactionManager.java    License: MIT License 6 votes vote down vote up
@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();
		}
	}
}
 
Example 8
@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();
}
 
Example 9
Source Project: lams   Source File: JpaTransactionManager.java    License: GNU General Public License v2.0 6 votes vote down vote up
@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();
		}
	}
}
 
Example 10
@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();
}
 
Example 11
@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();
}
 
Example 12
@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();
		}
	}
}
 
Example 13
@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();
}
 
Example 14
Source Project: sdn-rx   Source File: Neo4jTransactionManager.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected void doBegin(Object transaction, TransactionDefinition definition) throws TransactionException {
	Neo4jTransactionObject transactionObject = extractNeo4jTransaction(transaction);

	TransactionConfig transactionConfig = createTransactionConfigFrom(definition);
	boolean readOnly = definition.isReadOnly();


	TransactionSynchronizationManager.setCurrentTransactionReadOnly(readOnly);

	try {
		// Prepare configuration data
		Neo4jTransactionContext context = new Neo4jTransactionContext(
			databaseSelectionProvider.getDatabaseSelection().getValue(),
			bookmarkManager.getBookmarks()
		);

		// Configure and open session together with a native transaction
		Session session = this.driver
			.session(sessionConfig(readOnly, context.getBookmarks(), context.getDatabaseName()));
		Transaction nativeTransaction = session.beginTransaction(transactionConfig);

		// Synchronize on that
		Neo4jTransactionHolder transactionHolder = new Neo4jTransactionHolder(context, session, nativeTransaction);
		transactionHolder.setSynchronizedWithTransaction(true);
		transactionObject.setResourceHolder(transactionHolder);

		TransactionSynchronizationManager.bindResource(this.driver, transactionHolder);
	} catch (Exception ex) {
		throw new TransactionSystemException(String.format("Could not open a new Neo4j session: %s", ex.getMessage()));
	}
}
 
Example 15
Source Project: spring-analysis-note   Source File: JpaTransactionManagerTests.java    License: MIT License 5 votes vote down vote up
@Test
public void testTransactionCommitWithRollbackException() {
	given(manager.getTransaction()).willReturn(tx);
	given(tx.getRollbackOnly()).willReturn(true);
	willThrow(new RollbackException()).given(tx).commit();

	final List<String> l = new ArrayList<>();
	l.add("test");

	assertTrue(!TransactionSynchronizationManager.hasResource(factory));
	assertTrue(!TransactionSynchronizationManager.isSynchronizationActive());

	try {
		Object result = tt.execute(new TransactionCallback() {
			@Override
			public Object doInTransaction(TransactionStatus status) {
				assertTrue(TransactionSynchronizationManager.hasResource(factory));
				EntityManagerFactoryUtils.getTransactionalEntityManager(factory).flush();
				return l;
			}
		});
		assertSame(l, result);
	}
	catch (TransactionSystemException tse) {
		// expected
		assertTrue(tse.getCause() instanceof RollbackException);
	}

	assertTrue(!TransactionSynchronizationManager.hasResource(factory));
	assertTrue(!TransactionSynchronizationManager.isSynchronizationActive());

	verify(manager).flush();
	verify(manager).close();
}
 
Example 16
Source Project: spring-analysis-note   Source File: TransactionAspectSupport.java    License: MIT License 5 votes vote down vote up
private Mono<Void> completeTransactionAfterThrowing(@Nullable ReactiveTransactionInfo txInfo, Throwable ex) {
	if (txInfo != null && txInfo.getReactiveTransaction() != null) {
		if (logger.isTraceEnabled()) {
			logger.trace("Completing transaction for [" + txInfo.getJoinpointIdentification() +
					"] after exception: " + ex);
		}
		if (txInfo.transactionAttribute != null && txInfo.transactionAttribute.rollbackOn(ex)) {
			return txInfo.getTransactionManager().rollback(txInfo.getReactiveTransaction()).onErrorMap(ex2 -> {
						logger.error("Application exception overridden by rollback exception", ex);
						if (ex2 instanceof TransactionSystemException) {
							((TransactionSystemException) ex2).initApplicationException(ex);
						}
						return ex2;
					}
			);
		}
		else {
			// We don't roll back on this exception.
			// Will still roll back if TransactionStatus.isRollbackOnly() is true.
			return txInfo.getTransactionManager().commit(txInfo.getReactiveTransaction()).onErrorMap(ex2 -> {
						logger.error("Application exception overridden by commit exception", ex);
						if (ex2 instanceof TransactionSystemException) {
							((TransactionSystemException) ex2).initApplicationException(ex);
						}
						return ex2;
					}
			);
		}
	}
	return Mono.empty();
}
 
Example 17
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.debug("Support for WebLogic transaction names available");
		}
		else {
			logger.debug("Support for WebLogic transaction names not available");
		}

		// Obtain WebLogic ClientTransactionManager interface.
		Class<?> transactionManagerClass =
				getClass().getClassLoader().loadClass(CLIENT_TRANSACTION_MANAGER_CLASS_NAME);
		logger.trace("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.debug("Support for WebLogic forceResume not available");
		}
	}
	catch (Exception ex) {
		throw new TransactionSystemException(
				"Could not initialize WebLogicJtaTransactionManager because WebLogic API classes are not available",
				ex);
	}
}
 
Example 18
Source Project: spring-analysis-note   Source File: JtaTransactionManager.java    License: MIT License 5 votes vote down vote up
/**
 * Initialize the UserTransaction as well as the TransactionManager handle.
 * @see #initUserTransactionAndTransactionManager()
 */
@Override
public void afterPropertiesSet() throws TransactionSystemException {
	initUserTransactionAndTransactionManager();
	checkUserTransactionAndTransactionManager();
	initTransactionSynchronizationRegistry();
}
 
Example 19
Source Project: spring-analysis-note   Source File: JtaTransactionManager.java    License: MIT License 5 votes vote down vote up
/**
 * Look up the JTA UserTransaction in JNDI via the configured name.
 * <p>Called by {@code afterPropertiesSet} if no direct UserTransaction reference was set.
 * Can be overridden in subclasses to provide a different UserTransaction object.
 * @param userTransactionName the JNDI name of the UserTransaction
 * @return the UserTransaction object
 * @throws TransactionSystemException if the JNDI lookup failed
 * @see #setJndiTemplate
 * @see #setUserTransactionName
 */
protected UserTransaction lookupUserTransaction(String userTransactionName)
		throws TransactionSystemException {
	try {
		if (logger.isDebugEnabled()) {
			logger.debug("Retrieving JTA UserTransaction from JNDI location [" + userTransactionName + "]");
		}
		return getJndiTemplate().lookup(userTransactionName, UserTransaction.class);
	}
	catch (NamingException ex) {
		throw new TransactionSystemException(
				"JTA UserTransaction is not available at JNDI location [" + userTransactionName + "]", ex);
	}
}
 
Example 20
Source Project: spring-analysis-note   Source File: JtaTransactionManager.java    License: MIT License 5 votes vote down vote up
/**
 * 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 TransactionSynchronizationRegistry lookupTransactionSynchronizationRegistry(String registryName) throws TransactionSystemException {
	try {
		if (logger.isDebugEnabled()) {
			logger.debug("Retrieving JTA TransactionSynchronizationRegistry from JNDI location [" + registryName + "]");
		}
		return getJndiTemplate().lookup(registryName, TransactionSynchronizationRegistry.class);
	}
	catch (NamingException ex) {
		throw new TransactionSystemException(
				"JTA TransactionSynchronizationRegistry is not available at JNDI location [" + registryName + "]", ex);
	}
}
 
Example 21
public void rollback() {
    log.debug("Performing rollback");
    while (!operationExecutors.isEmpty()) {
        CompensatingTransactionOperationExecutor rollbackOperation = operationExecutors.pop();
        try {
            rollbackOperation.rollback();
        } catch (Exception e) {
            throw new TransactionSystemException(
                    "Error occurred during rollback", e);
        }
    }
}
 
Example 22
Source Project: spring-analysis-note   Source File: JtaTransactionManager.java    License: MIT License 5 votes vote down vote up
@Override
protected boolean isExistingTransaction(Object transaction) {
	JtaTransactionObject txObject = (JtaTransactionObject) transaction;
	try {
		return (txObject.getUserTransaction().getStatus() != Status.STATUS_NO_TRANSACTION);
	}
	catch (SystemException ex) {
		throw new TransactionSystemException("JTA failure on getStatus", ex);
	}
}
 
Example 23
Source Project: spring-analysis-note   Source File: JtaTransactionManager.java    License: MIT License 5 votes vote down vote up
@Override
protected Object doSuspend(Object transaction) {
	JtaTransactionObject txObject = (JtaTransactionObject) transaction;
	try {
		return doJtaSuspend(txObject);
	}
	catch (SystemException ex) {
		throw new TransactionSystemException("JTA failure on suspend", ex);
	}
}
 
Example 24
Source Project: syncope   Source File: SCIMExceptionMapper.java    License: Apache License 2.0 5 votes vote down vote up
private static ResponseBuilder processInvalidEntityExceptions(final Exception ex) {
    InvalidEntityException iee = null;

    if (ex instanceof InvalidEntityException) {
        iee = (InvalidEntityException) ex;
    }
    if (ex instanceof TransactionSystemException && ROLLBACK_EXCLASS.isAssignableFrom(ex.getCause().getClass())
            && ex.getCause().getCause() instanceof InvalidEntityException) {

        iee = (InvalidEntityException) ex.getCause().getCause();
    }

    if (iee != null) {
        ClientExceptionType exType;
        if (iee.getEntityClassSimpleName().endsWith("Policy")) {
            exType = ClientExceptionType.InvalidPolicy;
        } else if (iee.getEntityClassSimpleName().equals(PlainAttr.class.getSimpleName())) {
            exType = ClientExceptionType.InvalidValues;
        } else {
            try {
                exType = ClientExceptionType.valueOf("Invalid" + iee.getEntityClassSimpleName());
            } catch (IllegalArgumentException e) {
                // ignore
                exType = ClientExceptionType.InvalidEntity;
            }
        }

        StringBuilder msg = new StringBuilder();

        for (Map.Entry<Class<?>, Set<EntityViolationType>> violation : iee.getViolations().entrySet()) {
            for (EntityViolationType violationType : violation.getValue()) {
                msg.append(violationType.name()).append(": ").append(violationType.getMessage()).append('\n');
            }
        }

        return builder(exType, msg.toString());
    }

    return null;
}
 
Example 25
/**
 * This implementation checks the UserTransaction's rollback-only flag.
 */
@Override
public boolean isRollbackOnly() {
	if (this.userTransaction == null) {
		return false;
	}
	try {
		int jtaStatus = this.userTransaction.getStatus();
		return (jtaStatus == Status.STATUS_MARKED_ROLLBACK || jtaStatus == Status.STATUS_ROLLEDBACK);
	}
	catch (SystemException ex) {
		throw new TransactionSystemException("JTA failure on getStatus", ex);
	}
}
 
Example 26
/**
 * Look up the JTA UserTransaction in JNDI via the configured name.
 * <p>Called by {@code afterPropertiesSet} if no direct UserTransaction reference was set.
 * Can be overridden in subclasses to provide a different UserTransaction object.
 * @param userTransactionName the JNDI name of the UserTransaction
 * @return the UserTransaction object
 * @throws TransactionSystemException if the JNDI lookup failed
 * @see #setJndiTemplate
 * @see #setUserTransactionName
 */
protected UserTransaction lookupUserTransaction(String userTransactionName)
		throws TransactionSystemException {
	try {
		if (logger.isDebugEnabled()) {
			logger.debug("Retrieving JTA UserTransaction from JNDI location [" + userTransactionName + "]");
		}
		return getJndiTemplate().lookup(userTransactionName, UserTransaction.class);
	}
	catch (NamingException ex) {
		throw new TransactionSystemException(
				"JTA UserTransaction is not available at JNDI location [" + userTransactionName + "]", ex);
	}
}
 
Example 27
/**
 * Obtain the WebSphere UOWManager from the default JNDI location
 * "java:comp/websphere/UOWManager".
 * @return the UOWManager object
 * @throws TransactionSystemException if the JNDI lookup failed
 * @see #setJndiTemplate
 */
protected UOWManager lookupDefaultUowManager() throws TransactionSystemException {
	try {
		logger.debug("Retrieving WebSphere UOWManager from default JNDI location [" + DEFAULT_UOW_MANAGER_NAME + "]");
		return getJndiTemplate().lookup(DEFAULT_UOW_MANAGER_NAME, UOWManager.class);
	}
	catch (NamingException ex) {
		logger.debug("WebSphere UOWManager is not available at default JNDI location [" +
				DEFAULT_UOW_MANAGER_NAME + "] - falling back to UOWManagerFactory lookup");
		return UOWManagerFactory.getUOWManager();
	}
}
 
Example 28
Source Project: spring4-understanding   Source File: LobCreatorUtils.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Register a transaction synchronization for closing the given LobCreator,
 * preferring Spring transaction synchronization and falling back to
 * plain JTA transaction synchronization.
 * @param lobCreator the LobCreator to close after transaction completion
 * @param jtaTransactionManager the JTA TransactionManager to fall back to
 * when no Spring transaction synchronization is active (may be {@code null})
 * @throws IllegalStateException if there is neither active Spring transaction
 * synchronization nor active JTA transaction synchronization
 */
public static void registerTransactionSynchronization(
		LobCreator lobCreator, TransactionManager jtaTransactionManager) throws IllegalStateException {

	if (TransactionSynchronizationManager.isSynchronizationActive()) {
		logger.debug("Registering Spring transaction synchronization for LobCreator");
		TransactionSynchronizationManager.registerSynchronization(
			new SpringLobCreatorSynchronization(lobCreator));
	}
	else {
		if (jtaTransactionManager != null) {
			try {
				int jtaStatus = jtaTransactionManager.getStatus();
				if (jtaStatus == Status.STATUS_ACTIVE || jtaStatus == Status.STATUS_MARKED_ROLLBACK) {
					logger.debug("Registering JTA transaction synchronization for LobCreator");
					jtaTransactionManager.getTransaction().registerSynchronization(
							new JtaLobCreatorSynchronization(lobCreator));
					return;
				}
			}
			catch (Throwable ex) {
				throw new TransactionSystemException(
						"Could not register synchronization with JTA TransactionManager", ex);
			}
		}
		throw new IllegalStateException("Active Spring transaction synchronization or active " +
			"JTA transaction with specified [javax.transaction.TransactionManager] required");
	}
}
 
Example 29
Source Project: lams   Source File: LobCreatorUtils.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Register a transaction synchronization for closing the given LobCreator,
 * preferring Spring transaction synchronization and falling back to
 * plain JTA transaction synchronization.
 * @param lobCreator the LobCreator to close after transaction completion
 * @param jtaTransactionManager the JTA TransactionManager to fall back to
 * when no Spring transaction synchronization is active (may be {@code null})
 * @throws IllegalStateException if there is neither active Spring transaction
 * synchronization nor active JTA transaction synchronization
 */
public static void registerTransactionSynchronization(
		LobCreator lobCreator, TransactionManager jtaTransactionManager) throws IllegalStateException {

	if (TransactionSynchronizationManager.isSynchronizationActive()) {
		logger.debug("Registering Spring transaction synchronization for LobCreator");
		TransactionSynchronizationManager.registerSynchronization(
			new SpringLobCreatorSynchronization(lobCreator));
	}
	else {
		if (jtaTransactionManager != null) {
			try {
				int jtaStatus = jtaTransactionManager.getStatus();
				if (jtaStatus == Status.STATUS_ACTIVE || jtaStatus == Status.STATUS_MARKED_ROLLBACK) {
					logger.debug("Registering JTA transaction synchronization for LobCreator");
					jtaTransactionManager.getTransaction().registerSynchronization(
							new JtaLobCreatorSynchronization(lobCreator));
					return;
				}
			}
			catch (Throwable ex) {
				throw new TransactionSystemException(
						"Could not register synchronization with JTA TransactionManager", ex);
			}
		}
		throw new IllegalStateException("Active Spring transaction synchronization or active " +
			"JTA transaction with specified [javax.transaction.TransactionManager] required");
	}
}
 
Example 30
@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);
	}
}