use of org.neo4j.driver.exceptions.NoSuchRecordException in project neo4j-java-driver by neo4j.
the class AsyncTransactionIT method shouldFailSingleWithMultiRecordCursor.
@Test
void shouldFailSingleWithMultiRecordCursor() {
AsyncTransaction tx = await(session.beginTransactionAsync());
ResultCursor cursor = await(tx.runAsync("UNWIND ['a', 'b'] AS x RETURN x"));
NoSuchRecordException e = assertThrows(NoSuchRecordException.class, () -> await(cursor.singleAsync()));
assertThat(e.getMessage(), startsWith("Expected a result with a single record"));
}
use of org.neo4j.driver.exceptions.NoSuchRecordException in project neo4j-java-driver by neo4j.
the class AsyncResultCursorImplTest method shouldFailWhenAskedForSingleRecordButResultIsEmpty.
@Test
void shouldFailWhenAskedForSingleRecordButResultIsEmpty() {
PullAllResponseHandler pullAllHandler = mock(PullAllResponseHandler.class);
when(pullAllHandler.nextAsync()).thenReturn(completedWithNull());
AsyncResultCursorImpl cursor = newCursor(pullAllHandler);
NoSuchRecordException e = assertThrows(NoSuchRecordException.class, () -> await(cursor.singleAsync()));
assertThat(e.getMessage(), containsString("result is empty"));
}
use of org.neo4j.driver.exceptions.NoSuchRecordException in project neo4j-java-driver by neo4j.
the class AsyncSessionIT method shouldFailSingleWithEmptyCursor.
@Test
void shouldFailSingleWithEmptyCursor() {
ResultCursor cursor = await(session.runAsync("CREATE ()"));
NoSuchRecordException e = assertThrows(NoSuchRecordException.class, () -> await(cursor.singleAsync()));
assertThat(e.getMessage(), containsString("result is empty"));
}
use of org.neo4j.driver.exceptions.NoSuchRecordException in project multiverse-controller by multiverse-nms.
the class Neo4jWrapper method handleError.
private <T> void handleError(Throwable error, Handler<AsyncResult<T>> resultHandler) {
// NoSuchRecordException
if (error instanceof Neo4jException) {
Neo4jException ne = (Neo4jException) error;
String code = ne.code();
logger.error("Neo4jException: " + code);
String errorMessage = "INTERNAL";
if (code.contains("NotFound")) {
errorMessage = "NOT_FOUND";
} else if (code.contains("DatabaseFound")) {
errorMessage = "CONFLICT";
} else if (code.contains("Invalid")) {
errorMessage = "INVALID_ARGUMENTS";
} else if (code.contains("Constraint")) {
errorMessage = "CONFLICT";
}
resultHandler.handle(Future.failedFuture(errorMessage));
} else if (error instanceof NoSuchRecordException) {
logger.error("Neo4j NoSuchRecord: " + error.getMessage());
resultHandler.handle(Future.failedFuture("NOT_FOUND"));
} else {
logger.error("Exception: " + error.getMessage());
resultHandler.handle(Future.failedFuture("INTERNAL"));
}
}
use of org.neo4j.driver.exceptions.NoSuchRecordException in project neo4j-migrations by michael-simons.
the class Migrations method getLastAppliedVersion.
private Optional<MigrationVersion> getLastAppliedVersion() {
try (Session session = context.getSchemaSession()) {
Node lastMigration = session.readTransaction(tx -> tx.run("MATCH (l:__Neo4jMigration) WHERE coalesce(l.migrationTarget,'<default>') = coalesce($migrationTarget,'<default>') AND NOT (l)-[:MIGRATED_TO]->(:__Neo4jMigration) RETURN l", Collections.singletonMap(PROPERTY_MIGRATION_TARGET, config.getMigrationTargetIn(context).orElse(null))).single().get(0).asNode());
String version = lastMigration.get("version").asString();
String description = lastMigration.get("description").asString();
return Optional.of(MigrationVersion.withValueAndDescription(version, description));
} catch (NoSuchRecordException e) {
return Optional.empty();
}
}
Aggregations