練功房推薦書單

  • Google!Android 3手機應用程式設計入門(第四版)
  • 賈伯斯傳(軟皮精裝版)
  • 猛虎出閘制霸版:最新OCP Java SE 6 Programmer專業認證(附原始程式碼及範例檔)
  • SCWCD 5 猛虎出閘:Java Web 應用程式專業認證
[v2.1.8]修正刪除文章時需一併刪除該文章的評分(Karma)  XML
Forum Index » JForum中文社群 JForum Chinese Users Community
Author Message
andowson

六段學員
[Avatar]

Joined: 2007-01-02 22:20:40
Messages: 652
Location: 台北
Offline

1.修改generic_queries.sql,加上KarmaModel.deletePostKarma
# ###########
# KarmaModel
# ###########
...
KarmaModel.deletePostKarma = DELETE FROM jforum_karma WHERE post_id = ?
...


2.修改net/jforum/dao/KarmaDao.java,加上deletePostKarma(int postId) method宣告
public interface KarmaDAO
{
...
	/**
	 * Deletes the karma belonging to some post.
	 * This method will remove the post's karma from the
	 * karma table. 
	 *  
	 * @param postId The id of the post to delete	 
	 */
	public void deletePostKarma(int postId) ;
...
}


3.修改net/jforum/dao/generic/GenericKarmaDao.java,加上deletePostKarma(int postId) method實做
public class GenericKarmaDAO implements net.jforum.dao.KarmaDAO
{
...
	/**
	 * @see net.jforum.dao.KarmaDAO#deletePostKarma(int)
	 */
	public void deletePostKarma(int postId)
	{
		PreparedStatement p = null;		
		try {
			p = JForumExecutionContext.getConnection()
					.prepareStatement(SystemGlobals.getSql("KarmaModel.deletePostKarma"));
			p.setInt(1, postId);
			p.executeUpdate();
		}
		catch (SQLException e) {
			throw new DatabaseException(e);
		}
		finally {
			DbUtils.close(p);
		}
	}
...


4.修改net/jforum/view/forum/PostAction.java,修改delete() method,在Karma處理部分插入karmaDao.deletePostKarma(p.getId());在重算Karma之前
public class PostAction extends Command 
{
...
	public void delete()
	{
                ...
		// Karma
		KarmaDAO karmaDao = DataAccessDriver.getInstance().newKarmaDAO();
		karmaDao.deletePostKarma(p.getId());
		karmaDao.updateUserKarma(p.getUserId());
                ...
	}
...
}


5.重新編譯,並重新載入JForum

分享經驗 累積智慧
[WWW] [MSN]
 
Forum Index » JForum中文社群 JForum Chinese Users Community
Go to: