I am writing a micro-service that should work with multiple database.
For example, assume project A is working with MongoDB, then my service should know how to connect and work (querying, saving, etc...) with MongoDB (or any other SQL database).
I have read this document written by Oracle explaining the DAL and DAO models, but as I understand, I need to implement every method for every kind of query that I would like to execute.
For example, let's say I have this class:
public class Account {
private String userName;
private String firstName;
private String lastName;
private String email;
private int age;
}
As concluded from the link above, for every query that I want to execute I need to write a function in the DAO interface (like a db gateway), i.e:
getAccountByEmail(...)
getAccountByUsername(...)
getAccountByUsernameAndEmail(...)
This seems to me like a bad approach which will result in too much methods to handle.
There are also query fields the model does not contain. For instance, if my model has a creation date and I want to query the object in between two dates, I need a way to query the DB for those fields.
I have been looking around for a while now, but I couldn't find a guide or a best practice to approach this problem.
I would like to know if there is any other way to solve this but implementing every method.