workflowsequencedb.java
来自「一个用java编写的功能强大的OA系统」· Java 代码 · 共 232 行
JAVA
232 行
package com.redmoon.oa.flow;import java.sql.*;import cn.js.fan.base.*;import cn.js.fan.db.*;import cn.js.fan.util.*;import com.redmoon.oa.db.SequenceManager;public class WorkflowSequenceDb extends ObjectDb { public static final int TYPE_LOGIN = 0; public static final int TYPE_LOGOUT = 1; public static final int TYPE_ACTION = 2; public static final int TYPE_WARN = 3; public static final int TYPE_ERROR = 4; public WorkflowSequenceDb() { init(); } public WorkflowSequenceDb(int id) { init(); this.id = id; load(); } public void initDB() { tableName = "flow_sequence"; primaryKey = new PrimaryKey("ID", PrimaryKey.TYPE_INT); objectCache = new WorkflowSequenceCache(this); isInitFromConfigDB = false; QUERY_CREATE = "insert into " + tableName + " (ID, NAME, BEGIN_INDEX, CUR_INDEX, LENGTH) values (?,?,?,?,?)"; QUERY_SAVE = "update " + tableName + " set NAME=?,BEGIN_INDEX=?,CUR_INDEX=?,LENGTH=? where ID=?"; QUERY_LOAD = "select NAME,BEGIN_INDEX,CUR_INDEX,LENGTH from " + tableName + " where ID=?"; QUERY_DEL = "delete from " + tableName + " where ID=?"; QUERY_LIST = "select ID from " + tableName + " order by NAME ASC"; } public ObjectDb getObjectRaw(PrimaryKey pk) { return new WorkflowSequenceDb(pk.getIntValue()); } public WorkflowSequenceDb getWorkflowSequenceDb(int id) { WorkflowSequenceDb log = (WorkflowSequenceDb)getObjectDb(new Integer(id)); return log; } public void setId(int id) { this.id = id; } public void setBeginIndex(long beginIndex) { this.beginIndex = beginIndex; } public void setCurIndex(long curIndex) { this.curIndex = curIndex; } public void setLength(int length) { this.length = length; } public void setName(String name) { this.name = name; } public int getId() { return id; } public long getBeginIndex() { return beginIndex; } public long getCurIndex() { return curIndex; } public int getLength() { return length; } public String getName() { return name; } public boolean create() { Conn conn = new Conn(connname); boolean re = false; id = (int)SequenceManager.nextID(SequenceManager.OA_WORKFLOW_SEQUENCE); try { PreparedStatement pstmt = conn.prepareStatement(QUERY_CREATE); pstmt.setInt(1, id); pstmt.setString(2, name); pstmt.setLong(3, beginIndex); pstmt.setLong(4, curIndex); pstmt.setLong(5, length); re = conn.executePreUpdate()==1?true:false; if (re) { WorkflowSequenceCache rc = new WorkflowSequenceCache(this); rc.refreshCreate(); } } catch (SQLException e) { logger.error("create:" + e.getMessage()); } finally { if (conn != null) { conn.close(); conn = null; } } return re; } public synchronized boolean save() { Conn conn = new Conn(connname); boolean re = false; try { PreparedStatement pstmt = conn.prepareStatement(QUERY_SAVE); pstmt.setString(1, name); pstmt.setLong(2, beginIndex); pstmt.setLong(3, curIndex); pstmt.setInt(4, length); pstmt.setInt(5, id); re = conn.executePreUpdate()==1?true:false; logger.info("save curIndex=" + curIndex); if (re) { WorkflowSequenceCache rc = new WorkflowSequenceCache(this); primaryKey.setValue(new Integer(id)); rc.refreshSave(primaryKey); return true; } } catch (SQLException e) { logger.error("save:" + e.getMessage()); } finally { if (conn != null) { conn.close(); conn = null; } } return re; } public long getNextId() { String sql = "select CUR_INDEX from " + tableName + " where id=?"; long idx = -2; Conn conn = new Conn(connname); ResultSet rs = null; try { PreparedStatement pstmt = conn.prepareStatement(sql); pstmt.setInt(1, id); rs = conn.executePreQuery(); if (rs != null) { if (rs.next()) { idx = rs.getLong(1); } } } catch (Exception e) { logger.error("getNextId:" + e.getMessage()); } finally { if (conn != null) { conn.close(); conn = null; } } return idx + 1; } public void load() { Conn conn = new Conn(connname); ResultSet rs = null; try { PreparedStatement pstmt = conn.prepareStatement(QUERY_LOAD); pstmt.setInt(1, id); logger.info("load: id=" + id + " " + QUERY_LOAD); rs = conn.executePreQuery(); if (rs != null) { if (rs.next()) { name = StrUtil.getNullStr(rs.getString(1)); beginIndex = rs.getLong(2); curIndex = rs.getLong(3); length = rs.getInt(4); loaded = true; primaryKey.setValue(new Integer(id)); } } } catch (Exception e) { logger.error("load:" + e.getMessage()); } finally { if (conn != null) { conn.close(); conn = null; } } } public boolean del() { Conn conn = new Conn(connname); boolean re = false; try { PreparedStatement pstmt = conn.prepareStatement(QUERY_DEL); pstmt.setInt(1, id); re = conn.executePreUpdate()==1?true:false; if (re) { re = conn.executePreUpdate() >= 0 ? true : false; WorkflowSequenceCache rc = new WorkflowSequenceCache(this); rc.refreshDel(primaryKey); return true; } } catch (SQLException e) { logger.error("del:" + e.getMessage()); } finally { if (conn != null) { conn.close(); conn = null; } } return re; } private int id; private long beginIndex = 1; private long curIndex = 1; private int length = 0; private String name;}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?