private String cypherRequest(Statements statements) { try { return OBJECT_MAPPER.writeValueAsString(statements); } catch (JsonProcessingException jpe) { throw new ResultProcessingException("Could not create JSON due to " + jpe.getLocalizedMessage(), jpe); } }
private String cypherRequest(Statements statements) { try { return mapper.writeValueAsString(statements); } catch (JsonProcessingException jpe) { throw new ResultProcessingException("Could not create JSON due to " + jpe.getLocalizedMessage(), jpe); } }
private void initialise() { try { responseNode = mapper.readTree(buffer.asParser()); JsonNode errors = responseNode.findValue("errors"); if (errors.elements().hasNext()) { throw new ResultProcessingException(errors.elements().next().asText(), null); } } catch (IOException e) { e.printStackTrace(); } }
T nextDataRecord(String key) { try { if (results.hasNext()) { JsonNode dataNode = results.next(); T t = dataNode.has(key) ? mapper.treeToValue(dataNode.get(key), resultClass) : null; return t; } } catch (IOException e) { throw new ResultProcessingException("Error processing results", e); } return null; }
private String cypherRequest(Statement statement) { List<Statement> statementList = new ArrayList<>(); statementList.add(statement); try { return OBJECT_MAPPER.writeValueAsString(new Statements(statementList)); } catch (JsonProcessingException jpe) { throw new ResultProcessingException("Could not create JSON due to " + jpe.getLocalizedMessage(), jpe); } }
private String cypherRequest(Statement statement) { List<Statement> statementList = new ArrayList<>(); statementList.add(statement); try { return mapper.writeValueAsString(new Statements(statementList)); } catch (JsonProcessingException jpe) { throw new ResultProcessingException("Could not create JSON due to " + jpe.getLocalizedMessage(), jpe); } }
@Override public QueryStatisticsModel adapt(Result response) { try { org.neo4j.graphdb.QueryStatistics statistics = response.getQueryStatistics(); String stats = mapper.writeValueAsString(statistics); stats = stats.replace("Deleted", "_deleted"); stats = stats.replace("Added", "_added"); stats = stats.replace("Updates", "_updates"); stats = stats.replace("Created", "_created"); stats = stats.replace("Set", "_set"); stats = stats.replace("Removed", "_removed"); stats = stats.replace("deletedNodes", "nodes_deleted"); stats = stats.replace("deletedRelationships", "relationships_deleted"); //Modify the string to include contains_updates as it is a calculated value String containsUpdates = ",\"contains_updates\":" + statistics.containsUpdates(); int closingBraceIndex = stats.lastIndexOf("}"); stats = stats.substring(0, closingBraceIndex) + containsUpdates + "}"; return mapper.readValue(stats, QueryStatisticsModel.class); } catch (Exception e) { throw new ResultProcessingException("Could not read response statistics", e); } } }
@Override public QueryStatisticsModel adapt(Result response) { try { org.neo4j.graphdb.QueryStatistics statistics = response.getQueryStatistics(); String stats = mapper.writeValueAsString(statistics); stats = stats.replace("Deleted", "_deleted"); stats = stats.replace("Added", "_added"); stats = stats.replace("Updates", "_updates"); stats = stats.replace("Created", "_created"); stats = stats.replace("Set", "_set"); stats = stats.replace("Removed", "_removed"); stats = stats.replace("deletedNodes", "nodes_deleted"); stats = stats.replace("deletedRelationships", "relationships_deleted"); //Modify the string to include contains_updates as it is a calculated value String containsUpdates = ",\"contains_updates\":" + statistics.containsUpdates(); int closingBraceIndex = stats.lastIndexOf("}"); stats = stats.substring(0, closingBraceIndex) + containsUpdates + "}"; return mapper.readValue(stats,QueryStatisticsModel.class); } catch (Exception e) { throw new ResultProcessingException("Could not read response statistics", e); } } }
@Override public QueryStatisticsModel adapt(Result response) { try { org.neo4j.graphdb.QueryStatistics statistics = response.getQueryStatistics(); String stats = mapper.writeValueAsString(statistics); stats = stats.replace("Deleted", "_deleted"); stats = stats.replace("Added", "_added"); stats = stats.replace("Updates", "_updates"); stats = stats.replace("Created", "_created"); stats = stats.replace("Set", "_set"); stats = stats.replace("Removed", "_removed"); stats = stats.replace("deletedNodes", "nodes_deleted"); stats = stats.replace("deletedRelationships", "relationships_deleted"); //Modify the string to include contains_updates as it is a calculated value String containsUpdates = ",\"contains_updates\":" + statistics.containsUpdates(); int closingBraceIndex = stats.lastIndexOf("}"); stats = stats.substring(0, closingBraceIndex) + containsUpdates + "}"; return mapper.readValue(stats, QueryStatisticsModel.class); } catch (Exception e) { throw new ResultProcessingException("Could not read response statistics", e); } } }
private String newTransactionUrl() { String url = transactionEndpoint(driverConfig.getURI()); logger.debug("POST {}", url); CloseableHttpResponse response = executeHttpRequest(new HttpPost(url)); Header location = response.getHeaders("Location")[0]; try { response.close(); return location.getValue(); } catch (IOException e) { throw new ResultProcessingException("Failed to execute request: ", e); } }
public CloseableHttpResponse executeHttpRequest(HttpRequestBase request) { try { try(CloseableHttpResponse response = HttpRequest.execute(httpClient, request, driverConfig.getCredentials())) { HttpEntity responseEntity = response.getEntity(); if (responseEntity != null) { String responseText = EntityUtils.toString(responseEntity); logger.debug(responseText); EntityUtils.consume(responseEntity); if (responseText.contains("\"errors\":[{") || responseText.contains("\"errors\": [{")) { throw new ResultErrorsException(responseText); } } return response; } } catch (Exception e) { throw new ResultProcessingException("Failed to execute request: ", e); } finally { request.releaseConnection(); logger.debug("Connection released"); } }
@Override public GraphRowModel adapt(Map<String, Object> data) { if (columns == null) { throw new ResultProcessingException("Column data cannot be null!"); } Set<Long> nodeIdentities = new HashSet<>(); Set<Long> edgeIdentities = new HashSet<>(); GraphModel graphModel = new DefaultGraphModel(); List<String> variables = new ArrayList<>(); List<Object> values = new ArrayList<>(); // there is no guarantee that the objects in the data are ordered the same way as required by the columns // so we use the columns information to extract them in the correct order for post-processing. Iterator<String> iterator = columns.iterator(); adapt(iterator, data, graphModel, variables, values, nodeIdentities, edgeIdentities); DefaultRowModel rowModel = new DefaultRowModel(values.toArray(new Object[] {}), variables.toArray(new String[] {})); return new DefaultGraphRowModel(graphModel, rowModel.getValues()); }
/** * Reads the next row from the result object and transforms it into a RowModel object * * @param data the data to transform, given as a map * @return the data transformed to an {@link RowModel} */ public RowModel adapt(Map<String, Object> data) { if (columns == null) { throw new ResultProcessingException("Result columns should not be null"); } // there is no guarantee that the objects in the data are ordered the same way as required by the columns // so we use the columns information to extract them in the correct order for post-processing. Iterator<String> iterator = columns.iterator(); List<String> variables = new ArrayList<>(); List<Object> values = new ArrayList<>(); while (iterator.hasNext()) { String key = iterator.next(); Object value = data.get(key); if (isPath(value) || isNode(value) || isRelationship(value)) { continue; } variables.add(key); if (value != null && value.getClass().isArray()) { values.add(AdapterUtils.convertToIterable(value)); } values.add(value); } return new DefaultRowModel(values.toArray(new Object[] {}), variables.toArray(new String[] {})); }
/** * Reads the next row from the result object and transforms it into a RowModel object * * @param data the data to transform, given as a map * @return the data transformed to an {@link RowModel} */ public GraphRowModel adapt(Map<String, Object> data) { if (columns == null) { throw new ResultProcessingException("Result columns should not be null"); } Set<Long> nodeIdentities = new HashSet<>(); Set<Long> edgeIdentities = new HashSet<>(); DefaultGraphModel graphModel = new DefaultGraphModel(); List<String> variables = new ArrayList<>(); List<Object> values = new ArrayList<>(); // there is no guarantee that the objects in the data are ordered the same way as required by the columns // so we use the columns information to extract them in the correct order for post-processing. Iterator<String> iterator = columns.iterator(); adapt(iterator, data, graphModel, variables, values, nodeIdentities, edgeIdentities); DefaultRowModel rowModel = new DefaultRowModel(values.toArray(new Object[] {}), variables.toArray(new String[] {})); return new DefaultGraphRowModel(graphModel, rowModel.getValues()); }
/** * Reads the next row from the result object and transforms it into a RowModel object * * @param data the data to transform, given as a map * @return the data transformed to an {@link RowModel} */ public GraphRowModel adapt(Map<String, Object> data) { if (columns == null) { throw new ResultProcessingException("Column data cannot be null!"); } Set<Long> nodeIdentities = new HashSet<>(); Set<Long> edgeIdentities = new HashSet<>(); GraphModel graphModel = new DefaultGraphModel(); List<String> variables = new ArrayList<>(); List<Object> values = new ArrayList<>(); // there is no guarantee that the objects in the data are ordered the same way as required by the columns // so we use the columns information to extract them in the correct order for post-processing. Iterator<String> iterator = columns.iterator(); adapt(iterator, data, graphModel, variables, values, nodeIdentities, edgeIdentities); DefaultRowModel rowModel = new DefaultRowModel(values.toArray(new Object[] {}), variables.toArray(new String[] {})); return new DefaultGraphRowModel(graphModel, rowModel.getValues()); }
@Override public Response<GraphModel> execute(GraphModelRequest request) { if (request.getStatement().length() == 0) { return new EmptyResponse(); } else { String cypher = cypherRequest(request); try { return new GraphModelResponse(executeRequest(cypher)); } catch (Exception e) { throw new ResultProcessingException("Could not parse response", e); } } }
@Override public Response<GraphRowListModel> execute(GraphRowListModelRequest request) { if (request.getStatement().length() == 0) { return new EmptyResponse(); } else { String cypher = cypherRequest(request); try { return new GraphRowsModelResponse(executeRequest(cypher)); } catch (Exception e) { throw new ResultProcessingException("Could not parse response", e); } } }
retryStrategy.errorOccured(); } catch (Exception e) { throw new ResultProcessingException("Request retry has failed", e); response.close(); } catch (IOException ioe) { throw new ResultProcessingException("Failed to close response: ", e); throw new ResultProcessingException("Failed to execute request", e);
@Override public Response<RestModel> execute(RestModelRequest request) { if (request.getStatement().length() == 0) { return new EmptyResponse(); } else { String cypher = cypherRequest(request); try { return new RestModelResponse(executeRequest(cypher)); } catch (Exception e) { throw new ResultProcessingException("Could not parse response", e); } } }
@Override public Response<RowModel> execute(RowModelRequest request) { if (request.getStatement().length() == 0) { return new EmptyResponse(); } else { String cypher = cypherRequest(request); try { return new RowModelResponse(executeRequest(cypher)); } catch (Exception e) { throw new ResultProcessingException("Could not parse response", e); } } }