Skip to content

Conversation

mp911de
Copy link
Member

@mp911de mp911de commented Jan 30, 2019

We now support Optimistic Locking for insert, update and delete operations leveraging Cassandra's lightweight transaction support. Modifying statements are enhanced with IF conditions to conditionally insert and modify rows and to prevent concurrent modifications by throwing OptimisticLockingFailureException.

@Table class Person { @Id String id; String firstname; String lastname; @Version Long version; } Person daenerys = template.insert(new Person("Daenerys")); Person tmp = template.findOne(query(where("id").is(daenerys.getId())), Person.class); daenerys.setLastname("Targaryen"); template.save(daenerys); template.save(tmp); // throws OptimisticLockingFailureException

Depends on: DATACASS-575, #135.
Related ticket: DATACASS-576.

… UPDATE and DELETE. We now support conditions in lightweight transactions for UPDATE and DELETE statements. Conditions are Filter objects similar to the WHERE clause. Conditions are supported for entity- and query-based update/delete methods. UpdateOptions options = UpdateOptions.builder().ifCondition(where("firstname").is("Walter")).build(); User user = new User("heisenberg", "Walter", "White"); template.update(user, options); DeleteOptions options = DeleteOptions.builder().ifCondition(where("counter").is(42)).build(); Query query = Query.query(where("id").is("heisenberg")).queryOptions(options); template.delete(query, User.class);
We now support Optimistic Locking for insert, update and delete operations leveraging Cassandra's lightweight transaction support. Modifying statements are enhanced with IF conditions to conditionally insert and modify rows and to prevent concurrent modifications by throwing OptimisticLockingFailureException. @table class Person { @id String id; String firstname; String lastname; @Version Long version; } Person daenerys = template.insert(new Person("Daenerys")); Person tmp = template.findOne(query(where("id").is(daenerys.getId())), Person.class); daenerys.setLastname("Targaryen"); template.save(daenerys); template.save(tmp); // throws OptimisticLockingFailureException
Formatting. Reorder methods for consistent method ordering.
@mp911de mp911de force-pushed the issue/DATACASS-576 branch from 96a4b8c to d33c19a Compare January 30, 2019 20:25
@jxblum
Copy link
Contributor

jxblum commented Mar 1, 2019

We may want to consider support for version properties other than of type long, or primitive types in general.

Often times, it is even useful to use multiple properties in optimistic locking (e.g. user + timestamp).

Our initial implementation should satisfy most UCs for the time being.

@jxblum jxblum self-assigned this Mar 1, 2019
@jxblum jxblum added this to the Moore-M2 milestone Mar 1, 2019
@jxblum jxblum closed this in 159c678 Mar 1, 2019
@mp911de mp911de deleted the issue/DATACASS-576 branch March 1, 2019 09:27
@mp911de
Copy link
Member Author

mp911de commented Mar 1, 2019

@jxblum care to file a ticket against Spring Data Commons to discuss the idea?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants