public class

HibernateAttachmentDataDao

extends HibernateObjectDao
implements TransactionalAttachmentDataDao
java.lang.Object
   ↳ org.springframework.dao.support.DaoSupport
     ↳ org.springframework.orm.hibernate.support.HibernateDaoSupport
       ↳ com.atlassian.hibernate.HibernateObjectDao
         ↳ com.atlassian.confluence.pages.persistence.dao.hibernate.HibernateAttachmentDataDao

Class Overview

This class defines an AttachmentDataDao that stores Attachment data in a Hibernate-managed database.

As a result, it is transactional (can be rolled back), so it implements the TransactionalAttachmentDataDao interface.

Summary

[Expand]
Inherited Fields
From class com.atlassian.hibernate.HibernateObjectDao
From class org.springframework.dao.support.DaoSupport
Public Constructors
HibernateAttachmentDataDao()
Public Methods
void afterMigrationFrom()
Once a data migration has occurred, remove all records from the table, as they are no longer necessary, and we don't want foreign key violations to occur when removing Attachments.
List findAll()
Find all objects of the class provided by getPersistentClass()
List findAllSorted(String s)
Find all objects currently persisted of a particular type and sort results by named property.
InputStream getDataForAttachment(Attachment attachment)
Grabs the AttachmentData object for an Attachment
Class getPersistentClass()
void moveAttachment(Attachment attachment, Attachment oldAttachment, ContentEntityObject newContent)
Moves an attachment to a new file name or content object
void prepareForMigrationTo()
This implementation clears out the Attachment data table, so we have a clean base for migration.
void removeDataForAttachment(Attachment attachment, ContentEntityObject originalContent)
Removes all attachment data for the given attachment.
void replaceDataForAttachment(Attachment attachment, InputStream data)
Sets the data for attachment This method will overwrite any existing data for the attachment.
void save(EntityObject objectToSave)
Save an object.
void saveDataForAttachment(Attachment attachment, InputStream data)
Saves data to the attachment data store
void saveDataForAttachmentVersion(Attachment attachment, Attachment previousVersion, InputStream data)
Saves data to the attachment data store, for an attachment that has been updated.
Protected Methods
AttachmentData getAttachmentDataForAttachment(Attachment attachment)
Retrieves the attachment data object for a given attachment.
[Expand]
Inherited Methods
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.pages.persistence.dao.AttachmentDataDao
From interface org.springframework.beans.factory.InitializingBean

Public Constructors

public HibernateAttachmentDataDao ()

Public Methods

public void afterMigrationFrom ()

Once a data migration has occurred, remove all records from the table, as they are no longer necessary, and we don't want foreign key violations to occur when removing Attachments. It circumvents hibernate, so should only be called when nobody else can see the data.

public List findAll ()

Find all objects of the class provided by getPersistentClass()

Returns
  • a list of all objects of the appropriate class, or the empty list if no objects are found

public List findAllSorted (String s)

Find all objects currently persisted of a particular type and sort results by named property.

Parameters
s the name of the property to be sorted on. This should be null if no sorting is required.

public InputStream getDataForAttachment (Attachment attachment)

Grabs the AttachmentData object for an Attachment

Parameters
attachment the Attachment representing the data
Returns
  • an AttachmentData object

public Class getPersistentClass ()

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

Moves an attachment to a new file name or content object

Parameters
attachment the Attachment to be moved
oldAttachment the original version of the attachment
newContent the new content the Attachment belongs to

public void prepareForMigrationTo ()

This implementation clears out the Attachment data table, so we have a clean base for migration. It circumvents hibernate, so should only be called when nobody else can see the attachment data.

public void removeDataForAttachment (Attachment attachment, ContentEntityObject originalContent)

Removes all attachment data for the given attachment. Since Confluence 4.2 the contract of this method has been clarified. It now removes all versions of the given attachment.

Parameters
attachment The latest version of the attachment for which data should be removed
originalContent The content the attachment belongs to

public void replaceDataForAttachment (Attachment attachment, InputStream data)

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

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

public void save (EntityObject objectToSave)

Save an object. The object's last-modified time will be updated, and if the object is searchable it will be indexed.

public void saveDataForAttachment (Attachment attachment, InputStream data)

Saves data to the attachment data store

Parameters
attachment the Attachment the data belongs to
data the InputStream to be written

public void saveDataForAttachmentVersion (Attachment attachment, Attachment previousVersion, InputStream data)

Saves data to the attachment data store, for an attachment that has been updated.

This method assumes that the attachment has already been saved.
Parameters
attachment the new version of the attachment
previousVersion the previous version of the attachment
data the InputStream representing the data

Protected Methods

protected AttachmentData getAttachmentDataForAttachment (Attachment attachment)

Retrieves the attachment data object for a given attachment.

Parameters
attachment the attachment to retrieve data for
Returns
  • attachment data for the provided attachment
Throws
AttachmentDataNotFoundException if the attachment data is not found
IncorrectResultSizeDataAccessException if the database contains more than one data object associated with the given attachment