Search in sources :

Example 1 with NetworkException

use of org.structr.api.NetworkException in project structr by structr.

the class TransactionCommand method beginTx.

public TransactionCommand beginTx() throws FrameworkException {
    final DatabaseService graphDb = (DatabaseService) arguments.get("graphDb");
    TransactionReference tx = transactions.get();
    if (graphDb != null) {
        if (tx == null) {
            try {
                // start new transaction
                tx = new TransactionReference(graphDb.beginTx());
            } catch (NetworkException nex) {
                throw new DatabaseServiceNetworkException(503, nex.getMessage());
            }
            queues.set(new ModificationQueue());
            buffers.set(new ErrorBuffer());
            transactions.set(tx);
            currentCommand.set(this);
        }
        // increase depth
        tx.begin();
    } else {
        throw new DatabaseServiceNotAvailableException(503, "Database service is not available, ensure the database is running and that there is a working network connection to it");
    }
    return this;
}
Also used : ErrorBuffer(org.structr.common.error.ErrorBuffer) DatabaseServiceNotAvailableException(org.structr.common.error.DatabaseServiceNotAvailableException) DatabaseService(org.structr.api.DatabaseService) NetworkException(org.structr.api.NetworkException) DatabaseServiceNetworkException(org.structr.common.error.DatabaseServiceNetworkException) DatabaseServiceNetworkException(org.structr.common.error.DatabaseServiceNetworkException)

Example 2 with NetworkException

use of org.structr.api.NetworkException in project structr by structr.

the class Factory method page.

protected Result page(final QueryResult<S> input, final int offset, final int pageSize) throws FrameworkException {
    final SecurityContext securityContext = factoryProfile.getSecurityContext();
    final boolean dontCheckCount = securityContext.ignoreResultCount();
    final List<T> nodes = new ArrayList<>();
    int overallCount = 0;
    int position = 0;
    int count = 0;
    try (final QueryResult<S> tmp = input) {
        for (final S item : tmp) {
            final T n = instantiate(item);
            if (n != null) {
                overallCount++;
                position++;
                if (disablePaging || (position > offset && position <= offset + pageSize)) {
                    nodes.add(n);
                    // stop if we got enough nodes
                    if (++count == pageSize && dontCheckCount && !disablePaging) {
                        break;
                    }
                }
            }
        }
    } catch (NetworkException nex) {
        throw new FrameworkException(503, nex.getMessage());
    }
    // The overall count may be inaccurate
    return new Result(nodes, overallCount, true, false);
}
Also used : FrameworkException(org.structr.common.error.FrameworkException) SecurityContext(org.structr.common.SecurityContext) ArrayList(java.util.ArrayList) NetworkException(org.structr.api.NetworkException) QueryResult(org.structr.api.QueryResult) Result(org.structr.core.Result)

Example 3 with NetworkException

use of org.structr.api.NetworkException 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 4 with NetworkException

use of org.structr.api.NetworkException in project structr by structr.

the class BoltDatabaseService method beginTx.

@Override
public Transaction beginTx() {
    SessionTransaction session = sessions.get();
    if (session == null || session.isClosed()) {
        try {
            session = new SessionTransaction(this, driver.session());
            sessions.set(session);
        } catch (ServiceUnavailableException ex) {
            throw new NetworkException(ex.getMessage(), ex);
        } catch (ClientException cex) {
            logger.warn("Cannot connect to Neo4j database server at {}: {}", databaseUrl, cex.getMessage());
        }
    }
    return session;
}
Also used : ServiceUnavailableException(org.neo4j.driver.v1.exceptions.ServiceUnavailableException) ClientException(org.neo4j.driver.v1.exceptions.ClientException) NetworkException(org.structr.api.NetworkException)

Aggregations

NetworkException (org.structr.api.NetworkException)4 ServiceUnavailableException (org.neo4j.driver.v1.exceptions.ServiceUnavailableException)2 QueryResult (org.structr.api.QueryResult)2 ArrayList (java.util.ArrayList)1 Record (org.neo4j.driver.v1.Record)1 StatementResult (org.neo4j.driver.v1.StatementResult)1 Value (org.neo4j.driver.v1.Value)1 ClientException (org.neo4j.driver.v1.exceptions.ClientException)1 NoSuchRecordException (org.neo4j.driver.v1.exceptions.NoSuchRecordException)1 TransientException (org.neo4j.driver.v1.exceptions.TransientException)1 DatabaseService (org.structr.api.DatabaseService)1 NotFoundException (org.structr.api.NotFoundException)1 RetryException (org.structr.api.RetryException)1 SecurityContext (org.structr.common.SecurityContext)1 DatabaseServiceNetworkException (org.structr.common.error.DatabaseServiceNetworkException)1 DatabaseServiceNotAvailableException (org.structr.common.error.DatabaseServiceNotAvailableException)1 ErrorBuffer (org.structr.common.error.ErrorBuffer)1 FrameworkException (org.structr.common.error.FrameworkException)1 Result (org.structr.core.Result)1