Created
February 6, 2014 07:17
-
-
Save bmakarand2009/8839623 to your computer and use it in GitHub Desktop.
Measure the peformance of a JPA Query
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.webforefront.aop; | |
import org.apache.commons.lang.time.StopWatch; | |
import org.apache.commons.logging.Log; | |
import org.apache.commons.logging.LogFactory; | |
import org.aspectj.lang.ProceedingJoinPoint; | |
import org.aspectj.lang.annotation.Around; | |
import org.aspectj.lang.annotation.Pointcut; | |
import org.aspectj.lang.annotation.Aspect; | |
@Aspect | |
public class DAOInterceptor { | |
private Log log = LogFactory.getLog(DAOInterceptor.class); | |
@Around("execution(* com.webforefront.jpa.service..*.*(..))") | |
public Object logQueryTimes(ProceedingJoinPoint pjp) throws Throwable { | |
StopWatch stopWatch = new StopWatch(); | |
stopWatch.start(); | |
Object retVal = pjp.proceed(); | |
stopWatch.stop(); | |
String str = pjp.getTarget().toString(); | |
log.info(str.substring(str.lastIndexOf(".")+1, str.lastIndexOf("@")) + " - " + pjp.getSignature().getName() + ": " + stopWatch.getTime() + "ms"); | |
return retVal; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment