public abstract class AbstractHibernateAttachmentDao extends VersionedHibernateObjectDao<Attachment> implements AttachmentDaoInternal, FlushableCachingDao
The location of the storage of attachment data is dependent on the AttachmentDataDao set for this class. In some cases, since the removal of attachments is destructive, different implementations may wish to perform the removal of data in a different order. Subclasses will have to implement the #removeDataForAttachment(Attachment attachment) method.
| Modifier and Type | Class and Description |
|---|---|
class |
AbstractHibernateAttachmentDao.IntraHibernateAttachmentCopier
This attachment copier will copy attachment streams from the current instance of
AbstractHibernateAttachmentDao to another.
|
class |
AbstractHibernateAttachmentDao.IntraHibernateAttachmentMigrator
This attachment migrator will migrate attachment streams from the current instance of
AbstractHibernateAttachmentDao to another.
|
HibernateObjectDao.CacheabilityAttachmentDao.AttachmentCopier, AttachmentDao.AttachmentMigrator| Modifier and Type | Field and Description |
|---|---|
protected AttachmentDataDao |
dataDao |
cacheFactory, confluenceUserDaoNON_CACHEABLE| Constructor and Description |
|---|
AbstractHibernateAttachmentDao() |
| Modifier and Type | Method and Description |
|---|---|
void |
afterMigrationFrom()
This implementation removes all Attachments and
passes the migration tasks onto the AttachmentDataDao
|
int |
countLatestVersionsOfAttachments(ContentEntityObject content) |
int |
countLatestVersionsOfAttachmentsWithAnyStatus(ContentEntityObject content) |
List<Attachment> |
findAllVersions(Attachment attachment) |
List<Attachment> |
findAllVersions(Long id) |
List<Long> |
findLatestVersionIds() |
List<Long> |
findLatestVersionIds(List<Space> spacesToInclude)
Same as
findLatestVersionIdsIterator() but only gets the ids matching the list of spaces requested. |
Iterator<Long> |
findLatestVersionIdsIterator() |
Iterator<Long> |
findLatestVersionIdsIterator(List<Space> spacesToInclude)
Same as
findLatestVersionIdsIterator() but only gets the ids matching the list of spaces requested. |
void |
flush()
This implementation flushes the Hibernate session.
|
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() |
static AttachmentDao |
getInstance(AttachmentDataDao attachmentDataDao)
Returns the correct instance of AttachmentDao for the AttachmentDataDao that is given.
|
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 content)
Retrieves the latest versions of all attachments to ceo
|
PageResponse<Attachment> |
getLatestVersionsOfAttachments(ContentEntityObject ceo,
LimitedRequest request,
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 content)
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.
|
Class |
getPersistentClass()
Gets the type of
EntityObject this Dao works with. |
Map<Long,Long> |
getRemappedAttachmentIds()
Gets a list of remapped attachment IDs.
|
boolean |
isAttachmentPresent(Attachment attachment)
Check that an attachment exists
|
void |
moveAttachment(Attachment latestVersion,
Attachment oldAttachment,
ContentEntityObject newContent)
Moves an Attachment to a new file name or content object
|
protected void |
overwriteMetaData(Attachment sourceAttachment,
Attachment targetAttachment)
Overwrites attachment meta data.
|
void |
prepareForMigrationTo()
This implementation removes the contents of the table and
passes the migration tasks onto the AttachmentDataDao
|
protected void |
removeAllAttachmentVersions(Attachment latestVersion,
ContentEntityObject content) |
protected void |
removeAttachment(Attachment attachment,
ContentEntityObject content)
Severs the connection between attachment and content, and removes the attachment from the database
|
void |
removeAttachmentVersionFromServer(Attachment attachmentVersionToBeRemoved)
Removes an attachment version
|
protected abstract void |
removeAttachmentVersionFromServer(Attachment attachmentVersionToBeRemoved,
Attachment previousAttachmentVersion) |
protected void |
removeMetaData(Attachment attachment)
Removes attachment meta data.
|
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)
This implementation saves the Attachment and its previous version to the VersionedHibernateObjectDao.
|
void |
updateAttachment(Attachment attachment)
Update an existing attachment without creating a new version
|
findAllSorted, findLatestVersionsCount, findLatestVersionsCount, findLatestVersionsIterator, findLatestVersionsIterator, findNamedQueryStringParams, findNamedQueryStringParams, save, saveEntity, setCacheFactory, setConfluenceUserDao, updateEntityModificationData, updateModificationDataapplyTransactionTimeout, applyTransactionTimeout, checkDaoConfig, createHibernateTemplate, findAll, findAllSorted, findByClassIds, findByClassIdsFiltered, findNamedQuery, findNamedQuery, findNamedQuery, findNamedQuery, findNamedQuery, findNamedQueryStringParam, findNamedQueryStringParam, findNamedQueryStringParam, findNamedQueryStringParam, findNamedQueryStringParam, findNamedQueryStringParams, findNamedQueryStringParams, findNamedQueryStringParams, findNamedQueryStringParams, findNamedQueryStringParams, findNamedQueryStringParams, findNamedQueryStringParams, findNamedQueryStringParams, findNamedQueryStringParams, findNamedQueryStringParams, findNamedQueryStringParams, findNamedQueryStringParams, findNamedQueryStringParams, findNamedQueryStringParams, findNamedQueryStringParams, findNamedQueryStringParams, findNamedQueryStringParams, findSingleObject, getByClassId, getCountResult, getHibernateTemplate, getSession, getSessionFactory, index, indexEntity, refresh, refreshEntity, reIndex, reIndexEntity, remove, removeEntity, replicate, replicateEntity, save, saveEntity, saveRaw, saveRawEntity, setHibernateTemplate, setIndexer, setSessionFactory, unIndex, unIndexEntity, uniqueResultclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitfindAll, findLatestVersionsIterator, removeAttachmentFromServerfindAll, findAllSorted, findByClassIds, findByClassIdsFiltered, refresh, refreshEntity, remove, removeEntity, replicate, replicateEntity, save, saveEntity, saveRaw, saveRawEntityprotected AttachmentDataDao dataDao
public AttachmentDataDao getDataDao()
getDataDao in interface AttachmentDaopublic static AttachmentDao getInstance(AttachmentDataDao attachmentDataDao)
attachmentDataDao - the AttachmentDataDao that should be usedIllegalArgumentException - if dataDao is not supportedpublic Class getPersistentClass()
ObjectDaoInternalEntityObject this Dao works with.getPersistentClass in interface ObjectDaogetPersistentClass in interface ObjectDaoInternal<Attachment>public List<Attachment> getLatestVersionsOfAttachments(ContentEntityObject content)
AttachmentDaogetLatestVersionsOfAttachments in interface AttachmentDaocontent - 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 content)
AttachmentDaogetLatestVersionsOfAttachmentsWithAnyStatus in interface AttachmentDaocontent - the content to look up attachmentsAttachmentDao.countLatestVersionsOfAttachments(com.atlassian.confluence.core.ContentEntityObject)public PageResponse<Attachment> getLatestVersionsOfAttachments(ContentEntityObject ceo, LimitedRequest request, com.google.common.base.Predicate<? super Attachment> predicate)
AttachmentDaogetLatestVersionsOfAttachments in interface AttachmentDaoceo - the content to find attachments onrequest - 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 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 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 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 List<Attachment> findAllVersions(Attachment attachment)
findAllVersions in interface AttachmentDaopublic List<Attachment> findAllVersions(Long id)
public 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)
Due to the way Hibernate works, attachment must be the current Hibernate-managed object (without its version or ID having being changed), and previousVersion should be a clone of the unmodified Attachment object.
saveNewAttachmentVersion in interface AttachmentDaoattachment - the attachment to be saved, a clone of the old onepreviousVersion - the old attachment, which must be unmodifiedattachmentData - the new attachment datapublic boolean isAttachmentPresent(Attachment attachment)
AttachmentDaoisAttachmentPresent in interface AttachmentDaoattachment - the Attachment to be checkedpublic void moveAttachment(Attachment latestVersion, 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 AttachmentDaolatestVersion - the Attachment to be movedoldAttachment - the Attachment before it has been updatednewContent - the new content attachment belongs toprotected void removeAttachment(Attachment attachment, ContentEntityObject content)
attachment - the attachment to removecontent - the content to remove the attachment frompublic final void removeAttachmentVersionFromServer(Attachment attachmentVersionToBeRemoved)
AttachmentDaoremoveAttachmentVersionFromServer in interface AttachmentDaoattachmentVersionToBeRemoved - the Attachment version to be removedprotected abstract void removeAttachmentVersionFromServer(Attachment attachmentVersionToBeRemoved, @Nullable Attachment previousAttachmentVersion)
protected void removeMetaData(Attachment attachment)
The steps for removing attachment meta data are
attachment - the attachment version to be removedprotected void overwriteMetaData(Attachment sourceAttachment, Attachment targetAttachment)
The latest version of an attachment inherits the EntityObject.getId() of the first version, that means the
identifier which was given to the first version gets replaced by a new one if a second version gets uploaded, and
the second version inherits the identifier of the first one. Thus using the identifier of the latest version in
the frontend is guaranteed to never become stale.
Thus
The corresponding row of sourceAttachment in the ATTACHMENTS table will be removed, and its data
will be used to overwrite the corresponding row of targetAttachment. Calling this method assumes that you
removed all tuples having a referential constraint on the sourceAttachment's row ahead, since the state of
the Hibernate session will be synchronised with the database several times as part of this execution. The
sourceAttachment object will become untracked by Hibernate as a result of this call, and it will have the
id of the targetAttachment, thus anything relying on the old state should have cached it ahead
(e.g. shallow Attachment.clone()).
sourceAttachment - the attachment version to be movedtargetAttachment - the attachment version to be overwrittenpublic AttachmentDataStorageType getBackingStorageType()
AttachmentDaogetBackingStorageType in interface AttachmentDaoAttachmentDataDao.getStorageType()protected void removeAllAttachmentVersions(Attachment latestVersion, ContentEntityObject content)
public 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 updateAttachment(Attachment attachment)
AttachmentDaoupdateAttachment in interface AttachmentDaopublic void prepareForMigrationTo()
prepareForMigrationTo in interface AttachmentDaopublic void afterMigrationFrom()
afterMigrationFrom in interface AttachmentDaopublic Map<Long,Long> getRemappedAttachmentIds()
AttachmentDaogetRemappedAttachmentIds in interface AttachmentDaopublic 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 void flush()
flush in interface FlushableCachingDaopublic Iterator<Long> findLatestVersionIdsIterator(List<Space> spacesToInclude)
findLatestVersionIdsIterator() but only gets the ids matching the list of spaces requested.spacesToInclude - list of spaces to include. The length of this list should not exceed the allowed maximum
value of an "in" clause.public List<Long> findLatestVersionIds(List<Space> spacesToInclude)
findLatestVersionIdsIterator() but only gets the ids matching the list of spaces requested.spacesToInclude - list of spaces to include. The length of this list should not exceed the allowed maximum
value of an "in" clause.Copyright © 2003–2019 Atlassian. All rights reserved.