public class CachingAttachmentDao extends Object implements AttachmentDaoInternal, FlushableCachingDao, DelegatingAttachmentDao
getLatestAttachment(ContentEntityObject, String)
in an AttachmentCache. Other methods simply delegate to the underlying DAO.
Because the persistent ID of the latest version of an attachment never changes, there's no need to synchronise the cache when an attachment is modified. However, the cache is updated when attachments are removed through this interface.
If for some reason the cache does get out of sync with the database, the lookup using the cached ID will fail. In this situation, we fall back to using the lookup by content ID + file name. The cache will then be corrected once the right result is retrieved from the database.
AttachmentCacheAttachmentDao.AttachmentCopier, AttachmentDao.AttachmentMigrator| Constructor and Description |
|---|
CachingAttachmentDao(AttachmentDaoInternal delegate,
AttachmentCache cache) |
| Modifier and Type | Method and Description |
|---|---|
void |
afterMigrationFrom()
Perform any tasks necessary after Attachment data has been moved from
this data store to another.
|
int |
countLatestVersionsOfAttachments(ContentEntityObject content) |
int |
countLatestVersionsOfAttachmentsWithAnyStatus(ContentEntityObject content) |
List<Attachment> |
findAll()
Retrieves the latest versions of all Attachments
|
List<Attachment> |
findAllVersions(Attachment attachment) |
Iterator<Attachment> |
findLatestVersionsIterator()
Retrieves the latest versions of all Attachments and returns an
Iterator to the results.
|
void |
flush()
Flush the caches managed by this DAO.
|
Attachment |
getAttachment(ContentEntityObject content,
String fileName,
int version)
Return the attachment on the specified content with the given filename and version.
|
InputStream |
getAttachmentData(Attachment attachment)
Retrieves the InputStream representing the data for attachment
|
InputStream |
getAttachmentData(Attachment attachment,
Optional<RangeRequest> range)
Retrieves the InputStream representing the specified range of data for attachment
|
Optional<AttachmentStatisticsDTO> |
getAttachmentStatistics()
Fetches statistics about attachments
|
AttachmentDataStorageType |
getBackingStorageType()
Returns the backing storage type.
|
Attachment |
getById(long id)
Returns the attachment with the given persistent ID.
|
List<Attachment> |
getByIds(List<Long> ids)
Returns a list of attachments matching the given list of IDs.
|
AttachmentDao.AttachmentCopier |
getCopier(AttachmentDao destinationDao)
Get a copier object to copy attachments between data stores
|
AttachmentDataDao |
getDataDao() |
AttachmentDao |
getDelegate()
Returns the attachment DAO which this instance delegates to.
|
List<Attachment> |
getLastAddedVersionsOf(Attachment attachment)
Retrieves all the last added versions for each user who has added a version of the attachment
That is, if a user has added multiple versions, only the latest added version will be added to the list returned.
|
Attachment |
getLatestAttachment(ContentEntityObject content,
String fileName)
Return the latest version of the attachment on the specified content with the given filename.
|
List<Attachment> |
getLatestVersionsOfAttachments(ContentEntityObject ceo)
Retrieves the latest versions of all attachments to ceo
|
PageResponse<Attachment> |
getLatestVersionsOfAttachments(ContentEntityObject ceo,
LimitedRequest pageRequest,
com.google.common.base.Predicate<? super Attachment> predicate)
Retrieves a paginated list of the latest version of attachments to the ceo filtered by the predicate
|
List<Attachment> |
getLatestVersionsOfAttachmentsForMultipleCeos(Iterable<? extends ContentEntityObject> contentEntityObjects)
Retrieves the latest versions of all attachments for all CEOs provided
|
List<Attachment> |
getLatestVersionsOfAttachmentsWithAnyStatus(ContentEntityObject ceo)
Retrieves the latest versions of all attachments to ceo (including trashed)
|
List<Attachment> |
getLatestVersionsOfAttachmentsWithAnyStatusForContainers(Iterable<? extends ContentEntityObject> contentEntityObjects)
Retrieves the latest versions of all attachments for all CEOs provided (including trashed)
|
AttachmentDao.AttachmentMigrator |
getMigrator(AttachmentDao destinationDao)
Get a migrator object to migrate attachments between attachment datastores.
|
Map<Long,Long> |
getRemappedAttachmentIds()
Gets a list of remapped attachment IDs.
|
boolean |
isAttachmentPresent(Attachment attachment)
Check that an attachment exists
|
void |
moveAttachment(Attachment attachment,
Attachment oldAttachment,
ContentEntityObject newContent)
Moves an Attachment to a new file name or content object
|
void |
prepareForMigrationTo()
Prepare the data store for a migration from another type of data store.
|
void |
removeAttachmentFromServer(Attachment attachment)
Removes attachment (and all of its versions)
|
void |
removeAttachmentVersionFromServer(Attachment attachment)
Removes an attachment version
|
void |
replaceAttachmentData(Attachment attachment,
InputStream attachmentData)
Sets the attachment data for attachment
|
void |
saveNewAttachment(Attachment attachment,
InputStream attachmentData)
Saves a new attachment
|
void |
saveNewAttachmentVersion(Attachment attachment,
Attachment previousVersion,
InputStream attachmentData)
Saves a new version of attachment
|
void |
updateAttachment(Attachment attachment)
Update an existing attachment without creating a new version
|
public CachingAttachmentDao(AttachmentDaoInternal delegate, AttachmentCache cache)
public AttachmentDao getDelegate()
DelegatingAttachmentDaogetDelegate in interface DelegatingAttachmentDaopublic Attachment getById(long id)
AttachmentDaogetById in interface AttachmentDaoid - the persistent ID of the attachment to retrievepublic List<Attachment> getByIds(List<Long> ids)
AttachmentDaogetByIds in interface AttachmentDaoids - list of IDs to retrievepublic Attachment getLatestAttachment(ContentEntityObject content, String fileName)
AttachmentDaogetLatestAttachment in interface AttachmentDaocontent - the content to find the attachment onfileName - the file name of the attachmentpublic List<Attachment> getLastAddedVersionsOf(Attachment attachment)
AttachmentDaogetLastAddedVersionsOf in interface AttachmentDaoattachment - attachment (must be the latest version)public void removeAttachmentFromServer(Attachment attachment)
AttachmentDaoremoveAttachmentFromServer in interface AttachmentDaoattachment - the Attachment to be removedpublic void removeAttachmentVersionFromServer(Attachment attachment)
AttachmentDaoremoveAttachmentVersionFromServer in interface AttachmentDaoattachment - the Attachment version to be removedpublic void flush()
FlushableCachingDaoflush in interface FlushableCachingDaopublic List<Attachment> getLatestVersionsOfAttachments(ContentEntityObject ceo)
AttachmentDaogetLatestVersionsOfAttachments in interface AttachmentDaoceo - the content to look up attachmentsAttachmentDao.countLatestVersionsOfAttachments(com.atlassian.confluence.core.ContentEntityObject)public List<Attachment> getLatestVersionsOfAttachmentsForMultipleCeos(Iterable<? extends ContentEntityObject> contentEntityObjects)
AttachmentDaogetLatestVersionsOfAttachmentsForMultipleCeos in interface AttachmentDaocontentEntityObjects - CEOs to retrieve attachements forpublic List<Attachment> getLatestVersionsOfAttachmentsWithAnyStatusForContainers(Iterable<? extends ContentEntityObject> contentEntityObjects)
AttachmentDaoInternalgetLatestVersionsOfAttachmentsWithAnyStatusForContainers in interface AttachmentDaoInternalcontentEntityObjects - CEOs to retrieve attachements forpublic List<Attachment> getLatestVersionsOfAttachmentsWithAnyStatus(ContentEntityObject ceo)
AttachmentDaogetLatestVersionsOfAttachmentsWithAnyStatus in interface AttachmentDaoceo - the content to look up attachmentsAttachmentDao.countLatestVersionsOfAttachments(com.atlassian.confluence.core.ContentEntityObject)public PageResponse<Attachment> getLatestVersionsOfAttachments(ContentEntityObject ceo, LimitedRequest pageRequest, com.google.common.base.Predicate<? super Attachment> predicate)
AttachmentDaogetLatestVersionsOfAttachments in interface AttachmentDaoceo - the content to find attachments onpageRequest - the pagination requestpredicate - a predicate to filter the results bypublic int countLatestVersionsOfAttachments(ContentEntityObject content)
countLatestVersionsOfAttachments in interface AttachmentDaocontent - the content objectAttachmentDao.getLatestVersionsOfAttachments(com.atlassian.confluence.core.ContentEntityObject)public int countLatestVersionsOfAttachmentsWithAnyStatus(ContentEntityObject content)
countLatestVersionsOfAttachmentsWithAnyStatus in interface AttachmentDaocontent - the content object{com.atlassian.confluence.internal.pages.persistence.AttachmentDaoInternal#getLatestVersionsOfAttachmentsWithAnyStatusForContainers()}public Optional<AttachmentStatisticsDTO> getAttachmentStatistics()
AttachmentDaogetAttachmentStatistics in interface AttachmentDaopublic List<Attachment> findAll()
AttachmentDaoUse of this method is discouraged when there are a large amount of Attachments.
findAll in interface AttachmentDaoAttachmentDao.findLatestVersionsIterator()public Iterator<Attachment> findLatestVersionsIterator()
AttachmentDaofindLatestVersionsIterator in interface AttachmentDaopublic InputStream getAttachmentData(Attachment attachment) throws AttachmentDataNotFoundException
AttachmentDaogetAttachmentData in interface AttachmentDaoattachment - the attachment whose data will be returnedAttachmentDataNotFoundException - if the data could not be foundpublic InputStream getAttachmentData(Attachment attachment, Optional<RangeRequest> range) throws AttachmentDataNotFoundException
AttachmentDaogetAttachmentData in interface AttachmentDaoattachment - the attachment whose data will be returnedrange - the range of data to retrieve. See ByteRangesAttachmentDataNotFoundException - if the data could not be foundpublic void saveNewAttachment(Attachment attachment, InputStream attachmentData)
AttachmentDaosaveNewAttachment in interface AttachmentDaoattachment - the Attachment to be savedattachmentData - the attachment data to be savedpublic void saveNewAttachmentVersion(Attachment attachment, Attachment previousVersion, InputStream attachmentData)
AttachmentDaosaveNewAttachmentVersion in interface AttachmentDaoattachment - the Attachment to be savedpreviousVersion - the previous version of the AttachmentattachmentData - the attachment data to be savedpublic boolean isAttachmentPresent(Attachment attachment)
AttachmentDaoisAttachmentPresent in interface AttachmentDaoattachment - the Attachment to be checkedpublic void moveAttachment(Attachment attachment, Attachment oldAttachment, ContentEntityObject newContent)
AttachmentDaoThis method assumes that the filename and/or content of the attachment (and its previous versions) have already been updated.
moveAttachment in interface AttachmentDaoattachment - the Attachment to be movedoldAttachment - the Attachment before it has been updatednewContent - the new content attachment belongs topublic void replaceAttachmentData(Attachment attachment, InputStream attachmentData)
AttachmentDaoThis method will overwrite any existing data for the attachment version.
replaceAttachmentData in interface AttachmentDaoattachment - Attachment the data belongs toattachmentData - the data to savepublic AttachmentDao.AttachmentMigrator getMigrator(AttachmentDao destinationDao)
AttachmentDaoTo be used when switching datastore implementations
getMigrator in interface AttachmentDaodestinationDao - dao to move attachments topublic AttachmentDao.AttachmentCopier getCopier(AttachmentDao destinationDao)
AttachmentDaoThe source data store will remain untouched
getCopier in interface AttachmentDaodestinationDao - dao to copy attachments topublic void prepareForMigrationTo()
AttachmentDaoClasses implementing this method will perform any tasks necessary to allow the data store to be used. These tasks may assume that users are locked out of the system.
prepareForMigrationTo in interface AttachmentDaopublic void afterMigrationFrom()
AttachmentDaoafterMigrationFrom in interface AttachmentDaopublic List<Attachment> findAllVersions(Attachment attachment)
findAllVersions in interface AttachmentDaopublic Attachment getAttachment(ContentEntityObject content, String fileName, int version)
AttachmentDao
Note: unlike AttachmentManager.getAttachment(ContentEntityObject, String, int), this method does not accept zero as a special
flag to indicate the latest version of an attachment. To retrieve the latest version
of an attachment, use AttachmentDao.getLatestAttachment(ContentEntityObject, String).
getAttachment in interface AttachmentDaocontent - the content to find the attachment onfileName - the file name of the attachment, treated case-insensitivelyversion - the version of the attachmentpublic AttachmentDataStorageType getBackingStorageType()
AttachmentDaogetBackingStorageType in interface AttachmentDaoAttachmentDataDao.getStorageType()public void updateAttachment(Attachment attachment)
AttachmentDaoupdateAttachment in interface AttachmentDaopublic Map<Long,Long> getRemappedAttachmentIds()
AttachmentDaogetRemappedAttachmentIds in interface AttachmentDaopublic AttachmentDataDao getDataDao()
getDataDao in interface AttachmentDaoCopyright © 2003–2021 Atlassian. All rights reserved.