[DS-2701] Documentation, change new horribleLongMethodName to another findAll variant.

This commit is contained in:
Mark H. Wood
2015-08-25 10:10:58 -04:00
parent 2726e88a2d
commit b5da81f9cb
5 changed files with 68 additions and 51 deletions

View File

@@ -211,7 +211,7 @@ public class ItemServiceImpl extends DSpaceObjectServiceImpl<Item> implements It
public Iterator<Item> findInArchiveOrWithdrawnDiscoverableModifiedSince(Context context, Date since) public Iterator<Item> findInArchiveOrWithdrawnDiscoverableModifiedSince(Context context, Date since)
throws SQLException throws SQLException
{ {
return itemDAO.findInArchiveOrWithdrawnDiscoverableModifiedSince(context, since); return itemDAO.findAll(context, true, true, true, since);
} }
@Override @Override
@@ -230,7 +230,7 @@ public class ItemServiceImpl extends DSpaceObjectServiceImpl<Item> implements It
@Override @Override
public List<Community> getCommunities(Context context, Item item) throws SQLException { public List<Community> getCommunities(Context context, Item item) throws SQLException {
List<Community> result = new ArrayList<Community>(); List<Community> result = new ArrayList<>();
List<Collection> collections = item.getCollections(); List<Collection> collections = item.getCollections();
for (Collection collection : collections) { for (Collection collection : collections) {
List<Community> owningCommunities = collection.getCommunities(); List<Community> owningCommunities = collection.getCommunities();
@@ -245,7 +245,7 @@ public class ItemServiceImpl extends DSpaceObjectServiceImpl<Item> implements It
@Override @Override
public List<Bundle> getBundles(Item item, String name) throws SQLException { public List<Bundle> getBundles(Item item, String name) throws SQLException {
List<Bundle> matchingBundles = new ArrayList<Bundle>(); List<Bundle> matchingBundles = new ArrayList<>();
// now only keep bundles with matching names // now only keep bundles with matching names
List<Bundle> bunds = item.getBundles(); List<Bundle> bunds = item.getBundles();
for (Bundle bund : bunds) { for (Bundle bund : bunds) {
@@ -323,7 +323,7 @@ public class ItemServiceImpl extends DSpaceObjectServiceImpl<Item> implements It
@Override @Override
public List<Bitstream> getNonInternalBitstreams(Context context, Item item) throws SQLException { public List<Bitstream> getNonInternalBitstreams(Context context, Item item) throws SQLException {
List<Bitstream> bitstreamList = new ArrayList<Bitstream>(); List<Bitstream> bitstreamList = new ArrayList<>();
// Go through the bundles and bitstreams picking out ones which aren't // Go through the bundles and bitstreams picking out ones which aren't
// of internal formats // of internal formats
@@ -653,13 +653,7 @@ public class ItemServiceImpl extends DSpaceObjectServiceImpl<Item> implements It
public boolean isOwningCollection(Item item, Collection collection) { public boolean isOwningCollection(Item item, Collection collection) {
Collection owningCollection = item.getOwningCollection(); Collection owningCollection = item.getOwningCollection();
if (owningCollection != null && collection.getID().equals(owningCollection.getID())) return owningCollection != null && collection.getID().equals(owningCollection.getID());
{
return true;
}
// not the owner
return false;
} }
@Override @Override
@@ -881,13 +875,7 @@ public class ItemServiceImpl extends DSpaceObjectServiceImpl<Item> implements It
return true; return true;
} }
// is this person an COLLECTION_EDITOR for the owning collection? return collectionService.canEditBoolean(context, item.getOwningCollection(), false);
if (collectionService.canEditBoolean(context, item.getOwningCollection(), false))
{
return true;
}
return false;
} }

View File

@@ -57,10 +57,13 @@ public interface ItemDAO extends DSpaceObjectLegacySupportDAO<Item>
/** /**
* Get all Items installed or withdrawn, discoverable, and modified since a Date. * Get all Items installed or withdrawn, discoverable, and modified since a Date.
* @param context * @param context
* @param since earliest interesting last-modified date, or null for no date test. * @param archived
* @param withdrawn
* @param discoverable
* @param lastModified earliest interesting last-modified date.
* @return * @return
*/ */
public Iterator<Item> findInArchiveOrWithdrawnDiscoverableModifiedSince( public Iterator<Item> findAll(Context context, boolean archived,
Context context, Date since) boolean withdrawn, boolean discoverable, Date lastModified)
throws SQLException; throws SQLException;
} }

View File

@@ -44,6 +44,22 @@ public class ItemDAOImpl extends AbstractHibernateDSODAO<Item> implements ItemDA
return iterate(query); return iterate(query);
} }
@Override
public Iterator<Item> findAll(Context context, boolean archived,
boolean withdrawn, boolean discoverable, Date lastModified)
throws SQLException
{
Query query = createQuery(context, "SELECT i FROM Item i"
+ " WHERE (inArchive = :in_archive OR withdrawn = :withdrawn)"
+ " AND discoverable = :discoverable"
+ " AND last_modified > :last_modified");
query.setParameter("in_archive", archived);
query.setParameter("withdrawn", withdrawn);
query.setParameter("discoverable", discoverable);
query.setParameter("last_modified", lastModified);
return iterate(query);
}
@Override @Override
public Iterator<Item> findBySubmitter(Context context, EPerson eperson) throws SQLException { public Iterator<Item> findBySubmitter(Context context, EPerson eperson) throws SQLException {
Query query = createQuery(context, "FROM Item WHERE inArchive= :in_archive and submitter= :submitter"); Query query = createQuery(context, "FROM Item WHERE inArchive= :in_archive and submitter= :submitter");
@@ -128,29 +144,6 @@ public class ItemDAOImpl extends AbstractHibernateDSODAO<Item> implements ItemDA
return count(query); return count(query);
} }
private static final String FIND_ALL
= "select item_id FROM item WHERE (in_archive=TRUE OR withdrawn=TRUE)"
+ " AND discoverable=TRUE";
private static final String FIND_SINCE
= "select item_id FROM item WHERE (in_archive=TRUE OR withdrawn=TRUE)"
+ " AND discoverable=TRUE AND last_modified > :last_modified";
@Override
public Iterator<Item> findInArchiveOrWithdrawnDiscoverableModifiedSince(
Context context, Date since)
throws SQLException
{
Query query;
if (null == since){
query = createQuery(context, FIND_ALL);
}
else
{
query = createQuery(context, FIND_SINCE);
query.setParameter("last_modified", since);
}
return iterate(query);
}
@Override @Override
public Iterator<Item> findByLastModifiedSince(Context context, Date since) public Iterator<Item> findByLastModifiedSince(Context context, Date since)
throws SQLException throws SQLException

View File

@@ -8,10 +8,8 @@
package org.dspace.core; package org.dspace.core;
import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.CollectionUtils;
import org.dspace.core.GenericDAO;
import org.hibernate.*; import org.hibernate.*;
import org.hibernate.criterion.Projections; import org.hibernate.criterion.Projections;
import org.hibernate.type.StandardBasicTypes;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.Iterator; import java.util.Iterator;
@@ -19,7 +17,8 @@ import java.util.List;
import java.util.UUID; import java.util.UUID;
/** /**
* Hibernate implementation for generic DAO interface, also includes additional hibernate calls that are comonly used * Hibernate implementation for generic DAO interface. Also includes additional
* Hibernate calls that are commonly used.
* Each DAO should extend this class to prevent code duplication. * Each DAO should extend this class to prevent code duplication.
* *
* @author kevinvandevelde at atmire.com * @author kevinvandevelde at atmire.com
@@ -83,6 +82,14 @@ public abstract class AbstractHibernateDAO<T> implements GenericDAO<T> {
return result; return result;
} }
/**
* Execute a JPA Criteria query and return a collection of results.
*
* @param context
* @param query
* @return
* @throws SQLException
*/
public List<T> findMany(Context context, Query query) throws SQLException { public List<T> findMany(Context context, Query query) throws SQLException {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
List<T> result = (List<T>) query.list(); List<T> result = (List<T>) query.list();
@@ -116,8 +123,9 @@ public abstract class AbstractHibernateDAO<T> implements GenericDAO<T> {
} }
/** /**
* Retrieve a unique result from the query, if multiple results CAN be retrieved an exception will be thrown * Retrieve a unique result from the query. If multiple results CAN be
* so only use when the criteria state uniqueness in the database * retrieved an exception will be thrown,
* so only use when the criteria state uniqueness in the database.
* @param criteria * @param criteria
* @return * @return
*/ */
@@ -129,7 +137,8 @@ public abstract class AbstractHibernateDAO<T> implements GenericDAO<T> {
} }
/** /**
* Retrieve a single result from the query, best used if you expect a single result but this isn't enforced on the database * Retrieve a single result from the query. Best used if you expect a
* single result, but this isn't enforced on the database.
* @param criteria * @param criteria
* @return * @return
*/ */

View File

@@ -12,7 +12,7 @@ import java.util.List;
import java.util.UUID; import java.util.UUID;
/** /**
* Generic Database Access Object interface class that should be implemented by all DAO's. * Generic Database Access Object interface class that should be implemented by all DAOs.
* It offers up a lot of general methods so these don't need to be declared again in each DAO. * It offers up a lot of general methods so these don't need to be declared again in each DAO.
* The default hibernate implementation offers up a class that implements all these methods. * The default hibernate implementation offers up a class that implements all these methods.
* *
@@ -26,13 +26,37 @@ public interface GenericDAO<T>
public void delete(Context context, T t) throws SQLException; public void delete(Context context, T t) throws SQLException;
/**
* Fetch all persisted instances of a given object type.
*
* @param context
* @param clazz the desired type.
* @return
* @throws SQLException
*/
public List<T> findAll(Context context, Class<T> clazz) throws SQLException; public List<T> findAll(Context context, Class<T> clazz) throws SQLException;
/**
* Execute a JPQL query returning a unique result.
*
* @param context
* @param query
* @return
* @throws SQLException
*/
public T findUnique(Context context, String query) throws SQLException; public T findUnique(Context context, String query) throws SQLException;
public T findByID(Context context, Class clazz, int id) throws SQLException; public T findByID(Context context, Class clazz, int id) throws SQLException;
public T findByID(Context context, Class clazz, UUID id) throws SQLException; public T findByID(Context context, Class clazz, UUID id) throws SQLException;
/**
* Execute a JPQL query and return a collection of results.
*
* @param context
* @param query
* @return
* @throws SQLException
*/
public List<T> findMany(Context context, String query) throws SQLException; public List<T> findMany(Context context, String query) throws SQLException;
} }