Search in sources :

Example 66 with DatabaseException

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

the class GenericTopicDAO method getMaxPostId.

/**
	 * @see net.jforum.dao.TopicDAO#autoSetLastPostId(int)
	 */
public int getMaxPostId(int topicId) {
    int id = -1;
    PreparedStatement p = null;
    ResultSet rs = null;
    try {
        p = JForumExecutionContext.getConnection().prepareStatement(SystemGlobals.getSql("TopicModel.getMaxPostId"));
        p.setInt(1, topicId);
        rs = p.executeQuery();
        if (rs.next()) {
            id = rs.getInt("post_id");
        }
        return id;
    } 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)

Example 67 with DatabaseException

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

the class GenericTopicDAO method newMessages.

private List newMessages(List topicIds) {
    if (topicIds.size() == 0) {
        return new ArrayList();
    }
    PreparedStatement p = null;
    try {
        String sql = SystemGlobals.getSql("TopicModel.selectForNewMessages");
        StringBuffer sb = new StringBuffer();
        for (Iterator iter = topicIds.iterator(); iter.hasNext(); ) {
            sb.append(iter.next()).append(',');
        }
        sb.append("-1");
        sql = sql.replaceAll(":topicIds:", sb.toString());
        p = JForumExecutionContext.getConnection().prepareStatement(sql);
        return this.fillTopicsData(p);
    } catch (SQLException e) {
        throw new DatabaseException(e);
    } finally {
        DbUtils.close(p);
    }
}
Also used : SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) PreparedStatement(java.sql.PreparedStatement) DatabaseException(net.jforum.exceptions.DatabaseException)

Example 68 with DatabaseException

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

the class GenericTopicDAO method deleteByForum.

/**
	 * @see net.jforum.dao.TopicDAO#deleteByForum(int)
	 */
public void deleteByForum(int forumId) {
    PreparedStatement p = null;
    ResultSet rs = null;
    try {
        p = JForumExecutionContext.getConnection().prepareStatement(SystemGlobals.getSql("TopicModel.deleteByForum"));
        p.setInt(1, forumId);
        rs = p.executeQuery();
        List topics = new ArrayList();
        while (rs.next()) {
            Topic t = new Topic();
            t.setId(rs.getInt("topic_id"));
            t.setForumId(forumId);
            topics.add(t);
        }
        this.deleteTopics(topics, false);
    } catch (SQLException e) {
        throw new DatabaseException(e);
    } finally {
        DbUtils.close(rs, p);
    }
}
Also used : SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) ArrayList(java.util.ArrayList) PreparedStatement(java.sql.PreparedStatement) ArrayList(java.util.ArrayList) List(java.util.List) Topic(net.jforum.entities.Topic) DatabaseException(net.jforum.exceptions.DatabaseException)

Example 69 with DatabaseException

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

the class GenericTopicDAO method selectTopicTitlesByIds.

/**
	 * @see net.jforum.dao.TopicDAO#selectTopicTitlesByIds(java.util.Collection)
	 */
public List selectTopicTitlesByIds(Collection idList) {
    List l = new ArrayList();
    String sql = SystemGlobals.getSql("TopicModel.selectTopicTitlesByIds");
    StringBuffer sb = new StringBuffer(idList.size() * 2);
    for (Iterator iter = idList.iterator(); iter.hasNext(); ) {
        sb.append(iter.next()).append(",");
    }
    int len = sb.length();
    sql = sql.replaceAll(":ids:", len > 0 ? sb.toString().substring(0, len - 1) : "0");
    PreparedStatement p = null;
    ResultSet rs = null;
    try {
        p = JForumExecutionContext.getConnection().prepareStatement(sql);
        rs = p.executeQuery();
        while (rs.next()) {
            Map m = new HashMap();
            m.put("id", new Integer(rs.getInt("topic_id")));
            m.put("title", rs.getString("topic_title"));
            l.add(m);
        }
        return l;
    } catch (SQLException e) {
        throw new DatabaseException(e);
    } finally {
        DbUtils.close(rs, p);
    }
}
Also used : HashMap(java.util.HashMap) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) PreparedStatement(java.sql.PreparedStatement) Iterator(java.util.Iterator) ResultSet(java.sql.ResultSet) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) DatabaseException(net.jforum.exceptions.DatabaseException)

Example 70 with DatabaseException

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

the class GenericTopicDAO method addNew.

/**
	 * @see net.jforum.dao.TopicDAO#addNew(net.jforum.entities.Topic)
	 */
public int addNew(Topic topic) {
    PreparedStatement p = null;
    try {
        p = this.getStatementForAutoKeys("TopicModel.addNew");
        p.setInt(1, topic.getForumId());
        p.setString(2, topic.getTitle());
        p.setInt(3, topic.getPostedBy().getId());
        p.setTimestamp(4, new Timestamp(topic.getTime().getTime()));
        p.setInt(5, topic.getFirstPostId());
        p.setInt(6, topic.getLastPostId());
        p.setInt(7, topic.getType());
        p.setInt(8, topic.isModerated() ? 1 : 0);
        this.setAutoGeneratedKeysQuery(SystemGlobals.getSql("TopicModel.lastGeneratedTopicId"));
        int topicId = this.executeAutoKeysQuery(p);
        topic.setId(topicId);
        return topicId;
    } 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)

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