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: package xflow.util;
058:
059: import java.util.*;
060: import java.sql.*;
061: import javax.sql.*;
062: import javax.naming.*;
063: import xflow.common.*;
064: import org.apache.log4j.Logger;
065:
066: public class Persistence {
067:
068: private static InitialContext iniCtx;
069: private static DataSource ds;
070: private static Logger log = Logger.getLogger(Persistence.class);
071:
072: static public void init() {
073:
074: String dest = "create table destination (nid int, destnid int, rule varchar(300))";
075: String graph = "create table graph (gid int, nid int, name varchar(64), description varchar(500), version int)";
076: String node = "create table node (gid int, nid int identity, name varchar(64), nodetype varchar(32), description varchar(500))";
077: String nodeprops = "create table nodeprops (nid int, name varchar(64), value varchar(5000))";
078:
079: String workflow = "create table workflow (workflowId int identity, gid int, initiator varchar(64), isActive bit, timeStarted datetime, timeEnded datetime, status varchar(32), parentworkflowId int)";
080:
081: String inbox = "create table inbox (workflowId int, gid int, workflowName varchar(64), procName varchar(64), workitemId int, timeStarted datetime, timeout bit)";
082:
083: String workitem = "create table workitem (workitemId int identity, payload varchar(5000), payloadType varchar(16))";
084:
085: String workitemprops = "create table workitemprops (workitemId int, workflowName varchar(64), procName varchar(64), name varchar(64), value varchar(5000))";
086:
087: String workflowvars = "create table workflowvars (workflowId int, name varchar(64), value varchar(5000))";
088:
089: String waiting = "create table waiting (workflowId int, destNodeId int, fromNodeId int)";
090: String procstack = "create table procstack (workflowId int, cgid int, cNodeId int, endNodeId int)";
091:
092: Connection conn = null;
093: Statement s = null;
094:
095: // Create all the necessary tables used by xflow
096: try {
097: iniCtx = new InitialContext();
098: ds = (DataSource) iniCtx
099: .lookup(XflowConstants.XFLOW_DATASOURCE);
100: conn = ds.getConnection();
101: s = conn.createStatement();
102: s.execute(dest);
103: s.execute(graph);
104: s.execute(node);
105: s.execute(nodeprops);
106: s.execute(workflow);
107: s.execute(inbox);
108: s.execute(workitem);
109: s.execute(workitemprops);
110: s.execute(workflowvars);
111: s.execute(waiting);
112: s.execute(procstack);
113: log.info("XFlow Tables initialized");
114: } catch (Exception e) {
115: log.info(e.getMessage());
116: log.info("updating workflow table");
117: try {
118: s
119: .execute("alter table workflow add column status varchar(32)");
120: s
121: .execute("alter table workflow add column parentWorkflowId int");
122: s.execute("alter table inbox add column timeout bit");
123: log.info("workflow table updated");
124: } catch (Exception e2) {
125: log.info("workflow table up-to-date");
126: }
127: } finally {
128: if (conn != null) {
129: try {
130: conn.close();
131: } catch (Exception e) {
132: }
133: }
134: }
135: }
136:
137: public static Connection getConnection() throws SQLException {
138: return ds.getConnection();
139: }
140:
141: }
|