Class RecycleBinDriveStorage

java.lang.Object
org.exoplatform.documents.storage.RecycleBinDriveStorage

@Component public class RecycleBinDriveStorage extends Object
Keeps what the Recycle Bin of each drive holds: its number of items and their total size. The totals are changed in the database, by adding to or subtracting from the stored values, so that concurrent changes all count. Each write is a transaction of its own when its caller holds none: a caller that chains several of them is not atomic and says how it handles a failure in between. Called inside a transaction, a write joins it, and a write that fails marks that whole transaction for rollback: a caller that means to retry after a failure, as after create(long, long), holds none.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    add(long ownerId, long size)
    Counts one more item in the bin of a drive that already has a row.
    long
     
    void
    create(long ownerId, long size)
    Creates the row of a drive with its first item.
    List<org.exoplatform.documents.model.RecycleBinDrive>
    getDrives(long offset, int limit)
    Lists the drives whose bin holds items, largest first.
    void
    remove(long ownerId, long size)
    Counts one item less in the bin of a drive, and deletes the row of a drive left with none.
    void
    replaceAll(List<org.exoplatform.documents.model.RecycleBinDrive> totals)
    Replaces the totals of every drive by the ones counted from the trash, in one transaction: each drive counted gets its totals, and the row of a drive that was not counted is deleted.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

  • Method Details

    • add

      public boolean add(long ownerId, long size)
      Counts one more item in the bin of a drive that already has a row.
      Parameters:
      ownerId - identity id of the drive owner
      size - size of the item, in bytes
      Returns:
      false when the drive has no row yet: nothing was counted, and the caller creates the row with create(long, long)
    • create

      public void create(long ownerId, long size)
      Creates the row of a drive with its first item.
      Parameters:
      ownerId - identity id of the drive owner
      size - size of the item, in bytes
      Throws:
      RuntimeException - when the drive got a row meanwhile: nothing was counted, and the caller counts the item with add(long, long)
    • remove

      public void remove(long ownerId, long size)
      Counts one item less in the bin of a drive, and deletes the row of a drive left with none.
      Parameters:
      ownerId - identity id of the drive owner
      size - size of the item, in bytes
    • replaceAll

      public void replaceAll(List<org.exoplatform.documents.model.RecycleBinDrive> totals)
      Replaces the totals of every drive by the ones counted from the trash, in one transaction: each drive counted gets its totals, and the row of a drive that was not counted is deleted. An item that enters or leaves a bin while the trash is counted and these totals written may be missed or counted twice, until the next replacement.
      Parameters:
      totals - the totals of the drives whose bin holds items
    • getDrives

      public List<org.exoplatform.documents.model.RecycleBinDrive> getDrives(long offset, int limit)
      Lists the drives whose bin holds items, largest first.
      Parameters:
      offset - index of the first drive to return
      limit - maximum number of drives to return
      Returns:
      the drives of that page
    • countDrives

      public long countDrives()
      Returns:
      the number of drives whose bin holds items