org.springframework.transaction.TransactionException Java Examples

The following examples show how to use org.springframework.transaction.TransactionException. 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 File: AbstractPlatformTransactionManager.java    From spring-analysis-note with MIT License 6 votes vote down vote up
/**
 * Resume the given transaction. Delegates to the {@code doResume}
 * template method first, then resuming transaction synchronization.
 * @param transaction the current transaction object
 * @param resourcesHolder the object that holds suspended resources,
 * as returned by {@code suspend} (or {@code null} to just
 * resume synchronizations, if any)
 * @see #doResume
 * @see #suspend
 */
protected final void resume(@Nullable Object transaction, @Nullable SuspendedResourcesHolder resourcesHolder)
		throws TransactionException {

	if (resourcesHolder != null) {
		Object suspendedResources = resourcesHolder.suspendedResources;
		if (suspendedResources != null) {
			doResume(transaction, suspendedResources);
		}
		List<TransactionSynchronization> suspendedSynchronizations = resourcesHolder.suspendedSynchronizations;
		if (suspendedSynchronizations != null) {
			TransactionSynchronizationManager.setActualTransactionActive(resourcesHolder.wasActive);
			TransactionSynchronizationManager.setCurrentTransactionIsolationLevel(resourcesHolder.isolationLevel);
			TransactionSynchronizationManager.setCurrentTransactionReadOnly(resourcesHolder.readOnly);
			TransactionSynchronizationManager.setCurrentTransactionName(resourcesHolder.name);
			doResumeSynchronization(suspendedSynchronizations);
		}
	}
}
 
Example #2
Source File: HazelcastMQTransactionManager.java    From hazelcastmq with Apache License 2.0 6 votes vote down vote up
@Override
protected void doRollback(DefaultTransactionStatus status) throws
    TransactionException {
  HazelcastMQTransactionObject txObject =
      (HazelcastMQTransactionObject) status.
      getTransaction();
  HazelcastMQContext con = txObject.getHazelcastMQContextHolder().
      getHazelcastMQContext();

  if (status.isDebug() && log.isFinestEnabled()) {
    log.finest(format("Rolling back HazelcastMQ transaction on "
        + "HazelcastMQContext [%s].", con));
  }

  try {
    con.rollback();
  }
  catch (com.hazelcast.transaction.TransactionException ex) {
    throw new TransactionSystemException(
        "Could not rollback HazelcastMQ transaction", ex);
  }
}
 
Example #3
Source File: AbstractReactiveTransactionManager.java    From spring-analysis-note with MIT License 6 votes vote down vote up
/**
 * This implementation of commit handles participating in existing
 * transactions and programmatic rollback requests.
 * Delegates to {@code isRollbackOnly}, {@code doCommit}
 * and {@code rollback}.
 * @see ReactiveTransaction#isRollbackOnly()
 * @see #doCommit
 * @see #rollback
 */
@Override
public final Mono<Void> commit(ReactiveTransaction transaction) throws TransactionException {
	if (transaction.isCompleted()) {
		return Mono.error(new IllegalTransactionStateException(
				"Transaction is already completed - do not call commit or rollback more than once per transaction"));
	}

	return TransactionSynchronizationManager.currentTransaction().flatMap(synchronizationManager -> {
		GenericReactiveTransaction reactiveTx = (GenericReactiveTransaction) transaction;
		if (reactiveTx.isRollbackOnly()) {
			if (reactiveTx.isDebug()) {
				logger.debug("Transactional code has requested rollback");
			}
			return processRollback(synchronizationManager, reactiveTx);
		}
		return processCommit(synchronizationManager, reactiveTx);
	});
}
 
Example #4
Source File: OpenJpaDialect.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Override
public Object beginTransaction(EntityManager entityManager, TransactionDefinition definition)
		throws PersistenceException, SQLException, TransactionException {

	OpenJPAEntityManager openJpaEntityManager = getOpenJPAEntityManager(entityManager);

	if (definition.getIsolationLevel() != TransactionDefinition.ISOLATION_DEFAULT) {
		// Pass custom isolation level on to OpenJPA's JDBCFetchPlan configuration
		FetchPlan fetchPlan = openJpaEntityManager.getFetchPlan();
		if (fetchPlan instanceof JDBCFetchPlan) {
			IsolationLevel isolation = IsolationLevel.fromConnectionConstant(definition.getIsolationLevel());
			((JDBCFetchPlan) fetchPlan).setIsolation(isolation);
		}
	}

	entityManager.getTransaction().begin();

	if (!definition.isReadOnly()) {
		// Like with EclipseLink, make sure to start the logic transaction early so that other
		// participants using the connection (such as JdbcTemplate) run in a transaction.
		openJpaEntityManager.beginStore();
	}

	// Custom implementation for OpenJPA savepoint handling
	return new OpenJpaTransactionData(openJpaEntityManager);
}
 
Example #5
Source File: JdbcTransactionObjectSupport.java    From spring-analysis-note with MIT License 6 votes vote down vote up
/**
 * This implementation creates a JDBC 3.0 Savepoint and returns it.
 * @see java.sql.Connection#setSavepoint
 */
@Override
public Object createSavepoint() throws TransactionException {
	ConnectionHolder conHolder = getConnectionHolderForSavepoint();
	try {
		if (!conHolder.supportsSavepoints()) {
			throw new NestedTransactionNotSupportedException(
					"Cannot create a nested transaction because savepoints are not supported by your JDBC driver");
		}
		if (conHolder.isRollbackOnly()) {
			throw new CannotCreateTransactionException(
					"Cannot create savepoint for transaction which is already marked as rollback-only");
		}
		return conHolder.createSavepoint();
	}
	catch (SQLException ex) {
		throw new CannotCreateTransactionException("Could not create JDBC savepoint", ex);
	}
}
 
Example #6
Source File: SpringJpaXmlTest.java    From hypersistence-optimizer with Apache License 2.0 6 votes vote down vote up
@Before
public void init() {
    try {
        transactionTemplate.execute((TransactionCallback<Void>) transactionStatus -> {
            Tag hibernate = new Tag();
            hibernate.setName("hibernate");
            entityManager.persist(hibernate);

            Tag jpa = new Tag();
            jpa.setName("jpa");
            entityManager.persist(jpa);
            return null;
        });
    } catch (TransactionException e) {
        LOGGER.error("Failure", e);
    }

}
 
Example #7
Source File: SpringJpaTest.java    From hypersistence-optimizer with Apache License 2.0 6 votes vote down vote up
@Before
public void init() {
    try {
        transactionTemplate.execute((TransactionCallback<Void>) transactionStatus -> {
            Tag hibernate = new Tag();
            hibernate.setName("hibernate");
            entityManager.persist(hibernate);

            Tag jpa = new Tag();
            jpa.setName("jpa");
            entityManager.persist(jpa);
            return null;
        });
    } catch (TransactionException e) {
        LOGGER.error("Failure", e);
    }

}
 
Example #8
Source File: EclipseLinkJpaDialect.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Override
public Object beginTransaction(EntityManager entityManager, TransactionDefinition definition)
		throws PersistenceException, SQLException, TransactionException {

	if (definition.getIsolationLevel() != TransactionDefinition.ISOLATION_DEFAULT) {
		// Pass custom isolation level on to EclipseLink's DatabaseLogin configuration
		// (since Spring 4.1.2)
		UnitOfWork uow = entityManager.unwrap(UnitOfWork.class);
		uow.getLogin().setTransactionIsolation(definition.getIsolationLevel());
	}

	entityManager.getTransaction().begin();

	if (!definition.isReadOnly() && !this.lazyDatabaseTransaction) {
		// Begin an early transaction to force EclipseLink to get a JDBC Connection
		// so that Spring can manage transactions with JDBC as well as EclipseLink.
		entityManager.unwrap(UnitOfWork.class).beginEarlyTransaction();
	}

	return null;
}
 
Example #9
Source File: DefaultJpaDialectTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void testDefaultTransactionDefinition() throws Exception {
	DefaultTransactionDefinition definition = new DefaultTransactionDefinition();
	definition.setIsolationLevel(TransactionDefinition.ISOLATION_REPEATABLE_READ);

	try {
		dialect.beginTransaction(null, definition);
		fail("expected exception");
	}
	catch (TransactionException e) {
		// ok
	}
}
 
Example #10
Source File: JpaTransactionManager.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Override
public Object createSavepoint() throws TransactionException {
	if (getEntityManagerHolder().isRollbackOnly()) {
		throw new CannotCreateTransactionException(
				"Cannot create savepoint for transaction which is already marked as rollback-only");
	}
	return getSavepointManager().createSavepoint();
}
 
Example #11
Source File: RedissonTransactionManager.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Override
protected void doRollback(DefaultTransactionStatus status) throws TransactionException {
    RedissonTransactionObject to = (RedissonTransactionObject) status.getTransaction();
    try {
        to.getTransactionHolder().getTransaction().rollback();
    } catch (org.redisson.transaction.TransactionException e) {
        throw new TransactionSystemException("Unable to rollback transaction", e);
    }
}
 
Example #12
Source File: BehaviorDrivenInheritanceTest.java    From high-performance-java-persistence with Apache License 2.0 5 votes vote down vote up
@Test
public void test() {
    try {
        transactionTemplate.execute((TransactionCallback<Void>) transactionStatus -> {
            EmailSubscriber email = new EmailSubscriber();
            email.setEmailAddress("[email protected]");
            email.setFirstName("Vlad");
            email.setLastName("Mihalcea");

            entityManager.persist(email);

            SmsSubscriber sms = new SmsSubscriber();
            sms.setPhoneNumber("012-345-67890");
            sms.setFirstName("Vlad");
            sms.setLastName("Mihalcea");

            entityManager.persist(sms);

            return null;
        });
    } catch (TransactionException e) {
        LOGGER.error("Failure", e);
    }

    campaignService.send("Black Friday", "High-Performance Java Persistence is 40% OFF");

}
 
Example #13
Source File: AbstractTransactionStatus.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * Release the savepoint that is held for the transaction.
 */
public void releaseHeldSavepoint() throws TransactionException {
	Object savepoint = getSavepoint();
	if (savepoint == null) {
		throw new TransactionUsageException(
				"Cannot release savepoint - no savepoint associated with current transaction");
	}
	getSavepointManager().releaseSavepoint(savepoint);
	setSavepoint(null);
}
 
Example #14
Source File: ChainedTransactionManager.java    From easyooo-framework with Apache License 2.0 5 votes vote down vote up
@Override
public void rollback(TransactionStatus status) throws TransactionException {
	if(logger.isWarnEnabled()){
		logger.warn("Rollback all connected transactions.");
	}
	try{
		TransactionSynchronizationUtils.triggerBeforeCompletion();
		Map<DataSource, ConnectionHolder> connSet = RoutingSynchronizationManager.getSynchronizations();
		Exception rollbackException = null;
		ConnectionHolder rollbackExceptionConnection = null;

        for (ConnectionHolder connection:connSet.values()) {
            try {
            	connection.rollback();
            	if (logger.isDebugEnabled()) {
        			logger.debug("Connection["+ connection +"] has been rolled back.");
        		}
            } catch (Exception ex) {
                if (rollbackException == null) {
                    rollbackException = ex;
                    rollbackExceptionConnection = connection;
                } else {
                    logger.warn("Rollback exception (" + rollbackExceptionConnection + ") " + ex.getMessage(), ex);
                }
            }
        }
        
        if (rollbackException != null) {
            throw new UnexpectedRollbackException("Rollback exception, originated at ("+rollbackExceptionConnection+") "+
              rollbackException.getMessage(), rollbackException);
        }
	}finally{
		RoutingSynchronizationManager
				.invokeAfterCompletion(TransactionSynchronization.STATUS_ROLLED_BACK);
		RoutingSynchronizationManager.clearSynchronization();
	}
}
 
Example #15
Source File: AbstractPlatformTransactionManager.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * This implementation of rollback handles participating in existing
 * transactions. Delegates to {@code doRollback} and
 * {@code doSetRollbackOnly}.
 * @see #doRollback
 * @see #doSetRollbackOnly
 */
@Override
public final void rollback(TransactionStatus status) throws TransactionException {
	if (status.isCompleted()) {
		throw new IllegalTransactionStateException(
				"Transaction is already completed - do not call commit or rollback more than once per transaction");
	}

	DefaultTransactionStatus defStatus = (DefaultTransactionStatus) status;
	processRollback(defStatus, false);
}
 
Example #16
Source File: JdbcTransactionObjectSupport.java    From effectivejava with Apache License 2.0 5 votes vote down vote up
protected ConnectionHolder getConnectionHolderForSavepoint() throws TransactionException {
	if (!isSavepointAllowed()) {
		throw new NestedTransactionNotSupportedException(
				"Transaction manager does not allow nested transactions");
	}
	if (!hasConnectionHolder()) {
		throw new TransactionUsageException(
				"Cannot create nested transaction if not exposing a JDBC transaction");
	}
	return getConnectionHolder();
}
 
Example #17
Source File: InstanceManager.java    From oneops with Apache License 2.0 5 votes vote down vote up
private boolean acquireLock() {
	try {
		for (int i = 1; i <= this.poolSize; i++) {
			if (utilManager.acquireLock(LOCK_NAME_PREFIX + i, this.processId, lockTimeOutInSeconds)) {
				this.instanceId = i;
				logger.info(">>>>>>>Sensor process " + this.processId + " will be running as #" + i);
				startTheLockRefresh();
				try {
					this.state = State.Initializing;
					sensor.init(instanceId, poolSize);
					initJmsListeners(instanceId, poolSize);
					orphanEventHandler.start();
				} catch (Exception e) {
					cleanup();
					throw new RuntimeException(e);
				}finally {
					this.state=State.WaitingForLock;
				}
				this.state = State.Initalized;
				return true;
			}
		}
	} catch (TransactionException te) {
		//seems like DB is not accessible will retry
		logger.error(te);
	}

	return false;
}
 
Example #18
Source File: Neo4jTransactionManager.java    From sdn-rx with Apache License 2.0 5 votes vote down vote up
@Override
protected Object doGetTransaction() throws TransactionException {

	Neo4jTransactionHolder resourceHolder = (Neo4jTransactionHolder) TransactionSynchronizationManager
		.getResource(driver);
	return new Neo4jTransactionObject(resourceHolder);
}
 
Example #19
Source File: AbstractPlatformTransactionManager.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * This implementation of commit handles participating in existing
 * transactions and programmatic rollback requests.
 * Delegates to {@code isRollbackOnly}, {@code doCommit}
 * and {@code rollback}.
 * @see org.springframework.transaction.TransactionStatus#isRollbackOnly()
 * @see #doCommit
 * @see #rollback
 */
@Override
public final void commit(TransactionStatus status) throws TransactionException {
	if (status.isCompleted()) {
		throw new IllegalTransactionStateException(
				"Transaction is already completed - do not call commit or rollback more than once per transaction");
	}

	DefaultTransactionStatus defStatus = (DefaultTransactionStatus) status;
	if (defStatus.isLocalRollbackOnly()) {
		if (defStatus.isDebug()) {
			logger.debug("Transactional code has requested rollback");
		}
		processRollback(defStatus);
		return;
	}
	if (!shouldCommitOnGlobalRollbackOnly() && defStatus.isGlobalRollbackOnly()) {
		if (defStatus.isDebug()) {
			logger.debug("Global transaction is marked as rollback-only but transactional code requested commit");
		}
		processRollback(defStatus);
		// Throw UnexpectedRollbackException only at outermost transaction boundary
		// or if explicitly asked to.
		if (status.isNewTransaction() || isFailEarlyOnGlobalRollbackOnly()) {
			throw new UnexpectedRollbackException(
					"Transaction rolled back because it has been marked as rollback-only");
		}
		return;
	}

	processCommit(defStatus);
}
 
Example #20
Source File: JdbcTransactionObjectSupport.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
protected ConnectionHolder getConnectionHolderForSavepoint() throws TransactionException {
	if (!isSavepointAllowed()) {
		throw new NestedTransactionNotSupportedException(
				"Transaction manager does not allow nested transactions");
	}
	if (!hasConnectionHolder()) {
		throw new TransactionUsageException(
				"Cannot create nested transaction if not exposing a JDBC transaction");
	}
	return getConnectionHolder();
}
 
Example #21
Source File: SpannerTransactionManager.java    From spring-cloud-gcp with Apache License 2.0 5 votes vote down vote up
@Override
protected void doRollback(DefaultTransactionStatus defaultTransactionStatus)
		throws TransactionException {
	Tx tx = (Tx) defaultTransactionStatus.getTransaction();
	if (tx.getTransactionManager() != null
			&& tx.getTransactionManager().getState() == TransactionManager.TransactionState.STARTED) {
		tx.getTransactionManager().rollback();
	}
	if (tx.isReadOnly()) {
		tx.getTransactionContext().close();
	}
}
 
Example #22
Source File: CustomHibernateJpaDialect.java    From spring-boot with Apache License 2.0 5 votes vote down vote up
@Override
public Object beginTransaction(final EntityManager entityManager,
		final TransactionDefinition definition)
		throws PersistenceException, SQLException, TransactionException {

	Session session = (Session) entityManager.getDelegate();
	if (definition.getTimeout() != TransactionDefinition.TIMEOUT_DEFAULT) {
		getSession(entityManager).getTransaction().setTimeout(
				definition.getTimeout());
	}

	final TransactionData data = new TransactionData();

	session.doWork(new Work() {
		@Override
		public void execute(Connection connection) throws SQLException {
			Integer previousIsolationLevel = DataSourceUtils
					.prepareConnectionForTransaction(connection, definition);
			data.setPreviousIsolationLevel(previousIsolationLevel);
			data.setConnection(connection);
		}
	});

	entityManager.getTransaction().begin();

	Object springTransactionData = prepareTransaction(entityManager,
			definition.isReadOnly(), definition.getName());

	data.setSpringTransactionData(springTransactionData);

	return data;
}
 
Example #23
Source File: HibernateJpaDialect.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Override
public Object beginTransaction(EntityManager entityManager, TransactionDefinition definition)
		throws PersistenceException, SQLException, TransactionException {

	Session session = getSession(entityManager);

	if (definition.getTimeout() != TransactionDefinition.TIMEOUT_DEFAULT) {
		session.getTransaction().setTimeout(definition.getTimeout());
	}

	boolean isolationLevelNeeded = (definition.getIsolationLevel() != TransactionDefinition.ISOLATION_DEFAULT);
	Integer previousIsolationLevel = null;
	Connection preparedCon = null;

	if (isolationLevelNeeded || definition.isReadOnly()) {
		if (this.prepareConnection) {
			preparedCon = HibernateConnectionHandle.doGetConnection(session);
			previousIsolationLevel = DataSourceUtils.prepareConnectionForTransaction(preparedCon, definition);
		}
		else if (isolationLevelNeeded) {
			throw new InvalidIsolationLevelException(getClass().getSimpleName() +
					" does not support custom isolation levels since the 'prepareConnection' flag is off. " +
					"This is the case on Hibernate 3.6 by default; either switch that flag at your own risk " +
					"or upgrade to Hibernate 4.x, with 4.2+ recommended.");
		}
	}

	// Standard JPA transaction begin call for full JPA context setup...
	entityManager.getTransaction().begin();

	// Adapt flush mode and store previous isolation level, if any.
	FlushMode previousFlushMode = prepareFlushMode(session, definition.isReadOnly());
	return new SessionTransactionData(session, previousFlushMode, preparedCon, previousIsolationLevel);
}
 
Example #24
Source File: AbstractTransactionStatus.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Release the savepoint that is held for the transaction.
 */
public void releaseHeldSavepoint() throws TransactionException {
	if (!hasSavepoint()) {
		throw new TransactionUsageException(
				"Cannot release savepoint - no savepoint associated with current transaction");
	}
	getSavepointManager().releaseSavepoint(getSavepoint());
	setSavepoint(null);
}
 
Example #25
Source File: HibernateJpaDialect.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Object beginTransaction(EntityManager entityManager, TransactionDefinition definition)
		throws PersistenceException, SQLException, TransactionException {

	Session session = getSession(entityManager);

	if (definition.getTimeout() != TransactionDefinition.TIMEOUT_DEFAULT) {
		session.getTransaction().setTimeout(definition.getTimeout());
	}

	boolean isolationLevelNeeded = (definition.getIsolationLevel() != TransactionDefinition.ISOLATION_DEFAULT);
	Integer previousIsolationLevel = null;
	Connection preparedCon = null;

	if (isolationLevelNeeded || definition.isReadOnly()) {
		if (this.prepareConnection) {
			preparedCon = HibernateConnectionHandle.doGetConnection(session);
			previousIsolationLevel = DataSourceUtils.prepareConnectionForTransaction(preparedCon, definition);
		}
		else if (isolationLevelNeeded) {
			throw new InvalidIsolationLevelException(getClass().getSimpleName() +
					" does not support custom isolation levels since the 'prepareConnection' flag is off. " +
					"This is the case on Hibernate 3.6 by default; either switch that flag at your own risk " +
					"or upgrade to Hibernate 4.x, with 4.2+ recommended.");
		}
	}

	// Standard JPA transaction begin call for full JPA context setup...
	entityManager.getTransaction().begin();

	// Adapt flush mode and store previous isolation level, if any.
	FlushMode previousFlushMode = prepareFlushMode(session, definition.isReadOnly());
	return new SessionTransactionData(session, previousFlushMode, preparedCon, previousIsolationLevel);
}
 
Example #26
Source File: ReactiveFirestoreTransactionManager.java    From spring-cloud-gcp with Apache License 2.0 5 votes vote down vote up
@Override
protected Mono<Void> doBegin(TransactionSynchronizationManager synchronizationManager, Object transactionObject,
		TransactionDefinition transactionDefinition) throws TransactionException {
	return Mono.defer(() -> {
		Mono<ReactiveFirestoreResourceHolder> holder = startTransaction(transactionDefinition);

		return holder.doOnNext(extractFirestoreTransaction(transactionObject)::setResourceHolder)
				.onErrorMap(
						ex -> new TransactionSystemException("Could not start Firestore transaction", ex))
				.doOnSuccess(resourceHolder -> {
					synchronizationManager.bindResource(this.firestore, resourceHolder);
				})
				.then();
	});
}
 
Example #27
Source File: AbstractPlatformTransactionManager.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * This implementation of commit handles participating in existing
 * transactions and programmatic rollback requests.
 * Delegates to {@code isRollbackOnly}, {@code doCommit}
 * and {@code rollback}.
 * @see org.springframework.transaction.TransactionStatus#isRollbackOnly()
 * @see #doCommit
 * @see #rollback
 */
@Override
public final void commit(TransactionStatus status) throws TransactionException {
	if (status.isCompleted()) {
		throw new IllegalTransactionStateException(
				"Transaction is already completed - do not call commit or rollback more than once per transaction");
	}

	DefaultTransactionStatus defStatus = (DefaultTransactionStatus) status;
	if (defStatus.isLocalRollbackOnly()) {
		if (defStatus.isDebug()) {
			logger.debug("Transactional code has requested rollback");
		}
		processRollback(defStatus);
		return;
	}
	if (!shouldCommitOnGlobalRollbackOnly() && defStatus.isGlobalRollbackOnly()) {
		if (defStatus.isDebug()) {
			logger.debug("Global transaction is marked as rollback-only but transactional code requested commit");
		}
		processRollback(defStatus);
		// Throw UnexpectedRollbackException only at outermost transaction boundary
		// or if explicitly asked to.
		if (status.isNewTransaction() || isFailEarlyOnGlobalRollbackOnly()) {
			throw new UnexpectedRollbackException(
					"Transaction rolled back because it has been marked as rollback-only");
		}
		return;
	}

	processCommit(defStatus);
}
 
Example #28
Source File: SpringTransactionManager.java    From ignite with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override protected void doSetRollbackOnly(DefaultTransactionStatus status) throws TransactionException {
    IgniteTransactionObject txObj = (IgniteTransactionObject)status.getTransaction();
    Transaction tx = txObj.getTransactionHolder().getTransaction();

    assert tx != null;

    if (status.isDebug() && log.isDebugEnabled())
        log.debug("Setting Ignite transaction rollback-only: " + tx);

    tx.setRollbackOnly();
}
 
Example #29
Source File: ReactiveRedissonTransactionManager.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Override
protected Mono<Object> doSuspend(TransactionSynchronizationManager synchronizationManager, Object transaction) throws TransactionException {
    return Mono.fromSupplier(() -> {
        ReactiveRedissonTransactionObject to = (ReactiveRedissonTransactionObject) transaction;
        to.setResourceHolder(null);
        return synchronizationManager.unbindResource(redissonClient);
    });
}
 
Example #30
Source File: RedissonTransactionManager.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Override
protected void doCommit(DefaultTransactionStatus status) throws TransactionException {
    RedissonTransactionObject to = (RedissonTransactionObject) status.getTransaction();
    try {
        to.getTransactionHolder().getTransaction().commit();
    } catch (org.redisson.transaction.TransactionException e) {
        throw new TransactionSystemException("Unable to commit transaction", e);
    }
}