use of org.neo4j.driver.async.ResultCursor in project structr by structr.
the class AsyncSessionTransaction method run.
@Override
public Iterable<Map<String, Object>> run(final String statement, final Map<String, Object> map) {
try {
logQuery(statement, map);
final ResultCursor cursor = resolveImmediately(tx.runAsync(statement, map));
final List<Record> records = resolveImmediately(cursor.listAsync());
return Iterables.map(new RecordMapMapper(db), records);
} catch (TransientException tex) {
closed = true;
throw new RetryException(tex);
} catch (NoSuchRecordException nex) {
throw new NotFoundException(nex);
} catch (ServiceUnavailableException ex) {
throw new NetworkException(ex.getMessage(), ex);
} catch (DatabaseException dex) {
throw AsyncSessionTransaction.translateDatabaseException(dex);
} catch (ClientException cex) {
throw AsyncSessionTransaction.translateClientException(cex);
}
}
use of org.neo4j.driver.async.ResultCursor in project structr by structr.
the class AsyncSessionTransaction method getRelationship.
@Override
public Relationship getRelationship(final String statement, final Map<String, Object> map) {
try {
logQuery(statement, map);
final ResultCursor cursor = resolveImmediately(tx.runAsync(statement, map));
final CompletionStage<Record> peek = cursor.peekAsync();
final Record record = resolveImmediately(peek);
Relationship relationship = null;
if (record != null) {
relationship = record.get(0).asRelationship();
}
logSummary(resolveImmediately(cursor.consumeAsync()));
return relationship;
} catch (TransientException tex) {
closed = true;
throw new RetryException(tex);
} catch (NoSuchRecordException nex) {
throw new NotFoundException(nex);
} catch (ServiceUnavailableException ex) {
throw new NetworkException(ex.getMessage(), ex);
} catch (DatabaseException dex) {
throw AsyncSessionTransaction.translateDatabaseException(dex);
} catch (ClientException cex) {
throw AsyncSessionTransaction.translateClientException(cex);
}
}
use of org.neo4j.driver.async.ResultCursor in project structr by structr.
the class AsyncSessionTransaction method getStrings.
@Override
public Iterable<String> getStrings(final String statement, final Map<String, Object> map) {
try {
logQuery(statement, map);
final ResultCursor cursor = resolveImmediately(tx.runAsync(statement, map));
final List<String> immutable = resolveImmediately(cursor.peekAsync()).get(0).asList(Values.ofString());
logSummary(resolveImmediately(cursor.consumeAsync()));
return new LinkedList<>(immutable);
} catch (TransientException tex) {
closed = true;
throw new RetryException(tex);
} catch (NoSuchRecordException nex) {
throw new NotFoundException(nex);
} catch (ServiceUnavailableException ex) {
throw new NetworkException(ex.getMessage(), ex);
} catch (DatabaseException dex) {
throw AsyncSessionTransaction.translateDatabaseException(dex);
} catch (ClientException cex) {
throw AsyncSessionTransaction.translateClientException(cex);
}
}
use of org.neo4j.driver.async.ResultCursor in project structr by structr.
the class AsyncSessionTransaction method getNode.
@Override
public Node getNode(final String statement, final Map<String, Object> map) {
try {
logQuery(statement, map);
final ResultCursor cursor = resolveImmediately(tx.runAsync(statement, map));
final CompletionStage<Record> peek = cursor.peekAsync();
final Record record = resolveImmediately(peek);
Node node = null;
if (record != null) {
node = record.get(0).asNode();
}
logSummary(resolveImmediately(cursor.consumeAsync()));
return node;
} catch (TransientException tex) {
closed = true;
throw new RetryException(tex);
} catch (NoSuchRecordException nex) {
throw new NotFoundException(nex);
} catch (ServiceUnavailableException ex) {
throw new NetworkException(ex.getMessage(), ex);
} catch (DatabaseException dex) {
throw AsyncSessionTransaction.translateDatabaseException(dex);
} catch (ClientException cex) {
throw AsyncSessionTransaction.translateClientException(cex);
}
}
use of org.neo4j.driver.async.ResultCursor in project micronaut-neo4j by micronaut-projects.
the class Neo4jHealthIndicator method getResult.
@Override
public Publisher<HealthResult> getResult() {
try {
Mono<HealthResult> healthResultSingle = Mono.create(emitter -> {
AsyncSession session = boltDriver.asyncSession();
CompletionStage<ResultSummary> query = session.writeTransactionAsync(tx -> tx.runAsync("RETURN 1 AS result").thenCompose(ResultCursor::consumeAsync));
query.handleAsync((resultSummaryStage, throwable) -> {
if (throwable != null) {
return buildErrorResult(throwable);
} else {
HealthResult.Builder status = HealthResult.builder(NAME, HealthStatus.UP);
ServerInfo serverInfo = resultSummaryStage.server();
status.details(Collections.singletonMap("server", serverInfo.version() + "@" + serverInfo.address()));
return status.build();
}
}).thenComposeAsync(status -> session.closeAsync().handle((signal, throwable) -> status)).thenAccept(emitter::success);
});
return healthResultSingle.subscribeOn(Schedulers.fromExecutorService(ioExecutor));
} catch (Throwable e) {
return Mono.just(buildErrorResult(e));
}
}
Aggregations