Generic DAO interface


/ Published in: Java
Save to your folder(s)



Copy this code and paste it in your HTML
  1. /**
  2.  * Defines a generic DAO interface.
  3.  *
  4.  * @author javier
  5.  *
  6.  * @param <T>
  7.  * The type this DAO handles.
  8.  * @param <ID>
  9.  * The type of the id of the handled entity.
  10.  */
  11. public interface DAOInterface<T, ID extends Serializable>
  12. {
  13.  
  14. /**
  15.   * Makes the given entity persistent.
  16.   *
  17.   * @param entity The entity to persist.
  18.   * @throws When the quota of instances for that entity was exceeded.
  19.   */
  20. void makePersistent(T entity) throws QuotaExceededException;
  21.  
  22. /**
  23.   * Makes the given entity transient.
  24.   *
  25.   * @param entity The entity to make transient.
  26.   */
  27. void makeTransient(T entity);
  28.  
  29. /**
  30.   * @return the number of matching entities.
  31.   */
  32. int count(Filter filter);
  33.  
  34. /**
  35.   * Returns a single entity which has the given ID or throws an
  36.   * <code>EntityNotFoundException</code> if no matching entity is found.
  37.   *
  38.   * @param id
  39.   * The ID of the entity to return.
  40.   * @return The entity.
  41.   */
  42. T findById(ID id) throws EntityNotFoundException;
  43.  
  44. /**
  45.   * Returns all matching entities of type <code>T</code>.
  46.   *
  47.   * @param filter
  48.   * The <code>Filter</code> to use.
  49.   *
  50.   * @return An ordered <code>List</code> with the entities.
  51.   */
  52. List<T> find(Filter filter);
  53.  
  54. /**
  55.   * Returns all entities of type <code>T</code>.
  56.   *
  57.   * @return An ordered <code>List</code> with the entities.
  58.   */
  59. List<T> findAll();
  60.  
  61. /**
  62.   * Returns a page of entities.
  63.   *
  64.   * @param filter
  65.   * The <code>Filter</code> to use.
  66.   * @param startRow
  67.   * The offset.
  68.   * @param pageSize
  69.   * The number of entities to return.
  70.   *
  71.   * @return A <code>Pair</code> of values. The first value is the
  72.   * <code>List</code> of entities and the second one if the total
  73.   * number of existing entities.
  74.   */
  75. Pair<List<T>, Integer> findPaged(Filter filter, int startRow, int pageSize);
  76.  
  77. /**
  78.   * Flushing is the process of synchronising the underlying persistent
  79.   * store with persistable state held in memory.
  80.   */
  81. void flush();
  82. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.