Issueing transaction and rolling back in service scripts
I wrote a simple service below to update user information from mashups.
var result;
try{
// (I want to do) tx = getTransaction();
var user = Users[userName];
user.lastName = lastName;
user.firstName = firstName;
// throw new Exception(); (A)
user.emailAddress = emailAddress;
var param = {description : description};
user.SetDescription(param);
// oldGroup -> newGroup
if((oldGroup && newGroup) && (oldGroup != newGroup)){
param = {member: userName};
Groups[newGroup].AddMember(param);
// throw new Exception(); (B)
Groups[oldGroup].DeleteMember(param);
}
// (I want to do) tx.commit();
result = "Information is successfully updated.";
logger.info("Info of " + userName + "is updated.");
}
catch(err){
// (I want to do) tx.rollback();
result = "Failed: " + err.message;
logger.error(result);
}
This script actually works, but IF error occurs, on line (A) or (B) for example, the consistency of user data can be broken.
If I can issue transaction and do Commit or Rollback, this problem will be solved.
Are there any way to do this, or alternative ideas to do something like this?
Regards,
S.Yamabe

