Search in sources :

Example 1 with TransientException

use of org.neo4j.driver.v1.exceptions.TransientException in project structr by structr.

the class SessionTransaction method getStrings.

public QueryResult<String> getStrings(final String statement, final Map<String, Object> map) {
    final long t0 = System.currentTimeMillis();
    try {
        final StatementResult result = tx.run(statement, map);
        final Record record = result.next();
        final Value value = record.get(0);
        return new QueryResult<String>() {

            @Override
            public void close() {
                result.consume();
            }

            @Override
            public Iterator<String> iterator() {
                return value.asList(Values.ofString()).iterator();
            }
        };
    } 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);
    } finally {
        logQuery(statement, map, t0);
    }
}
Also used : StatementResult(org.neo4j.driver.v1.StatementResult) QueryResult(org.structr.api.QueryResult) TransientException(org.neo4j.driver.v1.exceptions.TransientException) Value(org.neo4j.driver.v1.Value) NotFoundException(org.structr.api.NotFoundException) Record(org.neo4j.driver.v1.Record) ServiceUnavailableException(org.neo4j.driver.v1.exceptions.ServiceUnavailableException) RetryException(org.structr.api.RetryException) NetworkException(org.structr.api.NetworkException) NoSuchRecordException(org.neo4j.driver.v1.exceptions.NoSuchRecordException)

Example 2 with TransientException

use of org.neo4j.driver.v1.exceptions.TransientException in project structr by structr.

the class SessionTransaction method close.

@Override
public void close() {
    if (!success) {
        // be sure that they contain the correct values after a rollback.
        for (final EntityWrapper entity : modifiedEntities) {
            entity.stale();
        }
    } else {
        // so that the relationship caches are rebuilt.
        for (final EntityWrapper entity : modifiedEntities) {
            entity.clearCaches();
        }
    }
    // mark this transaction as closed BEFORE trying to actually close it
    // so that it is closed in case of a failure
    closed = true;
    try {
        tx.close();
        session.close();
    } catch (TransientException tex) {
        // transient exceptions can be retried
        throw new RetryException(tex);
    } finally {
        // so that the relationship caches are rebuilt.
        for (final EntityWrapper entity : modifiedEntities) {
            entity.onClose();
        }
        // make sure that the resources are freed
        if (session.isOpen()) {
            session.close();
        }
    }
}
Also used : TransientException(org.neo4j.driver.v1.exceptions.TransientException) EntityWrapper(org.structr.bolt.wrapper.EntityWrapper) RetryException(org.structr.api.RetryException)

Aggregations

TransientException (org.neo4j.driver.v1.exceptions.TransientException)2 RetryException (org.structr.api.RetryException)2 Record (org.neo4j.driver.v1.Record)1 StatementResult (org.neo4j.driver.v1.StatementResult)1 Value (org.neo4j.driver.v1.Value)1 NoSuchRecordException (org.neo4j.driver.v1.exceptions.NoSuchRecordException)1 ServiceUnavailableException (org.neo4j.driver.v1.exceptions.ServiceUnavailableException)1 NetworkException (org.structr.api.NetworkException)1 NotFoundException (org.structr.api.NotFoundException)1 QueryResult (org.structr.api.QueryResult)1 EntityWrapper (org.structr.bolt.wrapper.EntityWrapper)1