import com.datastax.dse.graph.api.DseGraph;
import com.datastax.dse.graph.internal.DseGraphModule;
import org.apache.tinkerpop.gremlin.structure.Graph;
public class GraphConnection {
private static final String HOST = "localhost";
private static final int PORT = 9042;
private static final String GRAPH_NAME = "mygraph";
public static Graph createGraph() {
DseGraphModule dseGraphModule = DseGraph.moduleBuilder().build();
DseGraph dseGraph = DseGraph.builder()
.addContactPoints(HOST)
.withPort(PORT)
.withGraphName(GRAPH_NAME)
.build();
return dseGraph.traversal().withEmbedded(LambdaGraphTraversalSource.build()).getGraph();
}
}
import org.apache.tinkerpop.gremlin.structure.Graph;
import org.apache.tinkerpop.gremlin.structure.T;
import org.apache.tinkerpop.gremlin.structure.Vertex;
public class GraphUtils {
public static void createVertex(Graph graph, String label, String propertyKey, String propertyValue) {
Vertex vertex = graph.addVertex(T.label, label);
vertex.property(propertyKey, propertyValue);
}
}
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal;
import org.apache.tinkerpop.gremlin.structure.Graph;
public class GraphQueries {
public static void executeQuery(Graph graph) {
GraphTraversal traversal = graph.traversal();
traversal.V().has("label", "person").forEachRemaining(vertex -> System.out.println(vertex));
}
}