![]() |
# ###########
# KarmaModel
# ###########
...
KarmaModel.deletePostKarma = DELETE FROM jforum_karma WHERE post_id = ?
...
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) ;
...
}
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);
}
}
...
public class PostAction extends Command
{
...
public void delete()
{
...
// Karma
KarmaDAO karmaDao = DataAccessDriver.getInstance().newKarmaDAO();
karmaDao.deletePostKarma(p.getId());
karmaDao.updateUserKarma(p.getUserId());
...
}
...
}