Skip to content

Instantly share code, notes, and snippets.

@tareqabedrabbo
Last active December 17, 2015 16:38
Show Gist options
  • Save tareqabedrabbo/5639890 to your computer and use it in GitHub Desktop.
Save tareqabedrabbo/5639890 to your computer and use it in GitHub Desktop.
Neo4j optimistic locking
create n:Person {name: "Bob", updated: timestamp()}
return n
match n:Person
where n.name = "Bob"
and n.updated = 1369253063366
set n.title = "The Bat", n.updated = timestamp()
return count(n)
create n:Person {name: "Fred", title: "The Cat", updated: timestamp()}
return n
match b:Person, f:Person
where b.name = "Bob" and f.name = "Fred"
and b.updated = 1369253064500 and f.updated = 1369254187545
create b-[r:KNOWS]->f
set b.updated = timestamp(), f.updated = b.updated, r.updated = b.updated
return count(r)
{
"statements" : [ {
"statement" : "match b:Person where b.name ={name} and b.updated = {updated} set b.name = {new_name} return count(b)",
"parameters" : {"updated" : 1369254281895,"name" : "Bob","new_name": "bob"
}
} ]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment