I have a DAO with a method CommitmentListDAO.getListByOwnerBadge that returns an arraylist of commitment items against a supervisor badge (database field OWNED_BY)
String SQL_VIEW_LIST_BY_SUPERVISOR = SELECT_QUERY +
" WHERE c.OWNED_BY = ? " +
" ORDER BY p.PROGRAM_NAME";
Now, I want to add a pull down on my web form to allow the user to choose between Owned By or Tasked To
I’ll need to add a WHERE c.TASKED_TO = ? clause in the DAO.
Do I perform the logic for which field to search on within the DAO – say a passed in parameter of the pulldown (Never the request object) and rename the method to getListByBadge(String whichField, String badge) or should my CommitmentListForm class have this logic and then make the appropriate call to either getListByOwnerBadge or getListByTaskeToBadge
I would go with a DAO on it with two different methods to clearly differentiate what the call does.
The point of a DAO is to hide the SQL implementation details. You should always consider a question like this from the standpoint of, “What if I switched to a different persistence mechanism, like HBase?” The HBase implementation may not store this in a way that simply differentiates by a field name. The DAO should make it possible to hide that detail, thus the different methods.
Just my opinion, of course. 🙂