Search in sources :

Example 56 with DatabaseException

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

the class GenericUserDAO method getLastUserInfo.

/**
	 * @see net.jforum.dao.UserDAO#getLastUserInfo()
	 */
public User getLastUserInfo() {
    PreparedStatement p = null;
    ResultSet rs = null;
    try {
        User u = new User();
        p = JForumExecutionContext.getConnection().prepareStatement(SystemGlobals.getSql("UserModel.lastUserRegistered"));
        rs = p.executeQuery();
        rs.next();
        u.setUsername(rs.getString("username"));
        u.setId(rs.getInt("user_id"));
        return u;
    } catch (SQLException e) {
        throw new DatabaseException(e);
    } finally {
        DbUtils.close(rs, p);
    }
}
Also used : User(net.jforum.entities.User) SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) DatabaseException(net.jforum.exceptions.DatabaseException)

Example 57 with DatabaseException

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

the class GenericUserDAO method update.

/**
	 * @see net.jforum.dao.UserDAO#update(net.jforum.entities.User)
	 */
public void update(User user) {
    PreparedStatement p = null;
    try {
        p = JForumExecutionContext.getConnection().prepareStatement(SystemGlobals.getSql("UserModel.update"));
        p.setString(1, user.getAim());
        p.setString(2, user.getAvatar());
        p.setString(3, user.getGender());
        p.setInt(4, user.getThemeId());
        p.setInt(5, user.isPrivateMessagesEnabled() ? 1 : 0);
        p.setInt(6, user.isAvatarEnabled() ? 1 : 0);
        p.setInt(7, user.isBbCodeEnabled() ? 1 : 0);
        p.setInt(8, user.isHtmlEnabled() ? 1 : 0);
        p.setInt(9, user.isSmiliesEnabled() ? 1 : 0);
        p.setString(10, user.getEmail());
        p.setString(11, user.getFrom());
        p.setString(12, user.getIcq());
        p.setString(13, user.getInterests());
        p.setString(14, user.getOccupation());
        p.setString(15, user.getSignature());
        p.setString(16, user.getWebSite());
        p.setString(17, user.getYim());
        p.setString(18, user.getMsnm());
        p.setString(19, user.getPassword());
        p.setInt(20, user.isViewEmailEnabled() ? 1 : 0);
        p.setInt(21, user.isViewOnlineEnabled() ? 1 : 0);
        p.setInt(22, user.isNotifyOnMessagesEnabled() ? 1 : 0);
        p.setInt(23, user.getAttachSignatureEnabled() ? 1 : 0);
        p.setString(24, user.getUsername());
        p.setString(25, user.getLang());
        p.setInt(26, user.isNotifyPrivateMessagesEnabled() ? 1 : 0);
        p.setString(27, user.getBiography());
        if (user.getLastVisit() == null) {
            user.setLastVisit(new Date());
        }
        p.setTimestamp(28, new Timestamp(user.getLastVisit().getTime()));
        p.setInt(29, user.notifyAlways() ? 1 : 0);
        p.setInt(30, user.notifyText() ? 1 : 0);
        p.setInt(31, user.getRankId());
        p.setInt(32, user.getId());
        p.executeUpdate();
    } 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) Date(java.util.Date)

Example 58 with DatabaseException

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

the class GenericUserSessionDAO method update.

/**
	 * @see net.jforum.dao.UserSessionDAO#update(net.jforum.entities.UserSession,
	 *      java.sql.Connection)
	 */
public void update(UserSession us, Connection conn) {
    if (this.selectById(us, conn) == null) {
        this.add(us, conn, true);
        return;
    }
    PreparedStatement p = null;
    try {
        p = conn.prepareStatement(SystemGlobals.getSql("UserSessionModel.update"));
        p.setTimestamp(1, new Timestamp(us.getStartTime().getTime()));
        p.setLong(2, us.getSessionTime());
        p.setString(3, us.getSessionId());
        p.setInt(4, us.getUserId());
        p.executeUpdate();
    } 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)

Example 59 with DatabaseException

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

the class GenericUserSessionDAO method add.

private void add(UserSession us, Connection conn, boolean checked) {
    if (!checked && this.selectById(us, conn) != null) {
        return;
    }
    PreparedStatement p = null;
    try {
        p = conn.prepareStatement(SystemGlobals.getSql("UserSessionModel.add"));
        p.setString(1, us.getSessionId());
        p.setInt(2, us.getUserId());
        p.setTimestamp(3, new Timestamp(us.getStartTime().getTime()));
        p.executeUpdate();
    } 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)

Example 60 with DatabaseException

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

the class GenericGroupSecurityDAO method selectForumRoles.

private List selectForumRoles(int forumId) {
    List l = new ArrayList();
    PreparedStatement p = null;
    ResultSet rs = null;
    try {
        p = JForumExecutionContext.getConnection().prepareStatement(SystemGlobals.getSql("PermissionControl.selectForumRoles"));
        p.setString(1, String.valueOf(forumId));
        rs = p.executeQuery();
        while (rs.next()) {
            l.add(new Integer(rs.getInt("role_id")));
        }
    } 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)

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