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

📄 scorerecorddb.java

📁 cwbbs 云网论坛源码
💻 JAVA
字号:
package com.redmoon.forum.plugin;import java.sql.*;import java.util.*;import cn.js.fan.base.*;import cn.js.fan.db.*;import cn.js.fan.util.*;import com.redmoon.forum.*;public class ScoreRecordDb extends ObjectDb {    public static final String OPERATION_EXCHANGE = "exchange";    public static final String OPERATION_PAY = "pay";    public static final String OPERATION_TRANSFER = "transfer";    public ScoreRecordDb() {    }    public ScoreRecordDb(int id) {        this.id = id;        init();        load();    }    public void initDB() {        this.tableName = "sq_score_record";        primaryKey = new PrimaryKey("id", PrimaryKey.TYPE_INT);        objectCache = new ScoreRecordCache(this);        this.QUERY_CREATE =                "insert into " + tableName + " (id, title, lydate, buyer, seller, from_score, to_score, operation, from_value, to_value) values (?,?,?,?,?,?,?,?,?,?)";        this.QUERY_SAVE =                "update " + tableName + " set title=?, lydate=?, buyer=?, seller=?, from_score=?, to_score=?, operation=?, from_value=?, to_value=? where id=?";        this.QUERY_DEL =                "delete from " + tableName + " where id=?";        this.QUERY_LOAD =                "select title, lydate, buyer, seller, from_score, to_score, operation, from_value, to_value from " + tableName + " where id=?";        this.QUERY_LIST = "select id from " + tableName ;        isInitFromConfigDB = false;    }    public ScoreRecordDb getScoreRecordDb(int id) {        return (ScoreRecordDb) getObjectDb(new Integer(id));    }    public ObjectDb getObjectRaw(PrimaryKey pk) {        return new ScoreRecordDb(pk.getIntValue());    }    public boolean create(){        id = (int) SequenceMgr.nextID(SequenceMgr.SQ_SCORE_RECORD);        lydate = Long.toString(System.currentTimeMillis());        Conn conn = new Conn(connname);               boolean re = false;               try {                   PreparedStatement ps = conn.prepareStatement(QUERY_CREATE);                   ps.setInt(1, id);                   ps.setString(2, title);                   ps.setString(3, lydate);                   ps.setString(4, buyer);                   ps.setString(5, seller);                   ps.setString(6, fromScore);                   ps.setString(7, toScore);                   ps.setString(8, operation);                   ps.setDouble(9, fromValue);                   ps.setDouble(10, toValue);                   re = conn.executePreUpdate() == 1 ? true : false;                   if (re) {                       ScoreRecordCache src = new ScoreRecordCache(this);                       src.refreshCreate();                   }               } catch (SQLException e) {                   logger.error("create:" + e.getMessage());               } 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.setInt(1, id);            re = conn.executePreUpdate() == 1 ? true : false;            if (re) {                ScoreRecordCache src = new ScoreRecordCache(this);                primaryKey.setValue(new Integer(id));                src.refreshDel(primaryKey);            }        } catch (SQLException e) {            logger.error("del: " + e.getMessage());        } finally {            if (conn != null) {                conn.close();                conn = null;            }        }        return re;    }    public boolean save() throws ErrMsgException {        Conn conn = new Conn(connname);        boolean re = false;        try {            PreparedStatement ps = conn.prepareStatement(QUERY_SAVE);            ps.setString(1, title);            ps.setString(2, lydate);            ps.setString(3, buyer);            ps.setString(4, seller);            ps.setString(5, fromScore);            ps.setString(6, toScore);            ps.setString(7, operation);            ps.setDouble(8, fromValue);            ps.setDouble(9, toValue);            ps.setInt(10, id);            re = conn.executePreUpdate() == 1 ? true : false;            if (re) {                ScoreRecordCache src = new ScoreRecordCache(this);                primaryKey.setValue(new Integer(id));                src.refreshSave(primaryKey);            }        } catch (SQLException e) {            logger.error("save: " + e.getMessage());        } finally {            if (conn != null) {                conn.close();                conn = null;            }        }        return re;    }    public void load() {        ResultSet rs = null;        Conn conn = new Conn(connname);        try {            PreparedStatement ps = conn.prepareStatement(QUERY_LOAD);            ps.setInt(1, id);            rs = conn.executePreQuery();            if (rs != null && rs.next()) {                title = StrUtil.getNullStr(rs.getString(1));                lydate = StrUtil.getNullStr(rs.getString(2));                buyer = StrUtil.getNullStr(rs.getString(3));                seller = StrUtil.getNullStr(rs.getString(4));                fromScore = StrUtil.getNullStr(rs.getString(5));                toScore = StrUtil.getNullStr(rs.getString(6));                operation = StrUtil.getNullStr(rs.getString(7));                fromValue = rs.getInt(8);                toValue = rs.getInt(9);                loaded = true;                primaryKey.setValue(new Integer(id));            }        } 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 ListResult listResult(String listsql, int curPage, int pageSize) throws            ErrMsgException {        int total = 0;        ResultSet rs = null;        Vector result = new Vector();        ListResult lr = new ListResult();        lr.setTotal(total);        lr.setResult(result);        Conn conn = new Conn(connname);        try {                        String countsql = SQLFilter.getCountSql(listsql);            rs = conn.executeQuery(countsql);            if (rs != null && rs.next()) {                total = rs.getInt(1);            }            if (rs != null) {                rs.close();                rs = null;            }            if (total != 0) {                conn.setMaxRows(curPage * pageSize);             }            rs = conn.executeQuery(listsql);            if (rs == null) {                return lr;            } else {                rs.setFetchSize(pageSize);                int absoluteLocation = pageSize * (curPage - 1) + 1;                if (rs.absolute(absoluteLocation) == false) {                    return lr;                }                do {                    ScoreRecordDb srd = getScoreRecordDb(rs.getInt(1));                    result.addElement(srd);                } while (rs.next());            }        } catch (SQLException e) {            logger.error(e.getMessage());        } finally {            if (rs != null) {                try {                    rs.close();                } catch (Exception e) {}                rs = null;            }            if (conn != null) {                conn.close();                conn = null;            }        }        lr.setResult(result);        lr.setTotal(total);        return lr;    }    public void setId(int id) {        this.id = id;    }    public void setLydate(String lydate) {        this.lydate = lydate;    }    public void setBuyer(String buyer) {        this.buyer = buyer;    }    public void setSeller(String seller) {        this.seller = seller;    }    public void setFromScore(String fromScore) {        this.fromScore = fromScore;    }    public void setToScore(String toScore) {        this.toScore = toScore;    }    public void setOperation(String operation) {        this.operation = operation;    }    public void setTitle(String title) {        this.title = title;    }    public void setFromValue(double fromValue) {        this.fromValue = fromValue;    }    public void setToValue(double toValue) {        this.toValue = toValue;    }    public int getId() {        return id;    }    public String getLydate() {        return lydate;    }    public String getBuyer() {        return buyer;    }    public String getSeller() {        return seller;    }    public String getFromScore() {        return fromScore;    }    public String getToScore() {        return toScore;    }    public String getOperation() {        return operation;    }    public String getTitle() {        return title;    }    public double getFromValue() {        return fromValue;    }    public double getToValue() {        return toValue;    }    private int id;    private String lydate;    private String buyer;    private String seller;    private String fromScore;    private String toScore;    private String operation;    private String title;    private double fromValue;    private double toValue;}

⌨️ 快捷键说明

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