Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OrientDB, how to retrieve previous record version

I'm researching OrientDB in order to evaluate versioning capabilities of graph databases.

Each record in OrientDB has a @version property which increases every time a record is updated. This indicates support for versioning. I've set up a simple example (using OrientDB SQL) to test this:

create class Product
create property Product.name string
create property Product.price integer
insert into Product (name, price) values ('Fridge', 449)
update Product set price = 479 where name = 'Fridge'
select from Product

After executing the statements above, I get the following query result:

{
    "result": [
        {
            "@type": "d",
            "@rid": "#14:0",
            "@version": 2,
            "@class": "Product",
            "name": "Fridge",
            "price": 479
        }
    ],
    "notification": "Query executed in 0.031 sec. Returned 1 record(s)"
}

In this database state - how can I retrieve a previous version (version 1 in this simple case) of my record? Is this possible through an OrientDB SQL statement and/or via the OrientDB Java API? If not - what's the purpose of the @version property then?

like image 304
raisyn Avatar asked Aug 17 '14 15:08

raisyn


1 Answers

The purpose of the @version property is to check if any update have been made between the time you fetched the object and when you updated it.

For instance if in your code you fetch a product, you update its properties, in the meanwhile the object has changed in the database (another piece of code has updated it), then you save it : you are trying to update the object with the version 2, but it has the version 3 in database.

This can help you to prevent concurrent access to your database.

I don't know if the functionality you are looking for will be implemented in OrientDB. If you don't need it, then don't do it. If you really need this, you can do it yourself, maybe by creating a Product_old class and fill it with previous records on update.

like image 61
Jul13nT Avatar answered Oct 05 '22 22:10

Jul13nT