📄 leaf.java
字号:
int oldorders = orders; int neworders = lfparent.getChildCount() + 1; int parentLayer = lfparent.getLayer(); String sql = "update " + tableName + " set name=" + StrUtil.sqlstr(name) + ",description=" + StrUtil.sqlstr(description) + ",type=" + type + ",isHome=" + (isHome ? "1" : "0") + ",doc_id=" + docId + ",template_id=" + templateId + ",parent_code=" + StrUtil.sqlstr(newParentCode) + ",orders=" + neworders + ",layer=" + (parentLayer+1) + " 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) { removeFromCache(code); removeFromCache(newParentCode); removeFromCache(oldParentCode); LeafChildrenCacheMgr.remove(oldParentCode); LeafChildrenCacheMgr.remove(newParentCode); sql = "select code from " + tableName + " 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("update: " + e.getMessage()); } } catch (SQLException e) { logger.error("update: " + e.getMessage()); } boolean re = r == 1 ? true : false; if (re) { removeFromCache(code); } return re; } public boolean AddChild(Leaf childleaf) throws ErrMsgException { int childorders = child_count + 1; String updatesql = ""; String insertsql = "insert into " + tableName + " (code,name,parent_code,description,orders,root_code,child_count,layer,type,add_date) 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("" + System.currentTimeMillis()) + ")"; if (!SecurityUtil.isValidSql(insertsql)) throw new ErrMsgException("请勿输入非法字符如;号等!"); Conn conn = new Conn(connname); try { updatesql = "Update " + tableName + " set child_count=child_count+1" + " where code=" + StrUtil.sqlstr(code); conn.beginTrans(); conn.executeUpdate(insertsql); conn.executeUpdate(updatesql); removeFromCache(code); conn.commit(); } catch (SQLException e) { conn.rollback(); logger.error("AddChild: " + e.getMessage()); return false; } finally { if (conn != null) { conn.close(); conn = null; } } return true; } public void removeFromCache(String code) { try { rmCache.remove(code, dirCache); LeafChildrenCacheMgr.remove(code); } catch (Exception e) { logger.error("removeFromCache: " + e.getMessage()); } } 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(Leaf leaf) { RMConn rmconn = new RMConn(connname); try { String sql = "delete from " + tableName + " where code=" + StrUtil.sqlstr(leaf.getCode()); boolean r = rmconn.executeUpdate(sql) == 1 ? true : false; sql = "update " + tableName + " set orders=orders-1 where parent_code=" + StrUtil.sqlstr(leaf.getParentCode()) + " and orders>" + leaf.getOrders(); rmconn.executeUpdate(sql); sql = "update " + tableName + " set child_count=child_count-1 where code=" + StrUtil.sqlstr(leaf.getParentCode()); rmconn.executeUpdate(sql); removeAllFromCache(); } catch (SQLException e) { logger.error("delsingle: " + e.getMessage()); return false; } return true; } public void del(Leaf leaf) { delsingle(leaf); Iterator children = getChildren().iterator(); while (children.hasNext()) { Leaf lf = (Leaf) children.next(); del(lf); } } public Leaf getBrother(String direction) { String sql; RMConn rmconn = new RMConn(connname); Leaf bleaf = null; try { if (direction.equals("down")) { sql = "select code from " + tableName + " where parent_code=" + StrUtil.sqlstr(parent_code) + " and orders=" + (orders + 1); } else { sql = "select code from " + tableName + " where parent_code=" + StrUtil.sqlstr(parent_code) + " and orders=" + (orders - 1); } ResultIterator ri = rmconn.executeQuery(sql); if (ri != null && ri.hasNext()) { ResultRecord rr = (ResultRecord) ri.next(); bleaf = getLeaf(rr.getString(1)); } } catch (SQLException e) { logger.error("getBrother: " + e.getMessage()); } return bleaf; } public boolean move(String direction) { String sql = ""; boolean isexist = false; Leaf bleaf = getBrother(direction); if (bleaf != null) { isexist = true; } if (isexist) { Conn conn = new Conn(connname); try { conn.beginTrans(); if (direction.equals("down")) { sql = "update " + tableName + " set orders=orders+1" + " where code=" + StrUtil.sqlstr(code); conn.executeUpdate(sql); sql = "update " + tableName + " set orders=orders-1" + " where code=" + StrUtil.sqlstr(bleaf.getCode()); conn.executeUpdate(sql); } if (direction.equals("up")) { sql = "update " + tableName + " set orders=orders-1" + " where code=" + StrUtil.sqlstr(code); conn.executeUpdate(sql); sql = "update " + tableName + " set orders=orders+1" + " where code=" + StrUtil.sqlstr(bleaf.getCode()); conn.executeUpdate(sql); } conn.commit(); removeFromCache(code); removeFromCache(bleaf.getCode()); } catch (Exception e) { conn.rollback(); logger.error("move: " + e.getMessage()); return false; } finally { if (conn != null) { conn.close(); conn = null; } } } return true; } public void setOrders(int orders) { this.orders = orders; } public void setChildCount(int childCount) { this.child_count = childCount; } private int templateId = -1; private boolean loaded = false;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -