use of org.neo4j.kernel.api.exceptions.EntityNotFoundException in project neo4j by neo4j.
the class LockingStatementOperations method nodeDetachDelete.
@Override
public int nodeDetachDelete(final KernelStatement state, final long nodeId) throws KernelException {
final MutableInt count = new MutableInt();
TwoPhaseNodeForRelationshipLocking locking = new TwoPhaseNodeForRelationshipLocking(entityReadDelegate, relId -> {
state.assertOpen();
try {
entityWriteDelegate.relationshipDelete(state, relId);
count.increment();
} catch (EntityNotFoundException e) {
}
});
locking.lockAllNodesAndConsumeRelationships(nodeId, state);
state.assertOpen();
entityWriteDelegate.nodeDetachDelete(state, nodeId);
return count.intValue();
}
use of org.neo4j.kernel.api.exceptions.EntityNotFoundException in project neo4j by neo4j.
the class IndexStatisticsTest method internalExecuteCreationsDeletionsAndUpdates.
private UpdatesTracker internalExecuteCreationsDeletionsAndUpdates(long[] nodes, NewIndexDescriptor index, int numberOfCreations, boolean allowDeletions, boolean allowUpdates) throws KernelException {
Random random = ThreadLocalRandom.current();
UpdatesTracker updatesTracker = new UpdatesTracker();
int offset = 0;
while (updatesTracker.created() < numberOfCreations) {
int created = createNamedPeople(nodes, offset);
offset += created;
updatesTracker.increaseCreated(created);
// check index online
if (!updatesTracker.isPopulationCompleted() && indexOnlineMonitor.isIndexOnline(index)) {
updatesTracker.notifyPopulationCompleted();
}
// delete if allowed
if (allowDeletions && updatesTracker.created() % 5 == 0) {
long nodeId = nodes[random.nextInt(nodes.length)];
try {
deleteNode(nodeId);
updatesTracker.increaseDeleted(1);
} catch (EntityNotFoundException ex) {
// ignore
}
// check again index online
if (!updatesTracker.isPopulationCompleted() && indexOnlineMonitor.isIndexOnline(index)) {
updatesTracker.notifyPopulationCompleted();
}
}
// update if allowed
if (allowUpdates && updatesTracker.created() % 5 == 0) {
int randomIndex = random.nextInt(nodes.length);
try {
changeName(nodes[randomIndex], "name", NAMES[randomIndex % NAMES.length]);
} catch (EntityNotFoundException ex) {
// ignore
}
// check again index online
if (!updatesTracker.isPopulationCompleted() && indexOnlineMonitor.isIndexOnline(index)) {
updatesTracker.notifyPopulationCompleted();
}
}
}
// make sure population complete has been notified
updatesTracker.notifyPopulationCompleted();
return updatesTracker;
}
use of org.neo4j.kernel.api.exceptions.EntityNotFoundException in project neo4j by neo4j.
the class KernelIT method shouldNotBeAbleToCommitIfFailedTransactionContext.
@Test
public void shouldNotBeAbleToCommitIfFailedTransactionContext() throws Exception {
// WHEN
Node node = null;
int labelId = -1;
TransactionFailureException expectedException = null;
try (Transaction transaction = db.beginTx()) {
Statement statement = statementContextSupplier.get();
node = db.createNode();
labelId = statement.tokenWriteOperations().labelGetOrCreateForName("labello");
statement.dataWriteOperations().nodeAddLabel(node.getId(), labelId);
statement.close();
transaction.failure();
transaction.success();
} catch (TransactionFailureException e) {
expectedException = e;
} finally {
Assert.assertNotNull("Should have failed", expectedException);
}
// THEN
try (Transaction tx = db.beginTx()) {
Statement statement = statementContextSupplier.get();
try {
statement.readOperations().nodeHasLabel(node.getId(), labelId);
fail("should have thrown exception");
} catch (EntityNotFoundException e) {
// Yay!
}
}
}
use of org.neo4j.kernel.api.exceptions.EntityNotFoundException in project neo4j by neo4j.
the class KernelIT method deletingNodeWithLabelsShouldHaveThoseLabelRemovalsReflectedInTransaction.
@Test
public void deletingNodeWithLabelsShouldHaveThoseLabelRemovalsReflectedInTransaction() throws Exception {
// GIVEN
Transaction tx = db.beginTx();
Label label = label("labello");
Node node = db.createNode(label);
tx.success();
tx.close();
tx = db.beginTx();
Statement statement = statementContextSupplier.get();
// WHEN
statement.dataWriteOperations().nodeDelete(node.getId());
// Then
int labelId = statement.readOperations().labelGetForName(label.name());
try {
statement.readOperations().nodeGetLabels(node.getId());
fail();
} catch (EntityNotFoundException e) {
// Ok
}
try {
statement.readOperations().nodeHasLabel(node.getId(), labelId);
fail();
} catch (EntityNotFoundException e) {
// Ok
}
Set<Long> nodes = PrimitiveLongCollections.toSet(statement.readOperations().nodesGetForLabel(labelId));
statement.close();
tx.success();
tx.close();
assertEquals(emptySetOf(Long.class), nodes);
}
use of org.neo4j.kernel.api.exceptions.EntityNotFoundException in project neo4j by neo4j.
the class StorageLayer method relationshipVisit.
@Override
public <EXCEPTION extends Exception> void relationshipVisit(long relationshipId, RelationshipVisitor<EXCEPTION> relationshipVisitor) throws EntityNotFoundException, EXCEPTION {
// TODO Please don't create a record for this, it's ridiculous
RelationshipRecord record = relationshipStore.getRecord(relationshipId, relationshipStore.newRecord(), CHECK);
if (!record.inUse()) {
throw new EntityNotFoundException(EntityType.RELATIONSHIP, relationshipId);
}
relationshipVisitor.visit(relationshipId, record.getType(), record.getFirstNode(), record.getSecondNode());
}
Aggregations