title: Generic Dao and service Layer
body: <p>I am going to design a DAO layer for my application. My focus is that Services just calls DAO which is independent of underlaying implementation. </p>
  
  <pre><code>    public interface GenericSearchDao{
          List getAll();
          List getByQuery(String query);
  }
  
  public class UserJdbcSearch implements GenericSearchDao{
  
          public List getAll(){
                  // Get all users;
          }
  
          List getByQuery(String query){
                  // Get users by query;
          }
  
  }
  
  public class UserFileSystemSearch implements GenericSearchDao{
  
          public List getAll(){
                  // Get all users from file system;
          }
  
  
          List getByQuery(String query){
                  // Get users by query[this leads to invalid operation];
          }
  }
  
  public userService {
  
          private GenericSearchDao dao = new UserFileSystemSearch();
  
          public List getUsers(){
                  rturn dao.getAll();
          }
  
           public List getByQuery(String query){
                 return  dao.getByQuery(query);
          }
  }
  </code></pre>
  
  <p><strong>Help Required:</strong></p>
  
  <p>What should I do to get rid from 'getByQuery(query)' specific implementaions because datastore can be RDBMS, filesystem, FTP etc. </p>
  
  <p>How should I design my Dao layer generically?</p>
  
  <p>If any one says "remove the getByQuery() from GenericSearchDao" then what should i do in the case where i need data specific to business operation for eg : user with roles , user with products etc..</p>