mirror of
https://gitee.com/jmix/cuba.git
synced 2024-11-30 18:27:56 +08:00
PL-6159 Implement new Aspect for Perf4J logging
#PL-6159
This commit is contained in:
parent
6bd50f5187
commit
650664f740
@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Copyright (c) 2008-2015 Haulmont. All rights reserved.
|
||||
* Use is subject to license terms, see http://www.cuba-platform.com/license for details.
|
||||
*/
|
||||
package com.haulmont.cuba.core.sys;
|
||||
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
import org.perf4j.StopWatch;
|
||||
import org.perf4j.log4j.Log4JStopWatch;
|
||||
|
||||
/**
|
||||
* @author degtyarjov
|
||||
* @version $Id$
|
||||
*/
|
||||
public class PerformanceLogInterceptor {
|
||||
@SuppressWarnings("UnusedDeclaration")
|
||||
private Object aroundInvoke(ProceedingJoinPoint ctx) throws Throwable {
|
||||
StopWatch stopWatch = new Log4JStopWatch(ctx.getSignature().toShortString());
|
||||
try {
|
||||
stopWatch.start();
|
||||
Object res = ctx.proceed();
|
||||
return res;
|
||||
} finally {
|
||||
stopWatch.stop();
|
||||
}
|
||||
}
|
||||
}
|
@ -96,5 +96,4 @@ cuba.cluster.enabled=false
|
||||
cuba.cluster.jgroupsConfig=jgroups.xml
|
||||
|
||||
#pretty time property paths
|
||||
cuba.prettyTimeProperties=com/haulmont/cuba/core/app/prettytime/prettytime.properties
|
||||
cuba.useAstBasedJpqlTransformer=true
|
||||
cuba.prettyTimeProperties=com/haulmont/cuba/core/app/prettytime/prettytime.properties
|
@ -74,6 +74,8 @@
|
||||
|
||||
<bean id="mbeanInterceptor" class="com.haulmont.cuba.core.sys.MBeanInterceptor"/>
|
||||
|
||||
<bean id="performanceLogInterceptor" class="com.haulmont.cuba.core.sys.PerformanceLogInterceptor"/>
|
||||
|
||||
<aop:config proxy-target-class="false">
|
||||
<aop:aspect id="serviceAspect" ref="serviceInterceptor" order="1">
|
||||
<aop:around method="aroundInvoke" pointcut="@within(org.springframework.stereotype.Service)"/>
|
||||
@ -88,6 +90,14 @@
|
||||
<aop:around method="aroundInvoke"
|
||||
pointcut="execution(@com.haulmont.cuba.security.app.Authenticated * *(..))"/>
|
||||
</aop:aspect>
|
||||
|
||||
<aop:aspect id="performanceLogTypeAspect" ref="performanceLogInterceptor" order="3">
|
||||
<aop:around method="aroundInvoke" pointcut="@within(com.haulmont.cuba.core.sys.PerformanceLog)"/>
|
||||
</aop:aspect>
|
||||
|
||||
<aop:aspect id="performanceLogMethodAspect" ref="performanceLogInterceptor" order="4">
|
||||
<aop:around method="aroundInvoke" pointcut="execution(@com.haulmont.cuba.core.sys.PerformanceLog * *(..))"/>
|
||||
</aop:aspect>
|
||||
</aop:config>
|
||||
|
||||
<!-- MBeans registration -->
|
||||
|
@ -128,7 +128,7 @@ public interface GlobalConfig extends Config {
|
||||
* @return true or false
|
||||
*/
|
||||
@Property("cuba.useAstBasedJpqlTransformer")
|
||||
@DefaultBoolean(false)
|
||||
@DefaultBoolean(true)
|
||||
boolean getUseAstBasedJpqlTransformer();
|
||||
|
||||
/**
|
||||
|
@ -13,6 +13,7 @@ import java.util.Set;
|
||||
* @version $Id$
|
||||
*/
|
||||
public interface QueryTransformer {
|
||||
String NAME = "cuba_QueryTransformer";
|
||||
|
||||
/** Main entity alias placeholder */
|
||||
String ALIAS_PLACEHOLDER = "{E}";
|
||||
|
@ -6,8 +6,6 @@ package com.haulmont.cuba.core.global;
|
||||
|
||||
import com.haulmont.cuba.core.sys.jpql.DomainModel;
|
||||
import com.haulmont.cuba.core.sys.jpql.DomainModelBuilder;
|
||||
import com.haulmont.cuba.core.sys.jpql.transform.QueryTransformerAstBased;
|
||||
import org.antlr.runtime.RecognitionException;
|
||||
|
||||
/**
|
||||
* Factory to get {@link QueryParser} and {@link QueryTransformer} instances.
|
||||
@ -24,17 +22,13 @@ public class QueryTransformerFactory {
|
||||
|
||||
public static QueryTransformer createTransformer(String query) {
|
||||
if (useAst) {
|
||||
try {
|
||||
if (domainModel == null) {
|
||||
MetadataTools metadataTools = AppBeans.get(MetadataTools.NAME);
|
||||
MessageTools messageTools = AppBeans.get(MessageTools.NAME);
|
||||
DomainModelBuilder builder = new DomainModelBuilder(metadataTools, messageTools);
|
||||
domainModel = builder.produce();
|
||||
}
|
||||
return new QueryTransformerAstBased(domainModel, query);
|
||||
} catch (RecognitionException e) {
|
||||
throw new RuntimeException(e);
|
||||
if (domainModel == null) {
|
||||
MetadataTools metadataTools = AppBeans.get(MetadataTools.NAME);
|
||||
MessageTools messageTools = AppBeans.get(MessageTools.NAME);
|
||||
DomainModelBuilder builder = new DomainModelBuilder(metadataTools, messageTools);
|
||||
domainModel = builder.produce();
|
||||
}
|
||||
return AppBeans.getPrototype(QueryTransformer.NAME, domainModel, query);
|
||||
} else {
|
||||
return new QueryTransformerRegex(query);
|
||||
}
|
||||
|
@ -0,0 +1,19 @@
|
||||
/*
|
||||
* Copyright (c) 2008-2015 Haulmont. All rights reserved.
|
||||
* Use is subject to license terms, see http://www.cuba-platform.com/license for details.
|
||||
*/
|
||||
|
||||
package com.haulmont.cuba.core.sys;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* @author degtyarjov
|
||||
* @version $Id$
|
||||
*/
|
||||
@Target({java.lang.annotation.ElementType.METHOD, ElementType.TYPE})
|
||||
@Retention(java.lang.annotation.RetentionPolicy.RUNTIME)
|
||||
public @interface PerformanceLog {
|
||||
}
|
@ -6,6 +6,7 @@
|
||||
package com.haulmont.cuba.core.sys.jpql.transform;
|
||||
|
||||
import com.haulmont.cuba.core.global.QueryTransformer;
|
||||
import com.haulmont.cuba.core.sys.PerformanceLog;
|
||||
import com.haulmont.cuba.core.sys.jpql.*;
|
||||
import com.haulmont.cuba.core.sys.jpql.antlr2.JPA2Lexer;
|
||||
import com.haulmont.cuba.core.sys.jpql.model.Entity;
|
||||
@ -15,6 +16,9 @@ import org.antlr.runtime.tree.CommonErrorNode;
|
||||
import org.antlr.runtime.tree.CommonTree;
|
||||
import org.antlr.runtime.tree.TreeVisitor;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
@ -25,6 +29,9 @@ import java.util.Set;
|
||||
* @author Chevelev
|
||||
* @version $Id$
|
||||
*/
|
||||
@Scope(BeanDefinition.SCOPE_PROTOTYPE)
|
||||
@Component(QueryTransformer.NAME)
|
||||
@PerformanceLog
|
||||
public class QueryTransformerAstBased implements QueryTransformer {
|
||||
private DomainModel model;
|
||||
private String query;
|
||||
|
Loading…
Reference in New Issue
Block a user