如何在Java中将属性添加到顶点属性? [英] How to add property to vertex property in java?

查看:103
本文介绍了如何在Java中将属性添加到顶点属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将属性添加到顶点属性.在gremlin中,我将属性"phone"添加到顶点属性"places",其值为"place1"

I want to add property to a vertex property. In gremlin i add property "phone" to vertex property "places" that has value is "place1"

g.V(v).properties('places').hasValue('place1').property('phone',"123456789")

不使用事务提交就可以了.但是,当我在Java代码中使用这种方式时,它不起作用.因此,在Java代码中,如何向顶点属性添加属性? 感谢您的帮助.

It worked ok without using transaction commit. But when i used this way in java code, it not worked. So in java code, how to add a property to vertex property? Thank for your help.

推荐答案

您需要iterate()遍历.

g.V(v).properties('places').hasValue('place1').property('phone',"123456789").iterate()

一种思考方式:原始代码段是查询,但是您仍然需要执行它.

One way to think about: the original code snippet is the query, but then you still need to execute it.

这是一个完整的Gremlin Console示例,显示了差异.

Here's a full Gremlin Console example that shows the difference.

gremlin> graph = TitanFactory.open('inmemory'); g = graph.traversal()
==>graphtraversalsource[standardtitangraph[inmemory:[127.0.0.1]], standard]
gremlin> v = graph.addVertex('name','jenny','places','home')
==>v[4264]
gremlin> g.V(v).properties('places').hasValue('home')
==>vp[places->home]
gremlin> g.V(v).properties('places').hasValue('home').property('phone','867-5309'); 'traversal was not iterated'
==>traversal was not iterated
gremlin> g.V(v).properties('places').hasValue('home').properties()
gremlin> g.V(v).properties('places').hasValue('home').property('phone','867-5309').iterate(); 'iterated!'
==>iterated!
gremlin> g.V(v).properties('places').hasValue('home').properties()
==>p[phone->867-5309]
gremlin> graph.tx().commit()
==>null

如果要保留数据,则需要提交事务.

You need to commit the transaction if you want the data to be persisted.

这篇关于如何在Java中将属性添加到顶点属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆