⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sqlhistory.java

📁 一个工作流设计及定义的系统,可以直接与数据库结合进行系统工作流程的定义及应用.
💻 JAVA
字号:
/* * Copyright (c) 2005, John Mettraux, OpenWFE.org * All rights reserved. *  * Redistribution and use in source and binary forms, with or without  * modification, are permitted provided that the following conditions are met: *  * . Redistributions of source code must retain the above copyright notice, this *   list of conditions and the following disclaimer.   *  * . Redistributions in binary form must reproduce the above copyright notice,  *   this list of conditions and the following disclaimer in the documentation  *   and/or other materials provided with the distribution. *  * . Neither the name of the "OpenWFE" nor the names of its contributors may be *   used to endorse or promote products derived from this software without *   specific prior written permission. *  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE  * POSSIBILITY OF SUCH DAMAGE. * * $Id: SqlHistory.java,v 1.10 2005/05/17 16:40:27 jmettraux Exp $ *///// SqlHistory.java//// john.mettraux@openwfe.org//// generated with // jtmpl 1.1.00 16.08.2003 John Mettraux (jmettraux@openwfe.org)//package openwfe.org.engine.impl.history;import openwfe.org.MapUtils;import openwfe.org.AbstractService;import openwfe.org.ServiceException;import openwfe.org.ApplicationContext;import openwfe.org.sql.SqlUtils;import openwfe.org.sql.ds.OwfeDataSource;import openwfe.org.engine.history.History;import openwfe.org.engine.history.HistoryIterator;import openwfe.org.engine.history.HistoryException;import openwfe.org.engine.workitem.WorkItem;import openwfe.org.engine.expressions.FlowExpressionId;/** * storing workitem tracing into a relational database * (this implementation only cares about participant apply/reply) * * <p><font size=2>CVS Info : * <br>$Author: jmettraux $ * <br>$Id: SqlHistory.java,v 1.10 2005/05/17 16:40:27 jmettraux Exp $ </font> * * @author john.mettraux@openwfe.org */public class SqlHistory    extends AbstractService    implements History{    private final static org.apache.log4j.Logger log = org.apache.log4j.Logger        .getLogger(SqlHistory.class.getName());    //    // CONSTANTS & co    public final static String P_TABLE_NAME = "tableName";    public final static String P_LOG_LEVEL = "logLevel";    public final static String DEFAULT_TABLE_NAME = "owfehistory";    public final static String DEFAULT_LOG_LEVEL = EVT_DEBUG;    public final static String COLUMNS =        "date_, engineid, wfdname, wfdrevision, wfdid, expression, eventcode, participantname, message";    //    // FIELDS    private OwfeDataSource dataSource = null;    private String tableName = null;    private String logLevel = null;    //    // CONSTRUCTORS    public void init         (final String serviceName,          final ApplicationContext context,          final java.util.Map serviceParams)    throws         ServiceException    {        super.init(serviceName, context, serviceParams);        //        // determine data source        this.dataSource = SqlUtils.lookupDataSource(context, serviceParams);        log.info("dataSource set");        //        // determine table name                this.tableName = MapUtils.getAsString            (serviceParams, P_TABLE_NAME, DEFAULT_TABLE_NAME);        log.info("using tableName '"+this.tableName+"'");        //        // determine logging level                this.logLevel = MapUtils.getAsString            (serviceParams, P_LOG_LEVEL, DEFAULT_LOG_LEVEL);    }    //    // METHODS from History    public void log         (final FlowExpressionId fei,          final WorkItem wi,         final String eventCode,          final String participantName,         final String message)    {        if (shouldNotLog(eventCode)) return;        //        // prepare insert        StringBuffer sb = new StringBuffer();        sb.append("INSERT INTO ");        sb.append(this.tableName);        sb.append(" (");        sb.append(COLUMNS);        sb.append(" )");        sb.append(" VALUES ");        sb.append("( ");        sb.append("'");         sb.append(new java.sql.Timestamp(System.currentTimeMillis()));        sb.append("', ");        sb.append("'");         sb.append(fei.getEngineId());         sb.append("', ");        sb.append("'");         sb.append(fei.getWorkflowDefinitionName());         sb.append("', ");        sb.append("'");         sb.append(fei.getWorkflowDefinitionRevision());         sb.append("', ");        sb.append(fei.getWorkflowInstanceId());         sb.append(", ");        sb.append("'");         sb.append(fei.getExpressionName());         sb.append(" ");         sb.append(fei.getExpressionId());         sb.append("', ");        sb.append("'");         sb.append(eventCode);        sb.append("', ");        if (participantName != null)        {            sb.append("'");             sb.append(participantName);            sb.append("', ");        }        else        {            sb.append("'', ");        }        sb.append("'");         sb.append(message);        sb.append("'");        //sb.append(" );");        sb.append(" )");        String sql = sb.toString();        //log.debug("\n"+sql);        //        // insert        java.sql.Connection con = null;        java.sql.Statement st = null;        try        {            con = getDataSource().getConnection();            st = con.createStatement();            st.execute(sql);        }        catch (java.sql.SQLException se)        {            //log.warn("Failed to log to history", se);            getDataSource().logSQLException("log", log, se);        }        finally        {            try            {                if (st != null) st.close();                getDataSource().releaseConnection();            }            catch (java.sql.SQLException se)            {                // ignore            }        }    }    /**     * Not yet implemented     */    public HistoryIterator browse        (String workflowName,         String workflowRevision,         long workflowInstanceId,         long dateFrom,         long dateto)    throws        HistoryException    {        throw new HistoryException("Not yet implemented.");    }    //    // METHODS    public String getTableName ()    {        return this.tableName;    }    protected OwfeDataSource getDataSource ()    {        return this.dataSource;        /*        return (OwfeDataSource)this.applicationContext            .get(this.dataSourceName);        */    }    protected boolean shouldNotLog (String eventCode)    {        if (eventCode.startsWith("+")) return false;            // always log '+' messages        // debug, info or warn        if (this.logLevel.equals(EVT_DEBUG)) return false;        if (eventCode.equals(EVT_DEBUG)) return true;        // info or warn        if (this.logLevel.equals(EVT_INFO)) return false;        //if (eventCode.equals(EVT_INFO)) return true;        // warn        return true;    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -