AgileApps Support Wiki Pre Release

rollback

From AgileApps Support Wiki
Functions.rollback(String name)
Performs a rollback of the entire transaction
Syntax
void Functions.rollback()
Return
None

Examples

Single SavePoint Rollback

Rollback a record to the values contained in the last SavePoint

<syntaxhighlight lang="java" enclose="div">

Functions.addSavePoint("save_point");
                               
Parameters params = Functions.getParametersInstance();
params.add("first_name","Jack");
params.add("last_name","Nicholson");
Result result = Functions.addRecord("CONTACT",params);
Functions.rollbackToSavePoint("save_point"); 

</syntaxhighlight>

Multiple SavePoints Rollback

Restores multiple SavePoints to the initial state, and rolls back all of the addRecord actions.

<syntaxhighlight lang="java" enclose="div">

Functions.addSavePoint("save_point");

Parameters params = Functions.getParametersInstance(); params.add("first_name","Jack"); params.add("last_name","Nicholson");

Result result = Functions.addRecord("CONTACT",params);

Functions.addSavePoint("second_save_point");

Logger.info("Second Save Point :"

         + Functions.doesSavePointExist("second_save_point"), "Rollback");

Parameters secondParams = Functions.getParametersInstance(); secondParams.add("first_name","Anthony"); secondParams.add("last_name","Hopkins");

Result secondResult = Functions.addRecord("CONTACT",secondParams);

Functions.addSavePoint("third_save_point");

Parameters thirdParams = Functions.getParametersInstance(); thirdParams.add("first_name","Clint"); thirdParams.add("last_name","Eastwood");

Result thirdResult = Functions.addRecord("CONTACT",thirdParams);

Functions.rollbackToSavePoint("save_point"); </syntaxhighlight>

Rollback Entire Transaction

Roll back a series of transactions, to the original SavePoint.

From the web browser these results are seen:
  • If a record was added before this transaction, then the record will not exist
  • If a record was edited before this transaction, then no updates will be recorded for the record

<syntaxhighlight lang="java" enclose="div"> Functions.addSavePoint("save_point");

Parameters params = Functions.getParametersInstance(); params.add("first_name","Jack"); params.add("last_name","Nicholson");

Result result = Functions.addRecord("CONTACT",params);

Functions.addSavePoint("second_save_point");

Logger.info("Second Save Point: "

+ doesSavePointExists("second_save_point"), "Rollback");

Parameters secondParams = Functions.getParametersInstance(); secondParams.add("first_name","Anthony"); secondParams.add("last_name","Hopkins");

Result secondResult = Functions.addRecord("CONTACT",secondParams);

Functions.rollback(); // rollbacks all batabase operations like insert, update and delete before this. Functions.addSavePoint("third_save_point");

Parameters thirdParams = Functions.getParametersInstance(); thirdParams.add("first_name","Client"); thirdParams.add("last_name","Eastwood");

Result thirdResult = Functions.addRecord("CONTACT",thirdParams); </syntaxhighlight>