Search in sources :

Example 1 with Query

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);
    }
}
Also used : Query(com.buschmais.xo.api.Query) RuleExecutorException(com.buschmais.jqassistant.core.rule.api.executor.RuleExecutorException) XOException(com.buschmais.xo.api.XOException) RuleExecutorException(com.buschmais.jqassistant.core.rule.api.executor.RuleExecutorException) ScriptException(javax.script.ScriptException) Result(com.buschmais.jqassistant.core.analysis.api.Result)

Aggregations

Result (com.buschmais.jqassistant.core.analysis.api.Result)1 RuleExecutorException (com.buschmais.jqassistant.core.rule.api.executor.RuleExecutorException)1 Query (com.buschmais.xo.api.Query)1 XOException (com.buschmais.xo.api.XOException)1 ScriptException (javax.script.ScriptException)1