org.neo4j.driver.exceptions.NoSuchRecordException Java Examples

The following examples show how to use org.neo4j.driver.exceptions.NoSuchRecordException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FruitResource.java    From quarkus-quickstarts with Apache License 2.0 6 votes vote down vote up
@GET
@Path("{id}")
public CompletionStage<Response> getSingle(@PathParam("id") Long id) {
    AsyncSession session = driver.asyncSession();
    return session
            .readTransactionAsync(tx -> tx
                    .runAsync("MATCH (f:Fruit) WHERE id(f) = $id RETURN f", Values.parameters("id", id))
                    .thenCompose(fn -> fn.singleAsync()))
            .handle((record, exception) -> {
                if (exception != null) {
                    Throwable source = exception;
                    if (exception instanceof CompletionException) {
                        source = ((CompletionException) exception).getCause();
                    }
                    Status status = Status.INTERNAL_SERVER_ERROR;
                    if (source instanceof NoSuchRecordException) {
                        status = Status.NOT_FOUND;
                    }
                    return Response.status(status).build();
                } else {
                    return Response.ok(Fruit.from(record.get("f").asNode())).build();
                }
            })
            .thenCompose(response -> session.closeAsync().thenApply(signal -> response));
}
 
Example #2
Source File: ReactiveNeo4jTemplate.java    From sdn-rx with Apache License 2.0 5 votes vote down vote up
/**
 * @return A single result
 * @throws IncorrectResultSizeDataAccessException if there is no or more than one result
 */
public Mono<T> getSingleResult() {
	try {
		return fetchSpec.one();
	} catch (NoSuchRecordException e) {
		// This exception is thrown by the driver in both cases when there are 0 or 1+n records
		// So there has been an incorrect result size, but not to few results but to many.
		throw new IncorrectResultSizeDataAccessException(1);
	}
}
 
Example #3
Source File: Neo4jTemplate.java    From sdn-rx with Apache License 2.0 5 votes vote down vote up
public Optional<T> getSingleResult() {
	try {
		return fetchSpec.one();
	} catch (NoSuchRecordException e) {
		// This exception is thrown by the driver in both cases when there are 0 or 1+n records
		// So there has been an incorrect result size, but not to few results but to many.
		throw new IncorrectResultSizeDataAccessException(1);
	}
}
 
Example #4
Source File: MovieRepository.java    From sdn-rx with Apache License 2.0 5 votes vote down vote up
public Optional<Movie> findByTitle(String title) {
	try (Session session = driver.session()) {
		Record r = session.run("MATCH (m:Movie {title: $title}) RETURN m", Values.parameters("title", title))
			.single();
		Node movieNode = r.get("m").asNode();
		return Optional
			.of(new Movie(movieNode.id(), movieNode.get("title").asString(), movieNode.get("tagline").asString()));
	} catch (NoSuchRecordException e) {
		return Optional.empty();
	}
}
 
Example #5
Source File: StatementExecutor.java    From extended-objects with Apache License 2.0 5 votes vote down vote up
private Record getSingleResult(Result result) {
    try {
        return result.single();
    } catch (NoSuchRecordException e) {
        throw new XOException("Query returned no result.");
    } finally {
        result.consume();
    }
}