package org.splat.dal.dao.kernel;
import java.io.Serializable;
+import java.util.List;
+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;
/**
* @param <PK>
* Primary key class
*/
-public abstract class GenericDAOImpl<T, PK extends Serializable> extends HibernateDaoSupport implements
- GenericDAO<T, PK> {
+public abstract class GenericDAOImpl<T, PK extends Serializable> extends
+ HibernateDaoSupport implements GenericDAO<T, PK> {
/**
* Persist the newInstance object into database.
*
return (T) getSession().get(getType(), id);
}
- /** Save changes made to a persistent object.
- * @param transientObject transient instance of the object to update
+ /**
+ * Retrieve an object that was previously persisted to the database using the given criteria.
+ *
+ * @param aCondition
+ * a search condition
+ * @return an object found according to the given criteria
+ */
+ @SuppressWarnings("unchecked")
+ public T findByCriteria(Criterion aCondition) {
+ return (T) getSession().createCriteria(getType()).add(aCondition)
+ .uniqueResult();
+ }
+
+ /**
+ * Retrieve a list of objects which were previously persisted to the database using the given criteria.
+ *
+ * @param aCondition
+ * a search condition
+ * @return a list of objects filtered according to the given criteria
+ */
+ @SuppressWarnings("unchecked")
+ public List<T> getFilteredList(Criterion aCondition) {
+ return getSession().createCriteria(getType()).add(aCondition).list();
+ }
+
+ /**
+ * Retrieve a list of objects which were previously persisted to the database using the given criteria.
+ *
+ * @param aCondition
+ * a search 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
+ */
+ @SuppressWarnings("unchecked")
+ public List<T> getFilteredList(Criterion aCondition, Order anOrder) {
+ Criteria aCriteria = getSession().createCriteria(getType()).add(
+ aCondition);
+ if (anOrder != null) {
+ aCriteria.addOrder(anOrder);
+ }
+ return aCriteria.list();
+ }
+
+ /**
+ * Save changes made to a persistent object.
+ *
+ * @param transientObject
+ * transient instance of the object to update
*/
public void update(T transientObject) {
getSession().update(transientObject);
}
- /** Remove an object from persistent storage in the database.
- * @param persistentObject a persistent object to delete from the database
+ /**
+ * Remove an object from persistent storage in the database.
+ *
+ * @param persistentObject
+ * a persistent object to delete from the database
*/
public void delete(T persistentObject) {
getSession().delete(persistentObject);
/**
* Get persistent object type.
+ *
* @return Persistent object class to be processed by this DAO
*/
abstract protected Class<T> getType();