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

📄 jdbcworkflowstore.java

📁 osworkflow修改版本
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
        currentPrevTable = getInitProperty(props, "currentPrev.table", "OS_CURRENTSTEP_PREV");        historyPrevTable = getInitProperty(props, "historyPrev.table", "OS_HISTORYSTEP_PREV");        stepId = getInitProperty(props, "step.id", "ID");        stepEntryId = getInitProperty(props, "step.entryId", "ENTRY_ID");        stepStepId = getInitProperty(props, "step.stepId", "STEP_ID");        stepActionId = getInitProperty(props, "step.actionId", "ACTION_ID");        stepOwner = getInitProperty(props, "step.owner", "OWNER");        stepCaller = getInitProperty(props, "step.caller", "CALLER");        stepStartDate = getInitProperty(props, "step.startDate", "START_DATE");        stepFinishDate = getInitProperty(props, "step.finishDate", "FINISH_DATE");        stepDueDate = getInitProperty(props, "step.dueDate", "DUE_DATE");        stepStatus = getInitProperty(props, "step.status", "STATUS");        stepPreviousId = getInitProperty(props, "step.previousId", "PREVIOUS_ID");        String jndi = (String) props.get("datasource");        if (jndi != null) {            try {                ds = (DataSource) lookup(jndi);                if (ds == null) {                    ds = (DataSource) new javax.naming.InitialContext().lookup(jndi);                }            } catch (Exception e) {                throw new StoreException("Error looking up DataSource at " + jndi, e);            }        }    }    public Step markFinished(Step step, int actionId, Date finishDate, String status, String caller) throws StoreException {        Connection conn = null;        PreparedStatement stmt = null;        try {            conn = getConnection();            String sql = "UPDATE " + currentTable + " SET " + stepStatus + " = ?, " + stepActionId + " = ?, " + stepFinishDate + " = ?, " + stepCaller + " = ? WHERE " + stepId + " = ?";            if (log.isDebugEnabled()) {                log.debug("Executing SQL statement: " + sql);            }            stmt = conn.prepareStatement(sql);            stmt.setString(1, status);            stmt.setInt(2, actionId);            stmt.setTimestamp(3, new Timestamp(finishDate.getTime()));            stmt.setString(4, caller);            stmt.setLong(5, step.getId());            stmt.executeUpdate();            SimpleStep theStep = (SimpleStep) step;            theStep.setActionId(actionId);            theStep.setFinishDate(finishDate);            theStep.setStatus(status);            theStep.setCaller(caller);            return theStep;        } catch (SQLException e) {            throw new StoreException("Unable to mark step finished for #" + step.getEntryId(), e);        } finally {            cleanup(conn, stmt, null);        }    }    public void moveToHistory(Step step) throws StoreException {        Connection conn = null;        PreparedStatement stmt = null;        try {            conn = getConnection();            String sql = "INSERT INTO " + historyTable + " (" + stepId + "," + stepEntryId + ", " + stepStepId + ", " + stepActionId + ", " + stepOwner + ", " + stepStartDate + ", " + stepFinishDate + ", " + stepStatus + ", " + stepCaller + ") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)";            if (log.isDebugEnabled()) {                log.debug("Executing SQL statement: " + sql);            }            stmt = conn.prepareStatement(sql);            stmt.setLong(1, step.getId());            stmt.setLong(2, step.getEntryId());            stmt.setInt(3, step.getStepId());            stmt.setInt(4, step.getActionId());            stmt.setString(5, step.getOwner());            stmt.setTimestamp(6, new Timestamp(step.getStartDate().getTime()));            if (step.getFinishDate() != null) {                stmt.setTimestamp(7, new Timestamp(step.getFinishDate().getTime()));            } else {                stmt.setNull(7, Types.TIMESTAMP);            }            stmt.setString(8, step.getStatus());            stmt.setString(9, step.getCaller());            stmt.executeUpdate();            long[] previousIds = step.getPreviousStepIds();            if ((previousIds != null) && (previousIds.length > 0)) {                sql = "INSERT INTO " + historyPrevTable + " (" + stepId + ", " + stepPreviousId + ") VALUES (?, ?)";                log.debug("Executing SQL statement: " + sql);                cleanup(null, stmt, null);                stmt = conn.prepareStatement(sql);                for (int i = 0; i < previousIds.length; i++) {                    long previousId = previousIds[i];                    stmt.setLong(1, step.getId());                    stmt.setLong(2, previousId);                    stmt.executeUpdate();                }            }            sql = "DELETE FROM " + currentPrevTable + " WHERE " + stepId + " = ?";            if (log.isDebugEnabled()) {                log.debug("Executing SQL statement: " + sql);            }            cleanup(null, stmt, null);            stmt = conn.prepareStatement(sql);            stmt.setLong(1, step.getId());            stmt.executeUpdate();            sql = "DELETE FROM " + currentTable + " WHERE " + stepId + " = ?";            if (log.isDebugEnabled()) {                log.debug("Executing SQL statement: " + sql);            }            cleanup(null, stmt, null);            stmt = conn.prepareStatement(sql);            stmt.setLong(1, step.getId());            stmt.executeUpdate();        } catch (SQLException e) {            throw new StoreException("Unable to move current step to history step for #" + step.getEntryId(), e);        } finally {            cleanup(conn, stmt, null);        }    }    public List query(WorkflowExpressionQuery query) throws StoreException {        Expression expression = query.getExpression();        StringBuffer sel = new StringBuffer();        List values = new ArrayList();        String columnName = null;        if (expression.isNested()) {            columnName = buildNested((NestedExpression) expression, sel, values);        } else {            columnName = buildSimple((FieldExpression) expression, sel, values);        }        if (query.getSortOrder() != WorkflowExpressionQuery.SORT_NONE) {            sel.append(" ORDER BY ");            sel.append(fieldName(query.getOrderBy()));            if (query.getSortOrder() == WorkflowExpressionQuery.SORT_ASC) {                sel.append(" ASC");            } else {                sel.append(" DESC");            }        }        List results = doExpressionQuery(sel.toString(), columnName, values);        return results;    }    public List query(WorkflowQuery query) throws StoreException {        List results = new ArrayList();        // going to try to do all the comparisons in one query        String sel;        String table;        int qtype = query.getType();        if (qtype == 0) { // then not set, so look in sub queries                          // todo: not sure if you would have a query that would look in both old and new, if so, i'll have to change this - TR                          // but then again, why are there redundant tables in the first place? the data model should probably change            if (query.getLeft() != null) {                qtype = query.getLeft().getType();            }        }        if (qtype == WorkflowQuery.CURRENT) {            table = currentTable;        } else {            table = historyTable;        }        sel = "SELECT DISTINCT(" + stepEntryId + ") FROM " + table + " WHERE ";        sel += queryWhere(query);        if (log.isDebugEnabled()) {            log.debug(sel);        }        Connection conn = null;        Statement stmt = null;        ResultSet rs = null;        try {            conn = getConnection();            stmt = conn.createStatement();            rs = stmt.executeQuery(sel);            while (rs.next()) {                // get entryIds and add to results list                Long id = new Long(rs.getLong(stepEntryId));                results.add(id);            }        } catch (SQLException ex) {            throw new StoreException("SQL Exception in query: " + ex.getMessage());        } finally {            cleanup(conn, stmt, rs);        }        return results;    }    protected Connection getConnection() throws SQLException {        closeConnWhenDone = true;        return ds.getConnection();    }    protected long getNextEntrySequence(Connection c) throws SQLException {        if (log.isDebugEnabled()) {            log.debug("Executing SQL statement: " + entrySequence);        }        PreparedStatement stmt = null;        ResultSet rset = null;        try {            stmt = c.prepareStatement(entrySequence);            rset = stmt.executeQuery();            rset.next();            long id = rset.getLong(1);            return id;        } finally {            cleanup(null, stmt, rset);        }    }    protected long getNextStepSequence(Connection c) throws SQLException {        if (log.isDebugEnabled()) {            log.debug("Executing SQL statement: " + stepSequence);        }        PreparedStatement stmt = null;        ResultSet rset = null;        try {            stmt = c.prepareStatement(stepSequence);            rset = stmt.executeQuery();            rset.next();            long id = rset.getLong(1);            return id;        } finally {            cleanup(null, stmt, rset);        }    }    protected void addPreviousSteps(Connection conn, long id, long[] previousIds) throws SQLException {        if ((previousIds != null) && (previousIds.length > 0)) {            if (!((previousIds.length == 1) && (previousIds[0] == 0))) {                String sql = "INSERT INTO " + currentPrevTable + " (" + stepId + ", " + stepPreviousId + ") VALUES (?, ?)";                log.debug("Executing SQL statement: " + sql);                PreparedStatement stmt = conn.prepareStatement(sql);                for (int i = 0; i < previousIds.length; i++) {                    long previousId = previousIds[i];                    stmt.setLong(1, id);                    stmt.setLong(2, previousId);                    stmt.executeUpdate();                }                cleanup(null, stmt, null);            }        }    }    protected void cleanup(Connection connection, Statement statement, ResultSet result) {        if (result != null) {            try {                result.close();            } catch (SQLException ex) {                log.error("Error closing resultset", ex);            }        }        if (statement != null) {            try {                statement.close();            } catch (SQLException ex) {                log.error("Error closing statement", ex);            }        }        if ((connection != null) && closeConnWhenDone) {            try {                connection.close();            } catch (SQLException ex) {                log.error("Error closing connection", ex);            }        }    }    protected long createCurrentStep(Connection conn, long entryId, int wfStepId, String owner, Date startDate, Date dueDate, String status) throws SQLException {        String sql = "INSERT INTO " + currentTable + " (" + stepId + "," + stepEntryId + ", " + stepStepId + ", " + stepActionId + ", " + stepOwner + ", " + stepStartDate + ", " + stepDueDate + ", " + stepFinishDate + ", " + stepStatus + ", " + stepCaller + " ) VALUES (?, ?, ?, null, ?, ?, ?, null, ?, null)";        if (log.isDebugEnabled()) {            log.debug("Executing SQL statement: " + sql);        }        PreparedStatement stmt = conn.prepareStatement(sql);        long id = getNextStepSequence(conn);        stmt.setLong(1, id);        stmt.setLong(2, entryId);        stmt.setInt(3, wfStepId);        stmt.setString(4, owner);        stmt.setTimestamp(5, new Timestamp(startDate.getTime()));        if (dueDate != null) {            stmt.setTimestamp(6, new Timestamp(dueDate.getTime()));        } else {            stmt.setNull(6, Types.TIMESTAMP);        }        stmt.setString(7, status);        stmt.executeUpdate();        cleanup(null, stmt, null);        return id;    }    private String getInitProperty(Map props, String strName, String strDefault) {        Object o = props.get(strName);        if (o == null) {            return strDefault;        }        return (String) o;    }    private String buildNested(NestedExpression nestedExpression, StringBuffer sel, List values) {        sel.append("SELECT DISTINCT(");        sel.append(entryId);

⌨️ 快捷键说明

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