Search in sources :

Example 31 with TokenRead

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

the class BuiltInProcedures method indexDetails.

@Deprecated(since = "4.2.0", forRemoval = true)
@SystemProcedure
@Description("Detailed description of specific index.")
@Procedure(name = "db.indexDetails", mode = READ, deprecatedBy = "SHOW INDEXES YIELD * command")
public Stream<IndexDetailResult> indexDetails(@Name("indexName") String indexName) throws ProcedureException {
    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());
    IndexDescriptor index = null;
    for (IndexDescriptor candidate : indexes) {
        if (candidate.getName().equals(indexName)) {
            index = candidate;
            break;
        }
    }
    if (index == null) {
        throw new ProcedureException(Status.Schema.IndexNotFound, "Could not find index with name \"" + indexName + "\"");
    }
    final IndexDetailResult indexDetailResult = asIndexDetails(tokenRead, schemaRead, index);
    return Stream.of(indexDetailResult);
}
Also used : IndexingService(org.neo4j.kernel.impl.api.index.IndexingService) ProcedureException(org.neo4j.internal.kernel.api.exceptions.ProcedureException) 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 32 with TokenRead

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

the class UniqueIndexSeekIT method lockNodeUsingUniqueIndexSeek.

private static void lockNodeUsingUniqueIndexSeek(GraphDatabaseAPI database, String nameProperty) throws KernelException {
    try (Transaction transaction = database.beginTx()) {
        KernelTransaction kernelTransaction = ((InternalTransaction) transaction).kernelTransaction();
        TokenRead tokenRead = kernelTransaction.tokenRead();
        Read dataRead = kernelTransaction.dataRead();
        int propertyId = tokenRead.propertyKey(nameProperty);
        IndexDescriptor indexReference = kernelTransaction.schemaRead().indexGetForName(CONSTRAINT_NAME);
        try (NodeValueIndexCursor cursor = kernelTransaction.cursors().allocateNodeValueIndexCursor(kernelTransaction.cursorContext(), kernelTransaction.memoryTracker())) {
            dataRead.lockingNodeUniqueIndexSeek(indexReference, cursor, PropertyIndexQuery.ExactPredicate.exact(propertyId, "value"));
        }
        transaction.commit();
    }
}
Also used : TokenRead(org.neo4j.internal.kernel.api.TokenRead) Read(org.neo4j.internal.kernel.api.Read) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) Transaction(org.neo4j.graphdb.Transaction) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) NodeValueIndexCursor(org.neo4j.internal.kernel.api.NodeValueIndexCursor) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) TokenRead(org.neo4j.internal.kernel.api.TokenRead)

Example 33 with TokenRead

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

the class TxStateTransactionDataSnapshot method takeSnapshot.

private void takeSnapshot(MemoryTracker memoryTracker) {
    var cursorContext = transaction.cursorContext();
    try (StorageNodeCursor node = store.allocateNodeCursor(cursorContext);
        StoragePropertyCursor properties = store.allocatePropertyCursor(cursorContext, memoryTracker)) {
        TokenRead tokenRead = transaction.tokenRead();
        snapshotRemovedNodes(memoryTracker, node, properties, tokenRead);
        snapshotRemovedRelationships(memoryTracker, properties, tokenRead);
        snapshotModifiedNodes(memoryTracker, node, properties, tokenRead);
        snapshotModifiedRelationships(memoryTracker, properties, tokenRead);
    } catch (PropertyKeyIdNotFoundKernelException e) {
        throw new IllegalStateException("An entity that does not exist was modified.", e);
    }
}
Also used : StoragePropertyCursor(org.neo4j.storageengine.api.StoragePropertyCursor) StorageNodeCursor(org.neo4j.storageengine.api.StorageNodeCursor) TokenRead(org.neo4j.internal.kernel.api.TokenRead) PropertyKeyIdNotFoundKernelException(org.neo4j.internal.kernel.api.exceptions.PropertyKeyIdNotFoundKernelException)

Example 34 with TokenRead

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

the class BatchInsertIndexTest method batchInserterShouldUseConfiguredIndexProvider.

@ParameterizedTest
@EnumSource(SchemaIndex.class)
void batchInserterShouldUseConfiguredIndexProvider(SchemaIndex schemaIndex) throws Exception {
    configure(schemaIndex);
    BatchInserter inserter = newBatchInserter();
    inserter.createDeferredSchemaIndex(LABEL_ONE).on("key").create();
    inserter.shutdown();
    GraphDatabaseService db = startGraphDatabaseServiceAndAwaitIndexes();
    try (Transaction tx = db.beginTx()) {
        KernelTransaction kernelTransaction = ((InternalTransaction) tx).kernelTransaction();
        TokenRead tokenRead = kernelTransaction.tokenRead();
        SchemaRead schemaRead = kernelTransaction.schemaRead();
        int labelId = tokenRead.nodeLabel(LABEL_ONE.name());
        int propertyId = tokenRead.propertyKey("key");
        IndexDescriptor index = single(schemaRead.index(SchemaDescriptor.forLabel(labelId, propertyId)));
        assertTrue(schemaIndex.providerName().contains(index.getIndexProvider().getKey()), unexpectedIndexProviderMessage(index));
        assertTrue(schemaIndex.providerName().contains(index.getIndexProvider().getVersion()), unexpectedIndexProviderMessage(index));
        tx.commit();
    }
}
Also used : BatchInserter(org.neo4j.batchinsert.BatchInserter) GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) SchemaRead(org.neo4j.internal.kernel.api.SchemaRead) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) Transaction(org.neo4j.graphdb.Transaction) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) TokenRead(org.neo4j.internal.kernel.api.TokenRead) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 35 with TokenRead

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

the class SchemaImpl method getIndexes.

@Override
public Iterable<IndexDefinition> getIndexes(final Label label) {
    transaction.assertOpen();
    TokenRead tokenRead = transaction.tokenRead();
    SchemaRead schemaRead = transaction.schemaRead();
    List<IndexDefinition> definitions = new ArrayList<>();
    int labelId = tokenRead.nodeLabel(label.name());
    if (labelId == TokenRead.NO_TOKEN) {
        return emptyList();
    }
    Iterator<IndexDescriptor> indexes = schemaRead.indexesGetForLabel(labelId);
    addDefinitions(definitions, tokenRead, IndexDescriptor.sortByType(indexes));
    return definitions;
}
Also used : SchemaRead(org.neo4j.internal.kernel.api.SchemaRead) IndexDefinition(org.neo4j.graphdb.schema.IndexDefinition) ArrayList(java.util.ArrayList) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) TokenRead(org.neo4j.internal.kernel.api.TokenRead)

Aggregations

TokenRead (org.neo4j.internal.kernel.api.TokenRead)59 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)42 IndexDescriptor (org.neo4j.internal.schema.IndexDescriptor)27 Test (org.junit.jupiter.api.Test)19 InternalTransaction (org.neo4j.kernel.impl.coreapi.InternalTransaction)18 ArrayList (java.util.ArrayList)13 HashMap (java.util.HashMap)13 Transaction (org.neo4j.graphdb.Transaction)13 SchemaReadCore (org.neo4j.internal.kernel.api.SchemaReadCore)13 Label (org.neo4j.graphdb.Label)12 SchemaRead (org.neo4j.internal.kernel.api.SchemaRead)11 ConstraintDescriptor (org.neo4j.internal.schema.ConstraintDescriptor)11 InternalIndexState (org.neo4j.internal.kernel.api.InternalIndexState)10 RelationshipType (org.neo4j.graphdb.RelationshipType)7 PropertyKeyIdNotFoundKernelException (org.neo4j.internal.kernel.api.exceptions.PropertyKeyIdNotFoundKernelException)6 Arrays (java.util.Arrays)5 List (java.util.List)5 Map (java.util.Map)5 Collectors (java.util.stream.Collectors)5 Stream (java.util.stream.Stream)5