一个支持泛型的DAO接口类

2018-07-20    来源:open-open

容器云强势上线!快速搭建集群,上万Linux镜像随意使用
 
/**
 * Defines a generic DAO interface.
 * 
 * @author javier
 * 
 * @param <T>
 *            The type this DAO handles.
 * @param <ID>
 *            The type of the id of the handled entity.
 */
public interface DAOInterface<T, ID extends Serializable>
{

    /**
     * Makes the given entity persistent.
     *
     * @param entity The entity to persist.
     * @throws When the quota of instances for that entity was exceeded.
     */
    void makePersistent(T entity) throws QuotaExceededException;

    /**
     * Makes the given entity transient.
     *
     * @param entity The entity to make transient.
     */
    void makeTransient(T entity);

    /**
     * @return the number of matching entities.
     */
    int count(Filter filter);

    /**
     * Returns a single entity which has the given ID or throws an
     * <code>EntityNotFoundException</code> if no matching entity is found.
     * 
     * @param id
     *            The ID of the entity to return.
     * @return The entity.
     */
    T findById(ID id) throws EntityNotFoundException;

    /**
     * Returns all matching entities of type <code>T</code>.
     * 
     * @param filter
     *            The <code>Filter</code> to use.
     *
     * @return An ordered <code>List</code> with the entities.
     */
    List<T> find(Filter filter);

    /**
     * Returns all entities of type <code>T</code>.
     * 
     * @return An ordered <code>List</code> with the entities.
     */
    List<T> findAll();

    /**
     * Returns a page of entities.
     * 
     * @param filter
     *            The <code>Filter</code> to use.
     * @param startRow
     *            The offset.
     * @param pageSize
     *            The number of entities to return.
     *
     * @return A <code>Pair</code> of values. The first value is the
     *         <code>List</code> of entities and the second one if the total
     *         number of existing entities.
     */
    Pair<List<T>, Integer> findPaged(Filter filter, int startRow, int pageSize);

    /**
     * Flushing is the process of synchronising the underlying persistent
     * store with persistable state held in memory. 
     */
    void flush();
}
 

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点!
本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。

上一篇:Android 上进行图片旋转

下一篇:Android获得SD卡剩余容量的代码