Search in sources :

Example 1 with DatabaseException

use of org.neo4j.driver.exceptions.DatabaseException 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 DatabaseException

use of org.neo4j.driver.exceptions.DatabaseException 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 DatabaseException

use of org.neo4j.driver.exceptions.DatabaseException 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 DatabaseException

use of org.neo4j.driver.exceptions.DatabaseException 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 DatabaseException

use of org.neo4j.driver.exceptions.DatabaseException in project structr by structr.

the class ReactiveSessionTransaction method getBoolean.

@Override
public boolean getBoolean(final String statement, final Map<String, Object> map) {
    try {
        logQuery(statement, map);
        final RxResult result = tx.run(statement, map);
        final Publisher<Record> publisher = result.records();
        final Record record = Mono.from(publisher).block();
        final boolean value = record.get(0).asBoolean();
        logSummary(Mono.from(result.consume()).block());
        return value;
    } 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 ReactiveSessionTransaction.translateDatabaseException(dex);
    } catch (ClientException cex) {
        throw ReactiveSessionTransaction.translateClientException(cex);
    }
}
Also used : 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) RxResult(org.neo4j.driver.reactive.RxResult) NetworkException(org.structr.api.NetworkException) DatabaseException(org.neo4j.driver.exceptions.DatabaseException) NoSuchRecordException(org.neo4j.driver.exceptions.NoSuchRecordException)

Aggregations

DatabaseException (org.neo4j.driver.exceptions.DatabaseException)21 TransientException (org.neo4j.driver.exceptions.TransientException)21 ClientException (org.neo4j.driver.exceptions.ClientException)20 ServiceUnavailableException (org.neo4j.driver.exceptions.ServiceUnavailableException)19 NoSuchRecordException (org.neo4j.driver.exceptions.NoSuchRecordException)18 NetworkException (org.structr.api.NetworkException)18 NotFoundException (org.structr.api.NotFoundException)18 RetryException (org.structr.api.RetryException)18 Record (org.neo4j.driver.Record)12 ResultCursor (org.neo4j.driver.async.ResultCursor)9 RxResult (org.neo4j.driver.reactive.RxResult)9 LinkedList (java.util.LinkedList)2 Test (org.junit.jupiter.api.Test)2 Entity (org.neo4j.driver.types.Entity)2 Node (org.neo4j.driver.types.Node)2 Relationship (org.neo4j.driver.types.Relationship)2 Arrays (java.util.Arrays)1 Collections.emptyIterator (java.util.Collections.emptyIterator)1 Iterator (java.util.Iterator)1 Map (java.util.Map)1