Search in sources :

Example 1 with ResultCursor

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);
    }
}
Also used : ResultCursor(org.neo4j.driver.async.ResultCursor) TransientException(org.neo4j.driver.exceptions.TransientException) NotFoundException(org.structr.api.NotFoundException) Record(org.neo4j.driver.Record) ServiceUnavailableException(org.neo4j.driver.exceptions.ServiceUnavailableException) ClientException(org.neo4j.driver.exceptions.ClientException) RetryException(org.structr.api.RetryException) NetworkException(org.structr.api.NetworkException) DatabaseException(org.neo4j.driver.exceptions.DatabaseException) NoSuchRecordException(org.neo4j.driver.exceptions.NoSuchRecordException)

Example 2 with ResultCursor

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);
    }
}
Also used : ResultCursor(org.neo4j.driver.async.ResultCursor) TransientException(org.neo4j.driver.exceptions.TransientException) Relationship(org.neo4j.driver.types.Relationship) NotFoundException(org.structr.api.NotFoundException) Record(org.neo4j.driver.Record) ServiceUnavailableException(org.neo4j.driver.exceptions.ServiceUnavailableException) ClientException(org.neo4j.driver.exceptions.ClientException) RetryException(org.structr.api.RetryException) NetworkException(org.structr.api.NetworkException) DatabaseException(org.neo4j.driver.exceptions.DatabaseException) NoSuchRecordException(org.neo4j.driver.exceptions.NoSuchRecordException)

Example 3 with ResultCursor

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);
    }
}
Also used : ResultCursor(org.neo4j.driver.async.ResultCursor) TransientException(org.neo4j.driver.exceptions.TransientException) NotFoundException(org.structr.api.NotFoundException) ServiceUnavailableException(org.neo4j.driver.exceptions.ServiceUnavailableException) ClientException(org.neo4j.driver.exceptions.ClientException) RetryException(org.structr.api.RetryException) NetworkException(org.structr.api.NetworkException) DatabaseException(org.neo4j.driver.exceptions.DatabaseException) LinkedList(java.util.LinkedList) NoSuchRecordException(org.neo4j.driver.exceptions.NoSuchRecordException)

Example 4 with ResultCursor

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);
    }
}
Also used : ResultCursor(org.neo4j.driver.async.ResultCursor) TransientException(org.neo4j.driver.exceptions.TransientException) Node(org.neo4j.driver.types.Node) NotFoundException(org.structr.api.NotFoundException) Record(org.neo4j.driver.Record) ServiceUnavailableException(org.neo4j.driver.exceptions.ServiceUnavailableException) ClientException(org.neo4j.driver.exceptions.ClientException) RetryException(org.structr.api.RetryException) NetworkException(org.structr.api.NetworkException) DatabaseException(org.neo4j.driver.exceptions.DatabaseException) NoSuchRecordException(org.neo4j.driver.exceptions.NoSuchRecordException)

Example 5 with ResultCursor

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));
    }
}
Also used : Driver(org.neo4j.driver.Driver) Publisher(org.reactivestreams.Publisher) Singleton(jakarta.inject.Singleton) HealthIndicator(io.micronaut.management.health.indicator.HealthIndicator) Mono(reactor.core.publisher.Mono) HealthStatus(io.micronaut.health.HealthStatus) ServerInfo(org.neo4j.driver.summary.ServerInfo) TaskExecutors(io.micronaut.scheduling.TaskExecutors) CompletionStage(java.util.concurrent.CompletionStage) AsyncSession(org.neo4j.driver.async.AsyncSession) ResultSummary(org.neo4j.driver.summary.ResultSummary) Requires(io.micronaut.context.annotation.Requires) Schedulers(reactor.core.scheduler.Schedulers) ResultCursor(org.neo4j.driver.async.ResultCursor) HealthResult(io.micronaut.management.health.indicator.HealthResult) Collections(java.util.Collections) ExecutorService(java.util.concurrent.ExecutorService) Named(jakarta.inject.Named) ServerInfo(org.neo4j.driver.summary.ServerInfo) AsyncSession(org.neo4j.driver.async.AsyncSession) ResultSummary(org.neo4j.driver.summary.ResultSummary) HealthResult(io.micronaut.management.health.indicator.HealthResult)

Aggregations

ResultCursor (org.neo4j.driver.async.ResultCursor)10 ClientException (org.neo4j.driver.exceptions.ClientException)9 DatabaseException (org.neo4j.driver.exceptions.DatabaseException)9 NoSuchRecordException (org.neo4j.driver.exceptions.NoSuchRecordException)9 ServiceUnavailableException (org.neo4j.driver.exceptions.ServiceUnavailableException)9 TransientException (org.neo4j.driver.exceptions.TransientException)9 NetworkException (org.structr.api.NetworkException)9 NotFoundException (org.structr.api.NotFoundException)9 RetryException (org.structr.api.RetryException)9 Record (org.neo4j.driver.Record)4 ResultSummary (org.neo4j.driver.summary.ResultSummary)2 Requires (io.micronaut.context.annotation.Requires)1 HealthStatus (io.micronaut.health.HealthStatus)1 HealthIndicator (io.micronaut.management.health.indicator.HealthIndicator)1 HealthResult (io.micronaut.management.health.indicator.HealthResult)1 TaskExecutors (io.micronaut.scheduling.TaskExecutors)1 Named (jakarta.inject.Named)1 Singleton (jakarta.inject.Singleton)1 Collections (java.util.Collections)1 LinkedList (java.util.LinkedList)1