This post was inspired by the following question from StackOverflow: Reusable generic base class DAOs with Android Room. I reuse the original question and I try to approach the problem with Kripton.

Room’s approach avoids using an ancestor interface for DAO interface to define for the SELECT operations. A parent DAO interface can be used only to define operationINSERT/UPDATE/DELETE but no SELECT operation. The reason is that Room Library allows defining queries specifying all the SQL code. In the StackOverflow question, the model that developer want to solve is:

With Kripton, life is better.

Question: is there any way to create reusable generic base interface DAOs with Kripton?

The answer is YES. It’s possible to define SELECT, INSERT, UPDATE and DELETE operation on a generic parent interface.  Let’s take the previous question and previous model and see them in Kripton context. Translating model into Kripton style we obtain:

And the derived DAO interfaces:

Why Kripton allow us to do these? The answer is simple: because Kripton allows defining a query in explicit mode, specifying all the SQL or in compact mode, specifying only the necessary SQL part. Given a specific DAO interface, Kripton already knows that the interface is associated to a specific POJO and every operation that will be done on it (it is also possible to go beyond this, but this is not the situation). So… if we know that a SELECT work on a TABLE, which is the part of the query that we really need? The WHERE conditions!!!

This fact allows to bring commons method SELECT, UPDATE, INSERT and DELETE defined in a compact mode to a base DAO interface.

For any question don’t hesitate to comment this post.

For more information about how to define SQL method in Kripton, you can also read this post and this mini-guide on Kripton ORM.

For more information about Kripton Persistence Library:

Happy coding!


By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.