windows系统以cassandra为存储后端,使用janusgraph java api

老师让我们了解janusgraph并且使用java api熟悉增删查改功能.

因为大二毫无基础,第一次用idea第一次接触java,开始的时候连数据库都不了解.搭环境都用了一个月,后面补了一些基础知识后才发现原来搭环境非常简单.用了三个小时重新搭了环境并调用java api

1,看官网下载相应版本(非常重要!!!不要偷懒图方便省事!!!踩了无数坑)

github查看版本网址:

我用的版本janusgraph:0.6.2,cassandra:3.11.10

(这么多包足以看出我踩了多少坑)

2,因为我只是将canssandra作为存储后端,所以图的配置文件选用conf/

3,打开conf/gremlin.server/gremlin-server.yaml,将其中的图配置内容更改为janusgraph-cql.properties

这样就配置好了

 

4,开启canssandra和janusgraph的server

 

 

5,打开IDEA,创建一个maven工程

6,配置依赖,相关版本在github里你安装的janusgraph对应的文档连接,里面有相关配置信息.

我配置的依赖:

7,配置文件: 可直接从下载janusgraph的文件夹里复制过来,也可以自己建一个,内容在上面的文档里都有.

remote-graph.properties.xml

remote-objects.yaml 

注意,hosts文件是localhost,改成自己的host就可以了

8.编写测试非常简单的demo

package janusgraph_test;

import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
import org.apache.tinkerpop.gremlin.structure.Vertex;
import org.janusgraph.core.JanusGraph;
import org.janusgraph.core.JanusGraphFactory;
import org.janusgraph.core.schema.JanusGraphManagement;

public class test2 {
    public static void main(String[] args) throws Exception {
        //1,连接图
        JanusGraph graph = JanusGraphFactory.open("D:\\application\\janusgraph\\janusgraph-full-0.6.2\\conf\\janusgraph-cql.properties");
        //2,获得mgmt,这里没用到,但之后会很有用
        JanusGraphManagement mgmt = graph.openManagement();
        //3,获得遍历图柄
        GraphTraversalSource g = graph.traversal();
        //4加入属性为person,key值为name,value为John的顶点
        g.addV("person").property("name", "John").next();
        //5获取顶点并输出
        Vertex vertex = g.V().has("name","John").next();
        String name = vertex.value("name");
        System.out.println(name);

        //6释放资源
        g.close();
        mgmt.commit();
        graph.close();

    }
}

 

输出结果:说明连上啦

 

9,在idea里面可以看到cassandra里的键空间,我设置的janusgraph名字为janusgraphWithCassandra,这个在properties.xml文件里更改就可以

 

 

 

 

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值