leaf.java

来自「cwbbs 云网论坛源码」· Java 代码 · 共 1,053 行 · 第 1/3 页

JAVA
1,053
字号
        PreparedStatement pstmt = null;        ResultSet rs = null;        Conn conn = new Conn(connname);        try {            pstmt = conn.prepareStatement(sql);            pstmt.setString(1, code);            rs = conn.executePreQuery();            if (rs != null) {                while (rs.next()) {                    String c = rs.getString(1);                                        v.addElement(getLeaf(c));                }            }        } catch (SQLException e) {            logger.error("getChildren: " + e.getMessage());        } finally {            if (rs != null) {                try {                    rs.close();                } catch (Exception e) {}                rs = null;            }            if (pstmt != null) {                try {                    pstmt.close();                } catch (Exception e) {}                pstmt = null;            }            if (conn != null) {                conn.close();                conn = null;            }        }        return v;    }        public Vector getAllChild(Vector vt, Leaf leaf) throws ErrMsgException {        Vector children = leaf.getChildren();        if (children.isEmpty())            return children;        vt.addAll(children);        Iterator ir = children.iterator();        while (ir.hasNext()) {            Leaf lf = (Leaf) ir.next();            getAllChild(vt, lf);        }        return children;    }    public String toString() {        return "Leaf is " + name;    }    private int type;    public synchronized boolean update() {        String sql = "update sq_board set name=?,description=?,type=?,isHome=?,add_id=?,logo=?,today_count=?,today_date=?,topic_count=?,post_count=?,theme=?,skin=?,islocked=?,boardRule=?,color=?,child_count=?,webeditAllowType=?,plugin2Code=?,check_msg=?,del_mode=?,orders=?,display_style=?,is_bold=? where code=?";        int r = 0;        Conn conn = new Conn(connname);        PreparedStatement ps = null;        try {            ps = conn.prepareStatement(sql);            ps.setString(1, name);            ps.setString(2, description);            ps.setInt(3, type);            ps.setInt(4, isHome ? 1 : 0);            ps.setLong(5, addId);            ps.setString(6, logo);            ps.setInt(7, todayCount);            ps.setString(8, DateUtil.toLongString(todayDate));            ps.setInt(9, topicCount);            ps.setInt(10, postCount);            ps.setString(11, theme);            ps.setString(12, skin);            ps.setInt(13, locked ? 1 : 0);            ps.setString(14, boardRule);            ps.setString(15, color);            ps.setInt(16, child_count);            ps.setInt(17, webeditAllowType);            ps.setString(18, plugin2Code);            ps.setInt(19, checkMsg);            ps.setInt(20, delMode);            ps.setInt(21, orders);            ps.setInt(22, displayStyle);            ps.setInt(23, bold?1:0);            ps.setString(24, code);            r = conn.executePreUpdate();        } catch (Exception e) {            logger.error("update:" + e.getMessage());        } finally {            removeAllFromCache();            if (ps != null) {                try {                    ps.close();                } catch (Exception e) {}                ps = null;            }            if (conn != null) {                conn.close();                conn = null;            }        }        return r == 1;    }        public synchronized boolean updateParent(String newParentCode) throws            ErrMsgException {        if (newParentCode.equals(parent_code))            return false;        if (newParentCode.equals(code))            throw new ErrMsgException("不能将本节点设为父节点!");                Leaf lfparent = getLeaf(newParentCode);        int oldorders = orders;        int neworders = lfparent.getChildCount() + 1;        int parentLayer = lfparent.getLayer();        String sql = "update sq_board set name=" + StrUtil.sqlstr(name) +                     ",description=" + StrUtil.sqlstr(description) +                     ",type=" + type + ",isHome=" + (isHome ? "1" : "0") +                     ",add_id=" + addId + ",logo=" + StrUtil.sqlstr(logo) +                     ",parent_code=" + StrUtil.sqlstr(newParentCode) +                     ",orders=" +                     neworders +                     ",layer=" + (parentLayer + 1) + ",theme=" +                     StrUtil.sqlstr(theme) +                     ",skin=" + StrUtil.sqlstr(skin) + ",islocked=" +                     ((locked) ? 1 : 0) + ",color=" + StrUtil.sqlstr(color) +                     ",plugin2Code=" + StrUtil.sqlstr(plugin2Code) +                     ",check_msg=" +                     checkMsg + ",del_mode=" + delMode + ",display_style=" +                     displayStyle + ",is_bold=" + (bold?1:0) +                     " where code=" + StrUtil.sqlstr(code);        String oldParentCode = parent_code;        parent_code = newParentCode;        RMConn conn = new RMConn(connname);        int r = 0;        try {            r = conn.executeUpdate(sql);            try {                if (r == 1) {                    removeAllFromCache();                                        sql = "select code from sq_board where parent_code=" +                          StrUtil.sqlstr(oldParentCode) +                          " and orders>" + oldorders;                    ResultIterator ri = conn.executeQuery(sql);                    while (ri.hasNext()) {                        ResultRecord rr = (ResultRecord) ri.next();                        Leaf clf = getLeaf(rr.getString(1));                        clf.setOrders(clf.getOrders() - 1);                        clf.update();                    }                                        Vector vt = new Vector();                    getAllChild(vt, this);                    int childcount = vt.size();                    Iterator ir = vt.iterator();                    while (ir.hasNext()) {                        Leaf childlf = (Leaf) ir.next();                        int layer = parentLayer + 1 + 1;                        String pcode = childlf.getParentCode();                        while (!pcode.equals(code)) {                            layer++;                            Leaf lfp = getLeaf(pcode);                            pcode = lfp.getParentCode();                        }                        childlf.setLayer(layer);                        childlf.update();                    }                                        Leaf oldParentLeaf = getLeaf(oldParentCode);                    oldParentLeaf.setChildCount(oldParentLeaf.getChildCount() -                                                1);                    oldParentLeaf.update();                                        Leaf newParentLeaf = getLeaf(newParentCode);                    newParentLeaf.setChildCount(newParentLeaf.getChildCount() +                                                1);                    newParentLeaf.update();                }            } catch (Exception e) {                logger.error("updateParent1: " + e.getMessage());            }        } catch (SQLException e) {            logger.error("updateParent2: " + e.getMessage());        }        boolean re = r == 1 ? true : false;        removeAllFromCache();        return re;    }    public boolean AddChild(Leaf childleaf) throws            ErrMsgException {                int childorders = child_count + 1;        String updatesql = "";        String insertsql = "insert into sq_board (code,name,parent_code,description,orders,root_code,child_count,layer,type,logo,theme,skin,islocked,color,add_date,today_date,webeditAllowType,isHome,plugin2Code,check_msg,del_mode,display_style,is_bold) values (";        insertsql += StrUtil.sqlstr(childleaf.getCode()) + "," +                StrUtil.sqlstr(childleaf.getName()) +                "," + StrUtil.sqlstr(code) +                "," + StrUtil.sqlstr(childleaf.getDescription()) + "," +                childorders + "," + StrUtil.sqlstr(root_code) +                ",0," + (layer + 1) + "," + childleaf.getType() + "," +                StrUtil.sqlstr(childleaf.getLogo()) + "," +                StrUtil.sqlstr(childleaf.getTheme()) + "," +                StrUtil.sqlstr(childleaf.getSkin()) +                "," + (childleaf.isLocked() ? 1 : 0) + "," +                StrUtil.sqlstr(childleaf.getColor()) + "," +                StrUtil.sqlstr("" + System.currentTimeMillis()) + "," +                StrUtil.sqlstr("" + System.currentTimeMillis()) + "," +                childleaf.getWebeditAllowType() + "," +                (childleaf.isHome ? 1 : 0) + "," +                StrUtil.sqlstr(childleaf.getPlugin2Code()) + "," +                childleaf.getCheckMsg() + "," + childleaf.getDelMode() + "," +                displayStyle + "," + (childleaf.isBold()?1:0) + ")";        Conn conn = new Conn(connname);        try {                        updatesql = "Update sq_board set child_count=child_count+1" +                        " where code=" + StrUtil.sqlstr(code);            conn.beginTrans();            conn.executeUpdate(insertsql);            conn.executeUpdate(updatesql);            conn.commit();        } catch (SQLException e) {            conn.rollback();            logger.error("AddChild: " + e.getMessage());            return false;        } finally {            removeAllFromCache();            if (conn != null) {                conn.close();                conn = null;            }        }        return true;    }    public void removeAllFromCache() {        try {            rmCache.invalidateGroup(dirCache);            LeafChildrenCacheMgr.removeAll();        } catch (Exception e) {            logger.error("removeAllFromCache: " + e.getMessage());        }    }    public Leaf getLeaf(String code) {        Leaf leaf = null;        try {            leaf = (Leaf) rmCache.getFromGroup(code, dirCache);        } catch (Exception e) {            logger.error("getLeaf1: " + e.getMessage());        }        if (leaf == null) {            leaf = new Leaf(code);            if (leaf != null) {                if (!leaf.isLoaded())                    leaf = null;                else {                    try {                        rmCache.putInGroup(code, dirCache, leaf);                    } catch (Exception e) {                        logger.error("getLeaf2: " + e.getMessage());                    }                }            }        } else {            leaf.renew();        }        return leaf;    }    public boolean delsingle(ServletContext application, Leaf leaf) {                if (leaf.getType() == leaf.TYPE_BOARD) {            MsgDb md = new MsgDb();            md.delMsgOfBoard(application, leaf.getCode());        }                BoardRenderDb brd = new BoardRenderDb();        brd = brd.getBoardRenderDb(leaf.getCode());        if (brd != null && brd.isLoaded()) {            brd.del();        }                EntranceMgr em = new EntranceMgr();        Vector vEntrancePlugin = em.getAllEntranceUnitOfBoard(leaf.getCode());        if (vEntrancePlugin.size() > 0) {            Iterator irpluginentrance = vEntrancePlugin.iterator();            while (irpluginentrance.hasNext()) {                EntranceUnit eu = (EntranceUnit) irpluginentrance.next();                BoardEntranceDb bed = new BoardEntranceDb();                bed = bed.getBoardEntranceDb(leaf.getCode(), eu.getCode());                bed.del();            }        }                BoardManagerDb bmd = new BoardManagerDb();        Iterator ir = bmd.getBoardManagers(leaf.getCode()).iterator();        while (ir.hasNext()) {            UserDb ud = (UserDb) ir.next();            bmd = bmd.getBoardManagerDb(leaf.getCode(), ud.getName());            bmd.del();        }                BoardScoreDb bsd = new BoardScoreDb();        bsd.delBoardScoreDbsOfBoard(leaf.getCode());        String sql = "delete from sq_board where code=" +                     StrUtil.sqlstr(leaf.getCode());        Conn conn = new Conn(connname);        try {            conn.beginTrans();            boolean r = conn.executeUpdate(sql) == 1 ? true : false;            sql = "update sq_board set orders=orders-1 where parent_code=" +                  StrUtil.sqlstr(leaf.getParentCode()) + " and orders>" +                  leaf.getOrders();            conn.executeUpdate(sql);            sql = "update sq_board set child_count=child_count-1 where code=" +                  StrUtil.sqlstr(leaf.getParentCode());            conn.executeUpdate(sql);            conn.commit();            String lg = leaf.getLogo();                        if (lg != null && !lg.equals("")) {                try {                    String realpath = Global.getRealPath() + "forum/images/board_logo/";                    File file = new File(realpath + lg);                    file.delete();                } catch (Exception e) {                    logger.info("delsingle:" + e.getMessage());                }            }

⌨️ 快捷键说明

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