What is the best practice to update a Vertex after

2019-09-07 05:04发布

问题:

Let's exemplify

  1. I receive a Vertex with Tinkerpop Blueprint, then I use Frames to convert it in an entity.
  2. I close the database (so from now the node is detached from the DB)
  3. 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

回答1:

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.