01: /*******************************************************************************
02: * Licensed to the Apache Software Foundation (ASF) under one
03: * or more contributor license agreements. See the NOTICE file
04: * distributed with this work for additional information
05: * regarding copyright ownership. The ASF licenses this file
06: * to you under the Apache License, Version 2.0 (the
07: * "License"); you may not use this file except in compliance
08: * with the License. You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing,
13: * software distributed under the License is distributed on an
14: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15: * KIND, either express or implied. See the License for the
16: * specific language governing permissions and limitations
17: * under the License.
18: *******************************************************************************/package org.ofbiz.minilang.method.entityops;
19:
20: import org.ofbiz.base.util.Debug;
21: import org.ofbiz.entity.transaction.GenericTransactionException;
22: import org.ofbiz.entity.transaction.TransactionUtil;
23: import org.ofbiz.minilang.SimpleMethod;
24: import org.ofbiz.minilang.method.ContextAccessor;
25: import org.ofbiz.minilang.method.MethodContext;
26: import org.ofbiz.minilang.method.MethodOperation;
27: import org.w3c.dom.Element;
28:
29: /**
30: * Commits a transaction if beganTransaction is true, otherwise does nothing.
31: */
32: public class TransactionCommit extends MethodOperation {
33:
34: public static final String module = TransactionCommit.class
35: .getName();
36:
37: ContextAccessor beganTransactionAcsr;
38:
39: public TransactionCommit(Element element, SimpleMethod simpleMethod) {
40: super (element, simpleMethod);
41: beganTransactionAcsr = new ContextAccessor(element
42: .getAttribute("began-transaction-name"),
43: "beganTransaction");
44: }
45:
46: public boolean exec(MethodContext methodContext) {
47: boolean beganTransaction = false;
48:
49: Boolean beganTransactionBoolean = (Boolean) beganTransactionAcsr
50: .get(methodContext);
51: if (beganTransactionBoolean != null) {
52: beganTransaction = beganTransactionBoolean.booleanValue();
53: }
54:
55: try {
56: TransactionUtil.commit(beganTransaction);
57: } catch (GenericTransactionException e) {
58: Debug
59: .logError(
60: e,
61: "Could not commit transaction in simple-method, returning error.",
62: module);
63:
64: String errMsg = "ERROR: Could not complete the "
65: + simpleMethod.getShortDescription()
66: + " process [error committing a transaction: "
67: + e.getMessage() + "]";
68: methodContext.setErrorReturn(errMsg, simpleMethod);
69: return false;
70: }
71:
72: beganTransactionAcsr.remove(methodContext);
73: return true;
74: }
75:
76: public String rawString() {
77: // TODO: something more than the empty tag
78: return "<transaction-commit/>";
79: }
80:
81: public String expandedString(MethodContext methodContext) {
82: // TODO: something more than a stub/dummy
83: return this.rawString();
84: }
85: }
|