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;
}
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);
}
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);
}
}
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;
}
Aggregations