use of org.neo4j.graphdb.NotFoundException in project blueprints by tinkerpop.
the class Neo4j2Graph method removeVertex.
public void removeVertex(final Vertex vertex) {
this.autoStartTransaction(true);
try {
final Node node = ((Neo4j2Vertex) vertex).getRawElement();
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());
}
}
use of org.neo4j.graphdb.NotFoundException in project neo4j by neo4j.
the class GraphPropertiesProxy method getProperty.
@Override
public Object getProperty(String key) {
if (null == key) {
throw new IllegalArgumentException("(null) property key is not allowed");
}
try (Statement statement = actions.statement()) {
try {
int propertyKeyId = statement.readOperations().propertyKeyGetForName(key);
if (propertyKeyId == KeyReadOperations.NO_SUCH_PROPERTY_KEY) {
throw new NotFoundException(format("No such property, '%s'.", key));
}
Object value = statement.readOperations().graphGetProperty(propertyKeyId);
if (value == null) {
throw new PropertyNotFoundException(propertyKeyId, EntityType.GRAPH, -1);
}
return value;
} catch (PropertyNotFoundException e) {
throw new NotFoundException(e.getUserMessage(new StatementTokenNameLookup(statement.readOperations())), e);
}
}
}
use of org.neo4j.graphdb.NotFoundException in project neo4j by neo4j.
the class NodeProxy 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 propertyKeyId = statement.readOperations().propertyKeyGetForName(key);
Object value = statement.readOperations().nodeGetProperty(nodeId, propertyKeyId);
return value == null ? defaultValue : value;
} catch (EntityNotFoundException e) {
throw new NotFoundException(e);
}
}
use of org.neo4j.graphdb.NotFoundException in project neo4j by neo4j.
the class NodeProxy method createRelationshipTo.
@Override
public Relationship createRelationshipTo(Node otherNode, RelationshipType type) {
if (otherNode == null) {
throw new IllegalArgumentException("Other node is null.");
}
//}
try (Statement statement = actions.statement()) {
int relationshipTypeId = statement.tokenWriteOperations().relationshipTypeGetOrCreateForName(type.name());
long relationshipId = statement.dataWriteOperations().relationshipCreate(relationshipTypeId, nodeId, otherNode.getId());
return actions.newRelationshipProxy(relationshipId, nodeId, relationshipTypeId, otherNode.getId());
} catch (IllegalTokenNameException | RelationshipTypeIdNotFoundKernelException e) {
throw new IllegalArgumentException(e);
} catch (EntityNotFoundException e) {
throw new NotFoundException("Node[" + e.entityId() + "] is deleted and cannot be used to create a relationship");
} catch (InvalidTransactionTypeKernelException e) {
throw new ConstraintViolationException(e.getMessage(), e);
}
}
use of org.neo4j.graphdb.NotFoundException in project neo4j by neo4j.
the class NodeProxy method getDegree.
@Override
public int getDegree(RelationshipType type, Direction direction) {
try (Statement statement = actions.statement()) {
ReadOperations ops = statement.readOperations();
int typeId = ops.relationshipTypeGetForName(type.name());
if (typeId == NO_ID) {
// This type doesn't even exist. Return 0
return 0;
}
return ops.nodeGetDegree(nodeId, direction, typeId);
} catch (EntityNotFoundException e) {
throw new NotFoundException("Node not found.", e);
}
}
Aggregations