Please add the ability to configure the Cassandra consitency level
We'd like to have the ability to configure the Cassandra consistency level. Ideally we'd be able to do this per query or at the very least be able to configure it at the entity level.
Thanks,
Dan
target for 2.0.7
Guys, in this matter, what is the current default custom level used by Kundera in reads and in persists? I could not find this information in the documentation. Regards.
Current it is defaulted to ConsistenceLevel.ONE.
-Vivek
Right, Cassanrda leaves the default value up to the client and that is typically ONE.
Fixed and releasing in 2.0.7.
-Vivek
I can't seem to find any documentation on how to specify the consistency level per query. Nor can I find a clear example in any of the unit tests. Is there an example that explains how to do it somewhere?
Give below code snippet should help you out: (For example)
Map<String, Client> clientMap = (Map<String, Client>) em.getDelegate();
PelopsClient pc = (PelopsClient)clientMap.get("cassandra");
pc.setCqlVersion(CassandraConstants.CQL_VERSION_3_0);
pc.setConsistencyLevel(ConsistencyLevel.ALL);
Not sure, there was a test case earlier. I will have a look on it.
-Vivek
Hi, Is there any way to change CQL version using Spring?
Map<String, Client> clientMap = (Map<String, Client>) em.getDelegate();
map always empty for me.
Yes. You can change CQL version as:
Map<String, Client> clientMap = (Map<String, Client>) em.getDelegate();
ThriftClient tc = (ThriftClient) clientMap.get("cassandra");
tc.setCqlVersion(CassandraConstants.CQL_VERSION_3_0);
-Vivek
But clientMap is always empty for me and
clientMap.get("cassandra")
returns null
clientMap.get("cassandra") => replace "cassandra" with configured persistence unit.
-Vivek
Unfortunately, but not working for me. I've sent you a project with a test.
On which id?
Not sure why is it not working for you. You can refer: https://github.com/impetus-opensource/Kundera/blob/trunk/kundera-cassandra/src/test/java/com/impetus/client/crud/compositeType/CompositeDataTypeTest.java
for sample test case as well.
-Vivek
So as per your project:
I guess,
Map<String, Client> clientMap = (Map<String, Client>) em.getDelegate();
ThriftClient tc = (ThriftClient) clientMap.get("mto_pu");
tc.setCqlVersion(CassandraConstants.CQL_VERSION_3_0);
should work for you. Also you have annotated your EntityManager with @PersistenceContext but no unit name specified.
-Vivek
Thanks for you advices, but it doesn't work for me. Did you tried to run TestCQLVersion from the my test project?
@RunWith(SpringJUnit4ClassRunner.class)
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD)
@ContextConfiguration(locations = {"classpath:application-context.xml"})
public class TestCQLVersion {
@PersistenceContext(unitName="mto_pu")
private EntityManager entityManager;
@Test
public void testCqlVersionSet(){
Map<String, Client> clientMap = (Map<String, Client>) entityManager.getDelegate();
ThriftClient tc = (ThriftClient) clientMap.get("mto_pu");
assertNotNull(tc);
assertTrue("Map is empty",0 < clientMap.size());
assertNotNull("Cassandra client is null",clientMap.get("cassandra"));
assertNotNull("Cassandra client by persistence unit name is null",clientMap.get("mto_pu"));
}
}
This test will be failed, because tc is null
I have not tried it yet. In your persistence.xml replace:
<persistence-unit name="mto_pu">
with
<persistence-unit name="mto_pu" transaction-type="JTA">
As you are initializing entity manager with @PersistenceContext, means container managed .
-Vivek
Thanks for your help, but test still fail, because clientMap is empty and tc is null. :(
Assigning to Amresh. He will be looking into this.
-Vivek