use of net.jforum.exceptions.DatabaseException in project jforum2 by rafaelsteil.
the class GenericKarmaDAO method addKarma.
/**
* @see net.jforum.dao.KarmaDAO#addKarma(net.jforum.entities.Karma)
*/
public void addKarma(Karma karma) {
PreparedStatement p = null;
try {
p = JForumExecutionContext.getConnection().prepareStatement(SystemGlobals.getSql("KarmaModel.add"));
p.setInt(1, karma.getPostId());
p.setInt(2, karma.getPostUserId());
p.setInt(3, karma.getFromUserId());
p.setInt(4, karma.getPoints());
p.setInt(5, karma.getTopicId());
p.setTimestamp(6, new Timestamp((new Date()).getTime()));
p.executeUpdate();
this.updateUserKarma(karma.getPostUserId());
} catch (SQLException e) {
throw new DatabaseException(e);
} finally {
DbUtils.close(p);
}
}
use of net.jforum.exceptions.DatabaseException in project jforum2 by rafaelsteil.
the class GenericKarmaDAO method getUserTotalKarma.
public void getUserTotalKarma(User user) {
PreparedStatement p = null;
ResultSet rs = null;
try {
p = JForumExecutionContext.getConnection().prepareStatement(SystemGlobals.getSql("KarmaModel.getUserTotalVotes"));
p.setInt(1, user.getId());
rs = p.executeQuery();
user.setKarma(new KarmaStatus());
if (rs.next()) {
user.getKarma().setTotalPoints(rs.getInt("points"));
user.getKarma().setVotesReceived(rs.getInt("votes"));
}
if (// prevetns division by
user.getKarma().getVotesReceived() != 0)
// zero.
user.getKarma().setKarmaPoints(user.getKarma().getTotalPoints() / user.getKarma().getVotesReceived());
this.getVotesGiven(user);
} catch (SQLException e) {
throw new DatabaseException(e);
} finally {
DbUtils.close(rs, p);
}
}
use of net.jforum.exceptions.DatabaseException in project jforum2 by rafaelsteil.
the class GenericBookmarkDAO method remove.
/**
* @see net.jforum.dao.BookmarkDAO#remove(int)
*/
public void remove(int bookmarkId) {
PreparedStatement p = null;
try {
p = JForumExecutionContext.getConnection().prepareStatement(SystemGlobals.getSql("BookmarkModel.remove"));
p.setInt(1, bookmarkId);
p.executeUpdate();
} catch (SQLException e) {
throw new DatabaseException(e);
} finally {
DbUtils.close(p);
}
}
use of net.jforum.exceptions.DatabaseException in project jforum2 by rafaelsteil.
the class GenericBookmarkDAO method selectById.
/**
* @see net.jforum.dao.BookmarkDAO#selectById(int)
*/
public Bookmark selectById(int bookmarkId) {
Bookmark b = null;
PreparedStatement p = null;
ResultSet rs = null;
try {
p = JForumExecutionContext.getConnection().prepareStatement(SystemGlobals.getSql("BookmarkModel.selectById"));
p.setInt(1, bookmarkId);
rs = p.executeQuery();
if (rs.next()) {
b = this.getBookmark(rs);
}
return b;
} catch (SQLException e) {
throw new DatabaseException(e);
} finally {
DbUtils.close(rs, p);
}
}
use of net.jforum.exceptions.DatabaseException in project jforum2 by rafaelsteil.
the class GenericBookmarkDAO method getForums.
protected List getForums(int userId) {
PreparedStatement p = null;
ResultSet rs = null;
try {
List l = new ArrayList();
p = JForumExecutionContext.getConnection().prepareStatement(SystemGlobals.getSql("BookmarkModel.selectForumBookmarks"));
p.setInt(1, userId);
rs = p.executeQuery();
while (rs.next()) {
Bookmark b = this.getBookmark(rs);
if (b.getTitle() == null || "".equals(b.getTitle())) {
b.setTitle(rs.getString("forum_name"));
}
if (b.getDescription() == null || "".equals(b.getDescription())) {
b.setDescription(rs.getString("forum_desc"));
}
l.add(b);
}
return l;
} catch (SQLException e) {
throw new DatabaseException(e);
} finally {
DbUtils.close(rs, p);
}
}
Aggregations