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

📄 userleveldb.java

📁 源码/软件简介: 云网论坛1.1RC国际版是采用JSP开发的集论坛、CMS(网站内容管理系统)、博客、聊天室、商城、交友、语音灌水等于一体的门户式社区。拥有CWBBS ( Cloud Web BBS
💻 JAVA
字号:
package com.redmoon.forum.setup;

import cn.js.fan.base.ObjectDb;
import java.sql.ResultSet;
import java.sql.SQLException;
import cn.js.fan.db.PrimaryKey;
import cn.js.fan.util.ErrMsgException;
import cn.js.fan.db.Conn;
import java.sql.PreparedStatement;
import java.util.Vector;

/**
 * <p>Title: </p>
 *
 * <p>Description: </p>
 *
 * <p>Copyright: Copyright (c) 2005</p>
 *
 * <p>Company: </p>
 *
 * @author not attributable
 * @version 1.0
 */
public class UserLevelDb extends ObjectDb {

    public UserLevelDb() {
        super();
    }

    public UserLevelDb(int level) {
        this.level = level;
        init();
        load();
    }

    public UserLevelDb getUserLevelDb(int level) {
        return (UserLevelDb)getObjectDb(new Integer(level));
    }

    public ObjectDb getObjectRaw(PrimaryKey pk) {
        return new UserLevelDb(pk.getIntValue());
    }

    public Vector getAllLevel() {
        UserLevelCache ulc = new UserLevelCache();
        return ulc.getAllLevel();
    }

    public void initDB() {
        this.tableName = "sq_setup_user_level";
        primaryKey = new PrimaryKey("levelAmount", PrimaryKey.TYPE_INT);
        objectCache = new UserLevelCache(this);

        this.QUERY_DEL =
                "delete FROM " + tableName + " WHERE levelAmount=?";
        this.QUERY_CREATE =
                "INSERT into " + tableName + " (levelAmount, description) VALUES (?,?)";
        this.QUERY_LOAD =
                "SELECT description FROM " + tableName + " WHERE levelAmount=?";
        this.QUERY_SAVE =
                "UPDATE " + tableName + " SET levelAmount=?,description=? WHERE levelAmount=?";
        this.QUERY_LIST = "select levelAmount from " + tableName + " order by levelAmount asc";
        isInitFromConfigDB = false;
    }

    public boolean save() throws ErrMsgException {
        // Based on the id in the object, get the message data from the database.
        Conn conn = new Conn(connname);
        PreparedStatement pstmt = null;
        try {
            pstmt = conn.prepareStatement(this.QUERY_SAVE);
            pstmt.setInt(1, newLevel);
            pstmt.setString(2, desc);
            pstmt.setInt(3, level);
            if (conn.executePreUpdate() == 1) {
                UserLevelCache mc = new UserLevelCache(this);
                primaryKey.setValue(new Integer(level));
                mc.refreshSave(primaryKey);
                mc.refreshCreate();
                return true;
            }
            else
                return false;
        } catch (SQLException e) {
            logger.error(e.getMessage());
            throw new ErrMsgException("保存时出错,请检查级别是否有重复!");
        } finally {
            if (pstmt!=null) {
                try { pstmt.close(); } catch (Exception e) {}
                pstmt = null;
            }
            if (conn != null) {
                conn.close();
                conn = null;
            }
        }
    }

    public void load() {
        // Based on the id in the object, get the message data from the database.
        PreparedStatement pstmt = null;
        ResultSet rs = null;
        Conn conn = new Conn(connname);
        try {
            pstmt = conn.prepareStatement(this.QUERY_LOAD);
            pstmt.setInt(1, level);
            //url,title,image,userName,sort,kind
            rs = conn.executePreQuery();
            if (rs.next()) {
                this.desc = rs.getString(1);
                primaryKey.setValue(new Integer(level));
            }
        } catch (SQLException e) {
            logger.error(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;
            }
        }
    }

    public boolean del() throws ErrMsgException {
        Conn conn = null;
        PreparedStatement pstmt = null;
        try {
            conn = new Conn(connname);
            pstmt = conn.prepareStatement(this.QUERY_DEL);
            pstmt.setInt(1, level);
            if (conn.executePreUpdate()==1) {
                UserLevelCache mc = new UserLevelCache(this);
                mc.refreshDel(primaryKey);
                return true;
            }
            else
                return false;
        } catch (SQLException e) {
            logger.error(e.getMessage());
            throw new ErrMsgException("删除出错!");
        } finally {
            if (pstmt != null) {
                try {
                    pstmt.close();
                } catch (Exception e) {}
                pstmt = null;
            }
            if (conn != null) {
                conn.close();
                conn = null;
            }
        }
    }

    public boolean create() throws ErrMsgException {
        Conn conn = null;
        boolean re = false;
        PreparedStatement pstmt = null;
        try {
            conn = new Conn(connname);
            pstmt = conn.prepareStatement(this.QUERY_CREATE);
            pstmt.setInt(1, level);
            pstmt.setString(2, desc);
            re = conn.executePreUpdate() == 1 ? true : false;
            if (re) {
                UserLevelCache mc = new UserLevelCache(this);
                mc.refreshCreate();
            }
        } catch (SQLException e) {
            logger.error("create:" + e.getMessage());
            throw new ErrMsgException("插入等级时出错!");
        } finally {
            if (pstmt != null) {
                try {
                    pstmt.close();
                } catch (Exception e) {}
                pstmt = null;
            }
            if (conn != null) {
                conn.close();
                conn = null;
            }
        }
        return re;
    }

    public void setLevel(int level) {
        this.level = level;
    }

    public void setDesc(String desc) {
        this.desc = desc;
    }

    public int getLevel() {
        return level;
    }

    public String getDesc() {
        return desc;
    }

    public void setNewLevel(int newLevel) {
        this.newLevel = newLevel;
    }

    private int level;
    private String desc;
    private int newLevel;
}

⌨️ 快捷键说明

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