orientechnologies / orientdb

OrientDB is the most versatile DBMS supporting Graph, Document, Reactive, Full-Text and Geospatial models in one Multi-Model product. OrientDB can run distributed (Multi-Master), supports SQL, ACID Transactions, Full-Text indexing and Reactive Queries.
https://orientdb.dev
Apache License 2.0
4.74k stars 870 forks source link

reattach graph elements #2007

Closed luigidellaquila closed 10 years ago

luigidellaquila commented 10 years ago

Hi, implementing CRUD applications, in may cases the user creates a new (temporary) vertex and stores temporary information on it, until he decides to save the vertex and make it persistent. A lot of time can spend from the creation to the save, so I think it's not a good practice to keep the database connection open. I would like to be able to reattach a vertex to a new connection, different from the one I used to create the temporary vertex.

Eg.

//create connection "db" Vertex v = db.addTemporaryVertex("MyClass"); db.shutdown(); //do your operations on v ... //after some minutes //create a new connection "db2" v.attach(db2); v.save(); db2.commit();

andrii0lomakin commented 10 years ago

Hi, just use following methods com.tinkerpop.blueprints.impls.orient.OrientElement#getRecord to get underlying record (you can close connections after that) instead of properties you can use fields.

And then you can just call graph.getVertex(record) to attach it and save.

On Wed, Jan 29, 2014 at 5:24 PM, luigidellaquila notifications@github.comwrote:

Hi, implementing CRUD applications, in may cases the user creates a new (temporary) vertex and stores temporary information on it, until he decides to save the vertex and make it persistent. A lot of time can spend from the creation to the save, so I think it's not a good practice to keep the database connection open. I would like to be able to reattach a vertex to a new connection, different from the one I used to create the temporary vertex.

Eg.

//create connection "db" Vertex v = db.addTemporaryVertex("MyClass"); db.shutdown(); //do your operations on v ... //after some minutes //create a new connection "db2" v.attach(db2); v.save(); db2.commit();

— Reply to this email directly or view it on GitHubhttps://github.com/orientechnologies/orientdb/issues/2007 .

Best regards, Andrey Lomakin.

Orient Technologies the Company behind OrientDB

lvca commented 10 years ago

Letting the developer to work with 2 APIs is not so good. We should find an elegant way to let the user to work with Graph Element in detach mode. This is very common on Web Apps. My idea is:

OrientElement detached = graph.detach( OrientElement );

The detached instance could be used offline, until the attach is called:

OrientElement attached = graph.attach( OrientElement );

Makes sense?

andrii0lomakin commented 10 years ago

Agree :-)