Search in sources :

Example 6 with TxState

use of org.neo4j.kernel.impl.api.state.TxState in project neo4j by neo4j.

the class RecordStorageReaderTestBase method createNode.

protected long createNode(Map<String, Object> properties, Label... labels) throws Exception {
    TxState txState = new TxState();
    long nodeId = commitContext.reserveNode();
    txState.nodeDoCreate(nodeId);
    for (Label label : labels) {
        txState.nodeDoAddLabel(getOrCreateLabelId(label), nodeId);
    }
    for (Map.Entry<String, Object> property : properties.entrySet()) {
        txState.nodeDoAddProperty(nodeId, getOrCreatePropertyKeyId(property.getKey()), Values.of(property.getValue()));
    }
    apply(txState);
    return nodeId;
}
Also used : TxState(org.neo4j.kernel.impl.api.state.TxState) Label(org.neo4j.graphdb.Label) SchemaDescriptor.forLabel(org.neo4j.internal.schema.SchemaDescriptor.forLabel) Map(java.util.Map)

Example 7 with TxState

use of org.neo4j.kernel.impl.api.state.TxState in project neo4j by neo4j.

the class RecordStorageReaderTestBase method createNodePropertyExistenceConstraint.

protected void createNodePropertyExistenceConstraint(Label label, String propertyKey) throws Exception {
    TxState txState = new TxState();
    NodeExistenceConstraintDescriptor constraint = ConstraintDescriptorFactory.existsForLabel(getOrCreateLabelId(label), getOrCreatePropertyKeyId(propertyKey));
    long id = commitContext.reserveSchema();
    txState.constraintDoAdd(constraint.withId(id).withName("constraint_" + id));
    apply(txState);
}
Also used : TxState(org.neo4j.kernel.impl.api.state.TxState) NodeExistenceConstraintDescriptor(org.neo4j.internal.schema.constraints.NodeExistenceConstraintDescriptor)

Example 8 with TxState

use of org.neo4j.kernel.impl.api.state.TxState in project neo4j by neo4j.

the class RecordStorageReaderTestBase method createRelationship.

protected long createRelationship(long sourceNode, long targetNode, RelationshipType relationshipType) throws Exception {
    TxState txState = new TxState();
    long relationshipId = commitContext.reserveRelationship();
    txState.relationshipDoCreate(relationshipId, getOrCreateRelationshipTypeId(relationshipType), sourceNode, targetNode);
    apply(txState);
    return relationshipId;
}
Also used : TxState(org.neo4j.kernel.impl.api.state.TxState)

Example 9 with TxState

use of org.neo4j.kernel.impl.api.state.TxState in project neo4j by neo4j.

the class CommitProcessTracingIT method tracePageCacheAccessOnCommandCreation.

@Test
void tracePageCacheAccessOnCommandCreation() throws KernelException {
    long sourceId;
    try (Transaction transaction = database.beginTx()) {
        sourceId = transaction.createNode(Label.label("a")).getId();
        transaction.commit();
    }
    var pageCacheTracer = new DefaultPageCacheTracer();
    try (var cursorContext = new CursorContext(pageCacheTracer.createPageCursorTracer("tracePageCacheAccessOnCommandCreation"));
        var reader = storageEngine.newReader()) {
        assertZeroCursor(cursorContext);
        try (CommandCreationContext context = storageEngine.newCommandCreationContext(INSTANCE)) {
            context.initialize(cursorContext);
            List<StorageCommand> commands = new ArrayList<>();
            var txState = new TxState();
            txState.nodeDoAddLabel(1, sourceId);
            storageEngine.createCommands(commands, txState, reader, context, IGNORE, LockTracer.NONE, 0, NO_DECORATION, cursorContext, INSTANCE);
        }
        assertCursor(cursorContext, 2);
    }
}
Also used : CommandCreationContext(org.neo4j.storageengine.api.CommandCreationContext) Transaction(org.neo4j.graphdb.Transaction) TxState(org.neo4j.kernel.impl.api.state.TxState) StorageCommand(org.neo4j.storageengine.api.StorageCommand) ArrayList(java.util.ArrayList) CursorContext(org.neo4j.io.pagecache.context.CursorContext) DefaultPageCacheTracer(org.neo4j.io.pagecache.tracing.DefaultPageCacheTracer) Test(org.junit.jupiter.api.Test)

Example 10 with TxState

use of org.neo4j.kernel.impl.api.state.TxState in project neo4j by neo4j.

the class DefaultRelationshipTraversalCursorTest method txState.

private static Read txState(Rel... rels) {
    KernelTransactionImplementation ktx = mock(KernelTransactionImplementation.class);
    Read read = new TestRead(ktx);
    when(ktx.securityContext()).thenReturn(SecurityContext.AUTH_DISABLED);
    if (rels.length > 0) {
        TxState txState = new TxState();
        for (Rel rel : rels) {
            txState.relationshipDoCreate(rel.relId, rel.type, rel.sourceId, rel.targetId);
        }
        when(read.hasTxStateWithChanges()).thenReturn(true);
        when(read.txState()).thenReturn(txState);
    }
    return read;
}
Also used : TxState(org.neo4j.kernel.impl.api.state.TxState) KernelTransactionImplementation(org.neo4j.kernel.impl.api.KernelTransactionImplementation)

Aggregations

TxState (org.neo4j.kernel.impl.api.state.TxState)17 IndexDescriptor (org.neo4j.internal.schema.IndexDescriptor)5 ArrayList (java.util.ArrayList)3 CommandCreationContext (org.neo4j.storageengine.api.CommandCreationContext)3 StorageCommand (org.neo4j.storageengine.api.StorageCommand)3 Test (org.junit.jupiter.api.Test)2 CursorContext (org.neo4j.io.pagecache.context.CursorContext)2 TransactionState (org.neo4j.kernel.api.txstate.TransactionState)2 IOException (java.io.IOException)1 DirectoryNotEmptyException (java.nio.file.DirectoryNotEmptyException)1 List (java.util.List)1 Map (java.util.Map)1 Stream (java.util.stream.Stream)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)1 Assertions.assertFalse (org.junit.jupiter.api.Assertions.assertFalse)1 Assertions.assertThrows (org.junit.jupiter.api.Assertions.assertThrows)1 Assertions.assertTrue (org.junit.jupiter.api.Assertions.assertTrue)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1 Dependencies (org.neo4j.collection.Dependencies)1