Coverage Report - com.ctrip.apollo.biz.aop.RepositoryAspect
 
Classes in this File Line Coverage Branch Coverage Complexity
RepositoryAspect
69%
9/13
N/A
2.5
 
 1  
 package com.ctrip.apollo.biz.aop;
 2  
 
 3  
 import com.dianping.cat.Cat;
 4  
 import com.dianping.cat.message.Message;
 5  
 import com.dianping.cat.message.Transaction;
 6  
 
 7  
 import org.aspectj.lang.ProceedingJoinPoint;
 8  
 import org.aspectj.lang.annotation.Around;
 9  
 import org.aspectj.lang.annotation.Aspect;
 10  
 import org.aspectj.lang.annotation.Pointcut;
 11  
 import org.springframework.stereotype.Component;
 12  
 
 13  
 /**
 14  
  * @author Jason Song(song_s@ctrip.com)
 15  
  */
 16  
 @Aspect
 17  
 @Component
 18  1
 public class RepositoryAspect {
 19  
 
 20  
   @Pointcut("execution(public * org.springframework.data.repository.Repository+.*(..))")
 21  
   public void anyRepositoryMethod() {
 22  0
   }
 23  
 
 24  
   @Around("anyRepositoryMethod()")
 25  
   public Object invokeWithCatTransaction(ProceedingJoinPoint joinPoint) throws Throwable {
 26  106
     String name =
 27  106
         joinPoint.getSignature().getDeclaringType().getSimpleName() + "." + joinPoint.getSignature()
 28  106
             .getName();
 29  106
     Transaction catTransaction = Cat.newTransaction("SQL", name);
 30  
     try {
 31  106
       Object result = joinPoint.proceed();
 32  106
       catTransaction.setStatus(Message.SUCCESS);
 33  106
       return result;
 34  0
     } catch (Throwable ex) {
 35  0
       catTransaction.setStatus(ex);
 36  0
       throw ex;
 37  
     } finally {
 38  106
       catTransaction.complete();
 39  
     }
 40  
   }
 41  
 }