Implement the ELSE script logic for COMMIT RETRY statement
@@ -16,6 +16,8 @@ import java.util.List;
*/
public class RetryStep extends AbstractExecutionStep {
public List<OStatement> body;
+ public List<OStatement> elseBody;
+ public boolean elseFail = true;
private final int retries;
Iterator iterator;
@@ -39,7 +41,7 @@ public class RetryStep extends AbstractExecutionStep {
if (OExecutionThreadLocal.isInterruptCurrentOperation()) {
throw new OCommandInterruptedException("The command has been interrupted");
}
- OScriptExecutionPlan plan = initPlan(ctx);
+ OScriptExecutionPlan plan = initPlan(body, ctx);
OExecutionStepInternal result = plan.executeFull();
if (result != null) {
this.finalResult = result;
@@ -53,7 +55,19 @@ public class RetryStep extends AbstractExecutionStep {
}
if (i == retries - 1) {
+ if (elseBody != null && elseBody.size() > 0) {
+ OScriptExecutionPlan plan = initPlan(elseBody, ctx);
+ OExecutionStepInternal result = plan.executeFull();
+ if (result != null) {
+ this.finalResult = result;
+ return result.syncPull(ctx, nRecords);
+ }
+ }
+ if(elseFail){
throw ex;
+ }else{
+ return new OInternalResultSet();
+ }
}
}
}
@@ -63,7 +77,7 @@ public class RetryStep extends AbstractExecutionStep {
}
- public OScriptExecutionPlan initPlan(OCommandContext ctx) {
+ public OScriptExecutionPlan initPlan(List<OStatement> body, OCommandContext ctx) {
OBasicCommandContext subCtx1 = new OBasicCommandContext();
subCtx1.setParent(ctx);
OScriptExecutionPlan plan = new OScriptExecutionPlan(subCtx1);
