Class AbstractHibernateAttachmentDao
- All Implemented Interfaces:
AttachmentDaoInternal,AttachmentDao,FlushableCachingDao,org.springframework.beans.factory.InitializingBean
- Direct Known Subclasses:
NonTransactionalHibernateAttachmentDao,TransactionalHibernateAttachmentDao
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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionclassThis attachment copier will copy attachment streams from the current instance of AbstractHibernateAttachmentDao to another.classDeprecated, for removal: This API element is subject to removal in a future version.since 8.8, no replacementNested classes/interfaces inherited from class com.atlassian.confluence.core.persistence.hibernate.HibernateObjectDao
HibernateObjectDao.CacheabilityNested classes/interfaces inherited from interface com.atlassian.confluence.pages.persistence.dao.AttachmentDao
AttachmentDao.AttachmentCopier, AttachmentDao.AttachmentMigrator -
Field Summary
FieldsFields inherited from class org.springframework.dao.support.DaoSupport
logger -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidThis implementation removes all Attachments and passes the migration tasks onto the AttachmentDataDaointlongcountLatestVersionsOfAttachmentsBySpaceAndStatuses(Space space, List<ContentStatus> statuses) Returns the number of the latest versions of attachments by their statuses in a spacelongReturns the number of the latest versions of attachments by their statusesintcountLatestVersionsOfAttachmentsOnPageSince(ContentEntityObject content, Date since) intfindAllVersions(Attachment attachment) findAllVersions(Long id) findLatestVersionIds(List<Space> spacesToInclude) Same asfindLatestVersionIdsIterator()but only gets the ids matching the list of spaces requested.findLatestVersionIdsIterator(List<Space> spacesToInclude) Same asfindLatestVersionIdsIterator()but only gets the ids matching the list of spaces requested.voidflush()This implementation flushes the Hibernate session.getAttachment(ContentEntityObject content, String fileName, int version) Return the attachment on the specified content with the given filename and version.getAttachmentData(Attachment attachment) Retrieves the InputStream representing the data for attachmentgetAttachmentData(Attachment attachment, Optional<RangeRequest> range) Retrieves the InputStream representing the specified range of data for attachmentFetches statistics about attachmentsReturns the backing storage type.getById(long id) Returns the attachment with the given persistent ID.Returns a list of attachments matching the given list of IDs.getCopier(AttachmentDao destinationDao) Get a copier object to copy attachments between data storesstatic AttachmentDaogetInstance(AttachmentDataDao attachmentDataDao) Returns the correct instance of AttachmentDao for the AttachmentDataDao that is given.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.getLatestAttachment(ContentEntityObject content, String fileName) Return the latest version of the attachment on the specified content with the given filename.Retrieves the latest versions of all attachments to ceogetLatestVersionsOfAttachments(ContentEntityObject ceo, LimitedRequest request) getLatestVersionsOfAttachmentsForMultipleCeos(Iterable<? extends ContentEntityObject> contentEntityObjects) Retrieves the latest versions of all attachments for all CEOs providedRetrieves the latest versions of all attachments to ceo (including trashed)getLatestVersionsOfAttachmentsWithAnyStatusForContainers(Iterable<? extends ContentEntityObject> contentEntityObjects) Retrieves the latest versions of all attachments for all CEOs provided (including trashed)getMigrator(AttachmentDao destinationDao) Get a migrator object to migrate attachments between attachment datastores.Gets a list of remapped attachment IDs.booleanisAttachmentPresent(Attachment attachment) Check that an attachment existsvoidmoveAttachment(Attachment latestVersion, Attachment oldAttachment, ContentEntityObject newContent) Moves an Attachment to a new file name or content objectprotected voidoverwriteMetaData(Attachment sourceAttachment, Attachment targetAttachment) Overwrites attachment meta data.voidThis implementation removes the contents of the table and passes the migration tasks onto the AttachmentDataDaoprotected voidprotected List<Attachment>removeAllAttachmentVersions(Attachment latestVersion, ContentEntityObject content) protected voidremoveAttachment(Attachment attachment, ContentEntityObject content) Severs the connection between attachment and content, and removes the attachment from the databasefinal voidremoveAttachmentVersionFromServer(Attachment attachmentVersionToBeRemoved) Removes an attachment versionprotected abstract voidremoveAttachmentVersionFromServer(Attachment attachmentVersionToBeRemoved, @Nullable Attachment previousAttachmentVersion) protected voidremoveMetaData(Attachment attachment) Removes attachment meta data.voidreplaceAttachmentData(Attachment attachment, InputStream attachmentData) Sets the attachment data for attachmentvoidsaveNewAttachment(Attachment attachment, InputStream attachmentData) Saves a new attachmentvoidsaveNewAttachmentVersion(Attachment attachment, Attachment previousVersion, InputStream attachmentData) This implementation saves the Attachment and its previous version to the VersionedHibernateObjectDao.scanFilteredAttachments(Space space, List<ContentStatus> statuses, LimitedRequest pageRequest) scanFilteredAttachments(List<ContentStatus> statuses, LimitedRequest pageRequest) voidsetEventPublisher(com.atlassian.event.api.EventPublisher eventPublisher) voidupdateAttachment(Attachment attachment) Update an existing attachment without creating a new versionMethods inherited from class com.atlassian.confluence.core.persistence.hibernate.VersionedHibernateObjectDao
applyChildVersioningPolicy, findAllSorted, findLatestVersionsCount, findLatestVersionsIterator, findLatestVersionsIterator, findNamedQueryStringParams, remove, saveMethods inherited from class com.atlassian.confluence.core.persistence.hibernate.ConfluenceHibernateObjectDao
findNamedQueryStringParams, getContentStatusStringList, getStatusNames, scanFilteredContents, scanFilteredContents, updateModificationDataMethods inherited from class com.atlassian.confluence.core.persistence.hibernate.HibernateObjectDao
applyTransactionTimeout, applyTransactionTimeout, checkDaoConfig, createHibernateTemplate, findAll, findAllSorted, findNamedQuery, findNamedQuery, findNamedQuery, findNamedQueryStringParam, findNamedQueryStringParam, findNamedQueryStringParam, findNamedQueryStringParams, findNamedQueryStringParams, findNamedQueryStringParams, findNamedQueryStringParams, findNamedQueryStringParams, findNamedQueryStringParams, findNamedQueryStringParams, findNamedQueryStringParams, findNamedQueryStringParams, findNamedQueryStringParams, findNamedQueryStringParams, findSingleObject, getByClassId, getCountResult, getHibernateTemplate, getSessionFactory, reIndex, save, saveEntity, saveRaw, setHibernateTemplate, setSessionFactory, uniqueResultMethods inherited from class org.springframework.dao.support.DaoSupport
afterPropertiesSet, initDaoMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.atlassian.confluence.pages.persistence.dao.AttachmentDao
findAll, removeAttachmentFromServerMethods inherited from interface com.atlassian.confluence.internal.pages.persistence.AttachmentDaoInternal
findLatestVersionsIterator, removeAllVersionsFromServer
-
Field Details
-
dataDao
-
-
Constructor Details
-
AbstractHibernateAttachmentDao
public AbstractHibernateAttachmentDao()
-
-
Method Details
-
getDataDao
- Specified by:
getDataDaoin interfaceAttachmentDao
-
getInstance
Returns the correct instance of AttachmentDao for the AttachmentDataDao that is given.- Parameters:
attachmentDataDao- the AttachmentDataDao that should be used- Returns:
- a matching AttachmentDao instance
- Throws:
IllegalArgumentException- if dataDao is not supported
-
getPersistentClass
- Specified by:
getPersistentClassin classHibernateObjectDao<Attachment>
-
getLatestVersionsOfAttachments
Description copied from interface:AttachmentDaoRetrieves the latest versions of all attachments to ceo- Specified by:
getLatestVersionsOfAttachmentsin interfaceAttachmentDao- Parameters:
content- the content to look up attachments- Returns:
- a List of Attachment objects
- See Also:
-
getLatestVersionsOfAttachmentsForMultipleCeos
public List<Attachment> getLatestVersionsOfAttachmentsForMultipleCeos(Iterable<? extends ContentEntityObject> contentEntityObjects) Description copied from interface:AttachmentDaoRetrieves the latest versions of all attachments for all CEOs provided- Specified by:
getLatestVersionsOfAttachmentsForMultipleCeosin interfaceAttachmentDao- Parameters:
contentEntityObjects- CEOs to retrieve attachements for- Returns:
- a List of Attachment objects
-
getLatestVersionsOfAttachmentsWithAnyStatusForContainers
public List<Attachment> getLatestVersionsOfAttachmentsWithAnyStatusForContainers(Iterable<? extends ContentEntityObject> contentEntityObjects) Description copied from interface:AttachmentDaoInternalRetrieves the latest versions of all attachments for all CEOs provided (including trashed)- Specified by:
getLatestVersionsOfAttachmentsWithAnyStatusForContainersin interfaceAttachmentDaoInternal- Parameters:
contentEntityObjects- CEOs to retrieve attachements for- Returns:
- a List of Attachment objects
-
getLatestVersionsOfAttachmentsWithAnyStatus
Description copied from interface:AttachmentDaoRetrieves the latest versions of all attachments to ceo (including trashed)- Specified by:
getLatestVersionsOfAttachmentsWithAnyStatusin interfaceAttachmentDao- Parameters:
content- the content to look up attachments- Returns:
- a List of Attachment objects
- See Also:
-
getLatestVersionsOfAttachments
- Specified by:
getLatestVersionsOfAttachmentsin interfaceAttachmentDao
-
countLatestVersionsOfAttachments
- Specified by:
countLatestVersionsOfAttachmentsin interfaceAttachmentDao- Parameters:
content- the content object- Returns:
- the number of current attachments on a content object
- See Also:
-
countLatestVersionsOfAttachmentsWithAnyStatus
- Specified by:
countLatestVersionsOfAttachmentsWithAnyStatusin interfaceAttachmentDao- Parameters:
content- the content object- Returns:
- the number of current attachments on a content object (including trashed)
-
countLatestVersionsOfAttachmentsOnPageSince
- Specified by:
countLatestVersionsOfAttachmentsOnPageSincein interfaceAttachmentDao- Parameters:
content- the content objectsince- the date of earliest change- Returns:
- the number of attachments on a content object (including trashed) changed since
- See Also:
-
scanFilteredAttachments
public List<Attachment> scanFilteredAttachments(Space space, List<ContentStatus> statuses, LimitedRequest pageRequest) - Specified by:
scanFilteredAttachmentsin interfaceAttachmentDaoInternal- Parameters:
space- space which the attachments belong tostatuses- list of statusespageRequest- the page being requested- Returns:
- the paginated list of
Attachmententities in the given space
-
scanFilteredAttachments
public List<Attachment> scanFilteredAttachments(List<ContentStatus> statuses, LimitedRequest pageRequest) - Specified by:
scanFilteredAttachmentsin interfaceAttachmentDaoInternal- Parameters:
statuses- list of statusespageRequest- the page being requested- Returns:
- the paginated list of
Attachmententities in the given space
-
countLatestVersionsOfAttachmentsByStatuses
Description copied from interface:AttachmentDaoInternalReturns the number of the latest versions of attachments by their statuses- Specified by:
countLatestVersionsOfAttachmentsByStatusesin interfaceAttachmentDaoInternal- Parameters:
statuses- list of statuses- Returns:
- the count
-
countLatestVersionsOfAttachmentsBySpaceAndStatuses
public long countLatestVersionsOfAttachmentsBySpaceAndStatuses(Space space, List<ContentStatus> statuses) Description copied from interface:AttachmentDaoInternalReturns the number of the latest versions of attachments by their statuses in a space- Specified by:
countLatestVersionsOfAttachmentsBySpaceAndStatusesin interfaceAttachmentDaoInternal- Parameters:
space- space which the attachments belong tostatuses- list of statuses- Returns:
- the count
-
getAttachmentStatistics
Description copied from interface:AttachmentDaoFetches statistics about attachments- Specified by:
getAttachmentStatisticsin interfaceAttachmentDao- Returns:
- an AttachmentStatisticsDTO with statistics about attachments such as total and current count
-
getById
Description copied from interface:AttachmentDaoReturns the attachment with the given persistent ID. Returns null if no such attachment exists.- Specified by:
getByIdin interfaceAttachmentDao- Parameters:
id- the persistent ID of the attachment to retrieve- Returns:
- the attachment with the given ID, or null if no attachment exists with the provided ID.
-
getByIds
Description copied from interface:AttachmentDaoReturns a list of attachments matching the given list of IDs. Returns an empty list if no such attachments exist. In the case where some IDs exist and some don't, only the existing Attachments will be returned.- Specified by:
getByIdsin interfaceAttachmentDao- Parameters:
ids- list of IDs to retrieve- Returns:
- the attachments with the given IDs, or an empty list if no attachments exist with the provided IDs.
-
getAttachment
Description copied from interface:AttachmentDaoReturn the attachment on the specified content with the given filename and version. Returns null if no such attachment exists.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, useAttachmentDao.getLatestAttachment(ContentEntityObject, String).- Specified by:
getAttachmentin interfaceAttachmentDao- Parameters:
content- the content to find the attachment onfileName- the file name of the attachment, treated case-insensitivelyversion- the version of the attachment- Returns:
- the attachment with the given name and version attached to that content, or null if the attachment does not exist.
-
getLatestAttachment
Description copied from interface:AttachmentDaoReturn the latest version of the attachment on the specified content with the given filename. Returns null if no attachment with that name on the content exists.- Specified by:
getLatestAttachmentin interfaceAttachmentDao- Parameters:
content- the content to find the attachment onfileName- the file name of the attachment- Returns:
- the latest version of attachment with the given name attached to that content, or null if the attachment does not exist.
-
getLastAddedVersionsOf
Description copied from interface:AttachmentDaoRetrieves 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. Result will be sorted with the earliest version coming first.- Specified by:
getLastAddedVersionsOfin interfaceAttachmentDao- Parameters:
attachment- attachment (must be the latest version)- Returns:
- the last added versions for each user who has added a version of the attachment
-
findAllVersions
- Specified by:
findAllVersionsin interfaceAttachmentDao
-
findAllVersions
-
getAttachmentData
Description copied from interface:AttachmentDaoRetrieves the InputStream representing the data for attachment- Specified by:
getAttachmentDatain interfaceAttachmentDao- Parameters:
attachment- the attachment whose data will be returned- Returns:
- InputStream of the data
- Throws:
AttachmentDataNotFoundException- if the data could not be found
-
getAttachmentData
public InputStream getAttachmentData(Attachment attachment, Optional<RangeRequest> range) throws AttachmentDataNotFoundException Description copied from interface:AttachmentDaoRetrieves the InputStream representing the specified range of data for attachment- Specified by:
getAttachmentDatain interfaceAttachmentDao- Parameters:
attachment- the attachment whose data will be returnedrange- the range of data to retrieve. Seecom.atlassian.filestore.client.api.entity.ByteRanges- Returns:
- InputStream of the data
- Throws:
AttachmentDataNotFoundException- if the data could not be found
-
saveNewAttachment
Description copied from interface:AttachmentDaoSaves a new attachment- Specified by:
saveNewAttachmentin interfaceAttachmentDao- Parameters:
attachment- the Attachment to be savedattachmentData- the attachment data to be saved
-
saveNewAttachmentVersion
public void saveNewAttachmentVersion(Attachment attachment, Attachment previousVersion, InputStream attachmentData) This implementation saves the Attachment and its previous version to the VersionedHibernateObjectDao.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.
- Specified by:
saveNewAttachmentVersionin interfaceAttachmentDao- Parameters:
attachment- the attachment to be saved, a clone of the old onepreviousVersion- the old attachment, which must be unmodifiedattachmentData- the new attachment data
-
isAttachmentPresent
Description copied from interface:AttachmentDaoCheck that an attachment exists- Specified by:
isAttachmentPresentin interfaceAttachmentDao- Parameters:
attachment- the Attachment to be checked
-
moveAttachment
public void moveAttachment(Attachment latestVersion, Attachment oldAttachment, ContentEntityObject newContent) Description copied from interface:AttachmentDaoMoves an Attachment to a new file name or content objectThis method assumes that the filename and/or content of the attachment (and its previous versions) have already been updated.
- Specified by:
moveAttachmentin interfaceAttachmentDao- Parameters:
latestVersion- the Attachment to be movedoldAttachment- the Attachment before it has been updatednewContent- the new content attachment belongs to
-
removeAttachment
Severs the connection between attachment and content, and removes the attachment from the database- Parameters:
attachment- the attachment to removecontent- the content to remove the attachment from
-
removeAttachmentVersionFromServer
Description copied from interface:AttachmentDaoRemoves an attachment version- Specified by:
removeAttachmentVersionFromServerin interfaceAttachmentDao- Parameters:
attachmentVersionToBeRemoved- the Attachment version to be removed
-
removeAttachmentVersionFromServer
protected abstract void removeAttachmentVersionFromServer(Attachment attachmentVersionToBeRemoved, @Nullable Attachment previousAttachmentVersion) -
removeMetaData
Removes attachment meta data.The steps for removing attachment meta data are
- the attachment object being de-referenced from its container (e.g. page)
- the original version (reference to the latest version) to be set to null
- the row removal to be recorded
- the un-index to be queued
- Parameters:
attachment- the attachment version to be removed
-
overwriteMetaData
Overwrites attachment meta data.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
- removing a historical version is "simple", as the only thing that references it is its container (e.g. page)
- removing the current version is "complex", as this requires the previous version to be "promoted" to the current version
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()).- Parameters:
sourceAttachment- the attachment version to be movedtargetAttachment- the attachment version to be overwritten
-
getBackingStorageType
Description copied from interface:AttachmentDaoReturns the backing storage type.- Specified by:
getBackingStorageTypein interfaceAttachmentDao- Returns:
- the backing storage type
- See Also:
-
removeAllAttachmentVersions
protected List<Attachment> removeAllAttachmentVersions(Attachment latestVersion, ContentEntityObject content) -
getMigrator
Description copied from interface:AttachmentDaoGet a migrator object to migrate attachments between attachment datastores.To be used when switching datastore implementations
- Specified by:
getMigratorin interfaceAttachmentDao- Parameters:
destinationDao- dao to move attachments to- Returns:
- A migrator
-
getCopier
Description copied from interface:AttachmentDaoGet a copier object to copy attachments between data storesThe source data store will remain untouched
- Specified by:
getCopierin interfaceAttachmentDao- Parameters:
destinationDao- dao to copy attachments to- Returns:
- A copier
-
updateAttachment
Description copied from interface:AttachmentDaoUpdate an existing attachment without creating a new version- Specified by:
updateAttachmentin interfaceAttachmentDao
-
prepareForMigrationTo
public void prepareForMigrationTo()This implementation removes the contents of the table and passes the migration tasks onto the AttachmentDataDao- Specified by:
prepareForMigrationToin interfaceAttachmentDao
-
afterMigrationFrom
public void afterMigrationFrom()This implementation removes all Attachments and passes the migration tasks onto the AttachmentDataDao- Specified by:
afterMigrationFromin interfaceAttachmentDao
-
getRemappedAttachmentIds
Description copied from interface:AttachmentDaoGets a list of remapped attachment IDs. The key is the old ID and the value is the new ID.- Specified by:
getRemappedAttachmentIdsin interfaceAttachmentDao- Returns:
- A map where the key is the original ID and the value is the new ID.
-
replaceAttachmentData
Description copied from interface:AttachmentDaoSets the attachment data for attachmentThis method will overwrite any existing data for the attachment version.
- Specified by:
replaceAttachmentDatain interfaceAttachmentDao- Parameters:
attachment- Attachment the data belongs toattachmentData- the data to save
-
flush
public void flush()This implementation flushes the Hibernate session.- Specified by:
flushin interfaceFlushableCachingDao
-
findLatestVersionIdsIterator
-
findLatestVersionIdsIterator
Same asfindLatestVersionIdsIterator()but only gets the ids matching the list of spaces requested.- Parameters:
spacesToInclude- list of spaces to include. The length of this list should not exceed the allowed maximum value of an "in" clause.- Returns:
- a list of the latest versions of attachments in the requested spaces
-
findLatestVersionIds
-
findLatestVersionIds
Same asfindLatestVersionIdsIterator()but only gets the ids matching the list of spaces requested.- Parameters:
spacesToInclude- list of spaces to include. The length of this list should not exceed the allowed maximum value of an "in" clause.- Returns:
- a list of the ids of the latest versions of attachments in the requested spaces
-
setEventPublisher
public void setEventPublisher(com.atlassian.event.api.EventPublisher eventPublisher) -
publishEvent
- Overrides:
publishEventin classHibernateObjectDao<Attachment>
-