📄 rankdb.java
字号:
package com.redmoon.oa.basic;import java.sql.*;import java.util.*;import cn.js.fan.base.*;import cn.js.fan.db.*;import cn.js.fan.util.*;public class RankDb extends ObjectDb { private String code; public RankDb() { init(); } public RankDb(String code) { this.code = code; init(); load(); } public String getCode() { return code; } public void setCode(String code) { this.code = code; } public void initDB() { tableName = "basic_rank"; primaryKey = new PrimaryKey("code", PrimaryKey.TYPE_STRING); objectCache = new RankCache(this); isInitFromConfigDB = false; QUERY_CREATE = "insert into " + tableName + " (code,name,orders) values (?,?,?)"; QUERY_SAVE = "update " + tableName + " set name=?,orders=? where code=?"; QUERY_LIST = "select code from " + tableName + " order by orders asc"; QUERY_DEL = "delete from " + tableName + " where code=?"; QUERY_LOAD = "select name,orders from " + tableName + " where code=?"; } public static String getRankName(String rankCode) { if (rankCode==null || rankCode.equals("")) return ""; RankDb rd = new RankDb(); return rd.getRankDb(rankCode).getName(); } public RankDb getRankDb(String code) { return (RankDb) getObjectDb(code); } public boolean create() throws ErrMsgException { Conn conn = new Conn(connname); boolean re = false; try { PreparedStatement ps = conn.prepareStatement(QUERY_CREATE); ps.setString(1, code); ps.setString(2, name); ps.setInt(3, orders); re = conn.executePreUpdate() == 1 ? true : false; if (re) { RankCache rc = new RankCache(this); rc.refreshCreate(); } } catch (SQLException e) { logger.error("create:" + e.getMessage()); throw new ErrMsgException("数据库操作失败!"); } finally { if (conn != null) { conn.close(); conn = null; } } return re; } public boolean del() throws ErrMsgException { Conn conn = new Conn(connname); boolean re = false; try { PreparedStatement ps = conn.prepareStatement(QUERY_DEL); ps.setString(1, code); re = conn.executePreUpdate() == 1 ? true : false; if (re) { RankCache rc = new RankCache(this); primaryKey.setValue(code); rc.refreshDel(primaryKey); } } catch (SQLException e) { logger.error("del: " + e.getMessage()); } finally { if (conn != null) { conn.close(); conn = null; } } return re; } public ObjectDb getObjectRaw(PrimaryKey pk) { return new RankDb(pk.getStrValue()); } public void load() { ResultSet rs = null; Conn conn = new Conn(connname); try { PreparedStatement ps = conn.prepareStatement(QUERY_LOAD); ps.setString(1, code); rs = conn.executePreQuery(); if (rs != null && rs.next()) { name = rs.getString(1); orders = rs.getInt(2); loaded = true; primaryKey.setValue(code); } } catch (SQLException e) { logger.error("load: " + e.getMessage()); } finally { if (rs != null) { try { rs.close(); } catch (SQLException e) {} rs = null; } if (conn != null) { conn.close(); conn = null; } } } public boolean save() throws ErrMsgException { Conn conn = new Conn(connname); boolean re = false; try { PreparedStatement ps = conn.prepareStatement(QUERY_SAVE); ps.setString(1, name); ps.setInt(2, orders); ps.setString(3, code); re = conn.executePreUpdate() == 1 ? true : false; if (re) { RankCache rc = new RankCache(this); primaryKey.setValue(code); rc.refreshSave(primaryKey); } } catch (SQLException e) { logger.error("save: " + e.getMessage()); } finally { if (conn != null) { conn.close(); conn = null; } } return re; } public boolean isExist(String tableName) { ResultSet rs = null; Conn conn = new Conn(connname); try { rs = conn.executeQuery("select code from basic_rank where name='" + tableName + "'"); if (rs.next()) { return true; } } catch (SQLException e) { logger.error("list:" + e.getMessage()); } finally { if (conn != null) { conn.close(); conn = null; } } return false; } public Vector list(String sql) { ResultSet rs = null; Conn conn = new Conn(connname); Vector result = new Vector(); try { rs = conn.executeQuery(sql); if (rs == null) { return null; } else { while (rs.next()) { result.addElement(getRankDb(rs.getString(1))); } } } catch (SQLException e) { logger.error("list:" + e.getMessage()); } finally { if (conn != null) { conn.close(); conn = null; } } return result; } public String getName() { return name; } public int getOrders() { return orders; } public void setName(String name) { this.name = name; } public void setOrders(int orders) { this.orders = orders; } private String name; private int orders = 1;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -