Search in sources :

Example 1 with EntityNotFoundException

use of org.neo4j.internal.kernel.api.exceptions.EntityNotFoundException in project neo4j by neo4j.

the class Operations method relationshipDelete.

@Override
public boolean relationshipDelete(long relationship) {
    ktx.assertOpen();
    TransactionState txState = ktx.txState();
    if (txState.relationshipIsAddedInThisTx(relationship)) {
        try {
            singleRelationship(relationship);
        } catch (EntityNotFoundException e) {
            throw new IllegalStateException("Relationship " + relationship + " was created in this transaction, but was not found when deleting it");
        }
        updater.onDeleteUncreated(relationshipCursor, propertyCursor);
        txState.relationshipDoDeleteAddedInThisTx(relationship);
        return true;
    }
    // tx-state aware
    allStoreHolder.singleRelationship(relationship, relationshipCursor);
    if (!relationshipCursor.next()) {
        return false;
    }
    sharedSchemaLock(ResourceTypes.RELATIONSHIP_TYPE, relationshipCursor.type());
    sharedTokenSchemaLock(ResourceTypes.RELATIONSHIP_TYPE);
    commandCreationContext.acquireRelationshipDeletionLock(txState, ktx.lockClient(), ktx.lockTracer(), relationshipCursor.sourceNodeReference(), relationshipCursor.targetNodeReference(), relationship);
    if (!allStoreHolder.relationshipExists(relationship)) {
        return false;
    }
    ktx.securityAuthorizationHandler().assertAllowsDeleteRelationship(ktx.securityContext(), token::relationshipTypeGetName, relationshipCursor.type());
    txState.relationshipDoDelete(relationship, relationshipCursor.type(), relationshipCursor.sourceNodeReference(), relationshipCursor.targetNodeReference());
    return true;
}
Also used : TransactionState(org.neo4j.kernel.api.txstate.TransactionState) EntityNotFoundException(org.neo4j.internal.kernel.api.exceptions.EntityNotFoundException)

Example 2 with EntityNotFoundException

use of org.neo4j.internal.kernel.api.exceptions.EntityNotFoundException in project neo4j by neo4j.

the class NodeEntity method removeProperty.

@Override
public Object removeProperty(String key) throws NotFoundException {
    KernelTransaction transaction = internalTransaction.kernelTransaction();
    int propertyKeyId;
    try {
        propertyKeyId = transaction.tokenWrite().propertyKeyGetOrCreateForName(key);
    } catch (IllegalTokenNameException e) {
        throw new IllegalArgumentException(format("Invalid property key '%s'.", key), e);
    } catch (KernelException e) {
        throw new TransactionFailureException("Unknown error trying to get property key token", e);
    }
    try {
        return transaction.dataWrite().nodeRemoveProperty(nodeId, propertyKeyId).asObjectCopy();
    } catch (EntityNotFoundException e) {
        throw new NotFoundException(e);
    } catch (InvalidTransactionTypeKernelException e) {
        throw new ConstraintViolationException(e.getMessage(), e);
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) TransactionFailureException(org.neo4j.graphdb.TransactionFailureException) InvalidTransactionTypeKernelException(org.neo4j.internal.kernel.api.exceptions.InvalidTransactionTypeKernelException) NotFoundException(org.neo4j.graphdb.NotFoundException) EntityNotFoundException(org.neo4j.internal.kernel.api.exceptions.EntityNotFoundException) ConstraintViolationException(org.neo4j.graphdb.ConstraintViolationException) EntityNotFoundException(org.neo4j.internal.kernel.api.exceptions.EntityNotFoundException) IllegalTokenNameException(org.neo4j.internal.kernel.api.exceptions.schema.IllegalTokenNameException) PropertyKeyIdNotFoundKernelException(org.neo4j.internal.kernel.api.exceptions.PropertyKeyIdNotFoundKernelException) InvalidTransactionTypeKernelException(org.neo4j.internal.kernel.api.exceptions.InvalidTransactionTypeKernelException) TokenCapacityExceededKernelException(org.neo4j.internal.kernel.api.exceptions.schema.TokenCapacityExceededKernelException) LabelNotFoundKernelException(org.neo4j.internal.kernel.api.exceptions.LabelNotFoundKernelException) KernelException(org.neo4j.exceptions.KernelException)

Example 3 with EntityNotFoundException

use of org.neo4j.internal.kernel.api.exceptions.EntityNotFoundException in project neo4j by neo4j.

the class NodeWriteTestBase method shouldThrowWhenSettingPropertyOnDeletedNode.

@Test
void shouldThrowWhenSettingPropertyOnDeletedNode() throws Exception {
    // Given
    long node = createNode();
    deleteNode(node);
    // When
    try (KernelTransaction tx = beginTransaction()) {
        int token = tx.token().propertyKeyGetOrCreateForName(propertyKey);
        tx.dataWrite().nodeSetProperty(node, token, stringValue("hello"));
        fail("Expected EntityNotFoundException");
    } catch (EntityNotFoundException e) {
    // wanted
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) EntityNotFoundException(org.neo4j.internal.kernel.api.exceptions.EntityNotFoundException) Test(org.junit.jupiter.api.Test)

Example 4 with EntityNotFoundException

use of org.neo4j.internal.kernel.api.exceptions.EntityNotFoundException in project neo4j by neo4j.

the class RelationshipEntity method setProperty.

@Override
public void setProperty(String key, Object value) {
    KernelTransaction transaction = internalTransaction.kernelTransaction();
    int propertyKeyId;
    try {
        propertyKeyId = transaction.tokenWrite().propertyKeyGetOrCreateForName(key);
    } catch (IllegalTokenNameException e) {
        throw new IllegalArgumentException(format("Invalid property key '%s'.", key), e);
    } catch (TokenCapacityExceededKernelException e) {
        throw new ConstraintViolationException(e.getMessage(), e);
    } catch (KernelException e) {
        throw new TransactionFailureException("Unknown error trying to create property key token", e);
    }
    try {
        transaction.dataWrite().relationshipSetProperty(id, propertyKeyId, Values.of(value, false));
    } catch (IllegalArgumentException e) {
        try {
            transaction.rollback();
        } catch (org.neo4j.internal.kernel.api.exceptions.TransactionFailureException ex) {
            ex.addSuppressed(e);
            throw new TransactionFailureException("Fail to rollback transaction.", ex);
        }
        throw e;
    } catch (EntityNotFoundException e) {
        throw new NotFoundException(e);
    } catch (InvalidTransactionTypeKernelException e) {
        throw new ConstraintViolationException(e.getMessage(), e);
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) InvalidTransactionTypeKernelException(org.neo4j.internal.kernel.api.exceptions.InvalidTransactionTypeKernelException) NotFoundException(org.neo4j.graphdb.NotFoundException) EntityNotFoundException(org.neo4j.internal.kernel.api.exceptions.EntityNotFoundException) TokenCapacityExceededKernelException(org.neo4j.internal.kernel.api.exceptions.schema.TokenCapacityExceededKernelException) EntityNotFoundException(org.neo4j.internal.kernel.api.exceptions.EntityNotFoundException) IllegalTokenNameException(org.neo4j.internal.kernel.api.exceptions.schema.IllegalTokenNameException) TransactionFailureException(org.neo4j.graphdb.TransactionFailureException) ConstraintViolationException(org.neo4j.graphdb.ConstraintViolationException) PropertyKeyIdNotFoundKernelException(org.neo4j.internal.kernel.api.exceptions.PropertyKeyIdNotFoundKernelException) InvalidTransactionTypeKernelException(org.neo4j.internal.kernel.api.exceptions.InvalidTransactionTypeKernelException) TokenCapacityExceededKernelException(org.neo4j.internal.kernel.api.exceptions.schema.TokenCapacityExceededKernelException) KernelException(org.neo4j.exceptions.KernelException)

Example 5 with EntityNotFoundException

use of org.neo4j.internal.kernel.api.exceptions.EntityNotFoundException 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

EntityNotFoundException (org.neo4j.internal.kernel.api.exceptions.EntityNotFoundException)10 NotFoundException (org.neo4j.graphdb.NotFoundException)7 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)7 KernelException (org.neo4j.exceptions.KernelException)6 ConstraintViolationException (org.neo4j.graphdb.ConstraintViolationException)6 TransactionFailureException (org.neo4j.graphdb.TransactionFailureException)6 InvalidTransactionTypeKernelException (org.neo4j.internal.kernel.api.exceptions.InvalidTransactionTypeKernelException)6 PropertyKeyIdNotFoundKernelException (org.neo4j.internal.kernel.api.exceptions.PropertyKeyIdNotFoundKernelException)6 IllegalTokenNameException (org.neo4j.internal.kernel.api.exceptions.schema.IllegalTokenNameException)6 TokenCapacityExceededKernelException (org.neo4j.internal.kernel.api.exceptions.schema.TokenCapacityExceededKernelException)6 LabelNotFoundKernelException (org.neo4j.internal.kernel.api.exceptions.LabelNotFoundKernelException)4 ConstraintValidationException (org.neo4j.internal.kernel.api.exceptions.schema.ConstraintValidationException)2 TransactionState (org.neo4j.kernel.api.txstate.TransactionState)2 Test (org.junit.jupiter.api.Test)1