minor
[cdmlib.git] / cdmlib-persistence / src / main / java / eu / etaxonomy / cdm / persistence / dao / common / ICdmEntityDao.java
index 54bd5e7689b719fed28e2d8614579449639ff25a..82063ddee4d7b99ba886bc6bfe385aa5cc7969c4 100644 (file)
@@ -12,11 +12,15 @@ package eu.etaxonomy.cdm.persistence.dao.common;
 import java.util.Collection;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 import java.util.UUID;
 
+import org.hibernate.Session;
 import org.springframework.dao.DataAccessException;
 
 import eu.etaxonomy.cdm.model.common.CdmBase;
+import eu.etaxonomy.cdm.persistence.dao.BeanInitializer;
+import eu.etaxonomy.cdm.persistence.query.OrderHint;
 
 /**
  * an data access interface that all data access classes implement
@@ -42,7 +46,13 @@ public interface ICdmEntityDao<T extends CdmBase> {
         */
        public UUID save(T newOrManagedObject) throws DataAccessException;
        
-       public Map<UUID, T> saveAll(Collection<T> cdmObjCollection) throws DataAccessException;
+       public UUID merge(T transientObject) throws DataAccessException;
+       
+       public void clear() throws DataAccessException;
+               
+       public Session getSession() throws DataAccessException;
+
+               public Map<UUID, T> saveAll(Collection<T> cdmObjCollection) throws DataAccessException;
 
        /**
         * @param transientObject
@@ -51,6 +61,13 @@ public interface ICdmEntityDao<T extends CdmBase> {
         */
        public UUID update(T transientObject) throws DataAccessException;
        
+       /**
+        * @param persistentObject
+        * @return
+        * @throws DataAccessException
+        */
+       public UUID refresh(T persistentObject) throws DataAccessException;
+       
        /**
         * @param persistentObject
         * @return
@@ -61,12 +78,83 @@ public interface ICdmEntityDao<T extends CdmBase> {
        /**
         * Returns a sublist of CdmBase instances stored in the database.
         * A maximum of 'limit' objects are returned, starting at object with index 'start'.
+        * @param limit the maximum number of entities returned (can be null to return all entities)
+        * @param start
+        * @return
+        * @throws DataAccessException
+        */
+       public List<T> list(Integer limit, Integer start) throws DataAccessException;
+       
+       /**
+        * Returns a sublist of CdmBase instances stored in the database. A maximum
+        * of 'limit' objects are returned, starting at object with index 'start'.
+        * 
+        * @param limit
+        *            the maximum number of entities returned (can be null to return
+        *            all entities)
+        * @param start
+        * @param orderHints
+        *            Supports path like <code>orderHints.propertyNames</code> which
+        *            include *-to-one properties like createdBy.username or
+        *            authorTeam.persistentTitleCache
+        * @return
+        * @throws DataAccessException
+        */
+       public List<T> list(Integer limit, Integer start, List<OrderHint> orderHints);
+       
+       
+       /**
+        * Returns a sublist of CdmBase instances stored in the database. A maximum
+        * of 'limit' objects are returned, starting at object with index 'start'.
+        * 
+        * @param type 
         * @param limit
+        *            the maximum number of entities returned (can be null to return
+        *            all entities)
         * @param start
+        * @param orderHints
+        *            Supports path like <code>orderHints.propertyNames</code> which
+        *            include *-to-one properties like createdBy.username or
+        *            authorTeam.persistentTitleCache
         * @return
         * @throws DataAccessException
         */
-       public List<T> list(int limit, int start) throws DataAccessException;
+       public <TYPE extends T> List<TYPE> list(Class<TYPE> type, Integer limit, Integer start, List<OrderHint> orderHints, List<String> propertyPaths);
+       
+       /**
+        * Returns a sublist of CdmBase instances stored in the database. A maximum
+        * of 'limit' objects are returned, starting at object with index 'start'.
+        * The bean properties specified by the parameter <code>propertyPaths</code>
+        * and recursively initialized for each of the entities in the resultset
+        * 
+        * For detailed description and examples redarding
+        * <code>propertyPaths</code> <b>please refer to:</b>
+        * {@link BeanInitializer#initialize(Object, List)}
+        * 
+        * @param limit
+        *            the maximum number of entities returned (can be null to return
+        *            all entities)
+        * @param start
+        * @param orderHints
+        *            Supports path like <code>orderHints.propertyNames</code> which
+        *            include *-to-one properties like createdBy.username or
+        *            authorTeam.persistentTitleCache
+        * @param propertyPaths
+        * @return
+        * @throws DataAccessException
+        */
+       public List<T> list(Integer limit, Integer start, List<OrderHint> orderHints, List<String> propertyPaths);
+       
+       /**
+        * Returns a sublist of CdmBase instances of type <TYPE> stored in the database.
+        * A maximum of 'limit' objects are returned, starting at object with index 'start'.
+        * @param limit the maximum number of entities returned (can be null to return all entities)
+        * @param start
+        * @return
+        * @throws DataAccessException
+        */
+       public <TYPE extends T> List<TYPE> list(Class<TYPE> type, Integer limit, Integer start) throws DataAccessException;
+       
 
        public List<T> rows(String tableName, int limit, int start) throws DataAccessException;
 
@@ -84,6 +172,45 @@ public interface ICdmEntityDao<T extends CdmBase> {
         */
        public T findByUuid(UUID Uuid) throws DataAccessException;
        
+       /**
+        * @param uuidSet
+        * @return
+        * @throws DataAccessException
+        */
+       public List<T> findByUuid(Set<UUID> uuidSet) throws DataAccessException;
+       
+       /**
+        * Finds the cdm entity specified by the <code>uuid</code> parameter and
+        * initializes all its *ToOne relations.
+        * 
+        * @param uuid
+        * @return
+        */
+       public T load(UUID uuid);
+       
+       /**
+        * Finds the cdm entity specified by the <code>uuid</code> parameter and
+        * recursively initializes all bean properties given in the
+        * <code>propertyPaths</code> parameter.
+        * <p>
+        * For detailed description and examples <b>please refer to:</b> 
+        * {@link BeanInitializer#initialize(Object, List)}
+        * 
+        * @param uuid
+        * @param propertyPaths properties to be initialized
+        * @return
+        */
+       public T load(UUID uuid, List<String> propertyPaths);
+       
+       
+       /**
+        * @param uuidSet
+        * @param propertyPaths
+        * @return
+        * @throws DataAccessException
+        */
+       public List<T> load(Set<UUID> uuidSet, List<String> propertyPaths) throws DataAccessException;
+       
        /**
         * @param uuid
         * @return
@@ -93,13 +220,24 @@ public interface ICdmEntityDao<T extends CdmBase> {
        
        public int count();
 
-       public int count(Class clazz);
+       /**
+        * Returns the number of objects of type <TYPE> - which must extend T
+        * @param <TYPE>
+        * @param clazz
+        * @return
+        */
+       public <TYPE extends T> int count(Class<TYPE> clazz);
 
        /**
-        * 
+        * FIXME Should this method exist : I would expect flushing of a session to be
+        * something that a DAO should hide?
         */
        public void flush();
        
-               
-       
+       /**
+        * Convenience method which makes it easy to discover what type of object this DAO returns at runtime
+        * 
+        * @return
+        */
+       public Class<T> getType();
 }