use of net.jforum.exceptions.DatabaseException in project jforum2 by rafaelsteil.
the class GenericGroupSecurityDAO method loadRoles.
protected RoleCollection loadRoles(int[] groupIds) {
String sql = SystemGlobals.getSql("PermissionControl.loadGroupRoles");
String groupIdAsString = SecurityCommon.groupIdAsString(groupIds);
if ("".equals(groupIdAsString)) {
// We suppose there is no "negative" group ids
sql = sql.replaceAll("#IN#", "-1");
} else {
sql = sql.replaceAll("#IN#", groupIdAsString);
}
RoleCollection roles = new RoleCollection();
PreparedStatement p = null;
ResultSet rs = null;
try {
p = JForumExecutionContext.getConnection().prepareStatement(sql);
rs = p.executeQuery();
roles = SecurityCommon.loadRoles(rs);
} catch (Exception e) {
throw new DatabaseException(e);
} finally {
DbUtils.close(rs, p);
}
return roles;
}
use of net.jforum.exceptions.DatabaseException in project jforum2 by rafaelsteil.
the class SecurityCommon method executeAddRole.
/**
* Execute the <i>add role</i> thing. As the SQL statement to insert user and group roles are
* diferent, they cannot be manipuled with a 'generic' statement, and is for this reason that
* <code>addRole</code> method is marked abstract. <br>
* The only job the <code>addRole</code> method should do is to get the correct SQL statement
* for each case - user or group - and the repass it to this method, who then do the job for us.
*
* @param sql The SQL statement to be executed.
* @param id The ID do insert. May be user's or group's id, depending of the situation ( the caller )
* @param role The role name to insert
* @param roleValues A <code>RoleValueCollection</code> collection containing the role values to
* insert. If none is wanted, just pass null as argument.
* @param supportAutoGeneratedKeys Set to <code>true</code> if <i>Statement.RETURN_GENERATED_KEYS</i> is supported
* by the Driver, or <code>false</code> if not.
* @param autoKeysQuery String
*/
public static void executeAddRole(String sql, int id, Role role, RoleValueCollection roleValues, boolean supportAutoGeneratedKeys, String autoKeysQuery) {
PreparedStatement p = null;
ResultSet rs = null;
try {
if (supportAutoGeneratedKeys) {
p = JForumExecutionContext.getConnection().prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);
} else {
p = JForumExecutionContext.getConnection().prepareStatement(sql);
}
p.setInt(1, id);
p.setString(2, role.getName());
p.executeUpdate();
if (roleValues != null) {
int roleId = -1;
if (supportAutoGeneratedKeys) {
rs = p.getGeneratedKeys();
rs.next();
roleId = rs.getInt(1);
} else {
p = JForumExecutionContext.getConnection().prepareStatement(autoKeysQuery);
rs = p.executeQuery();
if (rs.next()) {
roleId = rs.getInt(1);
}
}
rs.close();
rs = null;
p.close();
p = null;
if (roleId == -1) {
throw new SQLException("Could not obtain the latest role id");
}
p = JForumExecutionContext.getConnection().prepareStatement(SystemGlobals.getSql("PermissionControl.addRoleValues"));
for (Iterator iter = roleValues.iterator(); iter.hasNext(); ) {
RoleValue rv = (RoleValue) iter.next();
p.setInt(1, roleId);
p.setString(2, rv.getValue());
p.executeUpdate();
}
}
} 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 GenericSmilieDAO method selectById.
/**
* @see net.jforum.dao.SmilieDAO#selectById(int)
*/
public Smilie selectById(int id) {
PreparedStatement p = null;
ResultSet rs = null;
try {
p = JForumExecutionContext.getConnection().prepareStatement(SystemGlobals.getSql("SmiliesModel.selectById"));
p.setInt(1, id);
Smilie s = new Smilie();
rs = p.executeQuery();
if (rs.next()) {
s = this.getSmilie(rs);
}
return s;
} 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 GenericSummaryDAO method selectLastPosts.
/**
* @see net.jforum.dao.SummaryDAO#selectById(Date, Date)
*/
public List selectLastPosts(Date firstDate, Date lastDate) {
String query = SystemGlobals.getSql("SummaryDAO.selectPosts");
PreparedStatement p = null;
ResultSet rs = null;
try {
p = JForumExecutionContext.getConnection().prepareStatement(query);
p.setTimestamp(1, new Timestamp(firstDate.getTime()));
p.setTimestamp(2, new Timestamp(lastDate.getTime()));
List posts = new ArrayList();
rs = p.executeQuery();
while (rs.next()) {
posts.add(this.fillPost(rs));
}
return posts;
} 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 GenericSummaryDAO method listRecipients.
public List listRecipients() {
String query = SystemGlobals.getSql("SummaryDAO.selectAllRecipients");
PreparedStatement p = null;
ResultSet rs = null;
try {
p = JForumExecutionContext.getConnection().prepareStatement(query);
List recipients = new ArrayList();
rs = p.executeQuery();
String mail = null;
while (rs.next()) {
mail = rs.getString("user_email");
if (mail != null && !mail.trim().equals("")) {
recipients.add(mail);
}
}
return recipients;
} catch (SQLException e) {
throw new DatabaseException(e);
} finally {
DbUtils.close(rs, p);
}
}
Aggregations