Search in sources :

Example 1 with EntityNotFoundException

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();
}
Also used : MutableInt(org.apache.commons.lang3.mutable.MutableInt) EntityNotFoundException(org.neo4j.kernel.api.exceptions.EntityNotFoundException)

Example 2 with EntityNotFoundException

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;
}
Also used : Random(java.util.Random) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) EntityNotFoundException(org.neo4j.kernel.api.exceptions.EntityNotFoundException)

Example 3 with EntityNotFoundException

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!
        }
    }
}
Also used : TransactionFailureException(org.neo4j.graphdb.TransactionFailureException) Transaction(org.neo4j.graphdb.Transaction) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) Statement(org.neo4j.kernel.api.Statement) Node(org.neo4j.graphdb.Node) EntityNotFoundException(org.neo4j.kernel.api.exceptions.EntityNotFoundException) Test(org.junit.Test)

Example 4 with EntityNotFoundException

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);
}
Also used : Transaction(org.neo4j.graphdb.Transaction) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) Statement(org.neo4j.kernel.api.Statement) Node(org.neo4j.graphdb.Node) Label(org.neo4j.graphdb.Label) EntityNotFoundException(org.neo4j.kernel.api.exceptions.EntityNotFoundException) Test(org.junit.Test)

Example 5 with EntityNotFoundException

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());
}
Also used : RelationshipRecord(org.neo4j.kernel.impl.store.record.RelationshipRecord) EntityNotFoundException(org.neo4j.kernel.api.exceptions.EntityNotFoundException)

Aggregations

EntityNotFoundException (org.neo4j.kernel.api.exceptions.EntityNotFoundException)30 Statement (org.neo4j.kernel.api.Statement)20 NotFoundException (org.neo4j.graphdb.NotFoundException)14 PropertyNotFoundException (org.neo4j.kernel.api.exceptions.PropertyNotFoundException)14 PropertyKeyIdNotFoundKernelException (org.neo4j.kernel.api.exceptions.PropertyKeyIdNotFoundKernelException)7 Test (org.junit.Test)5 AutoIndexingKernelException (org.neo4j.kernel.api.exceptions.legacyindex.AutoIndexingKernelException)5 LegacyIndexNotFoundKernelException (org.neo4j.kernel.api.exceptions.legacyindex.LegacyIndexNotFoundKernelException)5 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)4 ConstraintViolationException (org.neo4j.graphdb.ConstraintViolationException)3 Node (org.neo4j.graphdb.Node)3 Transaction (org.neo4j.graphdb.Transaction)3 InvalidTransactionTypeKernelException (org.neo4j.kernel.api.exceptions.InvalidTransactionTypeKernelException)3 TokenNotFoundException (org.neo4j.kernel.impl.core.TokenNotFoundException)3 NodeItem (org.neo4j.storageengine.api.NodeItem)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 PrimitiveIntIterator (org.neo4j.collection.primitive.PrimitiveIntIterator)2 ReadOperations (org.neo4j.kernel.api.ReadOperations)2 StatementTokenNameLookup (org.neo4j.kernel.api.StatementTokenNameLookup)2