Class Trashcan

java.lang.Object
net.sf.basedb.core.Trashcan

public class Trashcan extends Object
This class contains functionality to manage items that have been marked for deletion.
Version:
2.0
Author:
nicklas
Last modified
$Date: 2021-06-04 12:40:45 +0200 (Fri, 04 Jun 2021) $
  • Field Details

    • log

      private static final Logger log
      Log trashcan events.
    • isDebug

      private static final boolean isDebug
  • Constructor Details

    • Trashcan

      public Trashcan()
  • Method Details

    • getItems

      public static ResultList<Removable> getItems(DbControl dc, Item itemType, int firstItem, int maxItems) throws BaseException
      Throws:
      BaseException
      See Also:
    • getItems

      public static ResultList<Removable> getItems(DbControl dc, Set<Item> itemTypes, int firstItem, int maxItems) throws BaseException
      Throws:
      BaseException
      See Also:
    • getItems

      public static ResultList<Removable> getItems(DbControl dc, Set<Item> itemTypes, int firstItem, int maxItems, Restriction restriction) throws BaseException
      Load all items flagged for deletion that are owned by or removed by the logged in user. A restriction may be specified to limit the returned items. Note that separate queries are used for each item type but the same restriction is applied to all of them. It is recommended that the restriction is created with Restrictions.conditionalRestriction(Filter, Restriction, Restriction, boolean) so that a restriction on, for example, the 'name' is only applied to Nameable items.
      Parameters:
      dc - The DbControl to use for database access
      itemTypes - Limit the list to only return items of the types, included in the set, use null or an empty set to return items of all types
      firstItem - The index of the first item to return (0-based)
      maxItems - The maximum number of items to return, or 0 to return all items
      restriction - A restriction to apply when loading items
      Returns:
      A list containing removable items
      Throws:
      BaseException - If there is an error of some kind
      Since:
      3.7
    • delete

      public static int delete(SessionControl sc, Collection<? extends Identifiable> items, boolean ignoreFlag, ProgressReporter progress) throws BaseException
      Delete items permanently. This method only delete items that
      • have been marked for deletion (unless the ignoreFlag parameter is set)
      • the logged in user has permission to delete
      • not are used by other items
      Other items are ignored. This method may have to open several transactions to be able to delete as many items as possible. This means that this operation is not atomic and if an exception is thrown some items may have been deleted and some may not.
      Parameters:
      sc - The session control to use for connecting to the database. To avoid multithread-related problems the session control is cloned before being used by this method.
      items - The items to remove
      ignoreFlag - TRUE to also remove items that hasn't been flagged for removal
      progress - An optional progress reporter
      Returns:
      The number of deleted items
      Throws:
      BaseException - If an item can't be deleted.
      Since:
      2.4
    • deleteAll

      public static int deleteAll(SessionControl sc, ProgressReporter progress)
      Delete all items in the trashcan of the logged in user. This method calls getItems(DbControl, Item, int, int) to load all items that have been flagged for removal and then delete(SessionControl, Collection, boolean, ProgressReporter) to remove those items. See the delete for more information about transactions.
      Parameters:
      sc - The session control to use for connecting to the database
      progress - An optional progress reporter
      Returns:
      The number of deleted items
      Since:
      2.4
    • breakCircularReferences

      private static int breakCircularReferences(SessionControl sc, Set<Identifiable> itemsToRemove)