Search in sources :

Example 6 with TokenNameLookup

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();
    }
}
Also used : IndexingService(org.neo4j.kernel.impl.api.index.IndexingService) ProcedureException(org.neo4j.kernel.api.exceptions.ProcedureException) Label(org.neo4j.graphdb.Label) Context(org.neo4j.procedure.Context) Status(org.neo4j.kernel.api.exceptions.Status) Iterators.asSet(org.neo4j.helpers.collection.Iterators.asSet) StatementTokenNameLookup(org.neo4j.kernel.api.StatementTokenNameLookup) Statement(org.neo4j.kernel.api.Statement) IndexNotFoundKernelException(org.neo4j.kernel.api.exceptions.index.IndexNotFoundKernelException) ArrayList(java.util.ArrayList) TokenNameLookup(org.neo4j.kernel.api.TokenNameLookup) Procedure(org.neo4j.procedure.Procedure) TokenAccess(org.neo4j.kernel.impl.api.TokenAccess) ReadOperations(org.neo4j.kernel.api.ReadOperations) Set(java.util.Set) READ(org.neo4j.procedure.Mode.READ) Description(org.neo4j.procedure.Description) NewIndexDescriptor(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) Stream(java.util.stream.Stream) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) Iterators.asList(org.neo4j.helpers.collection.Iterators.asList) DependencyResolver(org.neo4j.graphdb.DependencyResolver) Name(org.neo4j.procedure.Name) RelationshipType(org.neo4j.graphdb.RelationshipType) Comparator(java.util.Comparator) StatementTokenNameLookup(org.neo4j.kernel.api.StatementTokenNameLookup) Statement(org.neo4j.kernel.api.Statement) ArrayList(java.util.ArrayList) IndexNotFoundKernelException(org.neo4j.kernel.api.exceptions.index.IndexNotFoundKernelException) ReadOperations(org.neo4j.kernel.api.ReadOperations) StatementTokenNameLookup(org.neo4j.kernel.api.StatementTokenNameLookup) TokenNameLookup(org.neo4j.kernel.api.TokenNameLookup) NewIndexDescriptor(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor) ProcedureException(org.neo4j.kernel.api.exceptions.ProcedureException) Description(org.neo4j.procedure.Description) Procedure(org.neo4j.procedure.Procedure)

Example 7 with TokenNameLookup

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);
}
Also used : StatementTokenNameLookup(org.neo4j.kernel.api.StatementTokenNameLookup) TokenNameLookup(org.neo4j.kernel.api.TokenNameLookup) StatementTokenNameLookup(org.neo4j.kernel.api.StatementTokenNameLookup)

Example 8 with TokenNameLookup

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);
}
Also used : TokenNameLookup(org.neo4j.kernel.api.TokenNameLookup) SchemaReadOperations(org.neo4j.kernel.impl.api.operations.SchemaReadOperations) Test(org.junit.Test)

Example 9 with TokenNameLookup

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);
}
Also used : TokenNameLookup(org.neo4j.kernel.api.TokenNameLookup) Test(org.junit.Test)

Example 10 with TokenNameLookup

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)));
}
Also used : TokenNameLookup(org.neo4j.kernel.api.TokenNameLookup) KernelExceptionUserMessageMatcher(org.neo4j.test.mockito.matcher.KernelExceptionUserMessageMatcher) Test(org.junit.Test)

Aggregations

TokenNameLookup (org.neo4j.kernel.api.TokenNameLookup)12 Test (org.junit.Test)7 StatementTokenNameLookup (org.neo4j.kernel.api.StatementTokenNameLookup)3 NewIndexDescriptor (org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor)3 KernelExceptionUserMessageMatcher (org.neo4j.test.mockito.matcher.KernelExceptionUserMessageMatcher)3 ArrayList (java.util.ArrayList)2 Comparator (java.util.Comparator)2 List (java.util.List)2 Set (java.util.Set)2 TimeUnit (java.util.concurrent.TimeUnit)2 Stream (java.util.stream.Stream)2 DependencyResolver (org.neo4j.graphdb.DependencyResolver)2 Label (org.neo4j.graphdb.Label)2 RelationshipType (org.neo4j.graphdb.RelationshipType)2 Iterators.asList (org.neo4j.helpers.collection.Iterators.asList)2 Iterators.asSet (org.neo4j.helpers.collection.Iterators.asSet)2 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)2 ReadOperations (org.neo4j.kernel.api.ReadOperations)2 Statement (org.neo4j.kernel.api.Statement)2 ProcedureException (org.neo4j.kernel.api.exceptions.ProcedureException)2