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);
}
}
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);
}
}
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);
}
}
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);
}
}
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;
}
Aggregations