javaassist used in the hibernate,
分享于 点击 18129 次 点评:286
javaassist used in the hibernate,
javaassist opensource framework is the initials of the"Java Programming Assistant" , it makes Java bytecode manipulation simple and easy. you can manipulate the behaviors of the java the following aspects:1 soruce code level
2 bytecode level
hibernate use the javaassist to instead to the cglib in version 3.3, its function is similar to the cglib ,it can implement the lazy loading and generate the po objects
for examples:
package antlr;
import javassist.ClassPool;
import javassist.CtClass;
import javassist.CtMethod;
public class TestAntlr {
public static void main(String[] args) throws Exception {
ClassPool cp = ClassPool.getDefault();
CtClass cc = cp.get("antlr.Hello");
CtMethod m = cc.getDeclaredMethod("say");
// m.setBody("{System.out.println(\"s\");}");
m.insertBefore("System.out.println(\"ss\");");
Class c = cc.toClass();
Hello h = (Hello)c.newInstance();
h.say();
// ClassPool cp = ClassPool.getDefault();
// CtClass cc = cp.get("java.lang.String");
// CtMethod m = cc.getDeclaredMethod("toString");
//// m.setBody("{System.out.println(\"s\");}");
//
//// m.insertBefore("System.out.println(\"ss\");");
// Class c = cc.toClass();
// String h = (String)c.newInstance();
// h.toString();
}
}
package antlr;
class Hello{
public void say() {
System.out.println("Hello");
}
}
相关文章
- 暂无相关文章
用户点评