public abstract class

AbstractHibernateAttachmentDao

extends VersionedHibernateObjectDao<T extends EntityObject>
implements AttachmentDao FlushableCachingDao
java.lang.Object
   ↳ org.springframework.dao.support.DaoSupport
     ↳ org.springframework.orm.hibernate.support.HibernateDaoSupport
       ↳ com.atlassian.hibernate.HibernateObjectDao
         ↳ com.atlassian.confluence.core.persistence.hibernate.VersionedHibernateObjectDao<T extends com.atlassian.core.bean.EntityObject>
           ↳ com.atlassian.confluence.pages.persistence.dao.hibernate.AbstractHibernateAttachmentDao
Known Direct Subclasses

Class Overview

Abstract class that defines the basic methods necessary for saving Attachments to a database.

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.

Summary

Nested Classes
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. 
Fields
protected AttachmentDataDao dataDao
[Expand]
Inherited Fields
From class com.atlassian.confluence.core.persistence.hibernate.VersionedHibernateObjectDao
From class com.atlassian.hibernate.HibernateObjectDao
From class org.springframework.dao.support.DaoSupport
Public Constructors
AbstractHibernateAttachmentDao()
Public Methods
void afterMigrationFrom()
This implementation removes all Attachments and passes the migration tasks onto the AttachmentDataDao
int countLatestVersionsOfAttachments(ContentEntityObject content)
List<Attachment> findAllVersions(Attachment attachment)
List<Attachment> findAllVersions(Long id)
List<Long> findLatestVersionIds(List<Space> spacesToInclude)
Same as findLatestVersionIdsIterator() but only gets the ids matching the list of spaces requested.
List<Long> findLatestVersionIds()
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
Attachment getById(long id)
Returns the attachment with the given persistent ID.
List<Attachment> getByIds(List<Long> ids)
AttachmentDao.AttachmentCopier getCopier(AttachmentDao destinationDao)
Get a copier object to copy attachments between data stores The source data store will remain untouched
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
AttachmentDao.AttachmentMigrator getMigrator(AttachmentDao destinationDao)
Get a migrator object to migrate attachments between attachment datastores.
Class getPersistentClass()
void moveAttachment(Attachment latestVersion, 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()
This implementation removes the contents of the table and passes the migration tasks onto the AttachmentDataDao
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)
This implementation saves the Attachment and its previous version to the VersionedHibernateObjectDao.
Protected Methods
void removeAllAttachmentVersions(Attachment latestVersion, ContentEntityObject content)
void removeAttachment(Attachment attachment, ContentEntityObject content)
Severs the connection between attachment and content, and removes the attachment from the database
[Expand]
Inherited Methods
From class com.atlassian.confluence.core.persistence.hibernate.VersionedHibernateObjectDao
From class com.atlassian.hibernate.HibernateObjectDao
From class org.springframework.orm.hibernate.support.HibernateDaoSupport
From class org.springframework.dao.support.DaoSupport
From class java.lang.Object
From interface bucket.core.persistence.ObjectDao
From interface com.atlassian.confluence.core.persistence.VersionedObjectDao
From interface com.atlassian.confluence.pages.persistence.dao.AttachmentDao
From interface com.atlassian.confluence.pages.persistence.dao.FlushableCachingDao
From interface org.springframework.beans.factory.InitializingBean

Fields

protected AttachmentDataDao dataDao

Public Constructors

public AbstractHibernateAttachmentDao ()

Public Methods

public void afterMigrationFrom ()

This implementation removes all Attachments and passes the migration tasks onto the AttachmentDataDao

public int countLatestVersionsOfAttachments (ContentEntityObject content)

public List<Attachment> findAllVersions (Attachment attachment)

public List<Attachment> findAllVersions (Long id)

public List<Long> findLatestVersionIds (List<Space> spacesToInclude)

Same as findLatestVersionIdsIterator() 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

public List<Long> findLatestVersionIds ()

public Iterator<Long> findLatestVersionIdsIterator ()

public Iterator<Long> findLatestVersionIdsIterator (List<Space> spacesToInclude)

Same as findLatestVersionIdsIterator() 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

public void flush ()

This implementation flushes the Hibernate session.

Throws
RuntimeException if there was a problem flushing

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.

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

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 List<Attachment> getByIds (List<Long> ids)

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 AttachmentDataDao getDataDao ()

public static AttachmentDao getInstance (AttachmentDataDao attachmentDataDao)

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

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

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.

public List<Attachment> getLatestVersionsOfAttachments (ContentEntityObject content)

Retrieves the latest versions of all attachments to ceo

Parameters
content 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 Class getPersistentClass ()

public void moveAttachment (Attachment latestVersion, 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
latestVersion the Attachment to be moved
oldAttachment the Attachment before it has been updated
newContent the new content attachment belongs to

public void prepareForMigrationTo ()

This implementation removes the contents of the table and passes the migration tasks onto the AttachmentDataDao

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)

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.
Parameters
attachment the attachment to be saved, a clone of the old one
previousVersion the old attachment, which must be unmodified
attachmentData the new attachment data

Protected Methods

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

Parameters
attachment the attachment to remove
content the content to remove the attachment from