/** * Get a graph by name. * * @param name the name of the new graph * @return the graph or null if the graph was not found */ public ArangoGraph getGraph(String name) { return db.graph(name); }
throw ArangoDBExceptions.getArangoDBException(e); ArangoGraph g = db.graph(name); EdgeDefinition ed = ArangoDBUtil.createPropertyEdgeDefinitions(name, verticesCollectionNames, edgesCollectionNames); g.addEdgeDefinition(ed);
/** * 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()); }
V result; try { result = db.graph(graph.name()) .edgeCollection(ArangoDBUtil.getCollectioName(graph.name(), collection)) .getEdge(id, edgeClass);
V result; try { result = db.graph(graph.name()) .vertexCollection(ArangoDBUtil.getCollectioName(graph.name(), collection)).getVertex(id, docClass); } catch (ArangoDBException e) {
boolean dropCollections) { if (db != null) { ArangoGraph graph = db.graph(name); if (graph.exists()) { Collection<String> edgeDefinitions = dropCollections ? graph.getEdgeDefinitions() : Collections.emptyList();
VertexEntity vertexEntity; try { vertexEntity = db.graph(graphName) .vertexCollection(ArangoDBUtil.getCollectioName(graphName, document.collection())) .insertVertex(document);