/** * <p> * This method creates the specified number of vertices and connect each * vertex with all other vertices which have a higher id. * </p> * <p> * <b>Beware: The commit on the graph needs to be performed by the test!</b> * </p> * * @param graph * is the graph to add vertices to. * @param numberOfVertices * is the number of vertices to be created. * @throws IOException * is thrown in case of IO issues. */ public static void createGraph(DuctileDBGraph graph, int numberOfVertices) throws IOException { DuctileDBVertex[] vertices = new DuctileDBVertex[numberOfVertices]; for (int i = 0; i < numberOfVertices; ++i) { Set<String> types = new HashSet<>(); types.add("vertex" + i); DuctileDBVertex vertex = graph.addVertex(types, new HashMap<>()); vertices[i] = vertex; } for (int i = 0; i < numberOfVertices - 1; ++i) { for (int j = i + 1; j < numberOfVertices; ++j) { graph.addEdge(vertices[i], vertices[j], "connects"); } } }
@Override public DuctileVertex addVertex(Object... keyValues) { ElementHelper.legalPropertyKeyValueArray(keyValues); if (ElementHelper.getIdValue(keyValues).isPresent()) throw Vertex.Exceptions.userSuppliedIdsNotSupported(); tx().readWrite(); DuctileDBVertex vertex = baseGraph.addVertex(); String[] labels = ElementHelper.getLabelValue(keyValues).orElse("").split(DuctileVertex.LABEL_DELIMINATOR); for (String label : labels) { if (!label.isEmpty()) { vertex.addType(label); } } DuctileVertex ductileVertex = new DuctileVertex(vertex, this); ElementHelper.attachProperties(ductileVertex, keyValues); return ductileVertex; }
public static void addStarWarsFiguresData(DuctileDBGraph graph) throws IOException { logger.info("Add Star Wars figures test data..."); DuctileDBVertex lukeSkywalker = graph.addVertex(); lukeSkywalker.addType(PERSON_TYPE); lukeSkywalker.addType(YETI_TYPE); DuctileDBVertex leiaOrgana = graph.addVertex(); leiaOrgana.addType(PERSON_TYPE); leiaOrgana.addType(PRINCESS_TYPE); DuctileDBVertex hanSolo = graph.addVertex(); hanSolo.addType(PERSON_TYPE); hanSolo.setProperty(FIRST_NAME_PROPERTY, "Han"); hanSolo.setProperty(LAST_NAME_PROPERTY, "Solo"); DuctileDBVertex bobaFett = graph.addVertex(); bobaFett.addType(PERSON_TYPE); bobaFett.setProperty(FIRST_NAME_PROPERTY, "Boba"); bobaFett.setProperty(LAST_NAME_PROPERTY, "Fett"); DuctileDBVertex obiWanKenobi = graph.addVertex(); obiWanKenobi.addType(PERSON_TYPE); obiWanKenobi.addType(YETI_TYPE); DuctileDBVertex r2D2 = graph.addVertex(); r2D2.addType(ROBOT_TYPE); r2D2.setProperty(FIRST_NAME_PROPERTY, "R2-D2"); DuctileDBVertex c3PO = graph.addVertex(); c3PO.addType(ROBOT_TYPE);