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

📄 presentdb.java

📁 cwbbs 云网论坛源码
💻 JAVA
字号:
package com.redmoon.forum.plugin.present;import java.sql.*;import cn.js.fan.base.*;import cn.js.fan.db.*;import cn.js.fan.util.*;import cn.js.fan.web.*;import com.redmoon.forum.*;import com.redmoon.forum.plugin.*;public class PresentDb extends ObjectDb {    public PresentDb() {        super();    }    public PresentDb(long id) {        this.id = id;        init();        load();    }    public void initDB() {        this.tableName = "plugin_present";        primaryKey = new PrimaryKey("id", PrimaryKey.TYPE_LONG);        objectCache = new PresentCache(this);        this.QUERY_CREATE = "insert into plugin_present (msg_id, user_name, money_code, score, give_date,id,reason) values (?,?,?,?,?,?,?)";                this.QUERY_DEL = "delete from plugin_present where id=?";        this.QUERY_LOAD =            "select user_name, money_code, score, give_date, msg_id, reason from plugin_present where id=?";        isInitFromConfigDB = false;    }    public boolean del() {        int rowcount = 0;        Conn conn = null;        try {            conn = new Conn(connname);            PreparedStatement ps = conn.prepareStatement(this.QUERY_DEL);            ps.setLong(1, id);            rowcount = conn.executePreUpdate();        } catch (SQLException e) {            logger.error("del:" + e.getMessage());        } finally {            if (conn != null) {                conn.close();                conn = null;            }        }        if (rowcount > 0) {            PresentCache cc = new PresentCache(this);            primaryKey.setValue(new Long(msgId));            cc.refreshDel(primaryKey);        }        return rowcount>0? true:false;    }    public ObjectDb getObjectRaw(PrimaryKey pk) {        return new PresentDb(pk.getLongValue());    }    public boolean create() throws ResKeyException {        int rowcount = 0;        Conn conn = null;        try {            conn = new Conn(connname);                        PreparedStatement ps = conn.prepareStatement(this.QUERY_CREATE);            ps.setLong(1, msgId);            ps.setString(2, userName);            ps.setString(3, moneyCode);            ps.setInt(4, score);            ps.setString(5, "" + new java.util.Date().getTime());            ps.setLong(6, SequenceMgr.nextID(SequenceMgr.PLUGIN_PRESENT));            ps.setString(7, reason);            rowcount = conn.executePreUpdate();        } catch (SQLException e) {            logger.error("create:" + e.getMessage());            throw new ResKeyException(new SkinUtil(), SkinUtil.ERR_DB);        } finally {            if (conn != null) {                conn.close();                conn = null;            }            PresentCache uc = new PresentCache(this);            uc.refreshCreate();        }        return rowcount>0? true:false;    }    public boolean save() throws ResKeyException {        int rowcount = 0;        Conn conn = null;        try {            conn = new Conn(connname);            PreparedStatement ps = conn.prepareStatement(this.QUERY_SAVE);            ps.setLong(3, msgId);            rowcount = conn.executePreUpdate();        } catch (SQLException e) {            logger.error("save:" + e.getMessage());            throw new ResKeyException(SkinUtil.ERR_DB);        } finally {            PresentCache uc = new PresentCache(this);            primaryKey.setValue(new Long(msgId));            uc.refreshSave(primaryKey);            if (conn != null) {                conn.close();                conn = null;            }        }        return rowcount>0? true:false;    }    public PresentDb getPresentDb(long id) {        return (PresentDb)getObjectDb(new Long(id));    }    public void load() {        ResultSet rs = null;        Conn conn = new Conn(connname);        try {                        PreparedStatement ps = conn.prepareStatement(this.QUERY_LOAD);            ps.setLong(1, id);            primaryKey.setValue(new Long(id));            rs = conn.executePreQuery();            if (rs.next()) {                userName = rs.getString(1);                moneyCode = rs.getString(2);                score = rs.getInt(3);                giveDate = DateUtil.parse(rs.getString(4));                msgId = rs.getLong(5);                reason = StrUtil.getNullStr(rs.getString(6));                loaded = true;            }        } catch (SQLException e) {            logger.error("load:" + e.getMessage());        }        finally {            if (conn!=null) {                conn.close();                conn = null;            }        }    }    public ObjectBlockIterator listPresentOfMsg(long msgId) {        String sql = "select id from " + tableName + " where msg_id=" + msgId + " order by id";        int count = getObjectCount(sql);        ObjectBlockIterator oi = getObjects(sql, 0, count);        return oi;    }    public void setMsgId(long msgId) {        this.msgId = msgId;    }    public void setUserName(String userName) {        this.userName = userName;    }    public void setScore(int score) {        this.score = score;    }    public void setMoneyCode(String moneyCode) {        this.moneyCode = moneyCode;    }    public void setReason(String reason) {        this.reason = reason;    }    public void setGiveDate(Date giveDate) {        this.giveDate = giveDate;    }    public long getMsgId() {        return msgId;    }    public String getUserName() {        return userName;    }    public int getScore() {        return score;    }    public String getMoneyCode() {        return moneyCode;    }    public java.util.Date getGiveDate() {        return giveDate;    }    public String getReason() {        return reason;    }    public boolean doGive(MsgDb md, String giver, String moneyCode, int score, String reason) throws ResKeyException {        ScoreMgr sm = new ScoreMgr();        ScoreUnit su = sm.getScoreUnit(moneyCode);                boolean re = su.getScore().pay(giver, md.getName(), score);        if (re) {            PresentDb pd = new PresentDb();            pd.setUserName(giver);            pd.setMsgId(md.getId());            pd.setMoneyCode(moneyCode);            pd.setScore(score);            pd.setReason(reason);            re = pd.create();        }        return re;    }    private long msgId;    private String userName;    private int score;    private String moneyCode;    private java.util.Date giveDate;    private long id;    private String reason;}

⌨️ 快捷键说明

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