##### Coverage Report - com.ctrip.framework.apollo.biz.aop.RepositoryAspect

Classes in this File | Line Coverage | Branch Coverage | Complexity
RepositoryAspect |
69% | 9/13
N/A | N/A
| 2.5;2.5

1 |  |
     package com.ctrip.framework.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 | 120 |
         String name =
27 | 120 |
             joinPoint.getSignature().getDeclaringType().getSimpleName() + "." + joinPoint.getSignature()
28 | 120 |
                 .getName();
29 | 120 |
         Transaction catTransaction = Cat.newTransaction("SQL", name);
30 |  |
         try {
31 | 120 |
           Object result = joinPoint.proceed();
32 | 120 |
           catTransaction.setStatus(Message.SUCCESS);
33 | 120 |
           return result;
34 | 0 |
         } catch (Throwable ex) {
35 | 0 |
           catTransaction.setStatus(ex);
36 | 0 |
           throw ex;
37 |  |
         } finally {
38 | 120 |
           catTransaction.complete();
39 |  |
         }
40 |  |
       }
41 |  |
     }