使用Tinkerpop框架从数据库中分离后,更新顶点的最佳做法是什么? [英] What is the best practice to update a Vertex after is detached from DB with Tinkerpop Frames?
本文介绍了使用Tinkerpop框架从数据库中分离后,更新顶点的最佳做法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
- 我用Tinkerpop Blueprint接收一个顶点,然后使用Frames将它转换为实体。
- 我关闭数据库(所以从现在开始,数据库从数据库中分离出来)
- 然后我在网页上显示节点让用户修改它。
用户进行了一些修改,然后我应该坚持修改。
问题是数据库的实例已经关闭,所以实体与数据库分离:更新节点的最佳实践(考虑性能和内存使用情况)?
这可能是代码示例:
FramedGraph< OrientGraph> graph = factory.getFramedGraph();
User user = graph.addVertex(null,User.class);
graph.shutdown();
然后我想稍后更新节点:
user.name =唐老鸭;
用户....?
谢谢,
Andrea
解决方案
我发现这种方式,看起来效率很高:
public User persistUser用户用户){
FramedGraph< OrientGraph> graph = factory.getFramedGraph();
user = graph.frame(user.asVertex(),User.class);
factory.persist();
graph.shutdown();
所以框架自动将实体合并回数据库。
然后你必须坚持下去。
Let's exemplify
- I receive a Vertex with Tinkerpop Blueprint, then I use Frames to convert it in an entity.
- I close the database (so from now the node is detached from the DB)
- and I show the node on a web page to let the user modify it.
The user makes some modifications, then I shoud persist the changes.
The problem is that the Instance of the database is already closed, so the entity is detached from the database: What is the best practice (considering performance and memory usage too) to update the node?
This may be the code example:
FramedGraph<OrientGraph> graph = factory.getFramedGraph();
User user = graph.addVertex(null, User.class);
graph.shutdown();
then I want to update later the node:
user.name = "Donald Duck";
user.... ?
Thank you, Andrea
解决方案
I found this way, that seems quite efficient:
public User persistUser(User user){
FramedGraph<OrientGraph> graph = factory.getFramedGraph();
user = graph.frame(user.asVertex(), User.class);
factory.persist();
graph.shutdown();
So the framework automatically merge back the entity to the database. Then you have to persist.
这篇关于使用Tinkerpop框架从数据库中分离后,更新顶点的最佳做法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文