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;
/**
.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.
*
* @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();
}
* @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.
*