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: * Begins a transaction if one is not already in place; if does begin one puts true in the began-transaction-name env variable, otherwise it returns false.
31: */
32: public class TransactionBegin extends MethodOperation {
33:
34: public static final String module = TransactionBegin.class
35: .getName();
36:
37: ContextAccessor beganTransactionAcsr;
38:
39: public TransactionBegin(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: try {
49: beganTransaction = TransactionUtil.begin();
50: } catch (GenericTransactionException e) {
51: Debug
52: .logError(
53: e,
54: "Could not begin transaction in simple-method, returning error.",
55: module);
56:
57: String errMsg = "ERROR: Could not complete the "
58: + simpleMethod.getShortDescription()
59: + " process [error beginning a transaction: "
60: + e.getMessage() + "]";
61: methodContext.setErrorReturn(errMsg, simpleMethod);
62: return false;
63: }
64:
65: beganTransactionAcsr.put(methodContext, new Boolean(
66: beganTransaction));
67: return true;
68: }
69:
70: public String rawString() {
71: // TODO: something more than the empty tag
72: return "<transaction-begin/>";
73: }
74:
75: public String expandedString(MethodContext methodContext) {
76: // TODO: something more than a stub/dummy
77: return this.rawString();
78: }
79: }
|