Search in sources :

Example 56 with NotFoundException

use of org.neo4j.graphdb.NotFoundException in project neo4j by neo4j.

the class RelationshipProxy method getPropertyKeys.

@Override
public Iterable<String> getPropertyKeys() {
    try (Statement statement = actions.statement()) {
        List<String> keys = new ArrayList<>();
        PrimitiveIntIterator properties = statement.readOperations().relationshipGetPropertyKeys(getId());
        while (properties.hasNext()) {
            keys.add(statement.readOperations().propertyKeyGetName(properties.next()));
        }
        return keys;
    } catch (EntityNotFoundException e) {
        throw new NotFoundException("Relationship not found", e);
    } catch (PropertyKeyIdNotFoundKernelException e) {
        throw new IllegalStateException("Property key retrieved through kernel API should exist.");
    }
}
Also used : Statement(org.neo4j.kernel.api.Statement) ArrayList(java.util.ArrayList) NotFoundException(org.neo4j.graphdb.NotFoundException) EntityNotFoundException(org.neo4j.kernel.api.exceptions.EntityNotFoundException) PropertyNotFoundException(org.neo4j.kernel.api.exceptions.PropertyNotFoundException) PrimitiveIntIterator(org.neo4j.collection.primitive.PrimitiveIntIterator) EntityNotFoundException(org.neo4j.kernel.api.exceptions.EntityNotFoundException) PropertyKeyIdNotFoundKernelException(org.neo4j.kernel.api.exceptions.PropertyKeyIdNotFoundKernelException)

Example 57 with NotFoundException

use of org.neo4j.graphdb.NotFoundException in project neo4j by neo4j.

the class RelationshipProxy method getProperty.

@Override
public Object getProperty(String key, Object defaultValue) {
    if (null == key) {
        throw new IllegalArgumentException("(null) property key is not allowed");
    }
    try (Statement statement = actions.statement()) {
        int propertyId = statement.readOperations().propertyKeyGetForName(key);
        Object value = statement.readOperations().relationshipGetProperty(getId(), propertyId);
        return value == null ? defaultValue : value;
    } catch (EntityNotFoundException e) {
        throw new NotFoundException(e);
    }
}
Also used : Statement(org.neo4j.kernel.api.Statement) NotFoundException(org.neo4j.graphdb.NotFoundException) EntityNotFoundException(org.neo4j.kernel.api.exceptions.EntityNotFoundException) PropertyNotFoundException(org.neo4j.kernel.api.exceptions.PropertyNotFoundException) EntityNotFoundException(org.neo4j.kernel.api.exceptions.EntityNotFoundException)

Example 58 with NotFoundException

use of org.neo4j.graphdb.NotFoundException in project neo4j by neo4j.

the class SchemaImpl method getIndexFailure.

@Override
public String getIndexFailure(IndexDefinition index) {
    actions.assertInOpenTransaction();
    try (Statement statement = statementContextSupplier.get()) {
        ReadOperations readOps = statement.readOperations();
        NewIndexDescriptor descriptor = getIndexDescriptor(readOps, index);
        return readOps.indexGetFailure(descriptor);
    } catch (SchemaRuleNotFoundException | IndexNotFoundKernelException e) {
        throw new NotFoundException(format("No index for label %s on property %s", index.getLabel().name(), index.getPropertyKeys()));
    }
}
Also used : ReadOperations(org.neo4j.kernel.api.ReadOperations) KeyReadOperations(org.neo4j.kernel.impl.api.operations.KeyReadOperations) NewIndexDescriptor(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor) Statement(org.neo4j.kernel.api.Statement) NotFoundException(org.neo4j.graphdb.NotFoundException) SchemaRuleNotFoundException(org.neo4j.kernel.api.exceptions.schema.SchemaRuleNotFoundException) SchemaRuleNotFoundException(org.neo4j.kernel.api.exceptions.schema.SchemaRuleNotFoundException) IndexNotFoundKernelException(org.neo4j.kernel.api.exceptions.index.IndexNotFoundKernelException)

Example 59 with NotFoundException

use of org.neo4j.graphdb.NotFoundException in project graphdb by neo4j-attic.

the class SingleJvmTest method testMixingEntitiesFromWrongDbs.

@Test
public void testMixingEntitiesFromWrongDbs() throws Exception {
    initializeDbs(1);
    GraphDatabaseService haDb1 = haDbs.get(0);
    GraphDatabaseService mDb = master.getGraphDb();
    Transaction tx = mDb.beginTx();
    Node masterNode;
    try {
        masterNode = mDb.createNode();
        mDb.getReferenceNode().createRelationshipTo(masterNode, CommonJobs.REL_TYPE);
        tx.success();
    } finally {
        tx.finish();
    }
    tx = haDb1.beginTx();
    // try throw in node that does not exist and no tx on mdb
    try {
        Node node = haDb1.createNode();
        mDb.getReferenceNode().createRelationshipTo(node, CommonJobs.KNOWS);
        fail("Should throw not found exception");
    } catch (NotFoundException e) {
    // good
    } finally {
        tx.finish();
    }
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) Transaction(org.neo4j.graphdb.Transaction) Node(org.neo4j.graphdb.Node) NotFoundException(org.neo4j.graphdb.NotFoundException) Test(org.junit.Test)

Example 60 with NotFoundException

use of org.neo4j.graphdb.NotFoundException in project neo4j by neo4j.

the class DeferringLocksIT method removeNodeChangeNodeProperty.

@Test(timeout = TEST_TIMEOUT)
public void removeNodeChangeNodeProperty() throws Exception {
    // GIVEN
    final Barrier.Control barrier = new Barrier.Control();
    final long nodeId;
    try (Transaction tx = db.beginTx()) {
        Node node = db.createNode();
        nodeId = node.getId();
        node.setProperty(PROPERTY_KEY, VALUE_1);
        tx.success();
    }
    // WHEN
    Future<Void> future = t2.execute(new WorkerCommand<Void, Void>() {

        @Override
        public Void doWork(Void state) throws Exception {
            try (Transaction tx = db.beginTx()) {
                db.getNodeById(nodeId).delete();
                tx.success();
                barrier.reached();
            }
            return null;
        }
    });
    try {
        try (Transaction tx = db.beginTx()) {
            barrier.await();
            db.getNodeById(nodeId).setProperty(PROPERTY_KEY, VALUE_2);
            tx.success();
            barrier.release();
        }
    } catch (TransactionFailureException e) {
        // Node was already deleted, fine.
        assertThat(e.getCause(), instanceOf(InvalidRecordException.class));
    }
    future.get();
    try (Transaction tx = db.beginTx()) {
        try {
            db.getNodeById(nodeId);
            assertEquals(VALUE_2, db.getNodeById(nodeId).getProperty(PROPERTY_KEY, VALUE_2));
        } catch (NotFoundException e) {
        // Fine, its gone
        }
        tx.success();
    }
}
Also used : Node(org.neo4j.graphdb.Node) NotFoundException(org.neo4j.graphdb.NotFoundException) Barrier(org.neo4j.test.Barrier) TransactionFailureException(org.neo4j.graphdb.TransactionFailureException) NotFoundException(org.neo4j.graphdb.NotFoundException) InvalidRecordException(org.neo4j.kernel.impl.store.InvalidRecordException) TransactionFailureException(org.neo4j.graphdb.TransactionFailureException) Transaction(org.neo4j.graphdb.Transaction) Test(org.junit.Test)

Aggregations

NotFoundException (org.neo4j.graphdb.NotFoundException)87 Node (org.neo4j.graphdb.Node)43 Test (org.junit.Test)36 Relationship (org.neo4j.graphdb.Relationship)24 Transaction (org.neo4j.graphdb.Transaction)24 Statement (org.neo4j.kernel.api.Statement)18 EntityNotFoundException (org.neo4j.kernel.api.exceptions.EntityNotFoundException)14 PropertyNotFoundException (org.neo4j.kernel.api.exceptions.PropertyNotFoundException)13 ReentrantLock (java.util.concurrent.locks.ReentrantLock)8 EndNodeNotFoundException (org.neo4j.server.rest.domain.EndNodeNotFoundException)7 StartNodeNotFoundException (org.neo4j.server.rest.domain.StartNodeNotFoundException)7 RelationshipType (org.neo4j.graphdb.RelationshipType)5 ReadOperations (org.neo4j.kernel.api.ReadOperations)4 SchemaRuleNotFoundException (org.neo4j.kernel.api.exceptions.schema.SchemaRuleNotFoundException)4 KeyReadOperations (org.neo4j.kernel.impl.api.operations.KeyReadOperations)4 InvalidRecordException (org.neo4j.kernel.impl.nioneo.store.InvalidRecordException)4 Race (org.neo4j.test.Race)4 ArrayList (java.util.ArrayList)3 ConstraintViolationException (org.neo4j.graphdb.ConstraintViolationException)3 StatementTokenNameLookup (org.neo4j.kernel.api.StatementTokenNameLookup)3