cassandradatastaxcassandra-driver

Cassandra 3.x to 4.x driver differences


Can anyone tell me how to replication this old annotation from the Datastax 3.x series of drivers to the new 4.x series:

@Table(
        name = "mytable",
        readConsistency = "LOCAL_ONE",
        writeConsistency = "LOCAL_QUORUM")

I got the name down: @CqlName("mytable"), just not the consistencies.

We use mappers exclusively in our code - they are fast, and did a lot of boiler-plate stuff for you in the 3.x driver. In 4.x, not so much and it's frustrating. There are some things we rely on that I just cannot figure out - like this.

Also (different question but I'll ask here). Can I set a profile on a session? Struggling with that one too.


Solution

  • As driver upgrade guide says:

    the "mapper" and "accessor" concepts have been unified into a single "DAO" component, that handles both pre-defined CRUD patterns, and user-provided queries.

    In your case you're switching from @Table to @Entity, like this:

    @Entity
    @CqlName("mytable")
    class MyPojoClass {
    
    }
    

    And then you define Dao class where you define individual operations, like, insert/delete/select:

    @Dao
    public interface ProductDao {
    
      @Select
      MyPojoClass findBySomething();
    
      @Insert
      void save(MyPojoClass cls);
    
      @Delete
      void delete(MyPojoClass cls);
    }
    

    these operations could be annotated with @StatementAttributes annotation, that has consistencyLevel, executionProfileName, and many other attributes.

    P.S. For me, one of the big improvements in new Mapper is that you may use the same Entity class with multiple keyspaces & tables inside the same session...