]> SALOME platform Git repositories - tools/siman.git/blobdiff - Workspace/Siman-Common/src/org/splat/dal/dao/kernel/GenericDAOImpl.java
Salome HOME
Refactoring continues: UserService is created instead of UserDirectory. Database...
[tools/siman.git] / Workspace / Siman-Common / src / org / splat / dal / dao / kernel / GenericDAOImpl.java
index 64d3a6a4c598820d23f601a26fc7a9f491aa780c..88420adb4de1923016879dc1b3f9fe4be87de114 100644 (file)
@@ -11,10 +11,12 @@ package org.splat.dal.dao.kernel;
 
 import java.io.Serializable;
 import java.util.List;
+import java.util.Properties;
 
 import org.hibernate.Criteria;
 import org.hibernate.criterion.Criterion;
 import org.hibernate.criterion.Order;
+import org.hibernate.criterion.Restrictions;
 import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
 
 /**
@@ -66,6 +68,21 @@ public abstract class GenericDAOImpl<T, PK extends Serializable> extends
                                .uniqueResult();
        }
 
+       /**
+        * Retrieve an object that was previously persisted to the database using the given criteria.
+        * 
+        * @param andParams
+        *            a properties values to filter with AND condition
+        * @return an object found according to the given criteria
+        */
+       public T findByCriteria(Properties andParams) {
+               Criterion aCondition = null;
+               for (String aName: andParams.stringPropertyNames()) {
+                       aCondition = Restrictions.and(aCondition, Restrictions.eq(aName, andParams.get(aName)));
+               }
+               return findByCriteria(aCondition);
+       }
+
        /**
         * Retrieve a list of all objects of the considered type T which were previously persisted to the database.
         * 
@@ -84,10 +101,12 @@ public abstract class GenericDAOImpl<T, PK extends Serializable> extends
         * @return an ordered list of all objects of the considered type T
         */
        @SuppressWarnings("unchecked")
-       public List<T> getAll(Order anOrder) {
+       public List<T> getAll(Order ... anOrder) {
                Criteria aCriteria = getSession().createCriteria(getType());
-               if (anOrder != null) {
-                       aCriteria.addOrder(anOrder);
+               for (Order order : anOrder) {
+                       if (anOrder != null) {
+                               aCriteria.addOrder(order);
+                       }
                }
                return aCriteria.list();
        }
@@ -114,15 +133,45 @@ public abstract class GenericDAOImpl<T, PK extends Serializable> extends
         * @return a list of objects filtered according to the given criteria
         */
        @SuppressWarnings("unchecked")
-       public List<T> getFilteredList(Criterion aCondition, Order anOrder) {
+       public List<T> getFilteredList(Criterion aCondition, Order ... anOrder) {
                Criteria aCriteria = getSession().createCriteria(getType()).add(
                                aCondition);
-               if (anOrder != null) {
-                       aCriteria.addOrder(anOrder);
+               for (Order order : anOrder) {
+                       if (anOrder != null) {
+                               aCriteria.addOrder(order);
+                       }
                }
                return aCriteria.list();
        }
 
+       /**
+        * Retrieve a list of objects which were previously persisted to the database using the given criteria.
+        * 
+        * @param andParams
+        *            a properties values to filter with AND condition
+        * @return a list of objects filtered according to the given criteria
+        */
+       public List<T> getFilteredList(Properties andParams) {
+               return getFilteredList(andParams);
+       }
+
+       /**
+        * Retrieve a list of objects which were previously persisted to the database using the given criteria.
+        * 
+        * @param andParams
+        *            a properties values to filter with AND condition
+        * @param anOrder
+        *            a result list order. Null is ignored and in such case the result list is unordered.
+        * @return a list of objects filtered according to the given criteria
+        */
+       public List<T> getFilteredList(Properties andParams, Order ... anOrder) {
+               Criterion aCondition = null;
+               for (String aName: andParams.stringPropertyNames()) {
+                       aCondition = Restrictions.and(aCondition, Restrictions.eq(aName, andParams.get(aName)));
+               }
+               return getFilteredList(aCondition, anOrder);
+       }
+
        /**
         * Save changes made to a persistent object.
         *