📄 trashboxdao.java
字号:
Connection conn = dbManager.getConnection();
try
{
conn.setAutoCommit(false);
String sql = "delete from ejf_trash_box" + whereSql;
this.execUpdateSql(sql, paramValues, conn);
restorePosts(postList, conn);
// Add admin log
ActionLogDAO.getInstance().addAdminLog(request, "还原回收站帖子", "", conn);
conn.commit();
}
catch(SQLException se)
{
conn.rollback();
throw se;
}
finally
{
dbManager.closeConnection(conn);
}
}
private void removePosts(ArrayList<HashMap> postList,
Connection conn) throws SQLException
{
PreparedStatement pstmtUpdate1 = null;
PreparedStatement pstmtUpdate2 = null;
try
{
int topicID = 0;
int replyID = 0;
HashMap record = null;
for (int i=0; i<postList.size(); i++)
{
record = postList.get(i);
topicID = Integer.parseInt((String)record.get("TOPICID"));
replyID = Integer.parseInt((String)record.get("REPLYID"));
if (replyID > 0)
{
if (pstmtUpdate2 == null)
pstmtUpdate2 = conn.prepareStatement(adapter.Reply_Remove);
pstmtUpdate2.setInt(1, replyID);
pstmtUpdate2.addBatch();
}
else
{
if (pstmtUpdate1 == null)
pstmtUpdate1 = conn.prepareStatement(adapter.Topic_Remove);
pstmtUpdate1.setInt(1, topicID);
pstmtUpdate1.addBatch();
}
}
if (pstmtUpdate1 != null)
pstmtUpdate1.executeBatch();
if (pstmtUpdate2 != null)
pstmtUpdate2.executeBatch();
}
finally
{
dbManager.closePStatement(pstmtUpdate1);
dbManager.closePStatement(pstmtUpdate2);
}
}
private void restorePosts(ArrayList<HashMap> postList,
Connection conn) throws SQLException
{
PreparedStatement pstmtUpdate1 = null;
PreparedStatement pstmtUpdate2 = null;
PreparedStatement pstmtUpdate3 = null;
try
{
int topicID = 0;
int replyID = 0;
HashMap record = null;
for (int i=0; i<postList.size(); i++)
{
record = postList.get(i);
topicID = Integer.parseInt((String)record.get("TOPICID"));
replyID = Integer.parseInt((String)record.get("REPLYID"));
if (replyID > 0)
{
if (pstmtUpdate2 == null)
pstmtUpdate2 = conn.prepareStatement(adapter.Reply_ModState);
pstmtUpdate2.setString(1, "N");
pstmtUpdate2.setInt(2, replyID);
pstmtUpdate2.addBatch();
if (pstmtUpdate3 == null)
pstmtUpdate3 = conn.prepareStatement(adapter.Topic_IncReplies);
pstmtUpdate3.setInt(1, topicID);
pstmtUpdate3.addBatch();
}
else
{
if (pstmtUpdate1 == null)
pstmtUpdate1 = conn.prepareStatement(adapter.Topic_ModState);
pstmtUpdate1.setString(1, "N");
pstmtUpdate1.setInt(2, topicID);
pstmtUpdate1.addBatch();
}
}
if (pstmtUpdate1 != null)
pstmtUpdate1.executeBatch();
if (pstmtUpdate2 != null)
pstmtUpdate2.executeBatch();
if (pstmtUpdate3 != null)
pstmtUpdate3.executeBatch();
// Restore user posts & credits - Ignored
}
finally
{
dbManager.closePStatement(pstmtUpdate1);
dbManager.closePStatement(pstmtUpdate2);
}
}
/**
* Build search trash box where sql clause by query conditions
* @param
* request - HttpServletRequest
* paramValues - Array list to be filled with search parameter
* @return Where sql string
* @throws none
* @since 1.0
*/
private String buildSearchWhereSql(HttpServletRequest request, ArrayList<Object> paramValues)
{
StringBuilder whereSql = new StringBuilder(" where 1=1");
String trashType = PageUtils.getParam(request, "trashType");
if (trashType != null && trashType.equals("topic"))
whereSql.append(" and replyID=0");
else
whereSql.append(" and replyID>0");
String boardID = PageUtils.getParam(request, "boardID");
if (boardID != null && boardID.length() > 0 && !boardID.equals("all"))
{
whereSql.append(" and boardID=?");
paramValues.add(boardID);
}
String title = PageUtils.getParam(request, "topicTitle");
if (title != null && title.length() > 0)
{
whereSql.append(" and topicTitle like ?");
paramValues.add("%" + title + "%");
}
String userID = PageUtils.getParam(request, "userID");
if (userID != null && userID.length() > 0)
{
if (userID.indexOf('*') >= 0)
{
whereSql.append(" and userID like ?");
paramValues.add(userID.replace('*', '%'));
}
else
{
whereSql.append(" and userID=?");
paramValues.add(userID);
}
}
String deleteUser = PageUtils.getParam(request, "deleteUser");
if (deleteUser != null && deleteUser.length() > 0)
{
if (userID.indexOf('*') >= 0)
{
whereSql.append(" and deleteUser like ?");
paramValues.add(userID.replace('*', '%'));
}
else
{
whereSql.append(" and deleteUser=?");
paramValues.add(userID);
}
}
String days = PageUtils.getParam(request, "days");
if (days != null && days.length() > 0)
{
try
{
Calendar cal = Calendar.getInstance();
cal.add(Calendar.DATE, (-1)*Integer.parseInt(days)+1);
java.sql.Date createTime = new java.sql.Date(cal.getTimeInMillis()); // Check date format
whereSql.append(" and createTime<=?");
paramValues.add(createTime);
}
catch(Exception e){ /* Ignored */ }
}
return whereSql.toString();
}
/**
* Search trash box
* @param
* request - HttpServletRequest
* @return Trashed topic or reply list
* @throws SQLException
* @since 1.0
*/
public Object[] searchTrashBox(HttpServletRequest request, int pageNo) throws SQLException
{
Object[] result = new Object[2];
ArrayList<Object> paramValues = new ArrayList<Object>();
String whereSql = this.buildSearchWhereSql(request, paramValues);
String countSql = "select COUNT(*) from ejf_trash_box" + whereSql;
String querySql = "select * from ejf_trash_box" + whereSql;
int pageRows = 15;
int totalCount = 0;
Connection conn = null;
PreparedStatement pstmtQuery = null;
ResultSet rs = null;
try
{
conn = dbManager.getConnection();
totalCount = this.execSelectCountSql(countSql, paramValues, conn);
if (totalCount > 0)
{
querySql = adapter.getPageQuerySql(
new StringBuilder(querySql).append(" order by createTime DESC"),
pageNo, pageRows, totalCount);
ArrayList<HashMap> attachList = this.execSelectSql(querySql, paramValues);
result[1] = attachList;
}
}
finally
{
dbManager.closeResultSet(rs);
dbManager.closePStatement(pstmtQuery);
dbManager.closeConnection(conn);
}
// Get result page code
if (totalCount > 0)
{
result[0] = PageUtils.getPageHTMLStr(totalCount, pageNo, pageRows, 0);
}
return result;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -