Search in sources :

Example 26 with DatabaseException

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);
    }
}
Also used : SQLException(java.sql.SQLException) PreparedStatement(java.sql.PreparedStatement) Timestamp(java.sql.Timestamp) DatabaseException(net.jforum.exceptions.DatabaseException) Date(java.util.Date)

Example 27 with DatabaseException

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);
    }
}
Also used : SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) DatabaseException(net.jforum.exceptions.DatabaseException) KarmaStatus(net.jforum.entities.KarmaStatus)

Example 28 with DatabaseException

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);
    }
}
Also used : SQLException(java.sql.SQLException) PreparedStatement(java.sql.PreparedStatement) DatabaseException(net.jforum.exceptions.DatabaseException)

Example 29 with DatabaseException

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);
    }
}
Also used : Bookmark(net.jforum.entities.Bookmark) SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) DatabaseException(net.jforum.exceptions.DatabaseException)

Example 30 with DatabaseException

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);
    }
}
Also used : Bookmark(net.jforum.entities.Bookmark) SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) ArrayList(java.util.ArrayList) PreparedStatement(java.sql.PreparedStatement) List(java.util.List) ArrayList(java.util.ArrayList) DatabaseException(net.jforum.exceptions.DatabaseException)

Aggregations

DatabaseException (net.jforum.exceptions.DatabaseException)264 PreparedStatement (java.sql.PreparedStatement)255 SQLException (java.sql.SQLException)254 ResultSet (java.sql.ResultSet)138 List (java.util.List)64 ArrayList (java.util.ArrayList)63 Timestamp (java.sql.Timestamp)17 User (net.jforum.entities.User)15 Iterator (java.util.Iterator)12 Post (net.jforum.entities.Post)9 Date (java.util.Date)8 HashMap (java.util.HashMap)8 Map (java.util.Map)8 Topic (net.jforum.entities.Topic)8 Connection (java.sql.Connection)5 Bookmark (net.jforum.entities.Bookmark)5 KarmaStatus (net.jforum.entities.KarmaStatus)4 SimpleDateFormat (java.text.SimpleDateFormat)3 PrivateMessage (net.jforum.entities.PrivateMessage)3 Ranking (net.jforum.entities.Ranking)3