use of net.jforum.exceptions.DatabaseException in project jforum2 by rafaelsteil.
the class GenericUserDAO method isUsernameRegistered.
/**
* @see net.jforum.dao.UserDAO#isUsernameRegistered(java.lang.String)
*/
public boolean isUsernameRegistered(String username) {
boolean status = false;
PreparedStatement p = null;
ResultSet rs = null;
try {
p = JForumExecutionContext.getConnection().prepareStatement(SystemGlobals.getSql("UserModel.isUsernameRegistered"));
p.setString(1, username);
rs = p.executeQuery();
if (rs.next() && rs.getInt("registered") > 0) {
status = true;
}
return status;
} 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 selectById.
/**
* @see net.jforum.dao.UserDAO#selectById(int)
*/
public User selectById(int userId) {
String q = SystemGlobals.getSql("UserModel.selectById");
PreparedStatement p = null;
ResultSet rs = null;
try {
p = JForumExecutionContext.getConnection().prepareStatement(q);
p.setInt(1, userId);
rs = p.executeQuery();
User u = new User();
if (rs.next()) {
this.fillUserFromResultSet(u, rs);
u.setPrivateMessagesCount(rs.getInt("private_messages"));
rs.close();
p.close();
// User groups
p = JForumExecutionContext.getConnection().prepareStatement(SystemGlobals.getSql("UserModel.selectGroups"));
p.setInt(1, userId);
rs = p.executeQuery();
while (rs.next()) {
Group g = new Group();
g.setName(rs.getString("group_name"));
g.setId(rs.getInt("group_id"));
u.getGroupsList().add(g);
}
}
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 GenericKarmaDAO method update.
/**
* @see net.jforum.dao.KarmaDAO#update(net.jforum.entities.Karma)
*/
public void update(Karma karma) {
PreparedStatement p = null;
try {
p = JForumExecutionContext.getConnection().prepareStatement(SystemGlobals.getSql("KarmaModel.update"));
p.setInt(1, karma.getPoints());
p.setInt(2, karma.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 GenericKarmaDAO method getPostKarma.
/**
* @see net.jforum.dao.KarmaDAO#getPostKarma(int)
*/
public KarmaStatus getPostKarma(int postId) {
KarmaStatus karma = new KarmaStatus();
PreparedStatement p = null;
ResultSet rs = null;
try {
p = JForumExecutionContext.getConnection().prepareStatement(SystemGlobals.getSql("KarmaModel.getPostKarma"));
p.setInt(1, postId);
rs = p.executeQuery();
if (rs.next()) {
karma.setKarmaPoints(Math.round(rs.getDouble(1)));
}
return karma;
} 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 GenericKarmaDAO method getMostRatedUserByPeriod.
/**
*
* @param sql String
* @param firstPeriod Date
* @param lastPeriod Date
* @return List
*/
protected List getMostRatedUserByPeriod(String sql, Date firstPeriod, Date lastPeriod) {
if (firstPeriod.after(lastPeriod)) {
throw new DatabaseException("First Date needs to be before the Last Date");
}
PreparedStatement p = null;
ResultSet rs = null;
try {
p = JForumExecutionContext.getConnection().prepareStatement(sql);
p.setTimestamp(1, new Timestamp(firstPeriod.getTime()));
p.setTimestamp(2, new Timestamp(lastPeriod.getTime()));
rs = p.executeQuery();
return this.fillUser(rs);
} catch (SQLException e) {
throw new DatabaseException(e);
} finally {
DbUtils.close(rs, p);
}
}
Aggregations