ActiveJDBC instrumentation

60 views
Skip to first unread message

Aravind Kumar

unread,
Apr 5, 2015, 4:21:25 AM4/5/15
to activejd...@googlegroups.com
Hi there, 

I have been reading the ActiveJDBC source code.

I would like to know what this piece of code does ?


        CodeConverter conv = new CodeConverter();
       conv.redirectMethodCall(modelGetClass, newGetClass);

        for (CtMethod method : modelMethods) {
           int modifiers = method.getModifiers();
           if (Modifier.isStatic(modifiers)) {
               if (targetHasMethod(targetMethods, method)) {
                   Instrumentation.log("Detected method: " + method.getName() + ", skipping delegate.");
               } else {
                   CtMethod newMethod;
                   if (Modifier.isProtected(modifiers) || Modifier.isPublic(modifiers)) {
                       newMethod = CtNewMethod.copy(method, target, classMap);
                       newMethod.instrument(conv);
                   } else if ("modelClass".equals(method.getName())) {
                       newMethod = newGetClass;
                   } else {
                       newMethod = CtNewMethod.delegator(method, target);
                   }


                    for (Object attr : method.getMethodInfo().getAttributes()) {
                       if (attr instanceof SignatureAttribute) {
                           newMethod.getMethodInfo().addAttribute((SignatureAttribute) attr);
                       }
                   }
                   target.addMethod(newMethod);
               }
           }
       }



From what I understand,
  • it copies `Model.modelClass()` method to the target class 
  • Copies all the public and protected methods to target class and redirects the call to Model.modelClass() in the method body to Target.modelClass()
  • Creates methods which forwards to a delegate in the Model class and adds it to the target class.
What confuses me is the third point, How does it create a forwarding method to the methods with private and package visibility in the Model class ? Is there any reason why I do not see any private static method in Model.java (except `Model.modelClass()`) ? 

Igor Polevoy

unread,
Apr 6, 2015, 10:09:35 PM4/6/15
to activejd...@googlegroups.com
this code does what is described on this page: http://javalite.io/instrumentation

tx


On Sunday, April 5, 2015 at 3:21:25 AM UTC-5, Aravind Kumar wrote:
Hi there, 

I have been reading the ActiveJDBC source code.

I would like to know what this piece of code does ?


        CodeConverter conv = new CodeConverter();
       conv.redirectMethodCall(modelGetClass, newGetClass);

        for (CtMethod method : modelMethods) {
           int modifiers = method.getModifiers();
           if (Modifier.isStatic(modifiers)) {
               if (targetHasMethod(targetMethods, method)) {
                   Instrumentation.log("Detected method: " + method.getName() + ", skipping delegate.");
               } else {
                   CtMethod newMethod;
                   if (Modifier.isProtected(modifiers) || Modifier.isPublic(modifiers)) {
                       newMethod = CtNewMethod.copy(method, target, classMap);
                       newMethod.instrument(conv);
                   } else if ("modelClass".equals(method.getName())) {
                       newMethod = newGetClass;
                   } else {
                       newMethod = CtNewMethod.delegator(method, target);
                   }


                    for (Object attr : method.getMethodInfo().getAttributes()) {
                       if (attr instanceof SignatureAttribute) {
                           newMethod.getMethodInfo().
...
Reply all
Reply to author
Forward
0 new messages