Search in sources :

Example 26 with EntityNotFoundException

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

the class TestMigrateToDenseNodeSupport method verifyDenseRepresentation.

private void verifyDenseRepresentation(GraphDatabaseService db, Node node, boolean dense) {
    KernelAPI kernelAPI = ((GraphDatabaseAPI) db).getDependencyResolver().resolveDependency(KernelAPI.class);
    try (KernelTransaction tx = kernelAPI.newTransaction(KernelTransaction.Type.implicit, AnonymousContext.read());
        Statement statement = tx.acquireStatement()) {
        Cursor<NodeItem> nodeCursor = statement.readOperations().nodeCursorById(node.getId());
        assertEquals(dense, nodeCursor.get().isDense());
    } catch (TransactionFailureException | IllegalArgumentException | EntityNotFoundException e) {
        throw new RuntimeException(e);
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) TransactionFailureException(org.neo4j.kernel.api.exceptions.TransactionFailureException) NodeItem(org.neo4j.storageengine.api.NodeItem) Statement(org.neo4j.kernel.api.Statement) EntityNotFoundException(org.neo4j.kernel.api.exceptions.EntityNotFoundException) KernelAPI(org.neo4j.kernel.api.KernelAPI)

Example 27 with EntityNotFoundException

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

the class TwoPhaseNodeForRelationshipLockingTest method returnRelationships.

static void returnRelationships(EntityReadOperations ops, KernelStatement state, long nodeId, final boolean skipFirst, final RelationshipData... relIds) throws EntityNotFoundException {
    NodeItem nodeItem = mock(NodeItem.class);
    when(ops.nodeGetRelationships(state, nodeItem, Direction.BOTH)).thenAnswer(new Answer<Cursor<RelationshipItem>>() {

        private boolean first = skipFirst;

        @Override
        public Cursor<RelationshipItem> answer(InvocationOnMock invocation) throws Throwable {
            try {
                return new Cursor<RelationshipItem>() {

                    private int i = first ? 1 : 0;

                    private RelationshipData relationshipData = null;

                    @Override
                    public boolean next() {
                        boolean next = i < relIds.length;
                        relationshipData = next ? relIds[i++] : null;
                        return next;
                    }

                    @Override
                    public RelationshipItem get() {
                        if (relationshipData == null) {
                            throw new NoSuchElementException();
                        }
                        return relationshipData.asRelationshipItem();
                    }

                    @Override
                    public void close() {
                    }
                };
            } finally {
                first = false;
            }
        }
    });
    when(ops.nodeCursorById(state, nodeId)).thenAnswer(invocationOnMock -> {
        Cursor<NodeItem> cursor = new Cursor<NodeItem>() {

            private int i = 0;

            @Override
            public boolean next() {
                return i++ == 0;
            }

            @Override
            public NodeItem get() {
                if (i != 1) {
                    throw new NoSuchElementException();
                }
                return nodeItem;
            }

            @Override
            public void close() {
            }
        };
        if (!cursor.next()) {
            throw new EntityNotFoundException(EntityType.NODE, nodeId);
        }
        return cursor;
    });
}
Also used : EntityNotFoundException(org.neo4j.kernel.api.exceptions.EntityNotFoundException) Cursor(org.neo4j.cursor.Cursor) NodeItem(org.neo4j.storageengine.api.NodeItem) InvocationOnMock(org.mockito.invocation.InvocationOnMock) RelationshipItem(org.neo4j.storageengine.api.RelationshipItem) NoSuchElementException(java.util.NoSuchElementException)

Example 28 with EntityNotFoundException

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

the class PropertyIT method shouldNotAllowModifyingPropertiesOnDeletedRelationship.

@Test
public void shouldNotAllowModifyingPropertiesOnDeletedRelationship() throws Exception {
    // given
    Statement statement = statementInNewTransaction(AnonymousContext.writeToken());
    int prop1 = statement.tokenWriteOperations().propertyKeyGetOrCreateForName("prop1");
    int type = statement.tokenWriteOperations().relationshipTypeGetOrCreateForName("RELATED");
    long startNodeId = statement.dataWriteOperations().nodeCreate();
    long endNodeId = statement.dataWriteOperations().nodeCreate();
    long rel = statement.dataWriteOperations().relationshipCreate(type, startNodeId, endNodeId);
    statement.dataWriteOperations().relationshipSetProperty(rel, stringProperty(prop1, "As"));
    statement.dataWriteOperations().relationshipDelete(rel);
    // When
    try {
        statement.dataWriteOperations().relationshipRemoveProperty(rel, prop1);
        fail("Should have failed.");
    } catch (EntityNotFoundException e) {
        assertThat(e.getMessage(), equalTo("Unable to load RELATIONSHIP with id " + rel + "."));
    }
}
Also used : Statement(org.neo4j.kernel.api.Statement) EntityNotFoundException(org.neo4j.kernel.api.exceptions.EntityNotFoundException) Test(org.junit.Test)

Example 29 with EntityNotFoundException

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

the class PropertyIT method shouldNotAllowModifyingPropertiesOnDeletedNode.

@Test
public void shouldNotAllowModifyingPropertiesOnDeletedNode() throws Exception {
    // given
    Statement statement = statementInNewTransaction(AnonymousContext.writeToken());
    int prop1 = statement.tokenWriteOperations().propertyKeyGetOrCreateForName("prop1");
    long node = statement.dataWriteOperations().nodeCreate();
    statement.dataWriteOperations().nodeSetProperty(node, stringProperty(prop1, "As"));
    statement.dataWriteOperations().nodeDelete(node);
    // When
    try {
        statement.dataWriteOperations().nodeRemoveProperty(node, prop1);
        fail("Should have failed.");
    } catch (EntityNotFoundException e) {
        assertThat(e.getMessage(), equalTo("Unable to load NODE with id " + node + "."));
    }
}
Also used : Statement(org.neo4j.kernel.api.Statement) EntityNotFoundException(org.neo4j.kernel.api.exceptions.EntityNotFoundException) Test(org.junit.Test)

Example 30 with EntityNotFoundException

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

the class KernelIT method changesInTransactionContextShouldBeRolledBackWhenTxIsRolledBack.

@Test
public void changesInTransactionContextShouldBeRolledBackWhenTxIsRolledBack() throws Exception {
    // GIVEN
    Node node;
    int labelId;
    try (Transaction tx = db.beginTx()) {
        Statement statement = statementContextSupplier.get();
        // WHEN
        node = db.createNode();
        labelId = statement.tokenWriteOperations().labelGetOrCreateForName("labello");
        statement.dataWriteOperations().nodeAddLabel(node.getId(), labelId);
        statement.close();
    }
    // THEN
    try (Transaction tx = db.beginTx()) {
        try (Statement statement = statementContextSupplier.get()) {
            statement.readOperations().nodeHasLabel(node.getId(), labelId);
            fail("should have thrown exception");
        } catch (EntityNotFoundException e) {
        // Yay!
        }
    }
}
Also used : 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)

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