[강운덕] [LUCYSUS-1744] bytecode조작 클래스의 api가 exception을 던지도록 수정함.

git-svn-id: http://svn.bds.nhncorp.com/pe/hippo-tomcat-profiler/trunk@596 84d0f5b1-2673-498c-a247-62c4ff18d310
This commit is contained in:
Woonduk Kang
2012-09-06 08:10:57 +00:00
parent 9bb9633fc3
commit ee566a4dff
17 changed files with 271 additions and 157 deletions
@@ -1,10 +1,12 @@
package com.profiler.modifier.db.mysql;
import java.security.ProtectionDomain;
import java.sql.Connection;
import java.util.logging.Level;
import java.util.logging.Logger;
import com.profiler.interceptor.Interceptor;
import com.profiler.interceptor.bci.InstrumentException;
import com.profiler.interceptor.bci.JavaAssistClass;
import javassist.*;
@@ -31,28 +33,21 @@ public class MySQLStatementModifier extends AbstractModifier {
}
byteCodeInstrumentor.checkLibrary(classLoader, javassistClassName);
// classPool.insertClassPath(new ByteArrayClassPath(javassistClassName, classFileBuffer));
InstrumentClass aClass = byteCodeInstrumentor.getClass(javassistClassName);
Interceptor interceptor = newInterceptor(classLoader, protectedDomain, "com.profiler.modifier.db.mysql.interceptors.ExecuteQueryMethodInterceptor");
boolean executeQuery = aClass.addInterceptor("executeQuery", new String[]{"java.lang.String"}, interceptor);
if (logger.isLoggable(Level.INFO)) {
logger.info("executeQuery =" + executeQuery);
try {
InstrumentClass statementClass = byteCodeInstrumentor.getClass(javassistClassName);
Interceptor interceptor = newInterceptor(classLoader, protectedDomain, "com.profiler.modifier.db.mysql.interceptors.ExecuteQueryMethodInterceptor");
statementClass.addInterceptor("executeQuery", new String[]{"java.lang.String"}, interceptor);
Interceptor interceptor1 = newInterceptor(classLoader, protectedDomain, "com.profiler.modifier.db.mysql.interceptors.ExecuteUpdateMethodInterceptor");
statementClass.addInterceptor("executeUpdate", new String[]{"java.lang.String", "boolean", "boolean"}, interceptor1);
statementClass.addTraceVariable("__url", "__setUrl", "__getUrl", "java.lang.String");
return statementClass.toBytecode();
} catch (InstrumentException e) {
return null;
}
Interceptor interceptor1 = newInterceptor(classLoader, protectedDomain, "com.profiler.modifier.db.mysql.interceptors.ExecuteUpdateMethodInterceptor");
boolean executeUpdate = aClass.addInterceptor("executeUpdate", new String[]{"java.lang.String", "boolean", "boolean"}, interceptor1);
if (logger.isLoggable(Level.INFO)) {
logger.info("executeUpdate =" + executeUpdate);
}
// TODO 아무래도 에러 체크를 Exception으로 변경하는게 좋을것 같음.
aClass.addTraceVariable("__url", "__setUrl", "__getUrl", "java.lang.String");
if (executeQuery && executeQuery) {
return aClass.toBytecode();
}
return null;
}