use of jakarta.nosql.mapping.EntityNotFoundException in project jnosql-diana by eclipse.
the class AbstractGraphTemplate method edge.
@Override
public <O, I> EdgeEntity edge(O outgoing, String label, I incoming) {
requireNonNull(incoming, "incoming is required");
requireNonNull(label, "label is required");
requireNonNull(outgoing, "outgoing is required");
checkId(outgoing);
checkId(incoming);
if (isIdNull(outgoing)) {
throw new IllegalStateException("outgoing Id field is required");
}
if (isIdNull(incoming)) {
throw new IllegalStateException("incoming Id field is required");
}
Vertex outVertex = getVertex(outgoing).orElseThrow(() -> new EntityNotFoundException("Outgoing entity does not found"));
Vertex inVertex = getVertex(incoming).orElseThrow(() -> new EntityNotFoundException("Incoming entity does not found"));
final Predicate<Traverser<Edge>> predicate = t -> {
Edge e = t.get();
return e.inVertex().id().equals(inVertex.id()) && e.outVertex().id().equals(outVertex.id());
};
Optional<Edge> edge = getTraversal().V(outVertex.id()).out(label).has(id, inVertex.id()).inE(label).filter(predicate).tryNext();
return edge.<EdgeEntity>map(edge1 -> new DefaultEdgeEntity<>(edge1, incoming, outgoing)).orElseGet(() -> new DefaultEdgeEntity<>(getEdge(label, outVertex, inVertex), incoming, outgoing));
}
use of jakarta.nosql.mapping.EntityNotFoundException in project jnosql-diana by eclipse.
the class AbstractGraphTemplate method update.
@Override
public <T> T update(T entity) {
requireNonNull(entity, "entity is required");
checkId(entity);
if (isIdNull(entity)) {
throw new IllegalStateException("to update a graph id cannot be null");
}
getVertex(entity).orElseThrow(() -> new EntityNotFoundException("Entity does not find in the update"));
UnaryOperator<Vertex> update = e -> {
final Vertex vertex = getConverter().toVertex(entity);
GraphTransactionUtil.transaction(getGraph().tx());
return vertex;
};
return getFlow().flow(entity, update);
}
Aggregations