Search in sources :

Example 26 with TransactionState

use of org.neo4j.kernel.api.txstate.TransactionState in project neo4j by neo4j.

the class KernelToken method propertyKeyCreateForName.

@Override
public int propertyKeyCreateForName(String propertyKeyName, boolean internal) throws KernelException {
    ktx.assertOpen();
    TransactionState txState = ktx.txState();
    int id = reserveTokenId(commandCreationContext::reservePropertyKeyTokenId, tokenHolders.propertyKeyTokens());
    txState.propertyKeyDoCreateForName(propertyKeyName, internal, id);
    return id;
}
Also used : TransactionState(org.neo4j.kernel.api.txstate.TransactionState)

Example 27 with TransactionState

use of org.neo4j.kernel.api.txstate.TransactionState in project neo4j by neo4j.

the class Operations method relationshipCreate.

@Override
public long relationshipCreate(long sourceNode, int relationshipType, long targetNode) throws EntityNotFoundException {
    ktx.securityAuthorizationHandler().assertAllowsCreateRelationship(ktx.securityContext(), token::relationshipTypeGetName, relationshipType);
    ktx.assertOpen();
    sharedSchemaLock(ResourceTypes.RELATIONSHIP_TYPE, relationshipType);
    sharedTokenSchemaLock(ResourceTypes.RELATIONSHIP_TYPE);
    commandCreationContext.acquireRelationshipCreationLock(ktx.txState(), ktx.lockClient(), ktx.lockTracer(), sourceNode, targetNode);
    assertNodeExists(sourceNode);
    assertNodeExists(targetNode);
    TransactionState txState = ktx.txState();
    long id = commandCreationContext.reserveRelationship();
    txState.relationshipDoCreate(id, relationshipType, sourceNode, targetNode);
    return id;
}
Also used : TransactionState(org.neo4j.kernel.api.txstate.TransactionState)

Example 28 with TransactionState

use of org.neo4j.kernel.api.txstate.TransactionState in project neo4j by neo4j.

the class AllStoreHolder method countsForNodeInTxState.

private long countsForNodeInTxState(int labelId) {
    long count = 0;
    if (ktx.hasTxStateWithChanges()) {
        CountsDelta counts = new CountsDelta();
        try {
            TransactionState txState = ktx.txState();
            CursorContext cursorContext = ktx.cursorContext();
            try (var countingVisitor = new TransactionCountingStateVisitor(EMPTY, storageReader, txState, counts, cursorContext)) {
                txState.accept(countingVisitor);
            }
            if (counts.hasChanges()) {
                count += counts.nodeCount(labelId, cursorContext);
            }
        } catch (KernelException e) {
            throw new IllegalArgumentException("Unexpected error: " + e.getMessage());
        }
    }
    return count;
}
Also used : TransactionState(org.neo4j.kernel.api.txstate.TransactionState) CursorContext(org.neo4j.io.pagecache.context.CursorContext) CountsDelta(org.neo4j.storageengine.api.CountsDelta) IndexNotFoundKernelException(org.neo4j.internal.kernel.api.exceptions.schema.IndexNotFoundKernelException) KernelException(org.neo4j.exceptions.KernelException) TransactionCountingStateVisitor(org.neo4j.storageengine.api.txstate.TransactionCountingStateVisitor)

Example 29 with TransactionState

use of org.neo4j.kernel.api.txstate.TransactionState in project neo4j by neo4j.

the class AllStoreHolder method countsForRelationshipInTxState.

private long countsForRelationshipInTxState(int startLabelId, int typeId, int endLabelId) {
    long count = 0;
    if (ktx.hasTxStateWithChanges()) {
        CursorContext cursorContext = ktx.cursorContext();
        CountsDelta counts = new CountsDelta();
        try {
            TransactionState txState = ktx.txState();
            try (var countingVisitor = new TransactionCountingStateVisitor(EMPTY, storageReader, txState, counts, cursorContext)) {
                txState.accept(countingVisitor);
            }
            if (counts.hasChanges()) {
                count += counts.relationshipCount(startLabelId, typeId, endLabelId, cursorContext);
            }
        } catch (KernelException e) {
            throw new IllegalArgumentException("Unexpected error: " + e.getMessage());
        }
    }
    return count;
}
Also used : TransactionState(org.neo4j.kernel.api.txstate.TransactionState) CursorContext(org.neo4j.io.pagecache.context.CursorContext) CountsDelta(org.neo4j.storageengine.api.CountsDelta) IndexNotFoundKernelException(org.neo4j.internal.kernel.api.exceptions.schema.IndexNotFoundKernelException) KernelException(org.neo4j.exceptions.KernelException) TransactionCountingStateVisitor(org.neo4j.storageengine.api.txstate.TransactionCountingStateVisitor)

Example 30 with TransactionState

use of org.neo4j.kernel.api.txstate.TransactionState in project neo4j by neo4j.

the class AllStoreHolder method relationshipExists.

@Override
public boolean relationshipExists(long reference) {
    ktx.assertOpen();
    if (hasTxStateWithChanges()) {
        TransactionState txState = txState();
        if (txState.relationshipIsDeletedInThisTx(reference)) {
            return false;
        } else if (txState.relationshipIsAddedInThisTx(reference)) {
            return true;
        }
    }
    AccessMode mode = ktx.securityContext().mode();
    CursorContext cursorContext = ktx.cursorContext();
    boolean existsInRelStore = storageReader.relationshipExists(reference, cursorContext);
    if (mode.allowsTraverseAllRelTypes()) {
        return existsInRelStore;
    } else if (!existsInRelStore) {
        return false;
    } else {
        // DefaultNodeCursor already contains traversal checks within next()
        try (DefaultRelationshipScanCursor rels = cursors.allocateRelationshipScanCursor(cursorContext)) {
            ktx.dataRead().singleRelationship(reference, rels);
            return rels.next();
        }
    }
}
Also used : TransactionState(org.neo4j.kernel.api.txstate.TransactionState) AdminAccessMode(org.neo4j.internal.kernel.api.security.AdminAccessMode) AccessMode(org.neo4j.internal.kernel.api.security.AccessMode) RestrictedAccessMode(org.neo4j.kernel.impl.api.security.RestrictedAccessMode) OverriddenAccessMode(org.neo4j.kernel.impl.api.security.OverriddenAccessMode) CursorContext(org.neo4j.io.pagecache.context.CursorContext)

Aggregations

TransactionState (org.neo4j.kernel.api.txstate.TransactionState)38 StateHandlingStatementOperations (org.neo4j.kernel.impl.api.StateHandlingStatementOperations)13 Test (org.junit.Test)12 KernelStatement (org.neo4j.kernel.impl.api.KernelStatement)12 StoreReadLayer (org.neo4j.storageengine.api.StoreReadLayer)9 IndexReader (org.neo4j.storageengine.api.schema.IndexReader)9 PrimitiveLongIterator (org.neo4j.collection.primitive.PrimitiveLongIterator)8 IndexQuery (org.neo4j.kernel.api.schema_new.IndexQuery)8 AddedAndRemoved (org.neo4j.kernel.impl.newapi.TxStateIndexChanges.AddedAndRemoved)5 AddedWithValuesAndRemoved (org.neo4j.kernel.impl.newapi.TxStateIndexChanges.AddedWithValuesAndRemoved)5 UniquenessConstraintDescriptor (org.neo4j.kernel.api.schema_new.constaints.UniquenessConstraintDescriptor)4 CursorContext (org.neo4j.io.pagecache.context.CursorContext)3 ConstraintDescriptor (org.neo4j.kernel.api.schema_new.constaints.ConstraintDescriptor)3 KernelTransactionImplementation (org.neo4j.kernel.impl.api.KernelTransactionImplementation)3 KernelException (org.neo4j.exceptions.KernelException)2 EntityNotFoundException (org.neo4j.internal.kernel.api.exceptions.EntityNotFoundException)2 IndexNotFoundKernelException (org.neo4j.internal.kernel.api.exceptions.schema.IndexNotFoundKernelException)2 AccessMode (org.neo4j.internal.kernel.api.security.AccessMode)2 AdminAccessMode (org.neo4j.internal.kernel.api.security.AdminAccessMode)2 IndexDescriptor (org.neo4j.internal.schema.IndexDescriptor)2