dao pagination support for item and bitstream

This commit is contained in:
Terry W Brady
2017-03-02 11:59:11 -08:00
parent 5a2fdabaaf
commit 172c0228c1
10 changed files with 56 additions and 3 deletions

View File

@@ -95,6 +95,12 @@ public class BitstreamServiceImpl extends DSpaceObjectServiceImpl<Bitstream> imp
return bitstreamDAO.findAll(context, Bitstream.class);
}
@Override
public Iterator<Bitstream> findAll(Context context, int limit, int offset) throws SQLException
{
return bitstreamDAO.findAll(context, limit, offset);
}
@Override
public Bitstream create(Context context, InputStream is) throws IOException, SQLException {
// Store the bits

View File

@@ -200,6 +200,11 @@ public class ItemServiceImpl extends DSpaceObjectServiceImpl<Item> implements It
return itemDAO.findAll(context, true);
}
@Override
public Iterator<Item> findAll(Context context, Integer limit, Integer offset) throws SQLException {
return itemDAO.findAll(context, true, limit, offset);
}
@Override
public Iterator<Item> findAllUnfiltered(Context context) throws SQLException {
return itemDAO.findAll(context, true, true);

View File

@@ -26,6 +26,8 @@ import java.util.List;
*/
public interface BitstreamDAO extends DSpaceObjectLegacySupportDAO<Bitstream> {
public Iterator<Bitstream> findAll(Context context, int limit, int offset) throws SQLException;
public List<Bitstream> findDeletedBitstreams(Context context) throws SQLException;
public List<Bitstream> findDuplicateInternalIdentifier(Context context, Bitstream bitstream) throws SQLException;

View File

@@ -30,6 +30,8 @@ public interface ItemDAO extends DSpaceObjectLegacySupportDAO<Item>
{
public Iterator<Item> findAll(Context context, boolean archived) throws SQLException;
public Iterator<Item> findAll(Context context, boolean archived, int limit, int offset) throws SQLException;
public Iterator<Item> findAll(Context context, boolean archived, boolean withdrawn) throws SQLException;
/**

View File

@@ -153,4 +153,12 @@ public class BitstreamDAOImpl extends AbstractHibernateDSODAO<Bitstream> impleme
" and bit.id not in (select col.logo.id from Collection col)" +
" and bit.id not in (select bun.primaryBitstream.id from Bundle bun)"));
}
@Override
public Iterator<Bitstream> findAll(Context context, int limit, int offset) throws SQLException {
Query query = createQuery(context, "select b FROM Bitstream b");
query.setFirstResult(offset);
query.setMaxResults(limit);
return iterate(query);
}
}

View File

@@ -55,6 +55,16 @@ public class ItemDAOImpl extends AbstractHibernateDSODAO<Item> implements ItemDA
return iterate(query);
}
@Override
public Iterator<Item> findAll(Context context, boolean archived, int limit, int offset) throws SQLException {
Query query = createQuery(context, "FROM Item WHERE inArchive= :in_archive");
query.setParameter("in_archive", archived);
query.setFirstResult(offset);
query.setMaxResults(limit);
return iterate(query);
}
@Override
public Iterator<Item> findAll(Context context, boolean archived, boolean withdrawn) throws SQLException {
Query query = createQuery(context, "FROM Item WHERE inArchive= :in_archive or withdrawn = :withdrawn");

View File

@@ -27,6 +27,8 @@ public interface BitstreamService extends DSpaceObjectService<Bitstream>, DSpace
public List<Bitstream> findAll(Context context) throws SQLException;
public Iterator<Bitstream> findAll(Context context, int limit, int offset) throws SQLException;
/**
* Create a new bitstream, with a new ID. The checksum and file size are
* calculated. No authorization checks are made in this method.

View File

@@ -69,6 +69,18 @@ public interface ItemService extends DSpaceObjectService<Item>, DSpaceObjectLega
*/
public Iterator<Item> findAll(Context context) throws SQLException;
/**
* Get all the items in the archive. Only items with the "in archive" flag
* set are included. The order of the list is indeterminate.
*
* @param context DSpace context object
* @param limit limit
* @param offset offset
* @return an iterator over the items in the archive.
* @throws SQLException if database error
*/
public Iterator<Item> findAll(Context context, Integer limit, Integer offset) throws SQLException;
/**
* Get all "final" items in the archive, both archived ("in archive" flag) or
* withdrawn items are included. The order of the list is indeterminate.

View File

@@ -8,6 +8,8 @@
package org.dspace.app.rest.repository;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.UUID;
@@ -57,11 +59,15 @@ public class BitstreamRestRepository extends DSpaceRestRepository<BitstreamRest,
@Override
public Page<BitstreamRest> findAll(Context context, Pageable pageable) {
List<Bitstream> bit = null;
List<Bitstream> bit = new ArrayList<Bitstream>();
Iterator<Bitstream> it = null;
int total = 0;
try {
total = bs.countTotal(context);
bit = bs.findAll(context);
it = bs.findAll(context, pageable.getPageSize(), pageable.getOffset());
while(it.hasNext()) {
bit.add(it.next());
}
} catch (SQLException e) {
throw new RuntimeException(e.getMessage(), e);
}

View File

@@ -65,7 +65,7 @@ public class ItemRestRepository extends DSpaceRestRepository<ItemRest, UUID> {
int total = 0;
try {
total = is.countTotal(context);
it = is.findAll(context);
it = is.findAll(context, pageable.getPageSize(), pageable.getOffset());
while (it.hasNext()) {
Item i = it.next();
items.add(i);