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

📄 messagedb.java

📁 oa 源码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
            mc.refreshNewCountOfReceiver(receiver);            mc.refreshCreate();        } catch (Exception e) {            logger.error("create: " + e.getMessage());            throw new ErrMsgException("数据库操作错误!");        } finally {            if (conn != null) {                conn.close();                conn = null;            }        }        return re;    }    public ObjectDb getObjectDb(Object primaryKeyValue) {        MessageCache uc = new MessageCache(this);        primaryKey.setValue(primaryKeyValue);        return (MessageDb) uc.getObjectDb(primaryKey);    }    public synchronized boolean del() {        boolean re = false;        Conn conn = new Conn(connname);        try {            PreparedStatement ps = conn.prepareStatement(QUERY_DEL);            ps.setInt(1, id);            re = conn.executePreUpdate() == 1 ? true : false;            if (re) {                MessageCache mc = new MessageCache(this);                mc.refreshDel(primaryKey);                mc.refreshNewCountOfReceiver(receiver);            }        } catch (Exception e) {            logger.error("del:" + e.getMessage());        } finally {            if (conn != null) {                conn.close();                conn = null;            }        }        if (re) {                        if (attachments!=null) {                Iterator ir = attachments.iterator();                while (ir.hasNext()) {                    Attachment att = (Attachment)ir.next();                    att.del();                }            }            MessageCache uc = new MessageCache(this);            primaryKey.setValue(new Integer(id));            uc.refreshDel(primaryKey);        }        return re;    }    public int getObjectCount(String sql) {        MessageCache uc = new MessageCache(this);        return uc.getObjectCount(sql);    }    public int getMessageCount(String sql) {        return getObjectCount(sql);    }    public Object[] getObjectBlock(String query, int startIndex) {        MessageCache dcm = new MessageCache(this);        return dcm.getObjectBlock(query, startIndex);    }    public ObjectDb getObjectRaw(PrimaryKey pk) {        return new MessageDb(pk.getIntValue());    }    public void setQueryCreate() {        this.QUERY_CREATE =                "insert into oa_message (id,title,content,sender,receiver,type,ip,rq,isDraft) values (?,?,?,?,?,?,?,?,?)";    }    public void setQuerySave() {        this.QUERY_SAVE =                "update oa_message set isreaded=?,isDraft=? where id=?";    }    public void setQueryDel() {        this.QUERY_DEL = "delete from oa_message where id=?";    }    public void setQueryLoad() {        QUERY_LOAD = "select title,content,sender,receiver,rq,ip,type,isreaded,isDraft from oa_message where id=?";    }    public void setQueryList() {        QUERY_LIST = "select id from oa_message order by isreaded asc,rq desc";    }    public synchronized boolean save() {        boolean re = false;        Conn conn = new Conn(connname);        try {            PreparedStatement ps = conn.prepareStatement(QUERY_SAVE);            ps.setInt(1, readed?1:0);            ps.setInt(2, draft?1:0);            ps.setInt(3, id);            re = conn.executePreUpdate() == 1 ? true : false;        } catch (Exception e) {            logger.error("save:" + e.getMessage());        } finally {            if (conn != null) {                conn.close();                conn = null;            }        }        if (re) {            MessageCache uc = new MessageCache(this);            primaryKey.setValue(new Integer(id));            uc.refreshSave(primaryKey);            uc.refreshNewCountOfReceiver(receiver);        }        return re;    }    public void setPrimaryKey() {        primaryKey = new PrimaryKey("id", PrimaryKey.TYPE_INT);    }    public synchronized void load() {        Conn conn = new Conn(connname);        ResultSet rs = null;        try {            PreparedStatement pstmt = conn.prepareStatement(QUERY_LOAD);            pstmt.setInt(1, id);            rs = conn.executePreQuery();            if (rs != null && rs.next()) {                title = rs.getString(1);                content = rs.getString(2);                sender = rs.getString(3);                receiver = rs.getString(4);                rq = DateUtil.format(rs.getTimestamp(5), "yy-MM-dd HH:mm");                ip = rs.getString(6);                type = rs.getInt(7);                readed = rs.getInt(8) == 1 ? true : false;                draft = rs.getInt(9)==1?true:false;                loaded = true;                primaryKey.setValue(new Integer(id));                String LOAD_DOCUMENT_ATTACHMENTS =                        "SELECT id FROM oa_message_attach WHERE msgId=? order by orders";                attachments = new Vector();                pstmt = conn.prepareStatement(LOAD_DOCUMENT_ATTACHMENTS);                pstmt.setInt(1, id);                rs = conn.executePreQuery();                if (rs != null) {                    while (rs.next()) {                        int aid = rs.getInt(1);                        Attachment am = new Attachment(aid);                        attachments.addElement(am);                    }                }            }        } catch (Exception e) {            logger.error("load: " + e.getMessage());        } finally {            if (conn != null) {                conn.close();                conn = null;            }        }    }    public void setReaded(boolean readed) {        this.readed = readed;    }    public void setAttachments(Vector attachments) {        this.attachments = attachments;    }    public void setDraft(boolean draft) {        this.draft = draft;    }    public Vector getNewMsgsOfUser(String userName) {        Vector v = new Vector();        Conn conn = new Conn(connname);        ResultSet rs = null;        try {            String sql = "select id from oa_message where receiver=? and isDraft=0 and isreaded=0";            PreparedStatement pstmt = conn.prepareStatement(sql);            pstmt.setString(1, userName);            rs = conn.executePreQuery();            if (rs != null) {                while (rs.next()) {                    IMessage md = getMessageDb(rs.getInt(1));                                        v.addElement(md);                }            }        } catch (Exception e) {            logger.error("load: " + e.getMessage());        } finally {            if (conn != null) {                conn.close();                conn = null;            }        }        return v;    }    public Attachment getAttachment(int attId) {        Iterator ir = getAttachments().iterator();        while (ir.hasNext()) {            Attachment at = (Attachment)ir.next();            if (at.getId()==attId)                return at;        }        return null;    }    public boolean TransmitMsg(ServletContext application,                          HttpServletRequest request,                          String sender, int msgId) throws            ErrMsgException {        MessageForm mf = new MessageForm(application, request, this);        mf.checkTransmit();        this.sender = sender;        String[] ary = receiver.split(",");        int len = ary.length;        for (int i=0; i<len; i++) {            transmit(ary[i], msgId);        }        return true;    }        public boolean transmit(String toUser, int msgId) throws ErrMsgException {        Conn conn = null;        boolean re = false;        try {            conn = new Conn(connname);            PreparedStatement ps = conn.prepareStatement(QUERY_CREATE);            id = (int) SequenceManager.nextID(SequenceManager.OA_MESSAGE);            ps.setInt(1, id);            ps.setString(2, title);            ps.setString(3, content);            ps.setString(4, sender);            ps.setString(5, toUser);            ps.setInt(6, type);            ps.setString(7, ip);            java.util.Date curDate = new java.util.Date();            Timestamp ts = new Timestamp(curDate.getTime());            ps.setTimestamp(8, ts);            ps.setInt(9, 0);            re = conn.executePreUpdate() == 1 ? true : false;            MessageCache mc = new MessageCache(this);            mc.refreshNewCountOfReceiver(receiver);            mc.refreshCreate();            if (re) {                IMessage md = getMessageDb(msgId);                Vector v = md.getAttachments();                if (v.size()>0) {                    Iterator ir = v.iterator();                    FileUtil fu = new FileUtil();                    while (ir.hasNext()) {                        Attachment att = (Attachment)ir.next();                        String fullPath = Global.realPath + att.getVisualPath() + "/" + att.getDiskName();                        String newName = RandomSecquenceCreator.getId() + "." + StrUtil.getFileExt(att.getDiskName());                        String newFullPath = Global.realPath + att.getVisualPath() + "/" + newName;                        fu.CopyFile(fullPath, newFullPath);                        Attachment att2 = new Attachment();                        att2.setFullPath(newFullPath);                        att2.setMsgId(id);                        att2.setFullPath(fullPath);                        att2.setName(att.getName());                        att2.setDiskName(att.getDiskName());                        att2.setVisualPath(att.getVisualPath());                        re = att2.create();                    }                }            }        } catch (Exception e) {            logger.error("transmit: " + e.getMessage());            e.printStackTrace();            throw new ErrMsgException("数据库操作错误!");        } finally {            if (conn != null) {                conn.close();                conn = null;            }        }        return re;    }    public void setTitle(String title) {        this.title = title;    }    public void setContent(String content) {        this.content = content;    }    private Vector attachments;    private boolean draft;}

⌨️ 快捷键说明

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