private void addTriggerFailedAndExitTxn ( CodeBuilder b , String opType , LocalVariable forTryVar , boolean forTry , LocalVariable triggerVar , LocalVariable txnVar , LocalVariable stateVar , Label tryStart ) { if ( tryStart == null ) { addTriggerFailedAndExitTxn ( b , opType , triggerVar , txnVar , stateVar ) ; return ; } // } catch (... e) { // if (trigger != null) { // try { // trigger.failedXxx(this, state); // } catch (Throwable e) { // uncaught(e); // } // } // txn.exit(); // if (e instanceof Trigger.Abort) { // if (forTryVar) { // return false; // } else { // // Try to add some trace for context // throw ((Trigger.Abort) e).withStackTrace(); // } // } // if (e instanceof RepositoryException) { // throw ((RepositoryException) e).toPersistException(); // } // throw e; // } Label tryEnd = b . createLabel ( ) . setLocation ( ) ; b . exceptionHandler ( tryStart , tryEnd , null ) ; LocalVariable exceptionVar = b . createLocalVariable ( null , TypeDesc . OBJECT ) ; b . storeLocal ( exceptionVar ) ; addTriggerFailedAndExitTxn ( b , opType , triggerVar , txnVar , stateVar ) ; b . loadLocal ( exceptionVar ) ; TypeDesc abortException = TypeDesc . forClass ( Trigger . Abort . class ) ; b . instanceOf ( abortException ) ; Label nextCheck = b . createLabel ( ) ; b . ifZeroComparisonBranch ( nextCheck , "==" ) ; if ( forTryVar == null ) { if ( forTry ) { b . loadConstant ( false ) ; b . returnValue ( TypeDesc . BOOLEAN ) ; } else { b . loadLocal ( exceptionVar ) ; b . checkCast ( abortException ) ; b . invokeVirtual ( abortException , "withStackTrace" , abortException , null ) ; b . throwObject ( ) ; } } else { b . loadLocal ( forTryVar ) ; Label isForTry = b . createLabel ( ) ; b . ifZeroComparisonBranch ( isForTry , "!=" ) ; b . loadLocal ( exceptionVar ) ; b . checkCast ( abortException ) ; b . invokeVirtual ( abortException , "withStackTrace" , abortException , null ) ; b . throwObject ( ) ; isForTry . setLocation ( ) ; b . loadConstant ( false ) ; b . returnValue ( TypeDesc . BOOLEAN ) ; } nextCheck . setLocation ( ) ; b . loadLocal ( exceptionVar ) ; TypeDesc repException = TypeDesc . forClass ( RepositoryException . class ) ; b . instanceOf ( repException ) ; Label throwAny = b . createLabel ( ) ; b . ifZeroComparisonBranch ( throwAny , "==" ) ; b . loadLocal ( exceptionVar ) ; b . checkCast ( repException ) ; b . invokeVirtual ( repException , "toPersistException" , TypeDesc . forClass ( PersistException . class ) , null ) ; b . throwObject ( ) ; throwAny . setLocation ( ) ; b . loadLocal ( exceptionVar ) ; b . throwObject ( ) ; }
Generates exception handler code to call a trigger after the persistence operation has failed .