diff --git a/src/main/java/com/taobao/profile/dependence_query/mysql/MysqlProfFilter.java b/src/main/java/com/taobao/profile/dependence_query/mysql/MysqlProfFilter.java index be043d1..7322160 100644 --- a/src/main/java/com/taobao/profile/dependence_query/mysql/MysqlProfFilter.java +++ b/src/main/java/com/taobao/profile/dependence_query/mysql/MysqlProfFilter.java @@ -1,5 +1,8 @@ package com.taobao.profile.dependence_query.mysql; +import java.util.HashSet; +import java.util.Set; + import com.taobao.profile.config.ProfFilter; /** @@ -10,13 +13,32 @@ public class MysqlProfFilter extends ProfFilter { public final static String MysqlPath = "com/mysql/jdbc/ConnectionImpl"; + protected static Set includeMysqlPackage = new HashSet(); + private static MysqlProfFilter instance = new MysqlProfFilter(); protected MysqlProfFilter() { - includePackage.add(MysqlPath.toLowerCase()); + includeMysqlPackage.add(MysqlPath.toLowerCase()); } public static MysqlProfFilter getInstance(){ return instance; } - + + /** + * 为mysql重写isNeedInject方法 + * + * 是否是需要注入的类 + * + * @param className + * @return + */ + public static boolean isNeedInjectMysql(String className) { + String icaseName = className.toLowerCase().replace('.', '/'); + for (String v : includeMysqlPackage) { + if (icaseName.startsWith(v)) { + return true; + } + } + return false; + } } diff --git a/src/main/java/com/taobao/profile/instrument/ProfTransformer.java b/src/main/java/com/taobao/profile/instrument/ProfTransformer.java index d07a385..a3c215f 100644 --- a/src/main/java/com/taobao/profile/instrument/ProfTransformer.java +++ b/src/main/java/com/taobao/profile/instrument/ProfTransformer.java @@ -42,7 +42,7 @@ public class ProfTransformer implements ClassFileTransformer { private byte[] transform4Mysql(ClassLoader loader, String className, Class classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer){ try { - if(!MysqlProfFilter.getInstance().isNeedInject(className)){ + if(!MysqlProfFilter.isNeedInjectMysql(className)){ return null; }