use of com.buschmais.xo.api.Query in project jqa-core-framework by buschmais.
the class AnalyzerVisitor method executeCypher.
/**
* Execute the cypher query of a rule.
*
* @param executableRule
* The executable.
* @param executable
* The executable.
* @param parameters
* The parameters.
* @param severity
* The severity.
* @param <T>
* The rule type.
* @return The result.
* @throws RuleExecutorException
* If execution fails.
*/
private <T extends ExecutableRule> Result<T> executeCypher(T executableRule, CypherExecutable executable, Map<String, Object> parameters, Severity severity) throws RuleExecutorException {
String cypher = executable.getStatement();
List<Map<String, Object>> rows = new ArrayList<>();
try (Query.Result<Query.Result.CompositeRowObject> compositeRowObjects = executeQuery(cypher, parameters)) {
List<String> columnNames = null;
for (Query.Result.CompositeRowObject rowObject : compositeRowObjects) {
if (columnNames == null) {
columnNames = new ArrayList<>(rowObject.getColumns());
}
Map<String, Object> row = new LinkedHashMap<>();
for (String columnName : columnNames) {
row.put(columnName, rowObject.get(columnName, Object.class));
}
rows.add(row);
}
Result.Status status = verify(executableRule, columnNames, rows);
return new Result<>(executableRule, status, severity, columnNames, rows);
} catch (Exception e) {
throw new RuleExecutorException("Cannot execute query for rule '" + executableRule + "'.", e);
}
}
Aggregations