Search in sources :

Example 36 with TransactionState

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

the class Operations method nodeCreate.

@Override
public long nodeCreate() {
    ktx.securityAuthorizationHandler().assertAllowsCreateNode(ktx.securityContext(), token::labelGetName, null);
    ktx.assertOpen();
    TransactionState txState = ktx.txState();
    long nodeId = commandCreationContext.reserveNode();
    txState.nodeDoCreate(nodeId);
    return nodeId;
}
Also used : TransactionState(org.neo4j.kernel.api.txstate.TransactionState)

Example 37 with TransactionState

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

the class Operations method indexDoCreate.

private IndexDescriptor indexDoCreate(IndexPrototype prototype) {
    indexProviders.validateIndexPrototype(prototype);
    TransactionState transactionState = ktx.txState();
    long schemaRecordId = commandCreationContext.reserveSchema();
    IndexDescriptor index = prototype.materialise(schemaRecordId);
    index = indexProviders.completeConfiguration(index);
    transactionState.indexDoAdd(index);
    return index;
}
Also used : TransactionState(org.neo4j.kernel.api.txstate.TransactionState) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor)

Example 38 with TransactionState

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

the class Operations method nodeDelete.

private boolean nodeDelete(long node, boolean lock) {
    ktx.assertOpen();
    if (ktx.hasTxStateWithChanges()) {
        TransactionState state = ktx.txState();
        if (state.nodeIsAddedInThisTx(node)) {
            try {
                singleNode(node);
            } catch (EntityNotFoundException e) {
                throw new IllegalStateException("Node " + node + " was created in this transaction, but was not found when it was about to be deleted");
            }
            updater.onDeleteUncreated(nodeCursor, propertyCursor);
            state.nodeDoDelete(node);
            return true;
        }
        if (state.nodeIsDeletedInThisTx(node)) {
            // already deleted
            return false;
        }
    }
    if (lock) {
        commandCreationContext.acquireNodeDeletionLock(ktx.txState(), ktx.lockClient(), ktx.lockTracer(), node);
    }
    allStoreHolder.singleNode(node, nodeCursor);
    if (nodeCursor.next()) {
        acquireSharedNodeLabelLocks();
        sharedTokenSchemaLock(ResourceTypes.LABEL);
        ktx.securityAuthorizationHandler().assertAllowsDeleteNode(ktx.securityContext(), token::labelGetName, nodeCursor::labels);
        ktx.txState().nodeDoDelete(node);
        return true;
    }
    // tried to delete node that does not exist
    return false;
}
Also used : TransactionState(org.neo4j.kernel.api.txstate.TransactionState) EntityNotFoundException(org.neo4j.internal.kernel.api.exceptions.EntityNotFoundException)

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