如何在不使用Datastax Studio但通过Java创建图形及其模式的情况下? [英] How to create a graph and its schema without using Datastax Studio but through Java?
问题描述
我试图通过java创建我与DSE Graph的第一个连接..
I was trying to create my first connection with DSE Graph through java..
public static void main(String args[]){
DseCluster dseCluster = null;
try {
dseCluster = DseCluster.builder()
.addContactPoint("192.168.1.43")
.build();
DseSession dseSession = dseCluster.connect();
GraphTraversalSource g = DseGraph.traversal(dseSession, new GraphOptions().setGraphName("graph"));
GraphStatement graphStatement = DseGraph.statementFromTraversal(g.addV("test"));
GraphResultSet grs = dseSession.executeGraph(graphStatement.setGraphName("graph"));
System.out.println(grs.one().asVertex());
} finally {
if (dseCluster != null) dseCluster.close();
}
}
起初我得到的是图表没有存在..我不得不通过DataStax Studio创建与特定图形的连接,因为它不在那里..
At first I was getting that "graph" doesn't exist.. I had to create a connection to the specific graph through DataStax Studio since it wasn't there..
现在我需要放置标签,属性等在架构中..我知道如何在工作室中做到这一点( https://docs.datastax.com/en/latest-dse/datastax_enterprise/graph/using/createSchemaStudio.html )但我想在代码中这样做。如何在Java中访问模式对象,以便我可以进行以下更改:
Now I need to put the labels,properties etc in the schema.. I know how to do it in the studio (https://docs.datastax.com/en/latest-dse/datastax_enterprise/graph/using/createSchemaStudio.html) but I would like to do it in the code instead. How can I have access to the schema object in Java so I can make changes like those:
schema.config().option('graph.schema_mode').set('Development')
schema.vertexLabel('test').create()
还如何创建一个不存在代码的图形?我试图搜索java-dse-graph驱动程序代码,但我没有找到任何东西:/
also how is it possible to create a graph that doesn't exist through code? I tried to search through the java-dse-graph driver code but I didn't find anything :/
谢谢!
推荐答案
请注意,您可以使用SimpleGraphStatement设置图形选项,如文档所示:
http://docs.datastax.com/en/developer/java-driver-dse/1.1/manual / graph /#graph-options
Note that you can set graph options with a SimpleGraphStatement, as the docs show: http://docs.datastax.com/en/developer/java-driver-dse/1.1/manual/graph/#graph-options
这篇关于如何在不使用Datastax Studio但通过Java创建图形及其模式的情况下?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!