Search in sources :

Example 6 with SchemaReadCore

use of org.neo4j.internal.kernel.api.SchemaReadCore in project neo4j by neo4j.

the class BuiltInProcedures method schemaStatements.

@Deprecated(since = "4.2.0", forRemoval = true)
@SystemProcedure
@Description("List all statements for creating and dropping existing indexes and constraints. " + "Note that only index types introduced before Neo4j 4.3 are included.")
@Procedure(name = "db.schemaStatements", mode = READ, deprecatedBy = "SHOW INDEXES YIELD * command and SHOW CONSTRAINTS YIELD * command")
public Stream<SchemaStatementResult> schemaStatements() throws ProcedureException {
    if (callContext.isSystemDatabase()) {
        return Stream.empty();
    }
    SchemaReadCore schemaRead = kernelTransaction.schemaRead().snapshot();
    final TokenRead tokenRead = kernelTransaction.tokenRead();
    return SchemaStatementProcedure.createSchemaStatementResults(schemaRead, tokenRead).stream();
}
Also used : SchemaReadCore(org.neo4j.internal.kernel.api.SchemaReadCore) TokenRead(org.neo4j.internal.kernel.api.TokenRead) Description(org.neo4j.procedure.Description) SystemProcedure(org.neo4j.kernel.api.procedure.SystemProcedure) SystemProcedure(org.neo4j.kernel.api.procedure.SystemProcedure) Procedure(org.neo4j.procedure.Procedure)

Example 7 with SchemaReadCore

use of org.neo4j.internal.kernel.api.SchemaReadCore in project neo4j by neo4j.

the class BuiltInProcedures method listIndexes.

@Deprecated(since = "4.2.0", forRemoval = true)
@SystemProcedure
@Description("List all indexes in the database.")
@Procedure(name = "db.indexes", mode = READ, deprecatedBy = "SHOW INDEXES command")
public Stream<IndexResult> listIndexes() {
    if (callContext.isSystemDatabase()) {
        return Stream.empty();
    }
    TokenRead tokenRead = kernelTransaction.tokenRead();
    IndexingService indexingService = resolver.resolveDependency(IndexingService.class);
    SchemaReadCore schemaRead = kernelTransaction.schemaRead().snapshot();
    List<IndexDescriptor> indexes = asList(schemaRead.indexesGetAll());
    List<IndexResult> result = new ArrayList<>();
    for (IndexDescriptor index : indexes) {
        IndexResult indexResult;
        indexResult = asIndexResult(tokenRead, schemaRead, index);
        result.add(indexResult);
    }
    result.sort(Comparator.comparing(r -> r.name));
    return result.stream();
}
Also used : Mode(org.neo4j.procedure.Mode) Arrays(java.util.Arrays) StoreIdProvider(org.neo4j.storageengine.api.StoreIdProvider) SCHEMA(org.neo4j.procedure.Mode.SCHEMA) Status(org.neo4j.kernel.api.exceptions.Status) Iterators.asList(org.neo4j.internal.helpers.collection.Iterators.asList) TokenNameLookup(org.neo4j.common.TokenNameLookup) Config(org.neo4j.configuration.Config) ProcedureException(org.neo4j.internal.kernel.api.exceptions.ProcedureException) Value(org.neo4j.values.storable.Value) ProceduresTimeFormatHelper.formatTime(org.neo4j.procedure.builtin.ProceduresTimeFormatHelper.formatTime) ConstraintDescriptor(org.neo4j.internal.schema.ConstraintDescriptor) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) SystemProcedure(org.neo4j.kernel.api.procedure.SystemProcedure) SchemaReadCore(org.neo4j.internal.kernel.api.SchemaReadCore) IndexNotFoundKernelException(org.neo4j.internal.kernel.api.exceptions.schema.IndexNotFoundKernelException) Map(java.util.Map) SecurityContext(org.neo4j.internal.kernel.api.security.SecurityContext) Transaction(org.neo4j.graphdb.Transaction) IndexProviderDescriptor(org.neo4j.internal.schema.IndexProviderDescriptor) Procedure(org.neo4j.procedure.Procedure) PopulationProgress(org.neo4j.internal.kernel.api.PopulationProgress) LABELS(org.neo4j.kernel.impl.api.TokenAccess.LABELS) Collectors(java.util.stream.Collectors) ZoneId(java.time.ZoneId) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) AccessMode(org.neo4j.internal.kernel.api.security.AccessMode) List(java.util.List) Stream(java.util.stream.Stream) SchemaDescriptor(org.neo4j.internal.schema.SchemaDescriptor) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) Name(org.neo4j.procedure.Name) RelationshipType(org.neo4j.graphdb.RelationshipType) StoreIdDecodeUtils.decodeId(org.neo4j.procedure.builtin.StoreIdDecodeUtils.decodeId) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) Admin(org.neo4j.procedure.Admin) IndexingService(org.neo4j.kernel.impl.api.index.IndexingService) Label(org.neo4j.graphdb.Label) QueryExecutionEngine(org.neo4j.kernel.impl.query.QueryExecutionEngine) GraphDatabaseSettings(org.neo4j.configuration.GraphDatabaseSettings) InternalIndexState(org.neo4j.internal.kernel.api.InternalIndexState) Context(org.neo4j.procedure.Context) TokenRead(org.neo4j.internal.kernel.api.TokenRead) HashMap(java.util.HashMap) Node(org.neo4j.graphdb.Node) ArrayList(java.util.ArrayList) Iterators.stream(org.neo4j.internal.helpers.collection.Iterators.stream) DependencyResolver(org.neo4j.common.DependencyResolver) RELATIONSHIP_TYPES(org.neo4j.kernel.impl.api.TokenAccess.RELATIONSHIP_TYPES) READ(org.neo4j.procedure.Mode.READ) Description(org.neo4j.procedure.Description) TimeUnit(java.util.concurrent.TimeUnit) PROPERTY_KEYS(org.neo4j.kernel.impl.api.TokenAccess.PROPERTY_KEYS) ProcedureCallContext(org.neo4j.internal.kernel.api.procs.ProcedureCallContext) Relationship(org.neo4j.graphdb.Relationship) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) Comparator(java.util.Comparator) IndexingService(org.neo4j.kernel.impl.api.index.IndexingService) ArrayList(java.util.ArrayList) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) TokenRead(org.neo4j.internal.kernel.api.TokenRead) SchemaReadCore(org.neo4j.internal.kernel.api.SchemaReadCore) Description(org.neo4j.procedure.Description) SystemProcedure(org.neo4j.kernel.api.procedure.SystemProcedure) SystemProcedure(org.neo4j.kernel.api.procedure.SystemProcedure) Procedure(org.neo4j.procedure.Procedure)

Example 8 with SchemaReadCore

use of org.neo4j.internal.kernel.api.SchemaReadCore in project neo4j by neo4j.

the class SchemaReadWriteTestBase method shouldSeeUniqueConstraintFromTransaction.

@Test
void shouldSeeUniqueConstraintFromTransaction() throws Exception {
    ConstraintDescriptor existing;
    try (KernelTransaction transaction = beginTransaction()) {
        existing = transaction.schemaWrite().uniquePropertyConstraintCreate(uniqueForSchema(forLabel(label, prop1)).withName("existing constraint"));
        transaction.commit();
    }
    try (KernelTransaction transaction = beginTransaction()) {
        SchemaReadCore before = transaction.schemaRead().snapshot();
        ConstraintDescriptor newConstraint = transaction.schemaWrite().uniquePropertyConstraintCreate(uniqueForSchema(forLabel(label, prop2)).withName("new constraint"));
        SchemaRead schemaRead = transaction.schemaRead();
        SchemaReadCore after = schemaRead.snapshot();
        assertTrue(schemaRead.constraintExists(existing));
        assertTrue(schemaRead.constraintExists(newConstraint));
        assertThat(asList(schemaRead.constraintsGetForLabel(label))).contains(existing, newConstraint);
        assertThat(asList(before.constraintsGetForLabel(label))).contains(existing, newConstraint);
        assertThat(asList(after.constraintsGetForLabel(label))).contains(existing, newConstraint);
        assertThat(before.constraintGetForName("existing constraint")).isEqualTo(existing);
        assertThat(after.constraintGetForName("existing constraint")).isEqualTo(existing);
        assertThat(before.constraintGetForName("new constraint")).isEqualTo(newConstraint);
        assertThat(after.constraintGetForName("new constraint")).isEqualTo(newConstraint);
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) SchemaRead(org.neo4j.internal.kernel.api.SchemaRead) ConstraintDescriptor(org.neo4j.internal.schema.ConstraintDescriptor) SchemaReadCore(org.neo4j.internal.kernel.api.SchemaReadCore) Test(org.junit.jupiter.api.Test)

Example 9 with SchemaReadCore

use of org.neo4j.internal.kernel.api.SchemaReadCore in project neo4j by neo4j.

the class SchemaReadWriteTestBase method shouldNotSeeDroppedUniqueConstraintFromTransaction.

@Test
void shouldNotSeeDroppedUniqueConstraintFromTransaction() throws Exception {
    ConstraintDescriptor existing;
    try (KernelTransaction transaction = beginTransaction()) {
        existing = transaction.schemaWrite().uniquePropertyConstraintCreate(uniqueForSchema(forLabel(label, prop1)));
        transaction.commit();
    }
    try (KernelTransaction transaction = beginTransaction()) {
        SchemaReadCore before = transaction.schemaRead().snapshot();
        transaction.schemaWrite().constraintDrop(existing);
        SchemaRead schemaRead = transaction.schemaRead();
        assertFalse(schemaRead.constraintExists(existing));
        assertThat(asList(schemaRead.constraintsGetForLabel(label))).isEmpty();
        assertThat(asList(schemaRead.snapshot().constraintsGetForLabel(label))).isEmpty();
        assertThat(asList(before.constraintsGetForLabel(label))).isEmpty();
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) SchemaRead(org.neo4j.internal.kernel.api.SchemaRead) ConstraintDescriptor(org.neo4j.internal.schema.ConstraintDescriptor) SchemaReadCore(org.neo4j.internal.kernel.api.SchemaReadCore) Test(org.junit.jupiter.api.Test)

Example 10 with SchemaReadCore

use of org.neo4j.internal.kernel.api.SchemaReadCore in project neo4j by neo4j.

the class SchemaReadWriteTestBase method shouldNotSeeDroppedIndexFromTransactionInSnapshot.

@Test
void shouldNotSeeDroppedIndexFromTransactionInSnapshot() throws Exception {
    IndexDescriptor index;
    try (KernelTransaction transaction = beginTransaction()) {
        index = transaction.schemaWrite().indexCreate(forLabel(label, prop1), "my index");
        transaction.commit();
    }
    try (KernelTransaction transaction = beginTransaction()) {
        SchemaReadCore schemaReadBefore = transaction.schemaRead().snapshot();
        transaction.schemaWrite().indexDrop(index);
        SchemaReadCore schemaReadAfter = transaction.schemaRead().snapshot();
        assertFalse(schemaReadBefore.index(forLabel(label, prop2)).hasNext());
        assertFalse(schemaReadAfter.index(forLabel(label, prop2)).hasNext());
        assertThat(schemaReadBefore.indexGetForName("my index")).isEqualTo(NO_INDEX);
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) SchemaReadCore(org.neo4j.internal.kernel.api.SchemaReadCore) Test(org.junit.jupiter.api.Test)

Aggregations

SchemaReadCore (org.neo4j.internal.kernel.api.SchemaReadCore)32 Test (org.junit.jupiter.api.Test)27 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)21 ConstraintDescriptor (org.neo4j.internal.schema.ConstraintDescriptor)17 IndexDescriptor (org.neo4j.internal.schema.IndexDescriptor)17 TokenRead (org.neo4j.internal.kernel.api.TokenRead)13 InternalIndexState (org.neo4j.internal.kernel.api.InternalIndexState)10 SchemaRead (org.neo4j.internal.kernel.api.SchemaRead)9 ProcedureException (org.neo4j.internal.kernel.api.exceptions.ProcedureException)5 SystemProcedure (org.neo4j.kernel.api.procedure.SystemProcedure)4 IndexingService (org.neo4j.kernel.impl.api.index.IndexingService)4 Description (org.neo4j.procedure.Description)4 Procedure (org.neo4j.procedure.Procedure)4 ArrayList (java.util.ArrayList)3 Arrays (java.util.Arrays)3 HashMap (java.util.HashMap)3 List (java.util.List)3 Map (java.util.Map)3 DependencyResolver (org.neo4j.common.DependencyResolver)3 Config (org.neo4j.configuration.Config)3