Search in sources :

Example 6 with ConnectionException

use of org.neo4j.server.http.cypher.format.api.ConnectionException in project neo4j by neo4j.

the class ExecutionResultSerializer method writeRecord.

void writeRecord(RecordEvent recordEvent) {
    try {
        TransactionStateChecker txStateChecker = TransactionStateChecker.create(transactionHandle.getContext());
        jsonGenerator.writeStartObject();
        try {
            writer.write(jsonGenerator, recordEvent, txStateChecker);
        } finally {
            jsonGenerator.writeEndObject();
        }
        flush();
    } catch (JsonGenerationException e) {
        throw new IllegalStateException(e);
    } catch (IOException e) {
        throw new ConnectionException("Failed to write to the connection", e);
    }
}
Also used : TransactionStateChecker(org.neo4j.server.http.cypher.TransactionStateChecker) IOException(java.io.IOException) JsonGenerationException(com.fasterxml.jackson.core.JsonGenerationException) ConnectionException(org.neo4j.server.http.cypher.format.api.ConnectionException)

Example 7 with ConnectionException

use of org.neo4j.server.http.cypher.format.api.ConnectionException in project neo4j by neo4j.

the class ExecutionResultSerializer method writeStatementEnd.

void writeStatementEnd(StatementEndEvent statementEndEvent) {
    try {
        jsonGenerator.writeEndArray();
        if (inputStatement.includeStats()) {
            writeStats(statementEndEvent.getQueryStatistics());
        }
        if (statementEndEvent.getQueryExecutionType().requestedExecutionPlanDescription()) {
            writeRootPlanDescription(statementEndEvent.getExecutionPlanDescription());
        }
        // </result>
        jsonGenerator.writeEndObject();
        currentState = State.RESULTS_OPEN;
        statementEndEvent.getNotifications().forEach(notifications::add);
    } catch (JsonGenerationException e) {
        throw new IllegalStateException(e);
    } catch (IOException e) {
        throw new ConnectionException("Failed to write to the connection", e);
    }
}
Also used : IOException(java.io.IOException) JsonGenerationException(com.fasterxml.jackson.core.JsonGenerationException) ConnectionException(org.neo4j.server.http.cypher.format.api.ConnectionException)

Example 8 with ConnectionException

use of org.neo4j.server.http.cypher.format.api.ConnectionException in project neo4j by neo4j.

the class ExecutionResultSerializer method writeStatementStart.

void writeStatementStart(StatementStartEvent statementStartEvent, InputStatement inputStatement) {
    this.inputStatement = inputStatement;
    this.writer = configureWriters(inputStatement.resultDataContents());
    try {
        ensureResultsFieldOpen();
        jsonGenerator.writeStartObject();
        Iterable<String> columns = statementStartEvent.getColumns();
        writeColumns(columns);
        jsonGenerator.writeArrayFieldStart("data");
        currentState = State.STATEMENT_OPEN;
    } catch (JsonGenerationException e) {
        throw new IllegalStateException(e);
    } catch (IOException e) {
        throw new ConnectionException("Failed to write to the connection", e);
    }
}
Also used : IOException(java.io.IOException) JsonGenerationException(com.fasterxml.jackson.core.JsonGenerationException) ConnectionException(org.neo4j.server.http.cypher.format.api.ConnectionException)

Example 9 with ConnectionException

use of org.neo4j.server.http.cypher.format.api.ConnectionException in project neo4j by neo4j.

the class ExecutionResultSerializer method writeTransactionInfo.

void writeTransactionInfo(TransactionInfoEvent transactionInfoEvent) {
    try {
        ensureDocumentOpen();
        ensureResultsFieldClosed();
        writeNotifications(notifications);
        writeErrors();
        if (transactionInfoEvent.getCommitUri() != null) {
            jsonGenerator.writeStringField("commit", transactionInfoEvent.getCommitUri().toString());
        }
        if (transactionInfoEvent.getNotification() == OPEN) {
            jsonGenerator.writeObjectFieldStart("transaction");
            if (transactionInfoEvent.getExpirationTimestamp() >= 0) {
                String expires = Instant.ofEpochMilli(transactionInfoEvent.getExpirationTimestamp()).atZone(ZoneId.of("GMT")).format(DateTimeFormatter.RFC_1123_DATE_TIME);
                jsonGenerator.writeStringField("expires", expires);
            }
            jsonGenerator.writeEndObject();
        }
        jsonGenerator.writeEndObject();
        flush();
    } catch (JsonGenerationException e) {
        throw new IllegalStateException(e);
    } catch (IOException e) {
        throw new ConnectionException("Failed to write to the connection", e);
    }
}
Also used : IOException(java.io.IOException) JsonGenerationException(com.fasterxml.jackson.core.JsonGenerationException) ConnectionException(org.neo4j.server.http.cypher.format.api.ConnectionException)

Example 10 with ConnectionException

use of org.neo4j.server.http.cypher.format.api.ConnectionException in project neo4j by neo4j.

the class ExecutionResultSerializer method writeNotifications.

private void writeNotifications(Iterable<Notification> notifications) {
    // don't add anything if notifications are empty
    if (!notifications.iterator().hasNext()) {
        return;
    }
    try {
        ensureResultsFieldClosed();
        jsonGenerator.writeArrayFieldStart("notifications");
        try {
            for (Notification notification : notifications) {
                jsonGenerator.writeStartObject();
                try {
                    jsonGenerator.writeStringField("code", notification.getCode());
                    jsonGenerator.writeStringField("severity", notification.getSeverity().toString());
                    jsonGenerator.writeStringField("title", notification.getTitle());
                    jsonGenerator.writeStringField("description", notification.getDescription());
                    writePosition(notification.getPosition());
                } finally {
                    jsonGenerator.writeEndObject();
                }
            }
        } finally {
            jsonGenerator.writeEndArray();
        }
    } catch (IOException e) {
        throw new ConnectionException("Failed to write to the response stream", e);
    }
}
Also used : IOException(java.io.IOException) Notification(org.neo4j.graphdb.Notification) ConnectionException(org.neo4j.server.http.cypher.format.api.ConnectionException)

Aggregations

IOException (java.io.IOException)21 ConnectionException (org.neo4j.server.http.cypher.format.api.ConnectionException)21 JsonGenerationException (com.fasterxml.jackson.core.JsonGenerationException)10 Test (org.junit.jupiter.api.Test)5 MemoryPool (org.neo4j.memory.MemoryPool)4 InputEventStream (org.neo4j.server.http.cypher.format.api.InputEventStream)4 Statement (org.neo4j.server.http.cypher.format.api.Statement)3 JsonParseException (com.fasterxml.jackson.core.JsonParseException)2 JsonToken (com.fasterxml.jackson.core.JsonToken)2 InOrder (org.mockito.InOrder)2 Notification (org.neo4j.graphdb.Notification)2 TransactionStateChecker (org.neo4j.server.http.cypher.TransactionStateChecker)2 FailureEvent (org.neo4j.server.http.cypher.format.api.FailureEvent)2 InputFormatException (org.neo4j.server.http.cypher.format.api.InputFormatException)2 JsonMappingException (com.fasterxml.jackson.databind.JsonMappingException)1 ArrayList (java.util.ArrayList)1 Log (org.neo4j.logging.Log)1