Bringing together the Apache Cassandra experts from the community and DataStax.

Want to learn? Have a question? Want to share your expertise? You are in the right place!

Not sure where to begin? Getting Started

 

question

vpanarin84_192084 avatar image
vpanarin84_192084 asked Erick Ramirez edited

Is it possible to extend my DaoBase class?

Hi!

While using DataStax Java Driver I've faced a situation when I need to extend DaoBase class. It is the ancestor for classes generated when the driver's object mapper is used.

Say, I define a mapper for my DAOs:

@Mapper
public interface MyMapper {
  @DaoFactory
  MyOperator operator(@DaoKeyspace String keyspace, @DaoTable String entitiesTable);
}

Then, I define the DAO itself:

@Dao
public interface MyOperator
{
  @Insert
  CompletableFuture<MyEntity> write(MyEntity ent);
}

When the annotations processor generates the classes, I see the following one:

public class MyOperatorImpl__MapperGenerated extends DaoBase implements MyOperator {
...
}

I would like MyOperatorImpl__MapperGenerated class to extend not DaoBase, but its child. This way I could override execute() method of DaoBase and add my code to it, for example, to log each query or to retry failed ones after a delay.

If there a way to achieve this? Couldn't find any options with annotations.

java driver
10 |1000 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

1 Answer

alexandre.dutra avatar image
alexandre.dutra answered

Unfortunately the parent class for DAOs is not configurable. I suggest that you use the decorator pattern instead to add functionality like logging or retrying.

Share
10 |1000 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.