private void enhanceJPACallback(CtClass ctClass, CtMethod method, Class anno) throws Exception { if (method.hasAnnotation(anno)) { CtMethod ctMethod = CtMethod.make( format( "public void {}() {\n" + " net.csdn.jpa.context.JPAContext jpaContext = getJPAConfig().reInitJPAContext();\n" + " try {\n" + " {}();\n" + " getJPAConfig().getJPAContext().closeTx(false);\n" + " } catch (Exception e) {\n" + " getJPAConfig().getJPAContext().closeTx(true);\n" + " } finally {\n" + " getJPAConfig().setJPAContext(jpaContext);\n" + " }\n" + " }", "$_" + method.getName(), method.getName()), ctClass); ctClass.addMethod(ctMethod); AnnotationsAttribute annotationsAttribute = EnhancerHelper.getAnnotations(ctMethod); EnhancerHelper.createAnnotation(annotationsAttribute, callback_classes.get(anno)); } }
private void setManyToManyHint(CtField ctField) { AnnotationsAttribute annotationsAttribute = EnhancerHelper.getAnnotations(ctField); EnhancerHelper.createAnnotation(annotationsAttribute, ManyToManyHint.class); }