/** * Insert an edge in the graph. The edge is updated with the id, rev and key (if not * present) * @param edge the edge * @throws ArangoDBGraphException If there was an error inserting the edge */ public void insertEdge(ArangoDBBaseEdge edge) { String graphName; try { graphName = edge.graph().name(); } catch (NullPointerException ex) { logger.error("Edge not paired: {}", edge); throw new ArangoDBGraphException("Edge does not have a graph. Can only delete paired edges."); } logger.debug("Insert edge {} in {}", edge, graphName); try { db.graph(graphName) .edgeCollection(ArangoDBUtil.getCollectioName(graphName, edge.collection())) .insertEdge(edge); } catch (ArangoDBException e) { logger.error("Failed to insert edge: {}", e.getErrorMessage()); throw ArangoDBExceptions.getArangoDBException(e); } edge.setPaired(true); }
/** * Delete an edge from the graph. * @param edge the edge * @throws ArangoDBGraphException If there was an error deleting the edge */ public void deleteEdge(ArangoDBBaseEdge edge) { String graphName; try { graphName = edge.graph().name(); } catch (NullPointerException ex) { logger.error("Edge not paired: {}", edge); throw new ArangoDBGraphException("Edge does not have a graph. Can only delete paired edges."); } logger.debug("Delete edge {} in {}", edge, graphName); try { db.graph(graphName) .edgeCollection(ArangoDBUtil.getCollectioName(graphName, edge.collection())) .deleteEdge(edge._key()); } catch (ArangoDBException e) { logger.error("Failed to delete vertex: {}", e.getErrorMessage()); throw ArangoDBExceptions.getArangoDBException(e); } edge.setPaired(false); }
/** * Delete a document from the graph. * @param document the document to delete * @throws ArangoDBGraphException If there was an error deleting the document */ public void deleteDocument( ArangoDBBaseDocument document) { String graphName; try { graphName = document.graph().name(); } catch (NullPointerException ex) { logger.error("Document not paired: {}", document); throw new ArangoDBGraphException("Document does not have a graph. Can only delete paired documents."); } logger.debug("Delete document {} in {}", document, graphName); try { db.graph(graphName) .vertexCollection(ArangoDBUtil.getCollectioName(graphName, document.collection())) .deleteVertex(document._key()); } catch (ArangoDBException e) { logger.error("Failed to delete document: {}", e.getErrorMessage()); throw ArangoDBExceptions.getArangoDBException(e); } document.setPaired(false); }
/** * Update the edge in the graph. * @param edge the edge * @throws ArangoDBGraphException If there was an error updating the edge */ public void updateEdge(ArangoDBBaseEdge edge) { String graphName; try { graphName = edge.graph().name(); } catch (NullPointerException ex) { logger.error("Edge not paired: {}", edge); throw new ArangoDBGraphException("Edge does not have a graph. Can only delete paired edges."); } logger.debug("Update edge {} in {}", edge, graphName); EdgeUpdateEntity edgeEntity; try { edgeEntity = db.graph(graphName) .edgeCollection(ArangoDBUtil.getCollectioName(graphName, edge.collection())) .updateEdge(edge._key(), edge); } catch (ArangoDBException e) { logger.error("Failed to update vertex: {}", e.getErrorMessage()); throw ArangoDBExceptions.getArangoDBException(e); } logger.info("Edge updated, new rev {}", edgeEntity.getRev()); edge._rev(edgeEntity.getRev()); }
/** * Update the document in the graph. * @param document the document * * @throws ArangoDBGraphException If there was an error updating the document */ public void updateDocument( ArangoDBBaseDocument document) { String graphName; try { graphName = document.graph().name(); } catch (NullPointerException ex) { logger.error("Document not paired: {}", document); throw new ArangoDBGraphException("Document does not have a graph. Can only delete paired documents."); } logger.debug("Update document {} in {}", document, graphName); VertexUpdateEntity vertexEntity; try { vertexEntity = db.graph(graphName) .vertexCollection(ArangoDBUtil.getCollectioName(graphName, document.collection())) .updateVertex(document._key(), document); } catch (ArangoDBException e) { logger.error("Failed to update document: {}", e.getErrorMessage()); throw ArangoDBExceptions.getArangoDBException(e); } logger.info("Document updated, new rev {}", vertexEntity.getRev()); document._rev(vertexEntity.getRev()); }
.getEdge(id, edgeClass); } catch (ArangoDBException e) { logger.error("Failed to retrieve edge: {}", e.getErrorMessage()); throw ArangoDBExceptions.getArangoDBException(e);
.vertexCollection(ArangoDBUtil.getCollectioName(graph.name(), collection)).getVertex(id, docClass); } catch (ArangoDBException e) { logger.error("Failed to retrieve vertex: {}", e.getErrorMessage()); throw new ArangoDBGraphException("Failed to retrieve vertex.", e);