📄 postwebhelper.java
字号:
/*
* Copyright (C) 2002 by MyVietnam.net
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or any later version.
*
* All copyright notices regarding mvnForum
* must remain intact in the scripts and in the outputted HTML
* The "powered by" text/logo with a link back to
* http://www.mvnForum.com and http://www.MyVietnam.net in the footer of the pages MUST
* remain visible when the pages are viewed on the internet or intranet.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* Support can be obtained from support forums at:
* http://www.mvnForum.com/mvnforum/index
*
* Correspondence and Marketing Questions can be sent to:
* info@MyVietnam.net
*
* @author: Minh Nguyen minhnn@MyVietnam.net
* @author: Mai Nguyen mai.nh@MyVietnam.net
*/
package net.myvietnam.mvnplugin.mvnforum.user;
import java.sql.*;
import java.util.Collection;
import java.util.ArrayList;
import net.myvietnam.mvncore.db.DBUtils;
import net.myvietnam.mvncore.exception.*;
import net.myvietnam.mvnplugin.mvnforum.db.PostBean;
class PostWebHelper extends net.myvietnam.mvnplugin.mvnforum.db.PostWebHelper {
// prevent instantiation and inheritance
private PostWebHelper() {
}
public static void createPost(int parentPostID, int forumID, int threadID,
int memberID, String memberName, String lastEditMemberName,
String postTopic, String postBody, Timestamp postCreationDate,
Timestamp postLastEditDate, String postCreationIP, String postLastEditIP,
int postEditCount, int postFormatOption, int postOption,
int postStatus, String postIcon, int postAttachCount)
throws CreateException, DatabaseException, ForeignKeyNotFoundException {
net.myvietnam.mvnplugin.mvnforum.db.PostWebHelper.create(parentPostID, forumID, threadID, memberID, memberName, lastEditMemberName, postTopic, postBody, postCreationDate, postLastEditDate, postCreationIP, postLastEditIP, postEditCount, postFormatOption, postOption, postStatus, postIcon, postAttachCount);
}
public static void updatePost(int postID, // primary key
String lastEditMemberName, String postTopic, String postBody,
Timestamp postLastEditDate, String postLastEditIP, int postFormatOption,
int postOption, int postStatus, String postIcon)
throws BadInputException, DatabaseException, ForeignKeyNotFoundException {
net.myvietnam.mvnplugin.mvnforum.db.PostWebHelper.update(postID, // primary key
lastEditMemberName, postTopic, postBody,
postLastEditDate, postLastEditIP, postFormatOption,
postOption, postStatus, postIcon);
}
public static PostBean getPost(int postID)
throws BadInputException, DatabaseException {
return net.myvietnam.mvnplugin.mvnforum.db.PostWebHelper.getBean(postID);
}
public static Collection getPosts_inThread_limit(int threadID, int offset, int rowsToReturn)
throws IllegalArgumentException, DatabaseException {
return net.myvietnam.mvnplugin.mvnforum.db.PostWebHelper.getBeans_inThread_limit(threadID, offset, rowsToReturn);
}
public static int getNumberOfPosts_inForum(int forumID)
throws AssertionException, DatabaseException {
return net.myvietnam.mvnplugin.mvnforum.db.PostWebHelper.getNumberOfBeans_inForum(forumID);
}
public static int getNumberOfPosts_inThread(int threadID)
throws AssertionException, DatabaseException {
return net.myvietnam.mvnplugin.mvnforum.db.PostWebHelper.getNumberOfBeans_inThread(threadID);
}
public static int getNumberOfPosts()
throws AssertionException, DatabaseException {
return net.myvietnam.mvnplugin.mvnforum.db.PostWebHelper.getNumberOfBeans();
}
/************************************************
* Customized methods come below
************************************************/
/**
* This method should be call only when we can make sure that postID is in database
*/
public static void increaseEditCount(int postID)
throws DatabaseException, BadInputException {
Connection connection = null;
PreparedStatement statement = null;
String sql = "UPDATE " + TABLE_NAME + " SET PostEditCount = PostEditCount + 1 WHERE PostID = ?";
try {
connection = DBUtils.getConnection();
statement = connection.prepareStatement(sql);
statement.setInt(1, postID);
if (statement.executeUpdate() != 1) {
throw new BadInputException("Cannot update the PostEditCount in table Post. Please contact Web site Administrator.");
}
//@todo: coi lai cho nay
// ATTENTION !!!
setDirty(true);
} catch (SQLException sqle) {
sqle.printStackTrace();
throw new DatabaseException("Error occured when update Post: column name = PostEditCount.");
} finally {
DBUtils.closeStatement(statement);
DBUtils.closeConnection(connection);
}
}
/*
// @todo: copy this method for derived class
public static Collection getLastPosts_inThread_limit(int offset, int rowsToReturn)
throws IllegalArgumentException, DatabaseException {
return net.myvietnam.webplugin.mvnforum.db.PostWebHelper.getLastBeans_inThread_limit(offset, rowsToReturn);
}
*/
/*
* Included columns: PostID, ParentPostID, ForumID, ThreadID, MemberID,
* MemberName, LastEditMemberName, PostTopic, PostBody, PostCreationDate,
* PostLastEditDate, PostCreationIP, PostLastEditIP, PostEditCount, PostFormatOption,
* PostOption, PostStatus, PostIcon, PostAttachCount
* Excluded columns:
*/
protected static Collection getLastBeans_inThread_limit(int threadID, int rowsToReturn)
throws IllegalArgumentException, DatabaseException {
if (rowsToReturn <= 0) throw new IllegalArgumentException("The rowsToReturn <= 0 is not allowed.");
Connection connection = null;
PreparedStatement statement = null;
ResultSet resultSet = null;
Collection retValue = new ArrayList();
StringBuffer sql = new StringBuffer(512);
sql.append("SELECT PostID, ParentPostID, ForumID, ThreadID, MemberID, MemberName, LastEditMemberName, PostTopic, PostBody, PostCreationDate, PostLastEditDate, PostCreationIP, PostLastEditIP, PostEditCount, PostFormatOption, PostOption, PostStatus, PostIcon, PostAttachCount");
sql.append(" FROM " + TABLE_NAME);
sql.append(" WHERE ThreadID = ?");
sql.append(" ORDER BY PostCreationDate DESC ");
sql.append(" LIMIT 0, ?");
try {
connection = DBUtils.getConnection();
statement = connection.prepareStatement(sql.toString());
statement.setInt(1, threadID);
statement.setInt(2, rowsToReturn);
resultSet = statement.executeQuery();
while (resultSet.next()) {
PostBean bean = new PostBean();
bean.setPostID(resultSet.getInt("PostID"));
bean.setParentPostID(resultSet.getInt("ParentPostID"));
bean.setForumID(resultSet.getInt("ForumID"));
bean.setThreadID(resultSet.getInt("ThreadID"));
bean.setMemberID(resultSet.getInt("MemberID"));
bean.setMemberName(resultSet.getString("MemberName"));
bean.setLastEditMemberName(resultSet.getString("LastEditMemberName"));
bean.setPostTopic(resultSet.getString("PostTopic"));
bean.setPostBody(resultSet.getString("PostBody"));
bean.setPostCreationDate(resultSet.getTimestamp("PostCreationDate"));
bean.setPostLastEditDate(resultSet.getTimestamp("PostLastEditDate"));
bean.setPostCreationIP(resultSet.getString("PostCreationIP"));
bean.setPostLastEditIP(resultSet.getString("PostLastEditIP"));
bean.setPostEditCount(resultSet.getInt("PostEditCount"));
bean.setPostFormatOption(resultSet.getInt("PostFormatOption"));
bean.setPostOption(resultSet.getInt("PostOption"));
bean.setPostStatus(resultSet.getInt("PostStatus"));
bean.setPostIcon(resultSet.getString("PostIcon"));
bean.setPostAttachCount(resultSet.getInt("PostAttachCount"));
retValue.add(bean);
}
return retValue;
} catch(SQLException sqle) {
sqle.printStackTrace();
throw new DatabaseException("Error executing SQL in PostWebHelper.getBeans_limit.");
} finally {
DBUtils.closeResultSet(resultSet);
DBUtils.closeStatement(statement);
DBUtils.closeConnection(connection);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -