Advertisement
Guest User

Untitled

a guest
Aug 20th, 2014
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package org.jlego.core.dao;
  2.  
  3. import java.util.List;
  4.  
  5. import javax.persistence.Query;
  6.  
  7. /**
  8.  * Base interface for all DAO classes <br/>
  9.  * Example:
  10.  *
  11.  * <code><br/>
  12.  * public class AnotherDao extends BaseDaoImpl <Long, User> implements BaseDao {<br/>
  13.  *        <br/>
  14.  * }<br/>
  15.  * </code>
  16.  *
  17.  * @author Ali Irawan
  18.  * @version 1.0
  19.  * @param <K>
  20.  *            key type
  21.  * @param <E>
  22.  *            value/entity type
  23.  */
  24. public interface BaseDao<K, E> {
  25.  
  26.     /**
  27.      * insert data to persistence
  28.      *
  29.      * @param entity
  30.      *            object to be inserted
  31.      * @throws CoreException
  32.      */
  33.  
  34.     public void persist(E entity);
  35.  
  36.     /**
  37.      * update data to persistence
  38.      *
  39.      * @param entity
  40.      *            object to be updated
  41.      * @throws CoreException
  42.      */
  43.  
  44.     public E merge(K id, E entity);
  45.  
  46.     /**
  47.      * delete data from persistence
  48.      *
  49.      * @param id
  50.      *            primary key that uniquely identify the object to be deleted
  51.      * @throws CoreException
  52.      */
  53.  
  54.     public void remove(K id);
  55.  
  56.     /**
  57.      * Search data from persistence using specified ID
  58.      *
  59.      * @param id
  60.      *            primary key that uniquely identify the object
  61.      * @return return the object defined by Key, if no data match the method
  62.      *         returns null
  63.      */
  64.     public E findByPk(K id);
  65.  
  66.     /**
  67.      * Query data with specified criteria
  68.      *
  69.      * @return list of data with specific entity type
  70.      */
  71.  
  72.     public E find(Criteria criteria);
  73.  
  74.     /**
  75.      * Query all data and return in a List
  76.      *
  77.      * @return list of data with specific entity type
  78.      */
  79.  
  80.     public List<E> findAll();
  81.  
  82.     /**
  83.      * Query data with specified criteria and return in a List
  84.      *
  85.      * @return list of data with specific entity type
  86.      */
  87.     public List<E> findAll(Criteria criteria);
  88.  
  89.     /**
  90.      * Return number of data in table
  91.      * @return count value
  92.      */
  93.     public long count();
  94.  
  95.     /**
  96.      * Create a query with JPQL language
  97.      * @param query JPQL language
  98.      * @return an instance of javax.persistence.Query
  99.      */
  100.     public Query createQuery(String query);
  101.  
  102.     /**
  103.      * Create a query with named query
  104.      * @param queryName name of named query (JPQL)
  105.      * @return an instance of javax.persistence.Query
  106.      */
  107.     public Query createNamedQuery(String queryName);
  108.  
  109.     /**
  110.      * Create a query with using native SQL language. This is database specific. Using it will reduce portability between databases
  111.      * @param sqlString SQL native language based on the database used
  112.      * @return an instance of javax.persistence.Query
  113.      */
  114.     public Query createNativeQuery(String sqlString);
  115.  
  116.     /**
  117.      * Flush cache
  118.      *
  119.      */
  120.     public void flush();
  121.    
  122. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement