Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 433 Vote(s) - 3.43 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Datastax cassandra object mapper setting consistency and if not exists

#1
I created entity which is annotated with `@Table` and it resembles my cassandra table. I can do save, get and everything without much problems.

My problem comes when I want to do something more exciting, like set consistency level or do if not exists insert or something like that. Basically there is annotation option for `@Table` where you can configure read and write consistency but what if you use Spring and set that through configuration file? I really like having external configuration for those things. Also how to do if not exists save?

I know that you can get `saveQuery` or `getQuery` as `Statement` and from it you can set consistency at least but it looks ugly, then you must take result set, do map and get your object.

Have two questions:

- Is there a better way of dynamically setting consistency level for object mapper actions both with accessor and entity?
- How to do if not exists save for mapped object?
Reply

#2

>>How to do if not exists save for mapped object?

You will need to use accessor interface and specify your custom query there. If you need to udate only a small subset of fields that will work perfectly.

If you need to save the whole object with IF NOT EXISTS it could be done using two steps: first to update a specfic field with IF NOT EXISTS to logically say that row is being updating and second to save the object to that row using mapper.save operation. It all depends on whether it is sutable for your app logic.

[docs from cassandra][1]


[1]:

[To see links please register here]


It could be wrapped into yout Dao object that uses mapper.save/load for simple operations.
Reply

#3
I understand this a very old question. but some of the answers here are outdated hence, I am adding my answer here.

With driver version 4.x you can use the @StatementAttributes annotation to set the consistency level and other statement attributes for each of the mapper dao methods.

@Dao
public interface ProductDao {
@Select
@StatementAttributes(consistencyLevel = "ONE", pageSize = 500)
Product findById(int productId);
}
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through