From cea4bf11d18bbe9c82d2fbd02e8faeb100dc1db6 Mon Sep 17 00:00:00 2001
From: Ben Alex List
will be
* returned if no matches are found)
@@ -133,7 +133,8 @@ public interface Dao {
* the query by example evaluation.
*
PersistableEntity
, ignoring the class of the passed
+ * PersistableEntity
(useful if you pass a superclass, as you
+ * want to find all subclass instances which match).
+ *
+ * @param value parameters to filter on (the class of this object will NOT
+ * be added to the filter)
+ * @param firstElement the first result (start at zero to obtain all
+ * results)
+ * @param maxElements the maximum number of results desired for this page
+ * of the result set
+ * @param orderByAsc the property name of the
+ * PersistableEntity
that should be used to order the
+ * results
+ *
+ * @return the requested page of the result list (a properly formed
+ * PaginatedList
is returned if no results match)
+ */
+ public PaginatedList scrollWithSubclasses(PersistableEntity value,
+ int firstElement, int maxElements, String orderByAsc);
+
/**
* Indicates whether the DAO instance provides persistence services for the
* specified class.
diff --git a/domain/src/main/java/org/acegisecurity/domain/hibernate/DaoHibernate.java b/domain/src/main/java/org/acegisecurity/domain/hibernate/DaoHibernate.java
index 80d59cbd83..d3429ad3b3 100644
--- a/domain/src/main/java/org/acegisecurity/domain/hibernate/DaoHibernate.java
+++ b/domain/src/main/java/org/acegisecurity/domain/hibernate/DaoHibernate.java
@@ -109,12 +109,24 @@ public class DaoHibernate extends HibernateDaoSupport implements Dao,
Assert.notNull(value);
Assert.hasText(orderByAsc,
"An orderByAsc is required (why not use your identity property?)");
+ Assert.isInstanceOf(this.supportsClass, value, "Can only scroll with values this DAO supports");
return (PaginatedList) getHibernateTemplate().execute(getFindByValueCallback(
- value, firstElement, maxElements, Order.asc(orderByAsc)));
+ value.getClass(), value, firstElement, maxElements, Order.asc(orderByAsc)));
}
- public boolean supports(Class clazz) {
+ public PaginatedList scrollWithSubclasses(PersistableEntity value, int firstElement,
+ int maxElements, String orderByAsc) {
+ Assert.notNull(value);
+ Assert.hasText(orderByAsc,
+ "An orderByAsc is required (why not use your identity property?)");
+ Assert.isInstanceOf(this.supportsClass, value, "Can only scroll with values this DAO supports");
+
+ return (PaginatedList) getHibernateTemplate().execute(getFindByValueCallback(
+ this.supportsClass, value, firstElement, maxElements, Order.asc(orderByAsc)));
+ }
+
+ public boolean supports(Class clazz) {
Assert.notNull(clazz);
return this.supportsClass.equals(clazz);
@@ -187,12 +199,12 @@ public class DaoHibernate extends HibernateDaoSupport implements Dao,
*
* @return a PaginatedList containing the requested objects
*/
- private HibernateCallback getFindByValueCallback(final Object bean,
+ private HibernateCallback getFindByValueCallback(final Class whichClass, final Object bean,
final int firstElement, final int count, final Order order) {
return new HibernateCallback() {
public Object doInHibernate(Session session)
throws HibernateException {
- Criteria criteria = session.createCriteria(bean.getClass());
+ Criteria criteria = session.createCriteria(whichClass);
criteria.addOrder(order);