diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/AbstractServer.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/AbstractServer.java index 4fe150eddeae782aa60d7272015ff923347aca7c..e9b2bad4bd5740591fc858f3de38d53f447e57d2 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/AbstractServer.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/AbstractServer.java @@ -223,8 +223,19 @@ public abstract class AbstractServer<T> extends AbstractServiceWithLogger<T> imp List<String> dataSetCodes, String reason, boolean force) { // TODO 2011-06-21, Piotr Buczek: loading less for deletion would probably be faster + + // first load by codes to get the ids dataSetTable.loadByDataSetCodes(dataSetCodes, false, false); + + // get recursively all datasets that are contained and contained + List<TechId> ids = + daoFactory.getDataDAO().listContainedDataSetsRecursively( + TechId.createList(dataSetTable.getDataSets())); + + dataSetTable.loadByIds(ids); + List<DataPE> dataSets = dataSetTable.getDataSets(); + Map<DataSetTypePE, List<DataPE>> groupedDataSets = new LinkedHashMap<DataSetTypePE, List<DataPE>>(); for (DataPE dataSet : dataSets) diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/TrashBO.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/TrashBO.java index 09728111c4e7582dbff13baa98df26909fdd3299..f7c446be98dea55f8cbcbd5f34d63abfbb215d31 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/TrashBO.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/TrashBO.java @@ -119,16 +119,7 @@ public class TrashBO extends AbstractBusinessObject implements ITrashBO { assert deletion != null; - LinkedHashSet<TechId> allIds = new LinkedHashSet<TechId>(); - // cascade deletion of contained datasets - List<TechId> containedDataSetIds = dataSetIds; - - while (allIds.addAll(containedDataSetIds)) - { - containedDataSetIds = getDataDAO().listContainedDataSets(containedDataSetIds); - } - - List<TechId> allIdsAsList = new ArrayList<TechId>(allIds); + List<TechId> allIdsAsList = getDataDAO().listContainedDataSetsRecursively(dataSetIds); checkForNonDeletableDataSets(allIdsAsList); TrashBatchOperation batchOperation = diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/IDataDAO.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/IDataDAO.java index 7189bd2c78655997f06e8bd43a47e5e2808e0efc..b828488fdd790f7560b787dd47caf884af3554ed 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/IDataDAO.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/IDataDAO.java @@ -143,6 +143,12 @@ public interface IDataDAO extends IGenericDAO<DataPE> /** Returns ids of contained data sets for a given collection of containers. */ public List<TechId> listContainedDataSets(final Collection<TechId> containerIds); + /** + * Returs ids of contained data sets, and of datasets contained in those datasets etc. Also + * includes the input ids. + */ + public List<TechId> listContainedDataSetsRecursively(final Collection<TechId> containersIds); + /** * Delete data sets with given ids by specified registrator with specified reason. */ diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/db/DataDAO.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/db/DataDAO.java index e50182a71412f461ffb28457a09d04724a2964db..d3059c07b3fb84cf48c6e8b28af11c12dfd4021b 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/db/DataDAO.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/db/DataDAO.java @@ -21,6 +21,8 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.Collections; +import java.util.LinkedHashSet; +import java.util.LinkedList; import java.util.List; import java.util.Set; import java.util.TreeSet; @@ -1117,4 +1119,22 @@ final class DataDAO extends AbstractGenericEntityWithPropertiesDAO<DataPE> imple return transformNumbers2TechIdList(totalResults); } + + public List<TechId> listContainedDataSetsRecursively(Collection<TechId> containersIds) + { + LinkedHashSet<TechId> allIds = new LinkedHashSet<TechId>(); + // cascade deletion of contained datasets + List<TechId> containedDataSetIds = new LinkedList<TechId>(); + + containedDataSetIds.addAll(containersIds); + + while (allIds.addAll(containedDataSetIds)) + { + containedDataSetIds = listContainedDataSets(containedDataSetIds); + } + + return new ArrayList<TechId>(allIds); + + } + }