Class RecycleBinDriveStorage
java.lang.Object
org.exoplatform.documents.storage.RecycleBinDriveStorage
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 -
Method Summary
Modifier and TypeMethodDescriptionbooleanadd(long ownerId, long size) Counts one more item in the bin of a drive that already has a row.longvoidcreate(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.voidremove(long ownerId, long size) Counts one item less in the bin of a drive, and deletes the row of a drive left with none.voidreplaceAll(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.
-
Constructor Details
-
RecycleBinDriveStorage
-
-
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 ownersize- 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 ownersize- size of the item, in bytes- Throws:
RuntimeException- when the drive got a row meanwhile: nothing was counted, and the caller counts the item withadd(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 ownersize- size of the item, in bytes
-
replaceAll
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
Lists the drives whose bin holds items, largest first.- Parameters:
offset- index of the first drive to returnlimit- 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
-