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);
}
}
}
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);
}
}
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;
}
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()));
}
}
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));
}
Aggregations