for (Statement stmt : cmd.getStatements()) {
stmt.validate();
}
// validation passed, kick off all statements
Response resp = new Response();
for (Statement stmt : cmd.getStatements()) {
// TODO : how to handle exceptions for simple statement?
if (stmt.isSimpleStatement()) {
if (stmt instanceof InsertStatement) {
InsertStatement insertStmt = (InsertStatement) stmt;
resp.getImmediateStmts().add(insertStmt.getRawStatement());
executeSimpleInsert(insertStmt);
} else {
// TODO supports other simple statements
}
} else {
ProcessContext context = new ProcessContext();
context.setClientId(userService.getCurrentUser().getEmail());
String pipelineId = pipeline.startNewPipeline(new ProcessorManager(), stmt.generateProcessors(), context);
resp.add(pipelineId, stmt.getRawStatement());
logger.info("started pipeline " + pipelineId + " for query: " + stmt.getRawStatement());
}
}
resp.setStatus(ResponseStatus.SUCCESS);
return resp;
} catch (RecognitionException e) { // syntax error (should not happen as ANTLR will always try to recover from error)
Response response = new Response();
response.setStatus(ResponseStatus.SYNTAX_ERROR);
response.setMessage(e.getMessage());
return response;
} catch (YaacException e) { // syntax error (throw from EGQLParser.displayRecognitionError )
Response response = new Response();
response.setStatus(ResponseStatus.SYNTAX_ERROR);
response.setMessage(e.getErrorMsg());
return response;
} catch (EGQLException e) { // logical exception
Response response = new Response();
response.setStatus(ResponseStatus.LOGICAL_ERROR);
response.setErrorCode(e.getErrorCode());
return response;
}
}