Search in sources :

Example 86 with DatabaseException

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

the class GenericKarmaDAO method getUserKarma.

/**
	 * @see net.jforum.dao.KarmaDAO#selectKarmaStatus(int)
	 */
public KarmaStatus getUserKarma(int userId) {
    KarmaStatus status = new KarmaStatus();
    PreparedStatement p = null;
    ResultSet rs = null;
    try {
        p = JForumExecutionContext.getConnection().prepareStatement(SystemGlobals.getSql("KarmaModel.getUserKarma"));
        p.setInt(1, userId);
        rs = p.executeQuery();
        if (rs.next()) {
            status.setKarmaPoints(Math.round(rs.getDouble("user_karma")));
        }
        return status;
    } 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 87 with DatabaseException

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

the class GenericKarmaDAO method userCanAddKarma.

/**
	 * @see net.jforum.dao.KarmaDAO#userCanAddKarma(int, int)
	 */
public boolean userCanAddKarma(int userId, int postId) {
    boolean status = true;
    PreparedStatement p = null;
    ResultSet rs = null;
    try {
        p = JForumExecutionContext.getConnection().prepareStatement(SystemGlobals.getSql("KarmaModel.userCanAddKarma"));
        p.setInt(1, postId);
        p.setInt(2, userId);
        rs = p.executeQuery();
        if (rs.next()) {
            status = rs.getInt(1) < 1;
        }
        return status;
    } 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 88 with DatabaseException

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

the class GenericLuceneDAO method getPostsToIndex.

/**
	 * @see net.jforum.dao.LuceneDAO#getPostsToIndex(LuceneReindexArgs, int, int)
	 */
public List getPostsToIndex(int fromPostId, int toPostId) {
    List l = new ArrayList();
    PreparedStatement p = null;
    ResultSet rs = null;
    try {
        p = JForumExecutionContext.getConnection().prepareStatement(SystemGlobals.getSql("SearchModel.getPostsToIndexForLucene"));
        p.setInt(1, fromPostId);
        p.setInt(2, toPostId);
        rs = p.executeQuery();
        while (rs.next()) {
            l.add(this.makePost(rs));
        }
    } catch (SQLException e) {
        throw new DatabaseException(e);
    } finally {
        DbUtils.close(rs, p);
    }
    return l;
}
Also used : SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) ResultSet(java.sql.ResultSet) ArrayList(java.util.ArrayList) List(java.util.List) PreparedStatement(java.sql.PreparedStatement) DatabaseException(net.jforum.exceptions.DatabaseException)

Example 89 with DatabaseException

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

the class GenericMailIntegrationDAO method update.

/**
	 * @see net.jforum.dao.MailIntegrationDAO#update(net.jforum.entities.MailIntegration)
	 */
public void update(MailIntegration integration) {
    PreparedStatement p = null;
    try {
        p = JForumExecutionContext.getConnection().prepareStatement(SystemGlobals.getSql("MailIntegration.update"));
        this.prepareForSave(integration, p);
        p.setInt(8, integration.getForumId());
        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 90 with DatabaseException

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

the class GenericMailIntegrationDAO method add.

/**
	 * @see net.jforum.dao.MailIntegrationDAO#add(net.jforum.entities.MailIntegration)
	 */
public void add(MailIntegration integration) {
    PreparedStatement p = null;
    try {
        p = JForumExecutionContext.getConnection().prepareStatement(SystemGlobals.getSql("MailIntegration.add"));
        this.prepareForSave(integration, p);
        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)

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