add pagination methods to find all

This commit is contained in:
Terry W Brady
2017-10-05 12:50:37 -07:00
parent 23f2573460
commit aa0ced3d10
4 changed files with 37 additions and 0 deletions

View File

@@ -237,6 +237,11 @@ public class ItemServiceImpl extends DSpaceObjectServiceImpl<Item> implements It
return itemDAO.findAllByCollection(context, collection);
}
@Override
public Iterator<Item> findAllByCollection(Context context, Collection collection, Integer limit, Integer offset) throws SQLException {
return itemDAO.findAllByCollection(context, collection, limit, offset);
}
@Override
public Iterator<Item> findInArchiveOrWithdrawnDiscoverableModifiedSince(Context context, Date since)
throws SQLException

View File

@@ -57,6 +57,8 @@ public interface ItemDAO extends DSpaceObjectLegacySupportDAO<Item>
public Iterator<Item> findAllByCollection(Context context, Collection collection) throws SQLException;
public Iterator<Item> findAllByCollection(Context context, Collection collection, Integer limit, Integer offset) throws SQLException;
/**
* Count number of items in a given collection
* @param context context

View File

@@ -233,6 +233,24 @@ public class ItemDAOImpl extends AbstractHibernateDSODAO<Item> implements ItemDA
return iterate(query);
}
@Override
public Iterator<Item> findAllByCollection(Context context, Collection collection, Integer limit, Integer offset) throws SQLException {
Query query = createQuery(context, "select i from Item i join i.collections c WHERE :collection IN c");
query.setParameter("collection", collection);
if(offset != null)
{
query.setFirstResult(offset);
}
if(limit != null)
{
query.setMaxResults(limit);
}
return iterate(query);
}
@Override
public int countItems(Context context, Collection collection, boolean includeArchived, boolean includeWithdrawn) throws SQLException {
Query query = createQuery(context, "select count(i) from Item i join i.collections c WHERE :collection IN c AND i.inArchive=:in_archive AND i.withdrawn=:withdrawn");

View File

@@ -146,6 +146,18 @@ public interface ItemService extends DSpaceObjectService<Item>, DSpaceObjectLega
*/
public Iterator<Item> findAllByCollection(Context context, Collection collection) throws SQLException;
/**
* Get all the items in this collection. The order is indeterminate.
*
* @param context DSpace context object
* @param collection Collection (parent)
* @return an iterator over the items in the collection.
* @param limit limited number of items
* @param offset offset value
* @throws SQLException if database error
*/
public Iterator<Item> findAllByCollection(Context context, Collection collection, Integer limit, Integer offset) throws SQLException;
/**
* See whether this Item is contained by a given Collection.
* @param item Item