001: /*
002: * ====================================================================
003: *
004: * XFLOW - Process Management System
005: * Copyright (C) 2003 Rob Tan
006: * All rights reserved.
007: *
008: * Redistribution and use in source and binary forms, with or without
009: * modification, are permitted provided that the following conditions
010: * are met:
011: *
012: * 1. Redistributions of source code must retain the above copyright
013: * notice, this list of conditions, and the following disclaimer.
014: *
015: * 2. Redistributions in binary form must reproduce the above copyright
016: * notice, this list of conditions, and the disclaimer that follows
017: * these conditions in the documentation and/or other materials
018: * provided with the distribution.
019: *
020: * 3. The name "XFlow" must not be used to endorse or promote products
021: * derived from this software without prior written permission. For
022: * written permission, please contact rcktan@yahoo.com
023: *
024: * 4. Products derived from this software may not be called "XFlow", nor
025: * may "XFlow" appear in their name, without prior written permission
026: * from the XFlow Project Management (rcktan@yahoo.com)
027: *
028: * In addition, we request (but do not require) that you include in the
029: * end-user documentation provided with the redistribution and/or in the
030: * software itself an acknowledgement equivalent to the following:
031: * "This product includes software developed by the
032: * XFlow Project (http://xflow.sourceforge.net/)."
033: * Alternatively, the acknowledgment may be graphical using the logos
034: * available at http://xflow.sourceforge.net/
035: *
036: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
037: * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
038: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
039: * DISCLAIMED. IN NO EVENT SHALL THE XFLOW AUTHORS OR THE PROJECT
040: * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
041: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
042: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
043: * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
044: * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
045: * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
046: * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
047: * SUCH DAMAGE.
048: *
049: * ====================================================================
050: * This software consists of voluntary contributions made by many
051: * individuals on behalf of the XFlow Project and was originally
052: * created by Rob Tan (rcktan@yahoo.com)
053: * For more information on the XFlow Project, please see:
054: * <http://xflow.sourceforge.net/>.
055: * ====================================================================
056: */
057:
058: package xflow.server.controller;
059:
060: import java.io.*;
061: import java.util.*;
062: import java.lang.*;
063: import java.sql.*;
064: import org.apache.log4j.Logger;
065: import xflow.common.*;
066: import xflow.protocol.*;
067: import xflow.util.*;
068: import xflow.server.util.*;
069:
070: import org.apache.log4j.Logger;
071:
072: public class ProcessStack {
073:
074: private static Logger log = Logger.getLogger(ProcessStack.class);
075:
076: public static void push(int workflowId, int cGid,
077: Node containerNode, Node endNode) throws XflowException {
078:
079: int containerNodeId = containerNode.getNodeId();
080: int endNodeId = endNode.getNodeId();
081:
082: Connection con = null;
083: Statement s = null;
084: try {
085: con = Persistence.getConnection();
086: s = con.createStatement();
087: String sql = "insert into procstack values (" + workflowId
088: + "," + cGid + "," + containerNodeId + ","
089: + endNodeId + ")";
090: log.info(sql);
091: s.execute(sql);
092: } catch (Exception e) {
093: e.printStackTrace();
094: throw new XflowException(
095: "Failed to save row in procstack in database");
096: } finally {
097: if (s != null) {
098: try {
099: s.close();
100: } catch (Exception e) {
101: e.printStackTrace();
102: }
103: }
104: if (con != null) {
105: try {
106: con.close();
107: } catch (Exception e) {
108: }
109: }
110: }
111: }
112:
113: public static PopNode pop(int workflowId, Node endNode)
114: throws XflowException {
115:
116: int endNodeId = endNode.getNodeId();
117: PopNode popNode = null;
118:
119: Connection con = null;
120: Statement s = null;
121: try {
122: con = Persistence.getConnection();
123: s = con.createStatement();
124: String sql = "select * from procstack where endnodeid = "
125: + endNodeId + " and workflowid = " + workflowId;
126: ResultSet rs = s.executeQuery(sql);
127: if (rs.next()) {
128: popNode = new PopNode();
129: popNode.nodeId = rs.getInt("cnodeid");
130: popNode.gid = rs.getInt("cgid");
131:
132: sql = "delete from procstack where endnodeid = "
133: + endNodeId + " and workflowid = " + workflowId;
134: log.info(sql);
135: s.execute(sql);
136: }
137: } catch (Exception e) {
138: e.printStackTrace();
139: throw new XflowException(
140: "Failed to delete row from procstack in database");
141: } finally {
142: if (s != null) {
143: try {
144: s.close();
145: } catch (Exception e) {
146: e.printStackTrace();
147: }
148: }
149: if (con != null) {
150: try {
151: con.close();
152: } catch (Exception e) {
153: }
154: }
155: }
156: return popNode;
157: }
158: }
|