How to set the consistency level with a Mapper object?

128 views
Skip to first unread message

Carlos Scheidecker

unread,
Sep 27, 2014, 8:25:07 AM9/27/14
to java-dri...@lists.datastax.com
Hello,

I understand that you can set the consistency level if you use the Statement object.

But if I use the mapper as:

MappingManager manager = new MappingManager(session);
Mapper<Token> mapper = manager.mapper(Token.class);
mapper.save(token);

How can I set the consistency leve?

So if I have replication factor of 3, I just want consistency level of one so that the writes are always fast, the system will then replicate it asynchornously for me.

How can I do it with a MappingManager ?

Or do I have to set that when I connect to the cluster first or at the Session level?

Thanks,

C.

Olivier Michallat

unread,
Sep 29, 2014, 11:31:51 AM9/29/14
to java-dri...@lists.datastax.com
Hi,

You have two options:
1) pass the writeConsistency and readConsistency parameters to the @Table annotation of your mapped class. They will be used for all the statements generated by this mapper.
2) use mapper.saveQuery to get back a Statement object, on which you can set the consistency level (and a number of other options) manually.

datastax_logo.png

OLIVIER MICHALLAT

Drivers & Tools Engineer | olivier....@datastax.com


linkedin.png facebook.png twitter.png g+.png



To unsubscribe from this group and stop receiving emails from it, send an email to java-driver-us...@lists.datastax.com.

Carlos Scheidecker

unread,
Oct 1, 2014, 7:31:26 AM10/1/14
to java-dri...@lists.datastax.com
Thanks Olivier! The Table annotation is great. But I liked the second one as well as it can return the query so that you can custom fix it.
Reply all
Reply to author
Forward
0 new messages