001package io.ebean.enhance.transactional; 002 003import io.ebean.enhance.asm.Label; 004import io.ebean.enhance.asm.MethodVisitor; 005import io.ebean.enhance.asm.commons.AdviceAdapter; 006 007/** 008 * FinallyAdapter adjusted to support both non-finally use (for ConstructorMethodAdapter) 009 * and finally use (for MethodAdapter that also enhances transactional methods) 010 */ 011public abstract class FinallyAdapter extends AdviceAdapter { 012 013 protected Label startFinally = new Label(); 014 015 public FinallyAdapter(final int api, MethodVisitor mv, int acc, String name, String desc) { 016 super(api, mv, acc, name, desc); 017 } 018 019 @Override 020 public void visitCode() { 021 super.visitCode(); 022 } 023 024 @Override 025 public void visitMaxs(int maxStack, int maxLocals) { 026 super.visitMaxs(maxStack, maxLocals); 027 } 028 029 protected void finallyVisitCode() { 030 super.visitCode(); 031 mv.visitLabel(startFinally); 032 } 033 034 protected void finallyVisitMaxs(int maxStack, int maxLocals) { 035 036 Label endFinally = new Label(); 037 mv.visitTryCatchBlock(startFinally, endFinally, endFinally, null); 038 mv.visitLabel(endFinally); 039 onFinally(ATHROW); 040 mv.visitInsn(ATHROW); 041 mv.visitMaxs(maxStack, maxLocals); 042 } 043 044 @Override 045 protected final void onMethodExit(int opcode) { 046 if (opcode != ATHROW) { 047 onFinally(opcode); 048 } 049 } 050 051 protected void onFinally(int opcode) { 052 } 053 054}