Skip to content

Commit

Permalink
DSC-1455 simplify the uuid iterator implementation retrieving just th…
Browse files Browse the repository at this point in the history
…e uuid from the database initial query
  • Loading branch information
abollini committed Jan 11, 2024
1 parent ec7fb82 commit d50aa9d
Show file tree
Hide file tree
Showing 8 changed files with 126 additions and 149 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
import org.dspace.core.Constants;
import org.dspace.core.Context;
import org.dspace.core.SelfNamedPlugin;
import org.dspace.core.UUIDIterator;
import org.dspace.eperson.Group;
import org.dspace.eperson.service.GroupService;
import org.dspace.scripts.handler.DSpaceRunnableHandler;
Expand Down Expand Up @@ -135,17 +134,13 @@ public void applyFiltersCommunity(Context context, Community community)
throws Exception { //only apply filters if community not in skip-list
if (!inSkipList(community.getHandle())) {
List<Community> subcommunities = community.getSubcommunities();
List<Collection> collections = community.getCollections();

UUIDIterator<Community> communityIterator = new UUIDIterator<>(context, subcommunities, Community.class);
UUIDIterator<Collection> collectionIterator = new UUIDIterator<>(context, collections, Collection.class);

while (communityIterator.hasNext()) {
applyFiltersCommunity(context, communityIterator.next());
for (Community subcommunity : subcommunities) {
applyFiltersCommunity(context, subcommunity);
}

while (collectionIterator.hasNext()) {
applyFiltersCollection(context, collectionIterator.next());
List<Collection> collections = community.getCollections();
for (Collection collection : collections) {
applyFiltersCollection(context, collection);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,6 @@ public RequestItem findByToken(Context context, String token) throws SQLExceptio
public Iterator<RequestItem> findByItem(Context context, Item item) throws SQLException {
Query query = createQuery(context, "FROM RequestItem WHERE item_id= :uuid");
query.setParameter("uuid", item.getID());
return iterate(context, query, RequestItem.class);
return iterate(query);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.dspace.core.AbstractHibernateDSODAO;
import org.dspace.core.Constants;
import org.dspace.core.Context;
import org.dspace.core.UUIDIterator;

/**
* Hibernate implementation of the Database Access Object interface class for the Bitstream object.
Expand Down Expand Up @@ -77,48 +78,51 @@ public List<Bitstream> findBitstreamsWithNoRecentChecksum(Context context) throw

@Override
public Iterator<Bitstream> findByCommunity(Context context, Community community) throws SQLException {
Query query = createQuery(context, "select b from Bitstream b " +
Query query = createQuery(context, "select b.id from Bitstream b " +
"join b.bundles bitBundles " +
"join bitBundles.items item " +
"join item.collections itemColl " +
"join itemColl.communities community " +
"WHERE :community IN community");

query.setParameter("community", community);

return iterate(context, query, Bitstream.class);
@SuppressWarnings("unchecked")
List<UUID> uuids = query.getResultList();
return new UUIDIterator<Bitstream>(context, uuids, Bitstream.class, this);
}

@Override
public Iterator<Bitstream> findByCollection(Context context, Collection collection) throws SQLException {
Query query = createQuery(context, "select b from Bitstream b " +
Query query = createQuery(context, "select b.id from Bitstream b " +
"join b.bundles bitBundles " +
"join bitBundles.items item " +
"join item.collections c " +
"WHERE :collection IN c");

query.setParameter("collection", collection);

return iterate(context, query, Bitstream.class);
@SuppressWarnings("unchecked")
List<UUID> uuids = query.getResultList();
return new UUIDIterator<Bitstream>(context, uuids, Bitstream.class, this);
}

@Override
public Iterator<Bitstream> findByItem(Context context, Item item) throws SQLException {
Query query = createQuery(context, "select b from Bitstream b " +
Query query = createQuery(context, "select b.id from Bitstream b " +
"join b.bundles bitBundles " +
"join bitBundles.items item " +
"WHERE :item IN item");

query.setParameter("item", item);

return iterate(context, query, Bitstream.class);
@SuppressWarnings("unchecked")
List<UUID> uuids = query.getResultList();
return new UUIDIterator<Bitstream>(context, uuids, Bitstream.class, this);
}

@Override
public Iterator<Bitstream> findShowableByItem(Context context, UUID itemId, String bundleName) throws SQLException {
Query query = createQuery(
context,
"select b from Bitstream b " +
"select b.id from Bitstream b " +
"join b.bundles bitBundle " +
"join bitBundle.items item " +
"WHERE item.id = :itemId " +
Expand Down Expand Up @@ -150,15 +154,18 @@ public Iterator<Bitstream> findShowableByItem(Context context, UUID itemId, Stri

query.setParameter("itemId", itemId);
query.setParameter("bundleName", bundleName);

return iterate(context, query, Bitstream.class);
@SuppressWarnings("unchecked")
List<UUID> uuids = query.getResultList();
return new UUIDIterator<Bitstream>(context, uuids, Bitstream.class, this);
}

@Override
public Iterator<Bitstream> findByStoreNumber(Context context, Integer storeNumber) throws SQLException {
Query query = createQuery(context, "select b from Bitstream b where b.storeNumber = :storeNumber");
Query query = createQuery(context, "select b.id from Bitstream b where b.storeNumber = :storeNumber");
query.setParameter("storeNumber", storeNumber);
return iterate(context, query, Bitstream.class);
@SuppressWarnings("unchecked")
List<UUID> uuids = query.getResultList();
return new UUIDIterator<Bitstream>(context, uuids, Bitstream.class, this);
}

@Override
Expand Down
Loading

0 comments on commit d50aa9d

Please sign in to comment.