📄 musicdirdb.java
字号:
package com.redmoon.forum.music;import java.io.*;import java.sql.*;import java.util.*;import cn.js.fan.base.*;import cn.js.fan.db.*;import cn.js.fan.security.*;import cn.js.fan.util.*;import com.cloudwebsoft.framework.db.JdbcTemplate;public class MusicDirDb extends ObjectDb implements Serializable { private String code = "", name = "", description = "", parentCode = "-1", rootCode = "", addDate = ""; private int orders = 1, layer = 1, childCount = 0; boolean isHome = false; private boolean loaded = false; public static final String ROOTCODE = "root"; public static final int NOTEMPLATE = -1; public MusicDirDb() { init(); } public MusicDirDb(String code) { this.code = code; load(); init(); } public ObjectDb getObjectRaw(PrimaryKey pk) { return new MusicDirDb(pk.getStrValue()); } public void setQueryCreate() { } public void setQuerySave() { this.QUERY_SAVE = "update sq_forum_music_dir set name=?,description=?,dir_type=?,orders=?,child_count=?,layer=? where code=?"; } public void setQueryDel() { } public void setQueryLoad() { this.QUERY_LOAD = "select code,name,description,parent_code,root_code,orders,layer,child_count,add_date,dir_type from sq_forum_music_dir where code=?"; } public void load() { ResultSet rs = null; Conn conn = new Conn(connname); try { PreparedStatement ps = conn.prepareStatement(this.QUERY_LOAD); ps.setString(1, code); rs = conn.executePreQuery(); if (rs != null && rs.next()) { this.code = rs.getString(1); name = rs.getString(2); description = rs.getString(3); parentCode = rs.getString(4); rootCode = rs.getString(5); orders = rs.getInt(6); layer = rs.getInt(7); childCount = rs.getInt(8); type = rs.getInt(10); loaded = true; } } catch (SQLException e) { logger.error("load:" + e.getMessage()); } finally { if (rs != null) { try { rs.close(); } catch (Exception e) {} rs = null; } if (conn != null) { conn.close(); conn = null; } } } public String getCode() { return code; } public void setCode(String code) { this.code = code; } public String getName() { return name; } public void setRootCode(String c) { this.rootCode = c; } public void setType(int t) { this.type = t; } public void setName(String n) { this.name = n; } public void setDescription(String desc) { this.description = desc; } public int getOrders() { return orders; } public boolean getIsHome() { return isHome; } public void setParentCode(String p) { this.parentCode = p; } public String getParentCode() { return this.parentCode; } public void setIsHome(boolean b) { this.isHome = b; } public void setLoaded(boolean loaded) { this.loaded = loaded; } public String getRootCode() { return rootCode; } public int getLayer() { return layer; } public String getDescription() { return description; } public int getType() { return type; } public int getChildCount() { return childCount; } public boolean isLoaded() { return loaded; } public Vector getChildren() { Vector v = new Vector(); String sql = "select code from sq_forum_music_dir where parent_code=? order by orders"; Conn conn = new Conn(connname); ResultSet rs = null; try { PreparedStatement pstmt = conn.prepareStatement(sql); pstmt.setString(1, code); rs = conn.executePreQuery(); if (rs != null) { while (rs.next()) { String c = rs.getString(1); v.addElement(getMusicDirDb(c)); } } } catch (SQLException e) { logger.error(e.getMessage()); } finally { if (rs != null) { try { rs.close(); } catch (Exception e) {} rs = null; } if (conn != null) { conn.close(); conn = null; } } return v; } public Vector getAllChild(Vector vt, MusicDirDb leaf) throws ErrMsgException { Vector children = leaf.getChildren(); if (children.isEmpty()) return children; vt.addAll(children); Iterator ir = children.iterator(); while (ir.hasNext()) { MusicDirDb lf = (MusicDirDb) ir.next(); getAllChild(vt, lf); } return children; } public String toString() { return "Leaf is " + name; } private int type; public synchronized boolean save() { Conn conn = new Conn(connname); int r = 0; boolean re = false; try { PreparedStatement ps = conn.prepareStatement(this.QUERY_SAVE); ps.setString(1, name); ps.setString(2, description); ps.setInt(3, type); ps.setInt(4, orders); ps.setInt(5, childCount); ps.setInt(6, layer); ps.setString(7, code); r = conn.executePreUpdate(); try { if (r == 1) { re = true; MusicDirCache dcm = new MusicDirCache(); dcm.refreshSave(code, parentCode); } } catch (Exception e) { logger.error(e.getMessage()); } } catch (SQLException e) { logger.error("修改出错!" + e.getMessage()); } finally { if (conn != null) { conn.close(); conn = null; } } return re; } public synchronized boolean save(String newParentCode) { if (newParentCode.equals(parentCode)) return false; MusicDirDb lfparent = getMusicDirDb(newParentCode); int oldorders = orders; int neworders = lfparent.getChildCount() + 1; int parentLayer = lfparent.getLayer(); String sql = "update sq_forum_music_dir set name=" + StrUtil.sqlstr(name) + ",description=" + StrUtil.sqlstr(description) + ",dir_type=" + type + ",parent_code=" + StrUtil.sqlstr(newParentCode) + ",orders=" + neworders + ",layer=" + (parentLayer + 1) + " where code=" + StrUtil.sqlstr(code); String oldParentCode = parentCode; parentCode = newParentCode; MusicDirCache dcm = new MusicDirCache(); int r = 0; RMConn conn = new RMConn(connname); try { r = conn.executeUpdate(sql); try { if (r == 1) { dcm.refreshSave(code, parentCode); dcm.removeFromCache(newParentCode); dcm.removeFromCache(oldParentCode); MusicDirChildrenCache.remove(oldParentCode); MusicDirChildrenCache.remove(newParentCode);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -