chx 学习jForum笔记四

2010.12.6 接上午。在net.jforum.repository/ForumRepository.java中


    public synchronized static void start(final ForumDAO forumDAO, final CategoryDAO categoryDAO, final ConfigDAO configModel)
    {
        instance = new ForumRepository();
       
        if (cache.get(FQN, LOADED) == null) {  //未读入缓存
            instance.loadCategories(categoryDAO); //取分类
            instance.loadForums(forumDAO);       //取板块
            instance.loadMostUsersEverOnline(configModel); //取最高在线人数
            instance.loadUsersInfo ();  //取用户信息
           
            final Integer totalMessages = (Integer)cache.get(FQN, TOTAL_MESSAGES); //取缓存信息数
           
            if (totalMessages == null) {
                cache.add(FQN, TOTAL_MESSAGES, Integer.valueOf(0)); //设置缓存信息数为零
            }
           
            cache.add(FQN, LOADED, "1"); //已读入缓存标记
        }
    }

 

还剩下loadUserInfo()没分析了。

 

    private void loadUsersInfo() //取用户信息
    {   //直接从数据表读取并写入缓存
        UserDAO udao = DataAccessDriver.getInstance().newUserDAO();
        cache.add(FQN, LAST_USER, udao.getLastUserInfo ());
        cache.add(FQN, TOTAL_USERS, Integer.valueOf(udao.getTotalUsers ()));
    }

 

在net.jforum.dao.generic/GenericUserDAO.java中

 

    public User getLastUserInfo()
    {  //取最后注册的用户姓名与ID
        PreparedStatement p = null;
        ResultSet rs = null;
        try {
            User user = new User();
            p = JForumExecutionContext.getConnection().prepareStatement(
                    SystemGlobals.getSql("UserModel.lastUserRegistered")); //取SQL语句
            rs = p.executeQuery();
            rs.next();
            user.setUsername(rs.getString("username"));  //用户名
            user.setId(rs.getInt("user_id"));  //用户ID
            return user;
        }
        catch (SQLException e) {
            throw new DatabaseException(e);
        }
        finally {
            DbUtils.close(rs, p);
        }
    }

 

    public int getTotalUsers()
    {  //取总注册人数
        PreparedStatement preparedStatement = null;
        try {
            preparedStatement = JForumExecutionContext.getConnection().prepareStatement(
                    SystemGlobals.getSql("UserModel.totalUsers"));  //取SQL语句
            return this.getTotalUsersCommon (preparedStatement); //防异常处理
        }
        catch (SQLException e) {
            throw new DatabaseException(e);
        }
        finally {
            DbUtils.close(preparedStatement);
        }
    }

 

    protected int getTotalUsersCommon(PreparedStatement p) throws SQLException//防异常处理
    {
        ResultSet rs = p.executeQuery();
        int total = 0;
        if (rs.next()) {
            total = rs.getInt(1);
        }
        rs.close();
        p.close();
        return total;
    }

 

小结:

根据ForumRepository的start,其动作为:取所有分类,取当前用户有权处理的所有板块,取最高在线人数,取最后注册用户信息及注册总人数,取缓存信息数。

 

取所有分类的语句在:“CategoryModel.selectAll”

取所有板块的语句在:“ForumModel.selectAll”

取最后注册的用户姓名与ID语句在: "UserModel.lastUserRegistered"

取总注册人数语句在: "UserModel.totalUsers")

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值