Search in sources :

Example 76 with DatabaseException

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

the class GenericTreeGroupDAO method selectGroups.

/**
	 * @see net.jforum.dao.TreeGroupDAO#selectGroups(int)
	 */
public List selectGroups(int parentId) {
    List list = new ArrayList();
    PreparedStatement p = null;
    ResultSet rs = null;
    try {
        p = JForumExecutionContext.getConnection().prepareStatement(SystemGlobals.getSql("TreeGroup.selectGroup"));
        p.setInt(1, parentId);
        rs = p.executeQuery();
        while (rs.next()) {
            GroupNode n = new GroupNode();
            n.setName(rs.getString("group_name"));
            n.setId(rs.getInt("group_id"));
            list.add(n);
        }
        return list;
    } catch (SQLException e) {
        throw new DatabaseException(e);
    } finally {
        DbUtils.close(rs, p);
    }
}
Also used : SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) ResultSet(java.sql.ResultSet) List(java.util.List) ArrayList(java.util.ArrayList) PreparedStatement(java.sql.PreparedStatement) GroupNode(net.jforum.util.GroupNode) DatabaseException(net.jforum.exceptions.DatabaseException)

Example 77 with DatabaseException

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

the class GenericUserDAO method decrementPosts.

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

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

the class GenericUserDAO method setActive.

/**
	 * @see net.jforum.dao.UserDAO#setActive(int, boolean)
	 */
public void setActive(int userId, boolean active) {
    PreparedStatement p = null;
    try {
        p = JForumExecutionContext.getConnection().prepareStatement(SystemGlobals.getSql("UserModel.activeStatus"));
        p.setInt(1, active ? 1 : 0);
        p.setInt(2, 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 79 with DatabaseException

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

the class GenericUserDAO method validateLostPasswordHash.

/**
	 * @see net.jforum.dao.UserDAO#validateLostPasswordHash(java.lang.String, java.lang.String)
	 */
public boolean validateLostPasswordHash(String email, String hash) {
    PreparedStatement p = null;
    ResultSet rs = null;
    try {
        p = JForumExecutionContext.getConnection().prepareStatement(SystemGlobals.getSql("UserModel.validateLostPasswordHash"));
        p.setString(1, hash);
        p.setString(2, email);
        boolean status = false;
        rs = p.executeQuery();
        if (rs.next() && rs.getInt("valid") > 0) {
            status = true;
            this.writeLostPasswordHash(email, "");
        }
        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 80 with DatabaseException

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

the class GenericUserDAO method hasUsernameChanged.

/**
	 * @see net.jforum.dao.UserDAO#hasUsernameChanged(int, java.lang.String)
	 */
public boolean hasUsernameChanged(int userId, String usernameToCheck) {
    PreparedStatement p = null;
    ResultSet rs = null;
    try {
        p = JForumExecutionContext.getConnection().prepareStatement(SystemGlobals.getSql("UserModel.getUsername"));
        p.setString(1, usernameToCheck);
        p.setInt(2, userId);
        String dbUsername = null;
        rs = p.executeQuery();
        if (rs.next()) {
            dbUsername = rs.getString("username");
        }
        boolean status = false;
        if (!usernameToCheck.equals(dbUsername)) {
            status = true;
        }
        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)

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