From aa0ced3d108a56ffa2acbdd999998bcc162b1331 Mon Sep 17 00:00:00 2001 From: Terry W Brady Date: Thu, 5 Oct 2017 12:50:37 -0700 Subject: [PATCH] add pagination methods to find all --- .../org/dspace/content/ItemServiceImpl.java | 5 +++++ .../java/org/dspace/content/dao/ItemDAO.java | 2 ++ .../dspace/content/dao/impl/ItemDAOImpl.java | 18 ++++++++++++++++++ .../dspace/content/service/ItemService.java | 12 ++++++++++++ 4 files changed, 37 insertions(+) diff --git a/dspace-api/src/main/java/org/dspace/content/ItemServiceImpl.java b/dspace-api/src/main/java/org/dspace/content/ItemServiceImpl.java index 72e63744c9..dc12482ff9 100644 --- a/dspace-api/src/main/java/org/dspace/content/ItemServiceImpl.java +++ b/dspace-api/src/main/java/org/dspace/content/ItemServiceImpl.java @@ -237,6 +237,11 @@ public class ItemServiceImpl extends DSpaceObjectServiceImpl implements It return itemDAO.findAllByCollection(context, collection); } + @Override + public Iterator findAllByCollection(Context context, Collection collection, Integer limit, Integer offset) throws SQLException { + return itemDAO.findAllByCollection(context, collection, limit, offset); + } + @Override public Iterator findInArchiveOrWithdrawnDiscoverableModifiedSince(Context context, Date since) throws SQLException diff --git a/dspace-api/src/main/java/org/dspace/content/dao/ItemDAO.java b/dspace-api/src/main/java/org/dspace/content/dao/ItemDAO.java index 80f7fa834d..ca4a74efd8 100644 --- a/dspace-api/src/main/java/org/dspace/content/dao/ItemDAO.java +++ b/dspace-api/src/main/java/org/dspace/content/dao/ItemDAO.java @@ -57,6 +57,8 @@ public interface ItemDAO extends DSpaceObjectLegacySupportDAO public Iterator findAllByCollection(Context context, Collection collection) throws SQLException; + public Iterator findAllByCollection(Context context, Collection collection, Integer limit, Integer offset) throws SQLException; + /** * Count number of items in a given collection * @param context context diff --git a/dspace-api/src/main/java/org/dspace/content/dao/impl/ItemDAOImpl.java b/dspace-api/src/main/java/org/dspace/content/dao/impl/ItemDAOImpl.java index 78193cd883..b535cda0cc 100644 --- a/dspace-api/src/main/java/org/dspace/content/dao/impl/ItemDAOImpl.java +++ b/dspace-api/src/main/java/org/dspace/content/dao/impl/ItemDAOImpl.java @@ -233,6 +233,24 @@ public class ItemDAOImpl extends AbstractHibernateDSODAO implements ItemDA return iterate(query); } + @Override + public Iterator 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"); diff --git a/dspace-api/src/main/java/org/dspace/content/service/ItemService.java b/dspace-api/src/main/java/org/dspace/content/service/ItemService.java index bf44b340c4..6578443abf 100644 --- a/dspace-api/src/main/java/org/dspace/content/service/ItemService.java +++ b/dspace-api/src/main/java/org/dspace/content/service/ItemService.java @@ -146,6 +146,18 @@ public interface ItemService extends DSpaceObjectService, DSpaceObjectLega */ public Iterator 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 findAllByCollection(Context context, Collection collection, Integer limit, Integer offset) throws SQLException; + /** * See whether this Item is contained by a given Collection. * @param item Item