01: /*
02: * $Id: TransactionRollback.java,v 1.1 2003/08/17 06:06:11 ajzeneski Exp $
03: *
04: * Copyright (c) 2001, 2002 The Open For Business Project - www.ofbiz.org
05: *
06: * Permission is hereby granted, free of charge, to any person obtaining a
07: * copy of this software and associated documentation files (the "Software"),
08: * to deal in the Software without restriction, including without limitation
09: * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10: * and/or sell copies of the Software, and to permit persons to whom the
11: * Software is furnished to do so, subject to the following conditions:
12: *
13: * The above copyright notice and this permission notice shall be included
14: * in all copies or substantial portions of the Software.
15: *
16: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17: * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18: * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19: * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20: * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
21: * OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
22: * THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23: */
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: /**
36: * Rolls back a transaction if beganTransaction is true, otherwise tries to do a setRollbackOnly.
37: *
38: * @author <a href="mailto:jonesde@ofbiz.org">David E. Jones</a>
39: * @version $Revision: 1.1 $
40: * @since 2.0
41: */
42: public class TransactionRollback extends MethodOperation {
43:
44: public static final String module = TransactionRollback.class
45: .getName();
46:
47: ContextAccessor beganTransactionAcsr;
48:
49: public TransactionRollback(Element element,
50: SimpleMethod simpleMethod) {
51: super (element, simpleMethod);
52: beganTransactionAcsr = new ContextAccessor(element
53: .getAttribute("began-transaction-name"),
54: "beganTransaction");
55: }
56:
57: public boolean exec(MethodContext methodContext) {
58: boolean beganTransaction = false;
59:
60: Boolean beganTransactionBoolean = (Boolean) beganTransactionAcsr
61: .get(methodContext);
62: if (beganTransactionBoolean != null) {
63: beganTransaction = beganTransactionBoolean.booleanValue();
64: }
65:
66: try {
67: TransactionUtil.rollback(beganTransaction);
68: } catch (GenericTransactionException e) {
69: Debug
70: .logError(
71: e,
72: "Could not rollback transaction in simple-method, returning error.",
73: module);
74:
75: String errMsg = "ERROR: Could not complete the "
76: + simpleMethod.getShortDescription()
77: + " process [error rolling back a transaction: "
78: + e.getMessage() + "]";
79: methodContext.setErrorReturn(errMsg, simpleMethod);
80: return false;
81: }
82:
83: beganTransactionAcsr.remove(methodContext);
84: return true;
85: }
86: }
|