如何覆盖 Titan 数据库中的顶点 ID? [英] How to overwrite vertices ID in Titan Database?

查看:20
本文介绍了如何覆盖 Titan 数据库中的顶点 ID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用一个框架来生成对象 Node 并且它们已经分配了一个 id.现在需要将它们转换为框架中控制的具有相同 ID 的 Titan 顶点(通过 node.id 访问)

I'm using a framework that generates objects Node and they already have assigned a id. Now they need to be converted to Titan vertices with the same ID controlled in the framework (accessed with node.id)

public long addNode(Node node) {    
   TitanVertex vertex = (TitanVertex) g.addVertex(null);
   g.commit();

   vertex.setProperty(ID, node.id);
   vertex.setProperty(TYPE, node.type);
   vertex.setProperty(VERSION, node.version);
   vertex.setProperty(TIME, node.time);
   vertex.setProperty(DATA, node.data);
   ...

错误:

java.lang.IllegalArgumentException: Name is reserved: id

但是好像不允许.我应该使用一些假属性来模仿辅助 ID 吗?泰坦有办法做到这一点吗?

But it seems to not allow it. Should I use some fake property to imitate a secondary Id? Does Titan has some way to do that?

谢谢!

推荐答案

实际上很少有图形数据库允许您设置元素标识符.无论您使用的是 Neo4j、OrientDB、Titan 等,它们都倾向于拥有自己的 ID 系统. TinkerGraph 确实是唯一允许分配 ID 的蓝图实现.

Very few graph databases actually allow you to set the element identifier. They all tend to have their own ID systems whether you are using Neo4j, OrientDB, Titan, etc. TinkerGraph is really the only Blueprints implementation that allows ID assignment.

如果您想保留您的 ID,那么您只需将其重命名为其他名称即可.代替id",也许您可​​以使用iid".为了使事情更加透明,从编程的角度来看,您可以考虑使用 IdGraph 包装器,这将允许您执行以下操作:

If you want to keep your ID, then you should simply rename it to something else. Instead of "id", perhaps you could use "iid". To make things more transparent, from a programming perspective, you might consider use of the IdGraph wrapper, which would allow you to do something like:

gremlin> base = TitanFactory.open('/tmp/titan-berkley')
==>titangraph[local:/tmp/titan-berkley]
gremlin> g = new IdGraph(base, true, false)            
==>idgraph[titangraph[local:/tmp/titan-berkley]]
gremlin> g.addVertex(45)  
==>v[45]
gremlin> g.v(45)
==>v[45]

您可以看到 IdGraph 允许它看起来好像您正在分配元素 ID 本身.在幕后,它实际上只是使用关键索引.

You can see IdGraph allows it to appear as though you are assigning the element id itself. Behind the scenes it is actually just using key indices.

这篇关于如何覆盖 Titan 数据库中的顶点 ID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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