Add scrollWithSubclasses() method.
This commit is contained in:
parent
958a45af69
commit
cea4bf11d1
|
@ -94,7 +94,7 @@ public interface Dao {
|
|||
public void delete(PersistableEntity value);
|
||||
|
||||
/**
|
||||
* Return all persistent instances.
|
||||
* Return all persistent instances, including subclasses.
|
||||
*
|
||||
* @return all persistence instances (an empty <code>List</code> will be
|
||||
* returned if no matches are found)
|
||||
|
@ -133,7 +133,8 @@ public interface Dao {
|
|||
* the query by example evaluation.
|
||||
* </p>
|
||||
*
|
||||
* @param value parameters to filter on
|
||||
* @param value parameters to filter on (the class of this object will 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
|
||||
|
@ -148,6 +149,28 @@ public interface Dao {
|
|||
public PaginatedList scroll(PersistableEntity value, int firstElement,
|
||||
int maxElements, String orderByAsc);
|
||||
|
||||
/**
|
||||
* Find persistent instances with properties matching those of the passed
|
||||
* <code>PersistableEntity</code>, ignoring the class of the passed
|
||||
* <code>PersistableEntity</code> (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
|
||||
* <code>PersistableEntity</code> that should be used to order the
|
||||
* results
|
||||
*
|
||||
* @return the requested page of the result list (a properly formed
|
||||
* <code>PaginatedList</code> 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.
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
Loading…
Reference in New Issue