Ejemplo n.º 1
0
  public byte[] modify(
      ClassLoader classLoader,
      String javassistClassName,
      ProtectionDomain protectedDomain,
      byte[] classFileBuffer) {
    if (logger.isInfoEnabled()) {
      logger.info("Modifying. {}", javassistClassName);
    }

    try {
      InstrumentClass statementClass =
          byteCodeInstrumentor.getClass(classLoader, javassistClassName, classFileBuffer);

      Interceptor interceptor = new StatementExecuteQueryInterceptor();
      statementClass.addGroupInterceptor(
          "executeQuery", new String[] {"java.lang.String"}, interceptor, MYSQLScope.SCOPE_NAME);

      // FIXME
      Interceptor executeUpdateInterceptor1 = new StatementExecuteUpdateInterceptor();
      statementClass.addGroupInterceptor(
          "executeUpdate",
          new String[] {"java.lang.String"},
          executeUpdateInterceptor1,
          MYSQLScope.SCOPE_NAME);

      Interceptor executeUpdateInterceptor2 = new StatementExecuteUpdateInterceptor();
      statementClass.addGroupInterceptor(
          "executeUpdate",
          new String[] {"java.lang.String", "int"},
          executeUpdateInterceptor2,
          MYSQLScope.SCOPE_NAME);

      Interceptor executeUpdateInterceptor3 = new StatementExecuteUpdateInterceptor();
      statementClass.addGroupInterceptor(
          "execute",
          new String[] {"java.lang.String"},
          executeUpdateInterceptor3,
          MYSQLScope.SCOPE_NAME);

      Interceptor executeUpdateInterceptor4 = new StatementExecuteUpdateInterceptor();
      statementClass.addGroupInterceptor(
          "execute",
          new String[] {"java.lang.String", "int"},
          executeUpdateInterceptor4,
          MYSQLScope.SCOPE_NAME);

      statementClass.addTraceValue(DatabaseInfoTraceValue.class);
      return statementClass.toBytecode();
    } catch (InstrumentException e) {
      if (logger.isWarnEnabled()) {
        logger.warn("{} modify fail. Cause:{}", this.getClass().getSimpleName(), e.getMessage(), e);
      }
      return null;
    }
  }