Search in sources :

Example 31 with DatabaseException

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

the class GenericBookmarkDAO method getUsers.

protected List getUsers(int userId) {
    List l = new ArrayList();
    PreparedStatement p = null;
    ResultSet rs = null;
    try {
        p = JForumExecutionContext.getConnection().prepareStatement(SystemGlobals.getSql("BookmarkModel.selectUserBookmarks"));
        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("username"));
            }
            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) ArrayList(java.util.ArrayList) ResultSet(java.sql.ResultSet) List(java.util.List) ArrayList(java.util.ArrayList) PreparedStatement(java.sql.PreparedStatement) DatabaseException(net.jforum.exceptions.DatabaseException)

Example 32 with DatabaseException

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

the class GenericBookmarkDAO method getTopics.

protected List getTopics(int userId) {
    PreparedStatement p = null;
    ResultSet rs = null;
    try {
        List l = new ArrayList();
        p = JForumExecutionContext.getConnection().prepareStatement(SystemGlobals.getSql("BookmarkModel.selectTopicBookmarks"));
        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("topic_title"));
            }
            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)

Example 33 with DatabaseException

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

the class GenericBookmarkDAO method add.

/**
	 * @see net.jforum.dao.BookmarkDAO#add(net.jforum.entities.Bookmark)
	 */
public void add(Bookmark b) {
    PreparedStatement p = null;
    try {
        p = JForumExecutionContext.getConnection().prepareStatement(SystemGlobals.getSql("BookmarkModel.add"));
        p.setInt(1, b.getUserId());
        p.setInt(2, b.getRelationId());
        p.setInt(3, b.getRelationType());
        p.setInt(4, b.isPublicVisible() ? 1 : 0);
        p.setString(5, b.getTitle());
        p.setString(6, b.getDescription());
        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 34 with DatabaseException

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

the class GenericCategoryDAO method selectAll.

/**
	 * @see net.jforum.dao.CategoryDAO#selectAll()
	 */
public List selectAll() {
    PreparedStatement p = null;
    ResultSet rs = null;
    try {
        p = JForumExecutionContext.getConnection().prepareStatement(SystemGlobals.getSql("CategoryModel.selectAll"));
        List l = new ArrayList();
        rs = p.executeQuery();
        while (rs.next()) {
            l.add(this.getCategory(rs));
        }
        return l;
    } 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) List(java.util.List) ArrayList(java.util.ArrayList) DatabaseException(net.jforum.exceptions.DatabaseException)

Example 35 with DatabaseException

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

the class GenericCategoryDAO method selectById.

/**
	 * @see net.jforum.dao.CategoryDAO#selectById(int)
	 */
public Category selectById(int categoryId) {
    PreparedStatement p = null;
    ResultSet rs = null;
    try {
        p = JForumExecutionContext.getConnection().prepareStatement(SystemGlobals.getSql("CategoryModel.selectById"));
        p.setInt(1, categoryId);
        rs = p.executeQuery();
        Category c = new Category();
        if (rs.next()) {
            c = this.getCategory(rs);
        }
        return c;
    } catch (SQLException e) {
        throw new DatabaseException(e);
    } finally {
        DbUtils.close(rs, p);
    }
}
Also used : Category(net.jforum.entities.Category) SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) 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