« - »

DAO Refactoring: RequestForApprovalDao

11 April 2009

The first step in refactoring the Approval Service to conform to our accepted DAO methodology is to create the RequestForApprovalDao. The current version of the Approval Service includes a RequestForApprovalManager in a package called org.restafarian.approval.data, which is a combination service layer/data access layer utility that will go away in our new version. To conform to our more recent naming conventions, we’ll create a new package called org.restafarian.approval.dao, and place our new DAO interface in there:

package org.restafarian.approval.dao;

import java.io.Serializable;
import java.util.List;

import org.restafarian.approval.beans.RequestForApproval;
import org.restafarian.core.dao.Dao;

/**
 * <p>This is the RequestForApproval data access object interface.</p>
 */
public interface RequestForApprovalDao extends Dao {

  /**
   * <p>Returns all RequestForApprovals in the database.</p>
   *
   * @return all RequestForApprovals in the database
   */
  public List<RequestForApproval> findAll();

  /**
   * <p>Returns all RequestForApprovals in the database that
   * match the specified search criteria.</p>
   *
   * @param requestForApproval an example RequestForApproval
   * @return all RequestForApprovals in the database that
   * match the specified search criteria
   */
  public List<RequestForApproval> findByExample(RequestForApproval requestForApproval);

  /**
   * <p>Returns all RequestForApprovals in the database that
   * match the specified search criteria.</p>
   *
   * @param propertyName the name of the specified property
   * @param propertyValue the search value for the specified
   * property
   * @return all RequestForApprovals in the database that
   * match the specified search criteria
   */
  public List<RequestForApproval> findByProperty(String propertyName, Object propertyValue);

  /**
   * <p>Returns all objects of this entity that satisfy the specified query.</p>
   *
   * @param hql the HQL statement to execute
   * @return all objects of this entity that satisfy the specified query
   */
  public List<RequestForApproval> executeQuery(String hql);

  /**
   * <p>Returns the RequestForApproval with the specified id.</p>
   *
   * @param id the id of the requested requestForApproval
   * @return the RequestForApproval with the specified id
   */
  public RequestForApproval findById(Serializable id);

  /**
   * <p>Saves the RequestForApproval passed.</p>
   *
   * @param requestForApproval the requestForApproval to save
   */
  public void save(RequestForApproval RequestForApproval);

  /**
   * <p>Deletes the RequestForApproval with the specified id.</p>
   *
   * @param requestForApproval the requestForApproval to delete
   */
  public void delete(RequestForApproval RequestForApproval);
}

One new wrinkle in this particular DAO is the new method called executeQuery(). The ability to run raw HQL was something that was not required in any of the DAOs that we have created up to this point, but is necessary in the Approval Service to support certain functionality of the service. There’s probably a nasty violation of the separation of concerns here by passing something that is very Hibernate-specific from the business layer through service layer and into the data access layer, thereby exposing the data access layer implementation method to the layers above. Even though I’m sharp enough to understand that, at the moment I’m just too lazy or too stupid to work out a way around it, so that’s just the way that it’s going to be for now.

Maybe we’ll look into that a little more later, but for now, it’s time to move on to our implementation of this new DAO interface, which will be the subject of our next installment.


http://blog.restafarian.org/2009/04/dao-refactoring-requestforapprovaldao/

Leave a reply

You must be logged in to post a comment.