use of org.apache.wiki.auth.NoSuchPrincipalException in project jspwiki by apache.
the class JDBCGroupDatabase method delete.
/**
* Looks up and deletes a {@link Group} from the group database. If the
* group database does not contain the supplied Group. this method throws a
* {@link NoSuchPrincipalException}. The method commits the results of the
* delete to persistent storage.
*
* @param group the group to remove
* @throws WikiSecurityException if the database does not contain the
* supplied group (thrown as {@link NoSuchPrincipalException})
* or if the commit did not succeed
*/
public void delete(Group group) throws WikiSecurityException {
if (!exists(group)) {
throw new NoSuchPrincipalException("Not in database: " + group.getName());
}
String groupName = group.getName();
Connection conn = null;
PreparedStatement ps = null;
try {
// Open the database connection
conn = m_ds.getConnection();
if (m_supportsCommits) {
conn.setAutoCommit(false);
}
ps = conn.prepareStatement(m_deleteGroup);
ps.setString(1, groupName);
ps.execute();
ps.close();
ps = conn.prepareStatement(m_deleteGroupMembers);
ps.setString(1, groupName);
ps.execute();
// Commit and close connection
if (m_supportsCommits) {
conn.commit();
}
} catch (SQLException e) {
closeQuietly(conn, ps, null);
throw new WikiSecurityException("Could not delete group " + groupName + ": " + e.getMessage(), e);
} finally {
closeQuietly(conn, ps, null);
}
}
Aggregations