use of org.neo4j.kernel.api.exceptions.KernelException in project neo4j by neo4j.
the class GraphDbStructureGuide method showStructure.
private void showStructure(Statement statement, DbStructureVisitor visitor) {
ReadOperations read = statement.readOperations();
try {
showTokens(visitor, read);
showSchema(visitor, read);
showStatistics(visitor, read);
} catch (KernelException e) {
throw new IllegalStateException("Kernel exception when traversing database schema structure and statistics. This is not expected to happen.", e);
}
}
use of org.neo4j.kernel.api.exceptions.KernelException in project neo4j by neo4j.
the class IndexStatisticsTest method repeatCreateNamedPeopleFor.
private long[] repeatCreateNamedPeopleFor(int totalNumberOfPeople) throws Exception {
// Parallelize the creation of persons
final long[] nodes = new long[totalNumberOfPeople];
final int threads = 100;
final int peoplePerThread = totalNumberOfPeople / threads;
final ExecutorService service = Executors.newFixedThreadPool(threads);
final AtomicReference<KernelException> exception = new AtomicReference<>();
final List<Callable<Void>> jobs = new ArrayList<>(threads);
// Start threads that creates these people, relying on batched writes to speed things up
for (int i = 0; i < threads; i++) {
final int finalI = i;
jobs.add(new Callable<Void>() {
@Override
public Void call() throws Exception {
int offset = finalI * peoplePerThread;
while (offset < (finalI + 1) * peoplePerThread) {
try {
offset += createNamedPeople(nodes, offset);
} catch (KernelException e) {
exception.compareAndSet(null, e);
throw new RuntimeException(e);
}
}
return null;
}
});
}
for (Future<?> job : service.invokeAll(jobs)) {
job.get();
}
service.awaitTermination(1, TimeUnit.SECONDS);
service.shutdown();
// Make any KernelException thrown from a creation thread visible in the main thread
Exception ex = exception.get();
if (ex != null) {
throw ex;
}
return nodes;
}
use of org.neo4j.kernel.api.exceptions.KernelException in project neo4j by neo4j.
the class GraphDatabaseFacade method nodesByLabelAndProperty.
private ResourceIterator<Node> nodesByLabelAndProperty(Label myLabel, String key, Object value) {
Statement statement = spi.currentStatement();
ReadOperations readOps = statement.readOperations();
int propertyId = readOps.propertyKeyGetForName(key);
int labelId = readOps.labelGetForName(myLabel.name());
if (propertyId == NO_SUCH_PROPERTY_KEY || labelId == NO_SUCH_LABEL) {
statement.close();
return emptyIterator();
}
NewIndexDescriptor descriptor = findAnyIndexByLabelAndProperty(readOps, propertyId, labelId);
try {
if (null != descriptor) {
// Ha! We found an index - let's use it to find matching nodes
IndexQuery.ExactPredicate query = IndexQuery.exact(descriptor.schema().getPropertyId(), value);
return map2nodes(readOps.indexQuery(descriptor, query), statement);
}
} catch (KernelException e) {
// weird at this point but ignore and fallback to a label scan
}
return getNodesByLabelAndPropertyWithoutIndex(propertyId, value, statement, labelId);
}
use of org.neo4j.kernel.api.exceptions.KernelException in project neo4j by neo4j.
the class ExceptionRepresentationTest method shouldRenderErrorsWithNeo4jStatusCode.
@Test
public void shouldRenderErrorsWithNeo4jStatusCode() throws Exception {
// Given
ExceptionRepresentation rep = new ExceptionRepresentation(new KernelException(UnknownError, "Hello") {
});
// When
JsonNode out = serialize(rep);
// Then
assertThat(out.get("errors").get(0).get("code").asText(), equalTo("Neo.DatabaseError.General.UnknownError"));
assertThat(out.get("errors").get(0).get("message").asText(), equalTo("Hello"));
}
use of org.neo4j.kernel.api.exceptions.KernelException in project neo4j by neo4j.
the class ExceptionRepresentationTest method shoudExcludeLegacyFormatIfAsked.
@Test
public void shoudExcludeLegacyFormatIfAsked() throws Exception {
// Given
ExceptionRepresentation rep = new ExceptionRepresentation(new KernelException(UnknownError, "Hello") {
}, /*legacy*/
false);
// When
JsonNode out = serialize(rep);
// Then
assertThat(out.get("errors").get(0).get("code").asText(), equalTo("Neo.DatabaseError.General.UnknownError"));
assertThat(out.get("errors").get(0).get("message").asText(), equalTo("Hello"));
assertThat(out.has("message"), equalTo(false));
}
Aggregations