How to create a graph and its schema without using Datastax Studio but through Java?

老子叫甜甜 提交于 2020-01-03 02:22:13

问题


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();
        }
    }

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..

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()

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 :/

Thanks!


回答1:


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



来源:https://stackoverflow.com/questions/41228539/how-to-create-a-graph-and-its-schema-without-using-datastax-studio-but-through-j

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!