📄 blogcache.java
字号:
userName = rs.getString(1);
v[i] = userName;
i++;
}
} catch (SQLException e) {
logger.error("getPostRank:" + e.getMessage());
} finally {
if (rs != null) {
try {
rs.close();
} catch (Exception e) {
e.printStackTrace();
}
rs = null;
}
if (conn != null) {
conn.close();
conn = null;
}
}
// Add the thread count to cache
if (v.length>0) {
try {
rmCache.putInGroup(POSTRANKBLOG, group, v);
} catch (Exception e) {
logger.error(e.getMessage());
}
}
return v;
}
}
/**
* 取得最新加入
* @param n int
* @return String[]
*/
public String[] getNewBlogs(int n) {
// 根据sql语句得出计算总数的sql查询语句
String sql = "select userName from blog_user_config order by addDate desc";
String[] v = new String[0];
try {
v = (String[])rmCache.getFromGroup(NEWBLOG, group);
} catch (Exception e) {
logger.error("getNewBlogs:" + e.getMessage());
}
// If already in cache, return the count.
if (v != null) {
return v;
}
// Otherwise, we have to load the count from the db.
else {
Conn conn = new Conn(connname);
ResultSet rs = null;
try {
conn.setMaxRows(n);
rs = conn.executeQuery(sql);
conn.setFetchSize(n);
v = new String[conn.getRows()];
String userName;
int i = 0;
while (rs.next()) {
userName = rs.getString(1);
v[i] = userName;
i++;
}
} catch (SQLException e) {
logger.error("getNewBlogs:" + e.getMessage());
} finally {
if (rs != null) {
try {
rs.close();
} catch (Exception e) {
e.printStackTrace();
}
rs = null;
}
if (conn != null) {
conn.close();
conn = null;
}
}
// Add the thread count to cache
if (v.length>0) {
try {
rmCache.putInGroup(NEWBLOG, group, v);
} catch (Exception e) {
logger.error(e.getMessage());
}
}
return v;
}
}
/**
* 取得推荐blog
* author mzlkr
* @param n int
* @return String[]
*/
public String[] getCommendBlogs(int n) {
String sql = "select userName from blog_user_config order by viewcount desc";
String[] v = new String[0];
try {
v = (String[])rmCache.getFromGroup(COMMENDBLOG, group);
} catch (Exception e) {
logger.error("getNewBlogs:" + e.getMessage());
}
// If already in cache, return the count.
if (v != null) {
return v;
}
// Otherwise, we have to load the count from the db.
else {
Conn conn = new Conn(connname);
ResultSet rs = null;
try {
conn.setMaxRows(n);
rs = conn.executeQuery(sql);
conn.setFetchSize(n);
v = new String[conn.getRows()];
String userName;
int i = 0;
while (rs.next()) {
userName = rs.getString(1);
v[i] = userName;
i++;
}
} catch (SQLException e) {
logger.error("getNewBlogs:" + e.getMessage());
} finally {
if (rs != null) {
try {
rs.close();
} catch (Exception e) {
e.printStackTrace();
}
rs = null;
}
if (conn != null) {
conn.close();
conn = null;
}
}
// Add the thread count to cache
if (v.length>0) {
try {
rmCache.putInGroup(NEWBLOG, group, v);
} catch (Exception e) {
logger.error(e.getMessage());
}
}
return v;
}
}
/**
* 取得博客类别中某一类文章的前n篇
* @param n int 前n篇
* @param kind String 博客类别(博客类别节点的父结点为root)
* @return long[] 贴子ID数组
*/
public long[] getBlogMsgsOfKind(int n, String kind) {
long[] v = new long[0];
// 取得kind节点的子节点
LeafChildrenCacheMgr lccm = new LeafChildrenCacheMgr(kind);
Vector vt = lccm.getDirList();
Iterator ir = vt.iterator();
String dirs = "";
UserDirDb udd = new UserDirDb();
while (ir.hasNext()) {
Leaf lf = (Leaf) ir.next();
// 取得各个子节点下的所有用户的blogUserDir
Vector vud = udd.ListAllUserDir(lf.getCode());
Iterator irud = vud.iterator();
while (irud.hasNext()) {
udd = (UserDirDb) irud.next();
if (dirs.equals(""))
dirs = StrUtil.sqlstr(udd.getCode());
else
dirs += "," + StrUtil.sqlstr(udd.getCode());
}
}
if (dirs.equals(""))
return v;
// 根据sql语句得出计算总数的sql查询语句
String sql = "select id from sq_thread where isBlog=1 and blogUserDir in (" + dirs +") order by lydate desc";
try {
v = (long[])rmCache.getFromGroup(sql, group);
} catch (Exception e) {
logger.error("getTopBlogs:" + e.getMessage());
}
// If already in cache, return the count.
if (v != null) {
return v;
}
// Otherwise, we have to load the count from the db.
else {
Conn conn = new Conn(connname);
ResultSet rs = null;
try {
conn.setMaxRows(n);
rs = conn.executeQuery(sql);
conn.setFetchSize(n);
v = new long[conn.getRows()];
int id;
int i = 0;
while (rs.next()) {
id = rs.getInt(1);
v[i] = id;
i++;
}
} catch (SQLException e) {
logger.error("getBlogMsgsOfKind:" + e.getMessage());
} finally {
if (rs != null) {
try {
rs.close();
} catch (Exception e) {
e.printStackTrace();
}
rs = null;
}
if (conn != null) {
conn.close();
conn = null;
}
}
// Add the thread count to cache
if (v.length>0) {
try {
rmCache.putInGroup(sql, group, v);
} catch (Exception e) {
logger.error(e.getMessage());
}
}
return v;
}
}
public void setGroup() {
group = "BLOG_";
}
public void setGroupCount() {
COUNT_GROUP_NAME = "BLOG_COUNT_";
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -