public interface

AttachmentDao

com.atlassian.confluence.pages.persistence.dao.AttachmentDao
Known Indirect Subclasses

Class Overview

This interface defines the methods for classes acting as a DAO at the level of meta-data storage for Attachments.

Summary

Nested Classes
interface AttachmentDao.AttachmentCopier  
interface AttachmentDao.AttachmentMigrator  
Public Methods
void afterMigrationFrom()
Perform any tasks necessary after Attachment data has been moved from this data store to another.
int countLatestVersionsOfAttachments(ContentEntityObject content)
List<Attachment> findAll()
Retrieves the latest versions of all Attachments Use of this method is discouraged when there are a large amount of Attachments.
List<Attachment> findAllVersions(Attachment attachment)
Iterator<Attachment> findLatestVersionsIterator()
Retrieves the latest versions of all Attachments and returns an Iterator to the results.
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
Attachment getById(long id)
Returns the attachment with the given persistent ID.
AttachmentDao.AttachmentCopier getCopier(AttachmentDao destinationDao)
Get a copier object to copy attachments between data stores The source data store will remain untouched
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
AttachmentDao.AttachmentMigrator getMigrator(AttachmentDao destinationDao)
Get a migrator object to migrate attachments between attachment datastores.
void moveAttachment(Attachment attachment, Attachment oldAttachment, ContentEntityObject newContent)
Moves an Attachment to a new file name or content object

This method assumes that the filename and/or content of the attachment (and its previous versions) have already been updated.
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 replaceAttachmentData(Attachment attachment, InputStream attachmentData)
Sets the attachment data for attachment This method will overwrite any existing data for the attachment version.
void saveNewAttachment(Attachment attachment, InputStream attachmentData)
Saves a new attachment
void saveNewAttachmentVersion(Attachment attachment, Attachment previousVersion, InputStream attachmentData)
Saves a new version of attachment

Public Methods

public void afterMigrationFrom ()

Perform any tasks necessary after Attachment data has been moved from this data store to another. These tasks may assume that users are locked out of the system.

Throws
RuntimeException if there was a problem

public int countLatestVersionsOfAttachments (ContentEntityObject content)

Parameters
content the content object
Returns
  • the number of current attachments on a content object

public List<Attachment> findAll ()

Retrieves the latest versions of all Attachments Use of this method is discouraged when there are a large amount of Attachments.

Returns
  • A List of Attachment objects

public List<Attachment> findAllVersions (Attachment attachment)

public Iterator<Attachment> findLatestVersionsIterator ()

Retrieves the latest versions of all Attachments and returns an Iterator to the results.

Returns
  • Iterator to the results

public Attachment getAttachment (ContentEntityObject content, String fileName, int version)

Return the attachment on the specified content with the given filename and version. Returns null if no such attachment exists.

Note: unlike 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 getLatestAttachment(ContentEntityObject, String).
Parameters
content the content to find the attachment on
fileName the file name of the attachment, treated case-insensitively
version 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.
Throws
IllegalArgumentException if the content or fileName is null

public InputStream getAttachmentData (Attachment attachment)

Retrieves the InputStream representing the data for attachment

Parameters
attachment the attachment whose data will be returned
Returns
  • InputStream of the data
Throws
AttachmentDataNotFoundException if the data could not be found

public Attachment getById (long id)

Returns the attachment with the given persistent ID. Returns null if no such attachment exists.

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.

public AttachmentDao.AttachmentCopier getCopier (AttachmentDao destinationDao)

Get a copier object to copy attachments between data stores The source data store will remain untouched

Parameters
destinationDao dao to copy attachments to
Returns
  • A copier

public 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. Result will be sorted with the earliest version coming first.

Parameters
attachment attachment (must be the latest version)
Returns
  • the last added versions for each user who has added a version of the attachment
Throws
IllegalArgumentException if the attachment is not the latest version or null

public Attachment getLatestAttachment (ContentEntityObject content, String fileName)

Return 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.

Parameters
content the content to find the attachment on
fileName 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.
Throws
IllegalArgumentException if the content or fileName is null

public List<Attachment> getLatestVersionsOfAttachments (ContentEntityObject ceo)

Retrieves the latest versions of all attachments to ceo

Parameters
ceo the content to look up attachments
Returns
  • a List of Attachment objects

public AttachmentDao.AttachmentMigrator getMigrator (AttachmentDao destinationDao)

Get a migrator object to migrate attachments between attachment datastores. To be used when switching datastore implementations

Parameters
destinationDao dao to move attachments to
Returns
  • A migrator

public void moveAttachment (Attachment attachment, Attachment oldAttachment, ContentEntityObject newContent)

Moves an Attachment to a new file name or content object

This method assumes that the filename and/or content of the attachment (and its previous versions) have already been updated.
Parameters
attachment the Attachment to be moved
oldAttachment the Attachment before it has been updated
newContent the new content attachment belongs to
Throws
IllegalArgumentException if attachment is not the latest version

public void prepareForMigrationTo ()

Prepare the data store for a migration from another type of data store.

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.
Throws
RuntimeException if there was a problem

public void removeAttachmentFromServer (Attachment attachment)

Removes attachment (and all of its versions)

Parameters
attachment the Attachment to be removed

public void replaceAttachmentData (Attachment attachment, InputStream attachmentData)

Sets the attachment data for attachment This method will overwrite any existing data for the attachment version.

Parameters
attachment Attachment the data belongs to
attachmentData the data to save

public void saveNewAttachment (Attachment attachment, InputStream attachmentData)

Saves a new attachment

Parameters
attachment the Attachment to be saved
attachmentData the attachment data to be saved

public void saveNewAttachmentVersion (Attachment attachment, Attachment previousVersion, InputStream attachmentData)

Saves a new version of attachment

Parameters
attachment the Attachment to be saved
previousVersion the previous version of the Attachment
attachmentData the attachment data to be saved