* @see edu.uga.galileo.voci.db.dao.RoleDAO#updateRole2User(User)
*/
public void updateRole2User( User user) throws RoleUpdateAddException
{
// delete current roles for this user
QueryParser qpp = new QueryParser("delete from role2user where user_id=?");
qpp.addPreparedStmtElementDefinition(user.getUserId());
try
{
Configuration.getConnectionPool().executeInsertOrUpdate(qpp);
}
catch( SQLException e )
{
Logger.error("SQLException prevented role2user record deletion", e);
throw new RoleUpdateAddException(
"SQLException prevented role2user record deletion: "
+ e.getMessage());
}
// update user roles
//get roleId's
int[] roleIds = getRoleIdsByNames(user.getRoles());
StringBuffer sql = new StringBuffer();
for( int i = 0; i < roleIds.length; i++ )
{
sql.append(" insert into role2user ");
sql.append(" ( user_id, role_id ) ");
sql.append(" values ");
sql.append(" ( ?, ?) ");
QueryParser qp = new QueryParser(sql.toString());
qp.addPreparedStmtElementDefinition(user.getUserId());
qp.addPreparedStmtElementDefinition( roleIds[i]);
try
{
Configuration.getConnectionPool().executeInsertOrUpdate(qp);
}