use of org.neo4j.graphdb.Notification in project neo4j by neo4j.
the class AuthProceduresIT method assertNotification.
private void assertNotification(LoginContext subject, String query, Notification wantedNotification) {
try (Transaction tx = systemDb.beginTransaction(KernelTransaction.Type.IMPLICIT, subject)) {
Result result = tx.execute(query);
Iterator<Notification> givenNotifications = result.getNotifications().iterator();
if (givenNotifications.hasNext()) {
// only checks first notification
assertEquals(wantedNotification, givenNotifications.next());
} else {
fail("Expected notifications from '" + query + "'");
}
tx.commit();
}
}
use of org.neo4j.graphdb.Notification in project neo4j by neo4j.
the class LineDelimitedEventSourceJoltSerializer method writeNotifications.
private void writeNotifications() {
if (notifications.isEmpty()) {
return;
}
try {
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);
}
}
use of org.neo4j.graphdb.Notification 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);
}
}
use of org.neo4j.graphdb.Notification in project neo4j by neo4j.
the class ExecutionResultSerializer method notifications.
public void notifications(Iterable<Notification> notifications) throws IOException {
//don't add anything if notifications are empty
if (!notifications.iterator().hasNext()) {
return;
}
try {
ensureResultsFieldClosed();
out.writeArrayFieldStart("notifications");
try {
for (Notification notification : notifications) {
out.writeStartObject();
try {
out.writeStringField("code", notification.getCode());
out.writeStringField("severity", notification.getSeverity().toString());
out.writeStringField("title", notification.getTitle());
out.writeStringField("description", notification.getDescription());
writePosition(notification.getPosition());
} finally {
out.writeEndObject();
}
}
} finally {
out.writeEndArray();
}
} catch (IOException e) {
throw loggedIOException(e);
}
}
use of org.neo4j.graphdb.Notification in project neo4j by neo4j.
the class ExecutionResultSerializerTest method shouldReturnNotifications.
@Test
public void shouldReturnNotifications() throws IOException {
// given
ByteArrayOutputStream output = new ByteArrayOutputStream();
ExecutionResultSerializer serializer = getSerializerWith(output);
Notification notification = NotificationCode.CARTESIAN_PRODUCT.notification(new InputPosition(1, 2, 3));
List<Notification> notifications = Arrays.asList(notification);
Result executionResult = mockExecutionResult(null, notifications, map("column1", "value1", "column2", "value2"));
// when
serializer.transactionCommitUri(URI.create("commit/uri/1"));
serializer.statementResult(executionResult, false);
serializer.notifications(notifications);
serializer.finish();
// then
String result = output.toString(UTF_8.name());
assertEquals("{\"commit\":\"commit/uri/1\",\"results\":[{\"columns\":[\"column1\",\"column2\"]," + "\"data\":[{\"row\":[\"value1\",\"value2\"],\"meta\":[null,null]}]}],\"notifications\":[{\"code\":\"Neo" + ".ClientNotification.Statement.CartesianProductWarning\",\"severity\":\"WARNING\",\"title\":\"This " + "query builds a cartesian product between disconnected patterns.\",\"description\":\"If a " + "part of a query contains multiple disconnected patterns, this will build a cartesian product" + " between all those parts. This may produce a large amount of data and slow down query " + "processing. While occasionally intended, it may often be possible to reformulate the query " + "that avoids the use of this cross product, perhaps by adding a relationship between the " + "different parts or by using OPTIONAL MATCH\",\"position\":{\"offset\":1,\"line\":2," + "\"column\":3}}],\"errors\":[]}", result);
}
Aggregations