学习 jForum笔记 四ForumAction 发现用户认证模板 .
2013-03-14 15:19
459 查看
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")
{
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")
相关文章推荐
- 学习 jForum笔记 三 .ForumAction 发现用户认证模板
- Angular2学习笔记.3、通过模板调用Controller事件实现用户输入和显示,UserInput
- mongo db 学习笔记 之二: mongodb 用户认证
- SpringSecurity学习笔记之五:认证用户
- 《Spring+Mybatis》拦截器实现用户权限认证学习笔记与代码
- 产品经理学习笔记(4)-第一种角色:产品策划——善于发现用户需求的人
- SharePoint【学习笔记】-- SharePoint 2010 启用Form认证并增加用户注册功能
- HTTP学习笔记10 用户身份认证
- 用户体验学习笔记(工程中发现的PM常犯错误)
- django学习笔记---文件上传,用户认证,单选框,复选框接受
- ASP.NET学习笔记(1)--用户控件
- [Linux学习笔记] Linux常用命令 - 用户版本信息查看
- 学习笔记之用户模式下的线程同步
- 学习笔记-mysql_用户管理
- Asp.net控件开发学习笔记(十一)----服务器控件模板
- .net中的认证和授权(学习笔记)
- 前端学习笔记2:使用表单标签,与用户交互
- [Silverlight学习笔记]关于用户注册之后不能直接登录的问题
- Django 学习笔记2 模板
- Spring MVC 学习笔记6 —— 实现简单的用户管理(2)添加和验证