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

📄 xlobsessionimpl.java

📁 一个工作流设计及定义的系统,可以直接与数据库结合进行系统工作流程的定义及应用.
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * 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: XlobSessionImpl.java,v 1.4 2005/07/17 16:31:49 jmettraux Exp $ *///// XlobSessionImpl.java//// john.mettraux@epfl.ch//// generated with // jtmpl 1.1.01 2004/05/19 (john.mettraux@openwfe.org)//package openwfe.org.xlob;import openwfe.org.Utils;import openwfe.org.MapUtils;import openwfe.org.ServiceException;import openwfe.org.ApplicationContext;import openwfe.org.xml.XmlUtils;import openwfe.org.xml.XmlCoder;import openwfe.org.xml.XmlCodingException;import openwfe.org.sql.SqlUtils;import openwfe.org.sql.ds.OwfeDataSource;import openwfe.org.engine.expressions.FlowExpressionId;/** * An implementation of XlobSession * * <p><font size=2>CVS Info : * <br>$Author: jmettraux $ * <br>$Id: XlobSessionImpl.java,v 1.4 2005/07/17 16:31:49 jmettraux Exp $ </font> * * @author john.mettraux@epfl.ch */public class XlobSessionImpl    implements XlobSession{    private final static org.apache.log4j.Logger log = org.apache.log4j.Logger        .getLogger(XlobSessionImpl.class.getName());    //    // CONSTANTS & co    private final static String FEI_FIELDS =        "prefix, "+        "engineId, "+        "initialEngineId, "+        "wfdUrl, "+        "wfdName, "+        "wfdRevision, "+        "wfInstanceId, "+        "expressionName, "+        "expressionId";    private final static String FIELDS =        FEI_FIELDS + ", xldoc";    /**     * The parameter 'xlobPrefix'.     */    public final static String P_PREFIX        = "xlobPrefix";    //    // FIELDS    private java.sql.Connection connection = null;    private OwfeDataSource dataSource = null;    private String prefix = null;    //    // CONSTRUCTORS    //    // METHODS    private java.sql.Connection getConnection ()        throws java.sql.SQLException    {        if (this.connection != null) return this.connection;        return this.dataSource.getConnection();    }    private void releaseConnection ()    {        if (this.dataSource != null) this.dataSource.releaseConnection();    }    private java.sql.PreparedStatement prepareStatement        (final String header, FlowExpressionId fei)    throws         java.sql.SQLException    {        log.debug("prepareStatement() for "+header+" / "+fei);        if (fei == null) fei = new FlowExpressionId();        final StringBuffer sb = new StringBuffer();        sb            .append(header)            .append(" FROM xldocument")            .append(" WHERE")            .append(" prefix = ?");        if (fei.getEngineId() != null)            sb.append(" AND engineId LIKE ?");        if (fei.getInitialEngineId() != null)            sb.append(" AND initialEngineId LIKE ?");        if (fei.getWorkflowDefinitionUrl() != null)            sb.append(" AND wfdUrl LIKE ?");        if (fei.getWorkflowDefinitionName() != null)            sb.append(" AND wfdName LIKE ?");        if (fei.getWorkflowDefinitionRevision() != null)            sb.append(" AND wfdRevision LIKE ?");        if (fei.getWorkflowInstanceId() != null)            sb.append(" AND wfInstanceId LIKE ?");        if (fei.getExpressionName() != null)            sb.append(" AND expressionName LIKE ?");        if (fei.getExpressionId() != null)            sb.append(" AND expressionId LIKE ?");        //        // prepare statement        final java.sql.PreparedStatement ps =             getConnection().prepareStatement(sb.toString());        int i = 1;        ps.setString(i++, this.prefix);        if (fei.getEngineId() != null)            ps.setString(i++, fei.getEngineId());        if (fei.getInitialEngineId() != null)            ps.setString(i++, fei.getInitialEngineId());        if (fei.getWorkflowDefinitionUrl() != null)            ps.setString(i++, fei.getWorkflowDefinitionUrl());        if (fei.getWorkflowDefinitionName() != null)            ps.setString(i++, fei.getWorkflowDefinitionName());        if (fei.getWorkflowDefinitionRevision() != null)            ps.setString(i++, fei.getWorkflowDefinitionRevision());        if (fei.getWorkflowInstanceId() != null)            ps.setString(i++, fei.getWorkflowInstanceId());        if (fei.getExpressionName() != null)            ps.setString(i++, fei.getExpressionName());        if (fei.getExpressionId() != null)            ps.setString(i++, fei.getExpressionId());        return ps;    }    private java.sql.ResultSet doQuery         (String selectable, final FlowExpressionId fei)    throws         XlobException    {        if (selectable == null) selectable = "xldoc";        log.debug("doQuery() for "+selectable+" / "+fei);        try        {            final java.sql.PreparedStatement ps =                 prepareStatement("SELECT "+selectable, fei);            return ps.executeQuery();        }        catch (final Throwable t)        {            throw new XlobException                ("query failure", t);        }    }    private org.jdom.Document extract (final java.sql.ResultSet rs)        throws XlobException    {        try        {            final java.sql.Clob clob = rs.getClob(1);            final org.jdom.input.SAXBuilder builder =                 new org.jdom.input.SAXBuilder();            return builder.build(clob.getCharacterStream());        }        catch (final Throwable t)        {            throw new XlobException("extraction failure", t);        }    }    private Object extractBean (final java.sql.ResultSet rs)        throws XlobException    {        try        {            final org.jdom.Document d = extract(rs);            return XmlCoder.decode(d);        }        catch (final XmlCodingException xce)        {            throw new XlobException                ("Failed to decode bean", xce);        }    }    private FlowExpressionId extractExpressionId (final java.sql.ResultSet rs)        throws java.sql.SQLException    {        int i = 1;        final FlowExpressionId fei = new FlowExpressionId();        fei.setEngineId(rs.getString(i++));        fei.setInitialEngineId(rs.getString(i++));        fei.setWorkflowDefinitionUrl(rs.getString(i++));        fei.setWorkflowDefinitionName(rs.getString(i++));        fei.setWorkflowDefinitionRevision(rs.getString(i++));        fei.setWorkflowInstanceId(rs.getString(i++));        fei.setExpressionName(rs.getString(i++));        fei.setExpressionId(rs.getString(i++));        return fei;    }    private boolean toNext (final java.sql.ResultSet rs)        throws XlobException    {        try        {            return rs.next();        }        catch (final Throwable t)        {            throw new XlobException("Failed to fetch next row", t);        }    }    private void close (final java.sql.ResultSet rs)    {        try        {            rs.close();        }        catch (final Throwable t)        {            // ignore        }    }    private void close (final java.sql.Statement st)    {        try        {            st.close();        }        catch (final Throwable t)        {            // ignore        }    }    //    // METHODS from XlobSession    /**     * Inits the session (once it got instantiated).     *     * @param prefix each OpenWFE using an xlob session must explicitely     * specify a prefix like 'worklist' or 'engine-alpha'.     */    public void init (final java.sql.Connection con, final String prefix)    {        this.connection = con;        this.prefix = prefix;    }    /**     * Inits the session (once it got instantiated).     *     * @param prefix each OpenWFE using an xlob session must explicitely     * specify a prefix like 'worklist' or 'engine-alpha'.     */    public void init (OwfeDataSource ds, String prefix)    {        this.dataSource = ds;        this.prefix = prefix;    }    /**     * Closes this session.     */    public void close ()    {        try        {            if (this.connection != null) this.connection.close();        }        catch (final Throwable t)        {            log.info("close() problem", t);        }    }    /**     * Updates or inserts an XML document for a given fei.     */    public void store (final FlowExpressionId fei, final org.jdom.Document doc)        throws XlobException    {        store(fei, XmlUtils.toString(doc));    }    /**     * Updates or inserts an XML document for a given fei.     */    public void store (final FlowExpressionId fei, final org.jdom.Element elt)        throws XlobException    {        store(fei, XmlUtils.toString(elt));    }    /**     * Turns a bean into an XML document (openwfe.org.xml.XmlCoder) and     * stores it.     */    public void storeBean (final FlowExpressionId fei, final Object bean)        throws XlobException    {        try        {            store(fei, XmlCoder.encode(bean));        }        catch (final XmlCodingException xce)        {            throw new XlobException("Failed to encode bean", xce);        }    }    /**     * Updates or inserts an XML document for a given fei.     */    public void store (final FlowExpressionId fei, final String sXml)        throws XlobException    {        java.sql.PreparedStatement ps = null;        try        {            if (isStored(fei)) remove(fei);            //            // insert the doc            final StringBuffer sb = new StringBuffer();            sb                .append("INSERT INTO xldocument ")                .append("(")

⌨️ 快捷键说明

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