Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support lightweight transactions (if [not] exists) [DATACASS-250] #426

spring-projects-issues opened this issue Jan 20, 2016 · 2 comments
in: core Issues in core support type: enhancement A general enhancement


Copy link

Anton Koscejev opened DATACASS-250 and commented

It would be nice to support lightweight transactions. At least in CassandraOperations, so that they can be used by custom repository methods.

Something like this:

<T> boolean insertIfNotExists(T entity);
<T> boolean updateIfExists(T entity);

Or this (note the exceptions):

<T> T insertIfNotExists(T entity) throws CassandraEntityExistsException;
<T> T updateIfExists(T entity) throws CassandraEntityDoesNotExistException;

Or perhaps simply adding it to WriteOptions:

public IfOption getIfOption() {
     return ifOption;
public void setIfOption(IfOption ifOption) {
     this.ifOption = ifOption;

With some Enum like this:

public enum IfOption {IF_EXISTS, IF_NOT_EXISTS}

Or as two separate options (but then have to ensure only one is specified).

With insert/update automatically chosen based on which option is specified, if any. And exceptions thrown in case of WriteOptions

Referenced from: pull request #107, and commits 8d64401, b72ad3d, 10eab88, 6ccab0f

Copy link

Antoine Toulme commented

Here is a long way to do it:
Insert insert = CassandraTemplate.createInsertQuery(cassandratemplate.getTableName(user.getClass()).toCql(), entity, options, cassandraTemplate.getConverter());

I think this could be repurposed into a method of CassandraTemplate easily

Copy link

John Blum commented

Reviewed, polished and merged! Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
in: core Issues in core support type: enhancement A general enhancement
None yet

No branches or pull requests

2 participants