Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright (c) 2010-2011. Axon Framework
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *     http://www.apache.org/licenses/LICENSE-2.0
   *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 
 package org.axonframework.eventhandling.transactionmanagers;
 
 
TransactionManager implementation that uses a org.springframework.transaction.PlatformTransactionManager as underlying transaction manager.

The transaction manager will commit the transaction when event handling is successful. If a non-transient (non-recoverable) exception occurs, the failing event is discarded and the transaction is committed. If a transient exception occurs, such as a failing connection, the transaction is rolled back and scheduled for a retry.

Author(s):
Allard Buijze
Since:
0.5
 
 public class SpringTransactionManager implements TransactionManager {
 
     private static final Logger logger = LoggerFactory.getLogger(SpringTransactionManager.class);
 
 
 
     @Override
     public void beforeTransaction(TransactionStatus transactionStatus) {
         transactionStatus.setRetryPolicy(.);
         transactionStatus.setMaxTransactionSize(25);
     }
 
     @SuppressWarnings({"ThrowableResultOfMethodCallIgnored"})
     @Override
     public void afterTransaction(TransactionStatus transactionStatus) {
         if (transactionStatus.isSuccessful()) {
             .commit(.get());
         } else {
             .warn("Found failed transaction: [{}]."transactionStatus.getException().getClass().getSimpleName());
             if (!isTransient(transactionStatus.getException())) {
                 .error("ERROR! Exception is not transient or recoverable! Committing transaction and "
                                      + "skipping Event processing"transactionStatus.getException());
                 transactionStatus.setRetryPolicy(.);
                 .commit(.get());
             } else {
                 .warn("Performing rollback on transaction due to recoverable exception: [{}]",
                             transactionStatus.getException().getClass().getSimpleName());
                 transactionStatus.setRetryPolicy(.);
                 if (.get() != null) {
                     .rollback(.get());
                 }
             }
         }
         .remove();
     }

    
The PlatformTransactionManager that manages the transactions with the underlying data source.

Parameters:
transactionManager the transaction manager that manages transactions with underlying data sources
 
     public void setTransactionManager(PlatformTransactionManager transactionManager) {
         this. = transactionManager;
     }
 
     @SuppressWarnings({"SimplifiableIfStatement"})
     private boolean isTransient(Throwable exception) {
         if (exception instanceof SQLTransientException || exception instanceof SQLRecoverableException) {
             return true;
         }
         if (exception.getCause() != null && exception.getCause() != exception) {
             return isTransient(exception.getCause());
         }
         return false;
     }
New to GrepCode? Check out our FAQ X