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

📄 tagmsgdb.java

📁 cwbbs 云网论坛源码
💻 JAVA
字号:
package com.redmoon.forum;import java.sql.*;import java.util.*;import cn.js.fan.db.*;import cn.js.fan.util.*;import cn.js.fan.web.*;import com.cloudwebsoft.framework.base.*;import com.cloudwebsoft.framework.db.*;import com.cloudwebsoft.framework.db.Connection;import com.cloudwebsoft.framework.util.*;public class TagMsgDb extends QObjectDb {    public TagMsgDb() {    }    public boolean del(JdbcTemplate jt) throws ResKeyException {        boolean re = super.del(jt);        if (re) {            TagDb td = new TagDb();            td = td.getTagDb(getLong("tag_id"));            td.set("count", new Integer(td.getInt("count") - 1));            td.save(jt);                        MsgCache mc = new MsgCache();            mc.refreshUpdate(getLong("msg_id"));        }        return re;    }        public void delTagOfUser(long tagId, String userName) {        String sql = "select tag_id, msg_id from " + table.getName() + " where tag_id=? and user_name=?";        Vector v = list(new JdbcTemplate(), sql, new Object[] {new Long(tagId), userName});        Iterator ir = v.iterator();        while (ir.hasNext()) {            TagMsgDb tmd = (TagMsgDb)ir.next();            try {                tmd.del();            }            catch (ResKeyException e) {                LogUtil.getLog(getClass()).error("delTagOfUser:" + e.getMessage());            }        }    }    public void delForTag(long tagId) {        PreparedStatement ps = null;        ResultSet rs = null;        Connection conn = new Connection(Global.defaultDB);        try {                        String sql = "select tag_id, msg_id from " + table.getName() + " where tag_id=?";            ps = conn.prepareStatement(sql);            ps.setLong(1, tagId);            rs = conn.executePreQuery();            while (rs.next()) {                TagMsgDb tmd = getTagMsgDb(rs.getLong(1), rs.getLong(2));                tmd.del();            }        } catch (SQLException e) {            LogUtil.getLog(getClass()).error("delForMsg:" + e.getMessage());        }        catch (ResKeyException e) {            LogUtil.getLog(getClass()).error("delForMsg2:" + e.getMessage());        }        finally {            if (rs!=null) {                try { rs.close(); } catch (Exception e) {}                rs = null;            }            if (ps != null) {                try {                    ps.close();                } catch (Exception e) {}                ps = null;            }            if (conn != null) {                try {                    conn.close();                } catch (Exception e) {}                conn = null;            }        }    }    public Vector getTagMsgDbOfMsg(long msgId) {        String sql = "select tag_id, msg_id from " + table.getName() + " where msg_id=?";                return list(new JdbcTemplate(), sql, new Object[] {new Long(msgId)});    }    public void createForMsg(long msgId, Vector tagNames, String userName) {        int len = tagNames.size();        PreparedStatement ps = null;        Connection conn = new Connection(Global.defaultDB);        try {            ps = conn.prepareStatement(table.getQueryCreate());            TagDb td2 = new TagDb();            for (int i = 0; i < len; i++) {                String tagName = (String)tagNames.elementAt(i);                TagDb td = td2.getTagDbByName(tagName);                if (td == null) {                                        td2.create(tagName, userName);                    td = td2.getTagDbByName((String) tagNames.elementAt(i));                }                ps.setLong(1, td.getLong("id"));                ps.setLong(2, msgId);                ps.setTimestamp(3, new Timestamp(new java.util.Date().getTime()));                ps.setString(4, userName);                ps.addBatch();                try {                    td.set("count", new Integer(td.getInt("count") + 1));                    td.save();                }                catch (ResKeyException e) {                    LogUtil.getLog(getClass()).error("createForMsg1:" + e.getMessage());                }            }            ps.executeBatch();            refreshCreate();        } catch (SQLException e) {            LogUtil.getLog(getClass()).error("createForMsg2:" + e.getMessage());        } finally {            if (ps != null) {                try {                    ps.close();                } catch (Exception e) {}                ps = null;            }            if (conn != null) {                try {                    conn.close();                } catch (Exception e) {}                conn = null;            }        }    }    public TagMsgDb getTagMsgDb(long tagId, long msgId) {        PrimaryKey pk = (PrimaryKey)primaryKey.clone();        pk.setKeyValue("tag_id", new Long(tagId));        pk.setKeyValue("msg_id", new Long(msgId));        TagMsgDb tmd = (TagMsgDb)getQObjectDb(pk.getKeys());        return tmd;    }    public void delForMsg(long msgId) {        PreparedStatement ps = null;        ResultSet rs = null;        Connection conn = new Connection(Global.defaultDB);        try {                        String sql = "select tag_id, msg_id from " + table.getName() + " where msg_id=?";            ps = conn.prepareStatement(sql);            ps.setLong(1, msgId);            rs = conn.executePreQuery();            while (rs.next()) {                TagMsgDb tmd = getTagMsgDb(rs.getLong(1), rs.getLong(2));                tmd.del();            }        } catch (SQLException e) {            LogUtil.getLog(getClass()).error("delForMsg:" + e.getMessage());        }        catch (ResKeyException e) {            LogUtil.getLog(getClass()).error("delForMsg2:" + e.getMessage());        }        finally {            if (rs!=null) {                try { rs.close(); } catch (Exception e) {}                rs = null;            }            if (ps != null) {                try {                    ps.close();                } catch (Exception e) {}                ps = null;            }            if (conn != null) {                try {                    conn.close();                } catch (Exception e) {}                conn = null;            }        }    }    public void editForMsg(long msgId, Vector tagNames, String userName) {        if (tagNames==null)            return;        int len = tagNames.size();        PreparedStatement ps = null;                delForMsg(msgId);        if (tagNames==null)            return;        Connection conn = new Connection(Global.defaultDB);        try {            ps = conn.prepareStatement(table.getQueryCreate());            TagDb td2 = new TagDb();            for (int i = 0; i < len; i++) {                String tagName = (String)tagNames.elementAt(i);                TagDb td = td2.getTagDbByName(tagName);                if (td == null) {                                        td2.create(tagName, userName);                    td = td2.getTagDbByName((String) tagNames.elementAt(i));                }                ps.setLong(1, td.getLong("id"));                ps.setLong(2, msgId);                ps.setTimestamp(3, new Timestamp(new java.util.Date().getTime()));                ps.setString(4, userName);                ps.addBatch();                try {                    td.set("count", new Integer(td.getInt("count") + 1));                    td.save();                }                catch (ResKeyException e) {                    LogUtil.getLog(getClass()).error("editForMsg1:" + e.getMessage());                }            }            ps.executeBatch();        } catch (SQLException e) {            LogUtil.getLog(getClass()).error("editForMsg2:" + e.getMessage());        } finally {            if (ps != null) {                try {                    ps.close();                } catch (Exception e) {}                ps = null;            }            if (conn != null) {                try {                    conn.close();                } catch (Exception e) {}                conn = null;            }        }                MsgCache mc = new MsgCache();        mc.refreshUpdate(msgId);    }}

⌨️ 快捷键说明

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