mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
CLOUDSTACK-1562: Replace @DB support to be the formal implementation instead of a temporary hacking one
This commit is contained in:
parent
837f7e1950
commit
89f4ac0439
@ -28,10 +28,7 @@ import javax.management.NotCompliantMBeanException;
|
|||||||
import javax.naming.ConfigurationException;
|
import javax.naming.ConfigurationException;
|
||||||
|
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
import org.springframework.aop.Advisor;
|
|
||||||
import org.springframework.aop.framework.Advised;
|
import org.springframework.aop.framework.Advised;
|
||||||
import org.springframework.aop.framework.ProxyFactory;
|
|
||||||
import org.springframework.aop.support.DefaultPointcutAdvisor;
|
|
||||||
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
|
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
|
||||||
import org.springframework.beans.factory.config.AutowireCapableBeanFactory;
|
import org.springframework.beans.factory.config.AutowireCapableBeanFactory;
|
||||||
import org.springframework.context.ApplicationContext;
|
import org.springframework.context.ApplicationContext;
|
||||||
@ -39,7 +36,6 @@ import org.springframework.context.ApplicationContextAware;
|
|||||||
import org.springframework.context.annotation.Primary;
|
import org.springframework.context.annotation.Primary;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import com.cloud.utils.db.TransactionContextBuilder;
|
|
||||||
import com.cloud.utils.mgmt.JmxUtil;
|
import com.cloud.utils.mgmt.JmxUtil;
|
||||||
import com.cloud.utils.mgmt.ManagementBean;
|
import com.cloud.utils.mgmt.ManagementBean;
|
||||||
|
|
||||||
|
|||||||
@ -33,7 +33,7 @@ public class TransactionContextBuilder implements MethodInterceptor {
|
|||||||
public Object AroundAnyMethod(ProceedingJoinPoint call) throws Throwable {
|
public Object AroundAnyMethod(ProceedingJoinPoint call) throws Throwable {
|
||||||
MethodSignature methodSignature = (MethodSignature)call.getSignature();
|
MethodSignature methodSignature = (MethodSignature)call.getSignature();
|
||||||
Method targetMethod = methodSignature.getMethod();
|
Method targetMethod = methodSignature.getMethod();
|
||||||
if(true) { // TODO ??? needToIntercept(targetMethod)) {
|
if(needToIntercept(targetMethod, call.getTarget())) {
|
||||||
Transaction txn = Transaction.open(call.getSignature().getName());
|
Transaction txn = Transaction.open(call.getSignature().getName());
|
||||||
Object ret = null;
|
Object ret = null;
|
||||||
try {
|
try {
|
||||||
@ -50,7 +50,7 @@ public class TransactionContextBuilder implements MethodInterceptor {
|
|||||||
public Object invoke(MethodInvocation method) throws Throwable {
|
public Object invoke(MethodInvocation method) throws Throwable {
|
||||||
Method targetMethod = method.getMethod();
|
Method targetMethod = method.getMethod();
|
||||||
|
|
||||||
if(needToIntercept(targetMethod)) {
|
if(needToIntercept(targetMethod, method.getThis())) {
|
||||||
Transaction txn = Transaction.open(targetMethod.getName());
|
Transaction txn = Transaction.open(targetMethod.getName());
|
||||||
Object ret = null;
|
Object ret = null;
|
||||||
try {
|
try {
|
||||||
@ -63,13 +63,25 @@ public class TransactionContextBuilder implements MethodInterceptor {
|
|||||||
return method.proceed();
|
return method.proceed();
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean needToIntercept(Method method) {
|
private boolean needToIntercept(Method method, Object target) {
|
||||||
DB db = method.getAnnotation(DB.class);
|
DB db = method.getAnnotation(DB.class);
|
||||||
if (db != null) {
|
if (db != null) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Class<?> clazz = method.getDeclaringClass();
|
Class<?> clazz = method.getDeclaringClass();
|
||||||
|
if(clazz.isInterface()) {
|
||||||
|
clazz = target.getClass();
|
||||||
|
for(Method m : clazz.getMethods()) {
|
||||||
|
// it is supposed that we need to check against type arguments,
|
||||||
|
// this can be simplified by just checking method name
|
||||||
|
if(m.getName().equals(method.getName())) {
|
||||||
|
if(m.getAnnotation(DB.class) != null)
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
do {
|
do {
|
||||||
db = clazz.getAnnotation(DB.class);
|
db = clazz.getAnnotation(DB.class);
|
||||||
if (db != null) {
|
if (db != null) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user