public abstract class AbstractHibernateAttachmentDao extends VersionedHibernateObjectDao<Attachment> implements AttachmentDao, 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.Cacheability
AttachmentDao.AttachmentCopier, AttachmentDao.AttachmentMigrator
Modifier and Type | Field and Description |
---|---|
protected AttachmentDataDao |
dataDao |
cacheFactory, confluenceUserDao
NON_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
|
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)
|
AttachmentDao.AttachmentMigrator |
getMigrator(AttachmentDao destinationDao)
Get a migrator object to migrate attachments between attachment datastores.
|
Class |
getPersistentClass() |
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, setCacheFactory, setConfluenceUserDao, updateModificationData
findAll, findAllSorted, findByClassIds, 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, index, refresh, reIndex, remove, replicate, save, saveRaw, setIndexer, unIndex, uniqueResult
checkDaoConfig, convertHibernateAccessException, createHibernateTemplate, getHibernateTemplate, getSession, getSession, getSessionFactory, releaseSession, setHibernateTemplate, setSessionFactory
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
findAll, findLatestVersionsIterator, removeAttachmentFromServer
findAll, findAllSorted, findByClassIds, refresh, remove, replicate, save, saveRaw
protected AttachmentDataDao dataDao
public AttachmentDataDao getDataDao()
public static AttachmentDao getInstance(AttachmentDataDao attachmentDataDao)
attachmentDataDao
- the AttachmentDataDao that should be usedIllegalArgumentException
- if dataDao is not supportedpublic Class getPersistentClass()
getPersistentClass
in interface ObjectDao
public List<Attachment> getLatestVersionsOfAttachments(ContentEntityObject content)
AttachmentDao
getLatestVersionsOfAttachments
in interface AttachmentDao
content
- 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> getLatestVersionsOfAttachmentsWithAnyStatus(ContentEntityObject content)
AttachmentDao
getLatestVersionsOfAttachmentsWithAnyStatus
in interface AttachmentDao
content
- 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)
AttachmentDao
getLatestVersionsOfAttachments
in interface AttachmentDao
ceo
- the content to find attachments onrequest
- 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 countLatestVersionsOfAttachmentsWithAnyStatus(ContentEntityObject content)
countLatestVersionsOfAttachmentsWithAnyStatus
in interface AttachmentDao
content
- the content objectAttachmentDao.getLatestVersionsOfAttachmentsWithAnyStatus(com.atlassian.confluence.core.ContentEntityObject)
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 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 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 List<Attachment> findAllVersions(Attachment attachment)
findAllVersions
in interface AttachmentDao
public List<Attachment> findAllVersions(Long id)
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 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)
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 AttachmentDao
attachment
- 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)
AttachmentDao
isAttachmentPresent
in interface AttachmentDao
attachment
- the Attachment to be checkedpublic void moveAttachment(Attachment latestVersion, 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
latestVersion
- 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)
AttachmentDao
removeAttachmentVersionFromServer
in interface AttachmentDao
attachmentVersionToBeRemoved
- 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()
AttachmentDao
getBackingStorageType
in interface AttachmentDao
AttachmentDataDao.getStorageType()
protected void removeAllAttachmentVersions(Attachment latestVersion, ContentEntityObject content)
public 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 updateAttachment(Attachment attachment)
AttachmentDao
updateAttachment
in interface AttachmentDao
public void prepareForMigrationTo()
prepareForMigrationTo
in interface AttachmentDao
public void afterMigrationFrom()
afterMigrationFrom
in interface AttachmentDao
public Map<Long,Long> getRemappedAttachmentIds()
AttachmentDao
getRemappedAttachmentIds
in interface AttachmentDao
public 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 void flush()
flush
in interface FlushableCachingDao
RuntimeException
- if there was a problem flushingpublic 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–2016 Atlassian. All rights reserved.