use of org.neo4j.kernel.api.TokenNameLookup in project neo4j by neo4j.
the class BuiltInProcedures method listIndexes.
@Description("List all indexes in the database.")
@Procedure(name = "db.indexes", mode = READ)
public Stream<IndexResult> listIndexes() throws ProcedureException {
try (Statement statement = tx.acquireStatement()) {
ReadOperations operations = statement.readOperations();
TokenNameLookup tokens = new StatementTokenNameLookup(operations);
List<NewIndexDescriptor> indexes = asList(operations.indexesGetAll());
Set<NewIndexDescriptor> uniqueIndexes = asSet(operations.uniqueIndexesGetAll());
indexes.addAll(uniqueIndexes);
indexes.sort(Comparator.comparing(a -> a.userDescription(tokens)));
ArrayList<IndexResult> result = new ArrayList<>();
for (NewIndexDescriptor index : indexes) {
try {
String type;
if (uniqueIndexes.contains(index)) {
type = IndexType.NODE_UNIQUE_PROPERTY.typeName();
} else {
type = IndexType.NODE_LABEL_PROPERTY.typeName();
}
result.add(new IndexResult("INDEX ON " + index.schema().userDescription(tokens), operations.indexGetState(index).toString(), type));
} catch (IndexNotFoundKernelException e) {
throw new ProcedureException(Status.Schema.IndexNotFound, e, "No index on ", index.userDescription(tokens));
}
}
return result.stream();
}
}
use of org.neo4j.kernel.api.TokenNameLookup in project neo4j by neo4j.
the class GraphDbStructureGuide method showSchema.
private void showSchema(DbStructureVisitor visitor, ReadOperations read) throws IndexNotFoundKernelException {
TokenNameLookup nameLookup = new StatementTokenNameLookup(read);
showIndices(visitor, read, nameLookup);
showUniqueIndices(visitor, read, nameLookup);
showUniqueConstraints(visitor, read, nameLookup);
}
use of org.neo4j.kernel.api.TokenNameLookup in project neo4j by neo4j.
the class OperationsFacadeTest method testThrowExceptionWhenUniqueIndexNotFound.
@Test
public void testThrowExceptionWhenUniqueIndexNotFound() throws SchemaRuleNotFoundException, DuplicateSchemaRuleException {
SchemaReadOperations readOperations = setupSchemaReadOperations();
TokenNameLookup tokenNameLookup = getDefaultTokenNameLookup();
Mockito.when(readOperations.uniqueIndexesGetForLabel(Mockito.any(KernelStatement.class), anyInt())).thenReturn(Iterators.emptyIterator());
expectedException.expect(SchemaRuleNotFoundException.class);
expectedException.expect(new KernelExceptionUserMessageMatcher<>(tokenNameLookup, "No constraint index was found for :Label1(Prop1)."));
operationsFacade.uniqueIndexGetForLabelAndPropertyKey(descriptor);
}
use of org.neo4j.kernel.api.TokenNameLookup in project neo4j by neo4j.
the class OperationsFacadeTest method testThrowExceptionWhenIndexNotFoundByLabelAndProperty.
@Test
public void testThrowExceptionWhenIndexNotFoundByLabelAndProperty() throws SchemaRuleNotFoundException {
setupSchemaReadOperations();
TokenNameLookup tokenNameLookup = getDefaultTokenNameLookup();
expectedException.expect(SchemaRuleNotFoundException.class);
expectedException.expect(new KernelExceptionUserMessageMatcher<>(tokenNameLookup, "No index was found for :Label1(Prop1)."));
operationsFacade.indexGetForLabelAndPropertyKey(descriptor);
}
use of org.neo4j.kernel.api.TokenNameLookup in project neo4j by neo4j.
the class SchemaStorageTest method shouldThrowExceptionOnNodeRuleNotFound.
@Test
public void shouldThrowExceptionOnNodeRuleNotFound() throws DuplicateSchemaRuleException, SchemaRuleNotFoundException {
// GIVEN
TokenNameLookup tokenNameLookup = getDefaultTokenNameLookup();
// EXPECT
expectedException.expect(SchemaRuleNotFoundException.class);
expectedException.expect(new KernelExceptionUserMessageMatcher(tokenNameLookup, "No node property existence constraint was found for :Label1(prop1)."));
// WHEN
storage.constraintsGetSingle(ConstraintDescriptorFactory.existsForLabel(labelId(LABEL1), propId(PROP1)));
}
Aggregations