Search in sources :

Example 46 with InternalTransaction

use of org.neo4j.kernel.impl.coreapi.InternalTransaction in project neo4j by neo4j.

the class IndexStatisticsTest method createSomePersons.

private void createSomePersons() throws KernelException {
    try (Transaction tx = db.beginTx()) {
        KernelTransaction ktx = ((InternalTransaction) tx).kernelTransaction();
        createPersonNode(ktx, "Davide");
        createPersonNode(ktx, "Stefan");
        createPersonNode(ktx, "John");
        createPersonNode(ktx, "John");
        tx.commit();
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) 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)

Example 47 with InternalTransaction

use of org.neo4j.kernel.impl.coreapi.InternalTransaction in project neo4j by neo4j.

the class IndexCRUDIT method addingALabelToPreExistingNodeShouldGetIndexed.

@Test
void addingALabelToPreExistingNodeShouldGetIndexed() throws Exception {
    // GIVEN
    String indexProperty = "indexProperty";
    GatheringIndexWriter writer = newWriter();
    createIndex(db, myLabel, indexProperty);
    // WHEN
    String otherProperty = "otherProperty";
    int value = 12;
    int otherValue = 17;
    Node node = createNode(map(indexProperty, value, otherProperty, otherValue));
    // THEN
    assertThat(writer.updatesCommitted.size()).isEqualTo(0);
    // AND WHEN
    try (Transaction tx = db.beginTx()) {
        node = tx.getNodeById(node.getId());
        node.addLabel(myLabel);
        tx.commit();
    }
    // THEN
    try (Transaction tx = db.beginTx()) {
        KernelTransaction ktx = ((InternalTransaction) tx).kernelTransaction();
        TokenRead tokenRead = ktx.tokenRead();
        int propertyKey1 = tokenRead.propertyKey(indexProperty);
        int label = tokenRead.nodeLabel(myLabel.name());
        LabelSchemaDescriptor descriptor = SchemaDescriptor.forLabel(label, propertyKey1);
        assertThat(writer.updatesCommitted).isEqualTo(asSet(IndexEntryUpdate.add(node.getId(), descriptor, Values.of(value))));
        tx.commit();
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) Transaction(org.neo4j.graphdb.Transaction) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) Node(org.neo4j.graphdb.Node) LabelSchemaDescriptor(org.neo4j.internal.schema.LabelSchemaDescriptor) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) TokenRead(org.neo4j.internal.kernel.api.TokenRead) Test(org.junit.jupiter.api.Test)

Example 48 with InternalTransaction

use of org.neo4j.kernel.impl.coreapi.InternalTransaction in project neo4j by neo4j.

the class IndexStatisticsTest method createPersonNameIndex.

private IndexDescriptor createPersonNameIndex() throws KernelException {
    try (Transaction tx = db.beginTx()) {
        KernelTransaction ktx = ((InternalTransaction) tx).kernelTransaction();
        int labelId = ktx.tokenWrite().labelGetOrCreateForName(PERSON_LABEL);
        int propertyKeyId = ktx.tokenWrite().propertyKeyGetOrCreateForName(NAME_PROPERTY);
        LabelSchemaDescriptor schema = forLabel(labelId, propertyKeyId);
        var index = ktx.schemaWrite().indexCreate(schema, "my index");
        tx.commit();
        return index;
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) Transaction(org.neo4j.graphdb.Transaction) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) LabelSchemaDescriptor(org.neo4j.internal.schema.LabelSchemaDescriptor) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction)

Example 49 with InternalTransaction

use of org.neo4j.kernel.impl.coreapi.InternalTransaction in project neo4j by neo4j.

the class LabelCountsTest method countsForNode.

/**
 * @param label the label to get the number of nodes of, or {@code null} to get the total number of nodes.
 */
private long countsForNode(Transaction tx, Label label) {
    KernelTransaction transaction = ((InternalTransaction) tx).kernelTransaction();
    Read read = transaction.dataRead();
    int labelId;
    if (label == null) {
        labelId = ANY_LABEL;
    } else {
        if (TokenRead.NO_TOKEN == (labelId = transaction.tokenRead().nodeLabel(label.name()))) {
            return 0;
        }
    }
    return read.countsForNode(labelId);
}
Also used : Read(org.neo4j.internal.kernel.api.Read) TokenRead(org.neo4j.internal.kernel.api.TokenRead) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction)

Example 50 with InternalTransaction

use of org.neo4j.kernel.impl.coreapi.InternalTransaction in project neo4j by neo4j.

the class CompositeCountsTest method countsForRelationship.

/**
 * @param start the label of the start node of relationships to get the number of, or {@code null} for "any".
 * @param type  the type of the relationships to get the number of, or {@code null} for "any".
 * @param end   the label of the end node of relationships to get the number of, or {@code null} for "any".
 */
private long countsForRelationship(Transaction tx, Label start, RelationshipType type, Label end) {
    KernelTransaction transaction = ((InternalTransaction) tx).kernelTransaction();
    TokenRead tokenRead = transaction.tokenRead();
    int startId;
    int typeId;
    int endId;
    // start
    if (start == null) {
        startId = ANY_LABEL;
    } else {
        if (TokenRead.NO_TOKEN == (startId = tokenRead.nodeLabel(start.name()))) {
            return 0;
        }
    }
    // type
    if (type == null) {
        typeId = TokenRead.NO_TOKEN;
    } else {
        if (TokenRead.NO_TOKEN == (typeId = tokenRead.relationshipType(type.name()))) {
            return 0;
        }
    }
    // end
    if (end == null) {
        endId = ANY_LABEL;
    } else {
        if (TokenRead.NO_TOKEN == (endId = tokenRead.nodeLabel(end.name()))) {
            return 0;
        }
    }
    return transaction.dataRead().countsForRelationship(startId, typeId, endId);
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) TokenRead(org.neo4j.internal.kernel.api.TokenRead)

Aggregations

InternalTransaction (org.neo4j.kernel.impl.coreapi.InternalTransaction)126 Transaction (org.neo4j.graphdb.Transaction)58 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)53 Test (org.junit.jupiter.api.Test)46 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)20 MethodSource (org.junit.jupiter.params.provider.MethodSource)18 Node (org.neo4j.graphdb.Node)16 NodeValueIndexCursor (org.neo4j.internal.kernel.api.NodeValueIndexCursor)15 ArrayList (java.util.ArrayList)13 Test (org.junit.Test)12 Result (org.neo4j.graphdb.Result)12 TokenRead (org.neo4j.internal.kernel.api.TokenRead)11 IndexDescriptor (org.neo4j.internal.schema.IndexDescriptor)10 IndexReadSession (org.neo4j.internal.kernel.api.IndexReadSession)8 ExecutingQuery (org.neo4j.kernel.api.query.ExecutingQuery)7 Relationship (org.neo4j.graphdb.Relationship)6 GraphDatabaseQueryService (org.neo4j.kernel.GraphDatabaseQueryService)6 GraphDatabaseFacade (org.neo4j.kernel.impl.factory.GraphDatabaseFacade)6 GraphDatabaseAPI (org.neo4j.kernel.internal.GraphDatabaseAPI)6 ReturnsDeepStubs (org.mockito.internal.stubbing.defaultanswers.ReturnsDeepStubs)5