ACID and multiple Transaction in OrientDb

149 views
Skip to first unread message

kurtuluş yılmaz

unread,
Mar 16, 2015, 2:10:09 PM3/16/15
to orient-...@googlegroups.com
Hi everbody;
Hi; how we can update one document and one graph db in an atomic operation. Db instances for graph and document databases are different so I try to use nested transaction but I failed. Is there any way to create atomic operation it includes update for document and graph databases. Following code segment just commits graphDb not documentDb. How can commit graphDb and documentDb in same transaction or in same thread.
Best Regards.

try{
            documentDb = new ODatabaseDocumentTx("remote:localhost/TestDocumentDb").open("root", "Kaos8619");

            OrientGraphFactory factory = new OrientGraphFactory("remote:localhost/GratefulDeadConcerts","root","Kaos8619").setupPool(1,10);
            db = factory.getTx();
            documentDb.getTransaction().begin();
            ODocument doc = new ODocument("Person");
            doc.field( "name", "Burhan" );
            doc.field( "surname", "Skywalker" );
            doc.field("age",33);
            doc.save();
            documentDb.commit();
            db.addVertex("class:Person", "name", "Burhan", "age", 33, "city", "Rome", "born", "Victoria, TX");
            db.commit();

        }finally {
            db.shutdown();
            documentDb.close();
        }

Colin

unread,
Mar 16, 2015, 5:09:44 PM3/16/15
to orient-...@googlegroups.com
You can actually get a reference to the underlying ODatabaseDocumentTx from the Graph DB by calling db.getRawGraph().

Try using that instead of creating two separate connections from the same thread.

Let me know how that works.

-Colin

Orient Technologies

The Company behind OrientDB

kurtuluş yılmaz

unread,
Mar 16, 2015, 8:49:34 PM3/16/15
to orient-...@googlegroups.com
Hi Colin.a
I really appreciate your  response. Your advice solved  my problem and opened my mind. First I added document to same Db with graph to GraphDb. First I tried your advice and I write code it works. After than I realized that I don't need ODatabaseDocumentTx for committing documents I just try OrientGraph instance and it persists both document and vertice. I succeed atomic operation which includes graph operation and document operation. You can see at Second Code Fragment.
Thank you again.

------------------------------------First--------------------------------------------------------------------------------------------------------------------------



  OrientGraphFactory factory = new OrientGraphFactory("remote:localhost/GratefulDeadConcerts","root","root").setupPool(1,10);
            db = factory.getTx();
            documentDb = db.getRawGraph();

            db.addVertex("class:Person", "name", "Sezer", "age", 33, "city", "Rome", "born", "Victoria, TX");

            documentDb.getTransaction().begin();
            ODocument doc = new ODocument("PersonExtended");
            doc.field( "name", "Sezer" );
            doc.field( "sml", 33 );
            doc.save();
            db.commit();

-------------------------------Second-------------------------------------------------------------

 OrientGraphFactory factory = new OrientGraphFactory("remote:localhost/GratefulDeadConcerts","root","root").setupPool(1,10);
            db = factory.getTx();
            db.addVertex("class:Person", "name", "Ahmet", "age", 33, "city", "Rome", "born", "Victoria, TX");
            ODocument doc = new ODocument("PersonExtended");
            doc.field( "name", "Ahmet" );
            doc.field( "sml", 33 );
            doc.save();
            db.commit();




16 Mart 2015 Pazartesi 23:09:44 UTC+2 tarihinde Colin yazdı:

Colin

unread,
Mar 16, 2015, 9:16:06 PM3/16/15
to orient-...@googlegroups.com
My pleasure.  :)

Just to be clear, so others know as well, a Vertex can mostly be used where a Document is used (it uses one under the covers), even if you don't need to add edges to it.  The main difference with the graph API is that it uses auto-start transactions and will auto-save when a property is set, unlike a Document.

-Colin

Orient Technologies

The Company behind OrientDB



Reply all
Reply to author
Forward
0 new messages