Coverage Report - org.apache.camel.spring.spi.TransactionInterceptor
 
Classes in this File Line Coverage Branch Coverage Complexity
TransactionInterceptor
0% 
N/A 
0
 
 1  
 /**
 2  
  * Licensed to the Apache Software Foundation (ASF) under one or more
 3  
  * contributor license agreements.  See the NOTICE file distributed with
 4  
  * this work for additional information regarding copyright ownership.
 5  
  * The ASF licenses this file to You under the Apache License, Version 2.0
 6  
  * (the "License"); you may not use this file except in compliance with
 7  
  * the License.  You may obtain a copy of the License at
 8  
  *
 9  
  *      http://www.apache.org/licenses/LICENSE-2.0
 10  
  *
 11  
  * Unless required by applicable law or agreed to in writing, software
 12  
  * distributed under the License is distributed on an "AS IS" BASIS,
 13  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14  
  * See the License for the specific language governing permissions and
 15  
  * limitations under the License.
 16  
  */
 17  
 package org.apache.camel.spring.spi;
 18  
 
 19  
 import org.apache.camel.Exchange;
 20  
 import org.apache.camel.RuntimeCamelException;
 21  
 import org.apache.camel.processor.DelegateProcessor;
 22  
 import org.apache.commons.logging.Log;
 23  
 import org.apache.commons.logging.LogFactory;
 24  
 
 25  
 import org.springframework.transaction.TransactionDefinition;
 26  
 import org.springframework.transaction.TransactionStatus;
 27  
 import org.springframework.transaction.support.TransactionCallbackWithoutResult;
 28  
 import org.springframework.transaction.support.TransactionTemplate;
 29  
 
 30  
 /**
 31  
  * @version $Revision: 1.1 $
 32  
  */
 33  0
 public class TransactionInterceptor extends DelegateProcessor {
 34  0
     private static final transient Log LOG = LogFactory.getLog(TransactionInterceptor.class);
 35  
     private final TransactionTemplate transactionTemplate;
 36  
 
 37  0
     public TransactionInterceptor(TransactionTemplate transactionTemplate) {
 38  0
         this.transactionTemplate = transactionTemplate;
 39  0
     }
 40  
 
 41  
     public void process(final Exchange exchange) {
 42  0
         LOG.info("transaction begin");
 43  
 
 44  0
         transactionTemplate.execute(new TransactionCallbackWithoutResult() {
 45  0
             protected void doInTransactionWithoutResult(TransactionStatus status) {
 46  
                 try {
 47  0
                     processNext(exchange);
 48  0
                 } catch (Exception e) {
 49  0
                     throw new RuntimeCamelException(e);
 50  0
                 }
 51  0
             }
 52  
         });
 53  
 
 54  0
         LOG.info("transaction commit");
 55  0
     }
 56  
 
 57  
     @Override
 58  
     public String toString() {
 59  0
         return "TransactionInterceptor:" + propagationBehaviorToString(transactionTemplate.getPropagationBehavior()) + "[" + getProcessor() + "]";
 60  
     }
 61  
 
 62  
     private String propagationBehaviorToString(int propagationBehavior) {
 63  
         String rc;
 64  0
         switch (propagationBehavior) {
 65  
         case TransactionDefinition.PROPAGATION_MANDATORY:
 66  0
             rc = "PROPAGATION_MANDATORY";
 67  0
             break;
 68  
         case TransactionDefinition.PROPAGATION_NESTED:
 69  0
             rc = "PROPAGATION_NESTED";
 70  0
             break;
 71  
         case TransactionDefinition.PROPAGATION_NEVER:
 72  0
             rc = "PROPAGATION_NEVER";
 73  0
             break;
 74  
         case TransactionDefinition.PROPAGATION_NOT_SUPPORTED:
 75  0
             rc = "PROPAGATION_NOT_SUPPORTED";
 76  0
             break;
 77  
         case TransactionDefinition.PROPAGATION_REQUIRED:
 78  0
             rc = "PROPAGATION_REQUIRED";
 79  0
             break;
 80  
         case TransactionDefinition.PROPAGATION_REQUIRES_NEW:
 81  0
             rc = "PROPAGATION_REQUIRES_NEW";
 82  0
             break;
 83  
         case TransactionDefinition.PROPAGATION_SUPPORTS:
 84  0
             rc = "PROPAGATION_SUPPORTS";
 85  0
             break;
 86  
         default:
 87  0
             rc = "UNKOWN"; 
 88  
         }
 89  0
         return rc;
 90  
     }
 91  
 }