Search in sources :

Example 1 with TransactionException

use of org.springframework.transaction.TransactionException in project ignite by apache.

the class CacheSpringStoreSessionListener method onSessionStart.

/**
 * {@inheritDoc}
 */
@Override
public void onSessionStart(CacheStoreSession ses) {
    if (ses.isWithinTransaction() && ses.attachment() == null) {
        try {
            TransactionDefinition def = definition(ses.transaction(), ses.cacheName());
            ses.attach(txMgr.getTransaction(def));
        } catch (TransactionException e) {
            throw new CacheWriterException("Failed to start store session [tx=" + ses.transaction() + ']', e);
        }
    }
}
Also used : TransactionDefinition(org.springframework.transaction.TransactionDefinition) DefaultTransactionDefinition(org.springframework.transaction.support.DefaultTransactionDefinition) TransactionException(org.springframework.transaction.TransactionException) CacheWriterException(javax.cache.integration.CacheWriterException)

Example 2 with TransactionException

use of org.springframework.transaction.TransactionException in project ignite by apache.

the class SpringTransactionManager method doBegin.

/**
 * {@inheritDoc}
 */
@Override
protected void doBegin(Object transaction, TransactionDefinition definition) throws TransactionException {
    if (definition.getIsolationLevel() == TransactionDefinition.ISOLATION_READ_UNCOMMITTED)
        throw new InvalidIsolationLevelException("Ignite does not support READ_UNCOMMITTED isolation level.");
    IgniteTransactionObject txObj = (IgniteTransactionObject) transaction;
    Transaction tx = null;
    try {
        if (txObj.getTransactionHolder() == null || txObj.getTransactionHolder().isSynchronizedWithTransaction()) {
            long timeout = ignite.configuration().getTransactionConfiguration().getDefaultTxTimeout();
            if (definition.getTimeout() > 0)
                timeout = TimeUnit.SECONDS.toMillis(definition.getTimeout());
            Transaction newTx = ignite.transactions().txStart(transactionConcurrency, convertToIgniteIsolationLevel(definition.getIsolationLevel()), timeout, 0);
            if (log.isDebugEnabled())
                log.debug("Started Ignite transaction: " + newTx);
            txObj.setTransactionHolder(new IgniteTransactionHolder(newTx), true);
        }
        txObj.getTransactionHolder().setSynchronizedWithTransaction(true);
        txObj.getTransactionHolder().setTransactionActive(true);
        tx = txObj.getTransactionHolder().getTransaction();
        // Bind the session holder to the thread.
        if (txObj.isNewTransactionHolder())
            TransactionSynchronizationManager.bindResource(this.ignite, txObj.getTransactionHolder());
    } catch (Exception ex) {
        if (tx != null)
            tx.close();
        throw new CannotCreateTransactionException("Could not create Ignite transaction", ex);
    }
}
Also used : Transaction(org.apache.ignite.transactions.Transaction) CannotCreateTransactionException(org.springframework.transaction.CannotCreateTransactionException) InvalidIsolationLevelException(org.springframework.transaction.InvalidIsolationLevelException) IgniteException(org.apache.ignite.IgniteException) InvalidIsolationLevelException(org.springframework.transaction.InvalidIsolationLevelException) TransactionSystemException(org.springframework.transaction.TransactionSystemException) TransactionException(org.springframework.transaction.TransactionException) CannotCreateTransactionException(org.springframework.transaction.CannotCreateTransactionException)

Example 3 with TransactionException

use of org.springframework.transaction.TransactionException in project metalnx-web by irods-contrib.

the class IRODSAuthenticationProvider method authenticate.

@Override
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
    String username = authentication.getName();
    String password = authentication.getCredentials().toString();
    AuthResponse authResponse;
    UsernamePasswordAuthenticationToken authObject;
    logger.debug("Setting username {}", username);
    try {
        authResponse = this.authenticateAgainstIRODS(username, password);
        // Settings iRODS account
        this.irodsAccount = authResponse.getAuthenticatedIRODSAccount();
        // Retrieving logging user
        User irodsUser = new User();
        try {
            irodsUser = this.irodsAccessObjectFactory.getUserAO(this.irodsAccount).findByName(username);
        } catch (JargonException e) {
            logger.error("Could not find user: " + e.getMessage());
        }
        GrantedAuthority grantedAuth;
        if (irodsUser.getUserType().equals(UserTypeEnum.RODS_ADMIN)) {
            grantedAuth = new IRODSAdminGrantedAuthority();
        } else {
            grantedAuth = new IRODSUserGrantedAuthority();
        }
        // Settings granted authorities
        List<GrantedAuthority> grantedAuths = new ArrayList<GrantedAuthority>();
        grantedAuths.add(grantedAuth);
        // Returning authentication token with the access object factory injected
        authObject = new UsernamePasswordAuthenticationToken(username, password, grantedAuths);
        // Creating UserTokenDetails instance for the current authenticated user
        UserTokenDetails userDetails = new UserTokenDetails();
        userDetails.setIrodsAccount(this.irodsAccount);
        userDetails.setUser(this.user);
        // Settings the user details object into the authentication object
        authObject.setDetails(userDetails);
    } catch (TransactionException e) {
        logger.error("Database not responding");
        throw new DataGridDatabaseException(e.getMessage());
    } catch (InvalidUserException | org.irods.jargon.core.exception.AuthenticationException e) {
        logger.error("Could not authenticate user: ", username);
        throw new DataGridAuthenticationException(e.getMessage());
    } catch (JargonException e) {
        logger.error("Server not responding");
        throw new DataGridServerException(e.getMessage());
    }
    return authObject;
}
Also used : DataGridUser(com.emc.metalnx.core.domain.entity.DataGridUser) User(org.irods.jargon.core.pub.domain.User) DataGridAuthenticationException(com.emc.metalnx.core.domain.exceptions.DataGridAuthenticationException) AuthenticationException(org.springframework.security.core.AuthenticationException) JargonException(org.irods.jargon.core.exception.JargonException) GrantedAuthority(org.springframework.security.core.GrantedAuthority) ArrayList(java.util.ArrayList) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken) InvalidUserException(org.irods.jargon.core.exception.InvalidUserException) DataGridAuthenticationException(com.emc.metalnx.core.domain.exceptions.DataGridAuthenticationException) AuthResponse(org.irods.jargon.core.connection.auth.AuthResponse) DataGridDatabaseException(com.emc.metalnx.core.domain.exceptions.DataGridDatabaseException) TransactionException(org.springframework.transaction.TransactionException) DataGridServerException(com.emc.metalnx.core.domain.exceptions.DataGridServerException)

Example 4 with TransactionException

use of org.springframework.transaction.TransactionException in project molgenis by molgenis.

the class PostgreSqlTransactionManager method doCommit.

@Override
protected void doCommit(DefaultTransactionStatus status) {
    MolgenisTransaction transaction = (MolgenisTransaction) status.getTransaction();
    if (LOG.isDebugEnabled()) {
        LOG.debug("Commit transaction [{}]", transaction.getId());
    }
    DefaultTransactionStatus jpaTransactionStatus = new DefaultTransactionStatus(transaction.getDataSourceTransaction(), status.isNewTransaction(), status.isNewSynchronization(), status.isReadOnly(), status.isDebug(), status.getSuspendedResources());
    if (!status.isReadOnly()) {
        transactionListeners.forEach(j -> j.commitTransaction(transaction.getId()));
    }
    try {
        super.doCommit(jpaTransactionStatus);
    } catch (TransactionException e) {
        throw translateTransactionException(e);
    }
    if (!status.isReadOnly()) {
        transactionListeners.forEach(j -> j.afterCommitTransaction(transaction.getId()));
    }
}
Also used : TransactionException(org.springframework.transaction.TransactionException) DefaultTransactionStatus(org.springframework.transaction.support.DefaultTransactionStatus)

Example 5 with TransactionException

use of org.springframework.transaction.TransactionException in project spring-framework by spring-projects.

the class AbstractReactiveTransactionManager method processCommit.

/**
 * Process an actual commit.
 * Rollback-only flags have already been checked and applied.
 * @param synchronizationManager the synchronization manager bound to the current transaction
 * @param status object representing the transaction
 * @throws TransactionException in case of commit failure
 */
private Mono<Void> processCommit(TransactionSynchronizationManager synchronizationManager, GenericReactiveTransaction status) throws TransactionException {
    AtomicBoolean beforeCompletionInvoked = new AtomicBoolean();
    Mono<Object> commit = prepareForCommit(synchronizationManager, status).then(triggerBeforeCommit(synchronizationManager, status)).then(triggerBeforeCompletion(synchronizationManager, status)).then(Mono.defer(() -> {
        beforeCompletionInvoked.set(true);
        if (status.isNewTransaction()) {
            if (status.isDebug()) {
                logger.debug("Initiating transaction commit");
            }
            return doCommit(synchronizationManager, status);
        }
        return Mono.empty();
    })).then(Mono.empty().onErrorResume(ex -> {
        Mono<Object> propagateException = Mono.error(ex);
        // Store result in a local variable in order to appease the
        // Eclipse compiler with regard to inferred generics.
        Mono<Object> result = propagateException;
        if (ErrorPredicates.UNEXPECTED_ROLLBACK.test(ex)) {
            result = triggerAfterCompletion(synchronizationManager, status, TransactionSynchronization.STATUS_ROLLED_BACK).then(propagateException);
        } else if (ErrorPredicates.TRANSACTION_EXCEPTION.test(ex)) {
            result = triggerAfterCompletion(synchronizationManager, status, TransactionSynchronization.STATUS_UNKNOWN).then(propagateException);
        } else if (ErrorPredicates.RUNTIME_OR_ERROR.test(ex)) {
            Mono<Void> mono;
            if (!beforeCompletionInvoked.get()) {
                mono = triggerBeforeCompletion(synchronizationManager, status);
            } else {
                mono = Mono.empty();
            }
            result = mono.then(doRollbackOnCommitException(synchronizationManager, status, ex)).then(propagateException);
        }
        return result;
    })).then(Mono.defer(() -> triggerAfterCommit(synchronizationManager, status).onErrorResume(ex -> triggerAfterCompletion(synchronizationManager, status, TransactionSynchronization.STATUS_COMMITTED).then(Mono.error(ex))).then(triggerAfterCompletion(synchronizationManager, status, TransactionSynchronization.STATUS_COMMITTED))));
    return commit.onErrorResume(ex -> cleanupAfterCompletion(synchronizationManager, status).then(Mono.error(ex))).then(cleanupAfterCompletion(synchronizationManager, status));
}
Also used : TransactionSuspensionNotSupportedException(org.springframework.transaction.TransactionSuspensionNotSupportedException) Predicate(java.util.function.Predicate) TransactionDefinition(org.springframework.transaction.TransactionDefinition) ObjectInputStream(java.io.ObjectInputStream) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) IOException(java.io.IOException) Mono(reactor.core.publisher.Mono) UnexpectedRollbackException(org.springframework.transaction.UnexpectedRollbackException) ReactiveTransaction(org.springframework.transaction.ReactiveTransaction) IllegalTransactionStateException(org.springframework.transaction.IllegalTransactionStateException) ReactiveTransactionManager(org.springframework.transaction.ReactiveTransactionManager) Serializable(java.io.Serializable) Flux(reactor.core.publisher.Flux) List(java.util.List) InvalidTimeoutException(org.springframework.transaction.InvalidTimeoutException) TransactionException(org.springframework.transaction.TransactionException) Optional(java.util.Optional) Log(org.apache.commons.logging.Log) Nullable(org.springframework.lang.Nullable) LogFactory(org.apache.commons.logging.LogFactory) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean)

Aggregations

TransactionException (org.springframework.transaction.TransactionException)20 CannotCreateTransactionException (org.springframework.transaction.CannotCreateTransactionException)8 UnexpectedRollbackException (org.springframework.transaction.UnexpectedRollbackException)8 PlatformTransactionManager (org.springframework.transaction.PlatformTransactionManager)7 HeuristicCompletionException (org.springframework.transaction.HeuristicCompletionException)6 TransactionDefinition (org.springframework.transaction.TransactionDefinition)5 Nullable (org.springframework.lang.Nullable)3 TransactionStatus (org.springframework.transaction.TransactionStatus)3 Mono (reactor.core.publisher.Mono)3 IOException (java.io.IOException)2 ObjectInputStream (java.io.ObjectInputStream)2 Serializable (java.io.Serializable)2 List (java.util.List)2 Map (java.util.Map)2 Optional (java.util.Optional)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 Predicate (java.util.function.Predicate)2 Log (org.apache.commons.logging.Log)2 LogFactory (org.apache.commons.logging.LogFactory)2 IllegalTransactionStateException (org.springframework.transaction.IllegalTransactionStateException)2