Search in sources :

Example 41 with NotFoundException

use of org.neo4j.graphdb.NotFoundException in project neo4j-mobile-android by neo4j-contrib.

the class NodeManager method getNodeForProxy.

NodeImpl getNodeForProxy(long nodeId) {
    NodeImpl node = nodeCache.get(nodeId);
    if (node != null) {
        return node;
    }
    ReentrantLock loadLock = lockId(nodeId);
    try {
        node = nodeCache.get(nodeId);
        if (node != null) {
            return node;
        }
        if (!persistenceManager.loadLightNode(nodeId)) {
            throw new NotFoundException("Node[" + nodeId + "] not found.");
        }
        node = new NodeImpl(nodeId);
        nodeCache.put(nodeId, node);
        return node;
    } finally {
        loadLock.unlock();
    }
}
Also used : ReentrantLock(java.util.concurrent.locks.ReentrantLock) NotFoundException(org.neo4j.graphdb.NotFoundException)

Example 42 with NotFoundException

use of org.neo4j.graphdb.NotFoundException in project neo4j-mobile-android by neo4j-contrib.

the class NodeManager method getRelationshipById.

public Relationship getRelationshipById(long relId) throws NotFoundException {
    RelationshipImpl relationship = relCache.get(relId);
    if (relationship != null) {
        return new RelationshipProxy(relId, this);
    }
    ReentrantLock loadLock = lockId(relId);
    try {
        relationship = relCache.get(relId);
        if (relationship != null) {
            return new RelationshipProxy(relId, this);
        }
        RelationshipRecord data = persistenceManager.loadLightRelationship(relId);
        if (data == null) {
            throw new NotFoundException("Relationship[" + relId + "]");
        }
        int typeId = data.getType();
        RelationshipType type = getRelationshipTypeById(typeId);
        if (type == null) {
            throw new NotFoundException("Relationship[" + data.getId() + "] exist but relationship type[" + typeId + "] not found.");
        }
        final long startNodeId = data.getFirstNode();
        final long endNodeId = data.getSecondNode();
        relationship = newRelationshipImpl(relId, startNodeId, endNodeId, type, typeId, false);
        relCache.put(relId, relationship);
        return new RelationshipProxy(relId, this);
    } finally {
        loadLock.unlock();
    }
}
Also used : ReentrantLock(java.util.concurrent.locks.ReentrantLock) RelationshipType(org.neo4j.graphdb.RelationshipType) RelationshipRecord(org.neo4j.kernel.impl.nioneo.store.RelationshipRecord) NotFoundException(org.neo4j.graphdb.NotFoundException)

Example 43 with NotFoundException

use of org.neo4j.graphdb.NotFoundException in project neo4j-mobile-android by neo4j-contrib.

the class NodeManager method getRelForProxy.

RelationshipImpl getRelForProxy(long relId) {
    RelationshipImpl relationship = relCache.get(relId);
    if (relationship != null) {
        return relationship;
    }
    ReentrantLock loadLock = lockId(relId);
    try {
        relationship = relCache.get(relId);
        if (relationship != null) {
            return relationship;
        }
        RelationshipRecord data = persistenceManager.loadLightRelationship(relId);
        if (data == null) {
            throw new NotFoundException("Relationship[" + relId + "] not found.");
        }
        int typeId = data.getType();
        RelationshipType type = getRelationshipTypeById(typeId);
        if (type == null) {
            throw new NotFoundException("Relationship[" + data.getId() + "] exist but relationship type[" + typeId + "] not found.");
        }
        relationship = newRelationshipImpl(relId, data.getFirstNode(), data.getSecondNode(), type, typeId, false);
        relCache.put(relId, relationship);
        return relationship;
    } finally {
        loadLock.unlock();
    }
}
Also used : ReentrantLock(java.util.concurrent.locks.ReentrantLock) RelationshipType(org.neo4j.graphdb.RelationshipType) RelationshipRecord(org.neo4j.kernel.impl.nioneo.store.RelationshipRecord) NotFoundException(org.neo4j.graphdb.NotFoundException)

Example 44 with NotFoundException

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

the class AbstractShellIT method assertNodeDoesntExist.

protected void assertNodeDoesntExist(long id) {
    try (Transaction ignore = db.beginTx()) {
        db.getNodeById(id);
        fail("Relationship " + id + " shouldn't exist");
    } catch (NotFoundException e) {
    // Good
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) NotFoundException(org.neo4j.graphdb.NotFoundException)

Example 45 with NotFoundException

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

the class Neo4jGraph method removeVertex.

public void removeVertex(final Vertex vertex) {
    this.autoStartTransaction();
    try {
        final Node node = ((Neo4jVertex) vertex).getRawVertex();
        for (final Relationship relationship : node.getRelationships(org.neo4j.graphdb.Direction.BOTH)) {
            relationship.delete();
        }
        node.delete();
    } catch (NotFoundException nfe) {
        throw ExceptionFactory.vertexWithIdDoesNotExist(vertex.getId());
    } catch (IllegalStateException ise) {
        // wrap the neo4j exception so that the message is consistent in blueprints.
        throw ExceptionFactory.vertexWithIdDoesNotExist(vertex.getId());
    }
}
Also used : Node(org.neo4j.graphdb.Node) Relationship(org.neo4j.graphdb.Relationship) NotFoundException(org.neo4j.graphdb.NotFoundException)

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