Search in sources :

Example 71 with DatabaseException

use of net.jforum.exceptions.DatabaseException in project jforum2 by rafaelsteil.

the class GenericTopicDAO method selectRecentTopics.

/**
	 * @see net.jforum.dao.TopicDAO#selectRecentTopics(int)
	 */
public List selectRecentTopics(int limit) {
    PreparedStatement p = null;
    try {
        p = JForumExecutionContext.getConnection().prepareStatement(SystemGlobals.getSql("TopicModel.selectRecentTopicsByLimit"));
        p.setInt(1, limit);
        List list = this.fillTopicsData(p);
        return list;
    } catch (SQLException e) {
        throw new DatabaseException(e);
    } finally {
        DbUtils.close(p);
    }
}
Also used : SQLException(java.sql.SQLException) PreparedStatement(java.sql.PreparedStatement) ArrayList(java.util.ArrayList) List(java.util.List) DatabaseException(net.jforum.exceptions.DatabaseException)

Example 72 with DatabaseException

use of net.jforum.exceptions.DatabaseException in project jforum2 by rafaelsteil.

the class GenericTopicDAO method updateReadStatus.

/**
	 * @see net.jforum.dao.TopicDAO#updateReadStatus(int, int, boolean)
	 */
public void updateReadStatus(int topicId, int userId, boolean read) {
    if (this.isUserSubscribed(topicId, userId)) {
        PreparedStatement p = null;
        try {
            p = JForumExecutionContext.getConnection().prepareStatement(SystemGlobals.getSql("TopicModel.updateReadStatus"));
            p.setInt(1, read ? 1 : 0);
            p.setInt(2, topicId);
            p.setInt(3, userId);
            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 73 with DatabaseException

use of net.jforum.exceptions.DatabaseException in project jforum2 by rafaelsteil.

the class GenericTopicDAO method incrementTotalReplies.

/**
	 * @see net.jforum.dao.TopicDAO#incrementTotalReplies(int)
	 */
public void incrementTotalReplies(int topicId) {
    PreparedStatement p = null;
    try {
        p = JForumExecutionContext.getConnection().prepareStatement(SystemGlobals.getSql("TopicModel.incrementTotalReplies"));
        p.setInt(1, topicId);
        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 74 with DatabaseException

use of net.jforum.exceptions.DatabaseException in project jforum2 by rafaelsteil.

the class GenericTopicDAO method setModerationStatus.

/**
	 * @see net.jforum.dao.TopicDAO#setModerationStatus(int, boolean)
	 */
public void setModerationStatus(int forumId, boolean status) {
    PreparedStatement p = null;
    try {
        p = JForumExecutionContext.getConnection().prepareStatement(SystemGlobals.getSql("TopicModel.setModerationStatus"));
        p.setInt(1, status ? 1 : 0);
        p.setInt(2, forumId);
        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 75 with DatabaseException

use of net.jforum.exceptions.DatabaseException in project jforum2 by rafaelsteil.

the class GenericTopicDAO method selectById.

/**
	 * @see net.jforum.dao.TopicDAO#selectById(int)
	 */
public Topic selectById(int topicId) {
    PreparedStatement p = null;
    try {
        p = JForumExecutionContext.getConnection().prepareStatement(SystemGlobals.getSql("TopicModel.selectById"));
        p.setInt(1, topicId);
        Topic t = new Topic();
        List l = this.fillTopicsData(p);
        p = null;
        if (l.size() > 0) {
            t = (Topic) l.get(0);
        }
        return t;
    } catch (SQLException e) {
        throw new DatabaseException(e);
    } finally {
        DbUtils.close(p);
    }
}
Also used : SQLException(java.sql.SQLException) PreparedStatement(java.sql.PreparedStatement) ArrayList(java.util.ArrayList) List(java.util.List) Topic(net.jforum.entities.Topic) 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