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.
AttachmentCache
AttachmentDao.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 |
countLatestVersionsOfAttachmentsOnPageSince(ContentEntityObject content,
Date since) |
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)
|
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
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getFilteredLatestVersionsOfAttachments
public CachingAttachmentDao(AttachmentDaoInternal delegate, AttachmentCache cache)
public AttachmentDao getDelegate()
DelegatingAttachmentDao
getDelegate
in interface DelegatingAttachmentDao
public Attachment getById(long id)
AttachmentDao
getById
in interface AttachmentDao
id
- the persistent ID of the attachment to retrievepublic List<Attachment> getByIds(List<Long> ids)
AttachmentDao
getByIds
in interface AttachmentDao
ids
- list of IDs to retrievepublic Attachment getLatestAttachment(ContentEntityObject content, String fileName)
AttachmentDao
getLatestAttachment
in interface AttachmentDao
content
- the content to find the attachment onfileName
- the file name of the attachmentpublic List<Attachment> getLastAddedVersionsOf(Attachment attachment)
AttachmentDao
getLastAddedVersionsOf
in interface AttachmentDao
attachment
- attachment (must be the latest version)public void removeAttachmentFromServer(Attachment attachment)
AttachmentDao
removeAttachmentFromServer
in interface AttachmentDao
attachment
- the Attachment to be removedpublic void removeAttachmentVersionFromServer(Attachment attachment)
AttachmentDao
removeAttachmentVersionFromServer
in interface AttachmentDao
attachment
- the Attachment version to be removedpublic void flush()
FlushableCachingDao
flush
in interface FlushableCachingDao
public List<Attachment> getLatestVersionsOfAttachments(ContentEntityObject ceo)
AttachmentDao
getLatestVersionsOfAttachments
in interface AttachmentDao
ceo
- the content to look up attachmentsAttachmentDao.countLatestVersionsOfAttachments(com.atlassian.confluence.core.ContentEntityObject)
public List<Attachment> getLatestVersionsOfAttachmentsForMultipleCeos(Iterable<? extends ContentEntityObject> contentEntityObjects)
AttachmentDao
getLatestVersionsOfAttachmentsForMultipleCeos
in interface AttachmentDao
contentEntityObjects
- CEOs to retrieve attachements forpublic List<Attachment> getLatestVersionsOfAttachmentsWithAnyStatusForContainers(Iterable<? extends ContentEntityObject> contentEntityObjects)
AttachmentDaoInternal
getLatestVersionsOfAttachmentsWithAnyStatusForContainers
in interface AttachmentDaoInternal
contentEntityObjects
- CEOs to retrieve attachements forpublic List<Attachment> getLatestVersionsOfAttachmentsWithAnyStatus(ContentEntityObject ceo)
AttachmentDao
getLatestVersionsOfAttachmentsWithAnyStatus
in interface AttachmentDao
ceo
- the content to look up attachmentsAttachmentDao.countLatestVersionsOfAttachments(com.atlassian.confluence.core.ContentEntityObject)
@Deprecated public PageResponse<Attachment> getLatestVersionsOfAttachments(ContentEntityObject ceo, LimitedRequest pageRequest, com.google.common.base.Predicate<? super Attachment> predicate)
AttachmentDaoInternal.getFilteredLatestVersionsOfAttachments(ContentEntityObject, LimitedRequest, java.util.function.Predicate)
AttachmentDao
getLatestVersionsOfAttachments
in interface AttachmentDao
ceo
- the content to find attachments onpageRequest
- the pagination requestpredicate
- a predicate to filter the results bypublic int countLatestVersionsOfAttachments(ContentEntityObject content)
countLatestVersionsOfAttachments
in interface AttachmentDao
content
- the content objectAttachmentDao.getLatestVersionsOfAttachments(com.atlassian.confluence.core.ContentEntityObject)
public int countLatestVersionsOfAttachmentsOnPageSince(ContentEntityObject content, Date since)
countLatestVersionsOfAttachmentsOnPageSince
in interface AttachmentDao
content
- the content objectsince
- the date of earliest change{com.atlassian.confluence.internal.pages.persistence.AttachmentDaoInternal#getLatestVersionsOfAttachmentsWithAnyStatusForContainers()}
public int countLatestVersionsOfAttachmentsWithAnyStatus(ContentEntityObject content)
countLatestVersionsOfAttachmentsWithAnyStatus
in interface AttachmentDao
content
- the content object{com.atlassian.confluence.internal.pages.persistence.AttachmentDaoInternal#getLatestVersionsOfAttachmentsWithAnyStatusForContainers()}
public Optional<AttachmentStatisticsDTO> getAttachmentStatistics()
AttachmentDao
getAttachmentStatistics
in interface AttachmentDao
public List<Attachment> findAll()
AttachmentDao
Use of this method is discouraged when there are a large amount of Attachments.
findAll
in interface AttachmentDao
AttachmentDao.findLatestVersionsIterator()
public Iterator<Attachment> findLatestVersionsIterator()
AttachmentDao
findLatestVersionsIterator
in interface AttachmentDao
public InputStream getAttachmentData(Attachment attachment) throws AttachmentDataNotFoundException
AttachmentDao
getAttachmentData
in interface AttachmentDao
attachment
- the attachment whose data will be returnedAttachmentDataNotFoundException
- if the data could not be foundpublic InputStream getAttachmentData(Attachment attachment, Optional<RangeRequest> range) throws AttachmentDataNotFoundException
AttachmentDao
getAttachmentData
in interface AttachmentDao
attachment
- the attachment whose data will be returnedrange
- the range of data to retrieve. See ByteRanges
AttachmentDataNotFoundException
- if the data could not be foundpublic void saveNewAttachment(Attachment attachment, InputStream attachmentData)
AttachmentDao
saveNewAttachment
in interface AttachmentDao
attachment
- the Attachment to be savedattachmentData
- the attachment data to be savedpublic void saveNewAttachmentVersion(Attachment attachment, Attachment previousVersion, InputStream attachmentData)
AttachmentDao
saveNewAttachmentVersion
in interface AttachmentDao
attachment
- the Attachment to be savedpreviousVersion
- the previous version of the AttachmentattachmentData
- the attachment data to be savedpublic boolean isAttachmentPresent(Attachment attachment)
AttachmentDao
isAttachmentPresent
in interface AttachmentDao
attachment
- the Attachment to be checkedpublic void moveAttachment(Attachment attachment, Attachment oldAttachment, ContentEntityObject newContent)
AttachmentDao
This method assumes that the filename and/or content of the attachment (and its previous versions) have already been updated.
moveAttachment
in interface AttachmentDao
attachment
- the Attachment to be movedoldAttachment
- the Attachment before it has been updatednewContent
- the new content attachment belongs topublic void replaceAttachmentData(Attachment attachment, InputStream attachmentData)
AttachmentDao
This method will overwrite any existing data for the attachment version.
replaceAttachmentData
in interface AttachmentDao
attachment
- Attachment the data belongs toattachmentData
- the data to savepublic AttachmentDao.AttachmentMigrator getMigrator(AttachmentDao destinationDao)
AttachmentDao
To be used when switching datastore implementations
getMigrator
in interface AttachmentDao
destinationDao
- dao to move attachments topublic AttachmentDao.AttachmentCopier getCopier(AttachmentDao destinationDao)
AttachmentDao
The source data store will remain untouched
getCopier
in interface AttachmentDao
destinationDao
- dao to copy attachments topublic void prepareForMigrationTo()
AttachmentDao
Classes 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 AttachmentDao
public void afterMigrationFrom()
AttachmentDao
afterMigrationFrom
in interface AttachmentDao
public List<Attachment> findAllVersions(Attachment attachment)
findAllVersions
in interface AttachmentDao
public 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 AttachmentDao
content
- the content to find the attachment onfileName
- the file name of the attachment, treated case-insensitivelyversion
- the version of the attachmentpublic AttachmentDataStorageType getBackingStorageType()
AttachmentDao
getBackingStorageType
in interface AttachmentDao
AttachmentDataDao.getStorageType()
public void updateAttachment(Attachment attachment)
AttachmentDao
updateAttachment
in interface AttachmentDao
public Map<Long,Long> getRemappedAttachmentIds()
AttachmentDao
getRemappedAttachmentIds
in interface AttachmentDao
public AttachmentDataDao getDataDao()
getDataDao
in interface AttachmentDao
Copyright © 2003–2020 Atlassian. All rights reserved.