2

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.

Jason Nethercott
  • 373
  • 3
  • 20
  • can you write things that you're struggling with? Mapper in 4.x is simply different, but it has more functionality compared to the 3.x mapper... – Alex Ott Mar 27 '20 at 17:39
  • In this example, how do I make my [Dao] [Insert] have a consistency level of one, and the [Dao] [Select] have a consistency level of quorum. It can be done if I use plain Statements... but, well, we like the [Mapper]. – Jason Nethercott Mar 27 '20 at 18:29
  • In this class... I need the Select and Insert interfaces to have different consistency levels. @@Dao public interface FieldTestsDao { @@Select PagingIterable findById(String id); @@Select FieldTests findByKeyFields(String id, String source, String subSource); @@Insert void save(FieldTests ft); – Jason Nethercott Mar 27 '20 at 18:31

1 Answers1

3

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...

Alex Ott
  • 80,552
  • 8
  • 87
  • 132
  • I think that documentation should be improved, especially for migrate path... I’ll ask developers about it. In the meantime you can always ask at https://community.datastax.com/ or in the driver mailing list at google groups – Alex Ott Mar 27 '20 at 20:31
  • JIRA is created to improve docs: https://datastax-oss.atlassian.net/browse/JAVA-2712 – Alex Ott Mar 28 '20 at 09:49
  • 1
    This github repo should help you. https://github.com/clun/java-cassandra-driver-from3x-to4x . We do have plan to incorporate in official documentation : – clunven Mar 30 '20 at 09:26