Search in sources :

Example 26 with TokenRead

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

the class RelationshipEntity method getAllProperties.

public Map<String, Object> getAllProperties(PropertyCursor propertyCursor) {
    KernelTransaction transaction = internalTransaction.kernelTransaction();
    Map<String, Object> properties = new HashMap<>();
    try {
        RelationshipScanCursor relationships = transaction.ambientRelationshipCursor();
        TokenRead token = transaction.tokenRead();
        singleRelationship(transaction, relationships);
        relationships.properties(propertyCursor);
        while (propertyCursor.next()) {
            properties.put(token.propertyKeyName(propertyCursor.propertyKey()), propertyCursor.propertyValue().asObjectCopy());
        }
    } catch (PropertyKeyIdNotFoundKernelException e) {
        throw new IllegalStateException("Property key retrieved through kernel API should exist.", e);
    }
    return properties;
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) RelationshipScanCursor(org.neo4j.internal.kernel.api.RelationshipScanCursor) HashMap(java.util.HashMap) TokenRead(org.neo4j.internal.kernel.api.TokenRead) PropertyKeyIdNotFoundKernelException(org.neo4j.internal.kernel.api.exceptions.PropertyKeyIdNotFoundKernelException)

Example 27 with TokenRead

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

the class SchemaImpl method getConstraints.

@Override
public Iterable<ConstraintDefinition> getConstraints(final Label label) {
    transaction.assertOpen();
    TokenRead tokenRead = transaction.tokenRead();
    SchemaRead schemaRead = transaction.schemaRead();
    int labelId = tokenRead.nodeLabel(label.name());
    if (labelId == TokenRead.NO_TOKEN) {
        return emptyList();
    }
    return asConstraintDefinitions(schemaRead.constraintsGetForLabel(labelId), tokenRead);
}
Also used : SchemaRead(org.neo4j.internal.kernel.api.SchemaRead) TokenRead(org.neo4j.internal.kernel.api.TokenRead)

Example 28 with TokenRead

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

the class SchemaImpl method getConstraints.

@Override
public Iterable<ConstraintDefinition> getConstraints(RelationshipType type) {
    transaction.assertOpen();
    TokenRead tokenRead = transaction.tokenRead();
    SchemaRead schemaRead = transaction.schemaRead();
    int typeId = tokenRead.relationshipType(type.name());
    if (typeId == TokenRead.NO_TOKEN) {
        return emptyList();
    }
    return asConstraintDefinitions(schemaRead.constraintsGetForRelationshipType(typeId), tokenRead);
}
Also used : SchemaRead(org.neo4j.internal.kernel.api.SchemaRead) TokenRead(org.neo4j.internal.kernel.api.TokenRead)

Example 29 with TokenRead

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

the class KernelTransactionSecurityContextTest method shouldAllowTokenReadAccessInWriteOnlyMode.

@Test
void shouldAllowTokenReadAccessInWriteOnlyMode() {
    // Given
    KernelTransactionImplementation tx = newTransaction(AnonymousContext.writeOnly());
    // When
    TokenRead tokenRead = tx.tokenRead();
    // Then
    assertNotNull(tokenRead);
}
Also used : TokenRead(org.neo4j.internal.kernel.api.TokenRead) Test(org.junit.jupiter.api.Test)

Example 30 with TokenRead

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

the class StartOldDbOnCurrentVersionAndCreateFusionIndexIT method countIndexedNodes.

private static int countIndexedNodes(GraphDatabaseAPI db, Label label, String... keys) throws Exception {
    try (InternalTransaction tx = (InternalTransaction) db.beginTx()) {
        KernelTransaction ktx = tx.kernelTransaction();
        TokenRead tokenRead = ktx.tokenRead();
        int labelId = tokenRead.nodeLabel(label.name());
        int[] propertyKeyIds = new int[keys.length];
        for (int i = 0; i < propertyKeyIds.length; i++) {
            propertyKeyIds[i] = tokenRead.propertyKey(keys[i]);
        }
        PropertyIndexQuery[] predicates = new PropertyIndexQuery[propertyKeyIds.length];
        for (int i = 0; i < propertyKeyIds.length; i++) {
            predicates[i] = PropertyIndexQuery.exists(propertyKeyIds[i]);
        }
        IndexDescriptor index = single(ktx.schemaRead().index(SchemaDescriptor.forLabel(labelId, propertyKeyIds)));
        IndexReadSession indexSession = ktx.dataRead().indexReadSession(index);
        int count = 0;
        try (NodeValueIndexCursor cursor = ktx.cursors().allocateNodeValueIndexCursor(ktx.cursorContext(), ktx.memoryTracker())) {
            ktx.dataRead().nodeIndexSeek(indexSession, cursor, unconstrained(), predicates);
            while (cursor.next()) {
                count++;
            }
        }
        tx.commit();
        return count;
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) PropertyIndexQuery(org.neo4j.internal.kernel.api.PropertyIndexQuery) 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) IndexReadSession(org.neo4j.internal.kernel.api.IndexReadSession)

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