1 24 package org.ofbiz.minilang.method.entityops; 25 26 import org.ofbiz.base.util.Debug; 27 import org.ofbiz.entity.transaction.GenericTransactionException; 28 import org.ofbiz.entity.transaction.TransactionUtil; 29 import org.ofbiz.minilang.SimpleMethod; 30 import org.ofbiz.minilang.method.ContextAccessor; 31 import org.ofbiz.minilang.method.MethodContext; 32 import org.ofbiz.minilang.method.MethodOperation; 33 import org.w3c.dom.Element ; 34 35 42 public class TransactionRollback extends MethodOperation { 43 44 public static final String module = TransactionRollback.class.getName(); 45 46 ContextAccessor beganTransactionAcsr; 47 48 public TransactionRollback(Element element, SimpleMethod simpleMethod) { 49 super(element, simpleMethod); 50 beganTransactionAcsr = new ContextAccessor(element.getAttribute("began-transaction-name"), "beganTransaction"); 51 } 52 53 public boolean exec(MethodContext methodContext) { 54 boolean beganTransaction = false; 55 56 Boolean beganTransactionBoolean = (Boolean ) beganTransactionAcsr.get(methodContext); 57 if (beganTransactionBoolean != null) { 58 beganTransaction = beganTransactionBoolean.booleanValue(); 59 } 60 61 try { 62 TransactionUtil.rollback(beganTransaction, "Explicit rollback in simple-method [" + this.simpleMethod.getShortDescription() + "]", null); 63 } catch (GenericTransactionException e) { 64 Debug.logError(e, "Could not rollback transaction in simple-method, returning error.", module); 65 66 String errMsg = "ERROR: Could not complete the " + simpleMethod.getShortDescription() + " process [error rolling back a transaction: " + e.getMessage() + "]"; 67 methodContext.setErrorReturn(errMsg, simpleMethod); 68 return false; 69 } 70 71 beganTransactionAcsr.remove(methodContext); 72 return true; 73 } 74 75 public String rawString() { 76 return "<transaction-rollback/>"; 78 } 79 public String expandedString(MethodContext methodContext) { 80 return this.rawString(); 82 } 83 } 84 | Popular Tags |