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;
}
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);
}
}
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
}
}
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);
}
}
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;
}
Aggregations