com.atlassian.confluence.pages.persistence.dao.hibernate
Class AbstractHibernateAttachmentDao

java.lang.Object
  extended by org.springframework.dao.support.DaoSupport
      extended by org.springframework.orm.hibernate.support.HibernateDaoSupport
          extended by com.atlassian.hibernate.HibernateObjectDao
              extended by com.atlassian.confluence.core.persistence.hibernate.VersionedHibernateObjectDao<Attachment>
                  extended by com.atlassian.confluence.pages.persistence.dao.hibernate.AbstractHibernateAttachmentDao
All Implemented Interfaces:
ObjectDao, VersionedObjectDao, AttachmentDao, FlushableCachingDao, org.springframework.beans.factory.InitializingBean
Direct Known Subclasses:
NonTransactionalHibernateAttachmentDao, TransactionalHibernateAttachmentDao

public abstract class AbstractHibernateAttachmentDao
extends VersionedHibernateObjectDao<Attachment>
implements AttachmentDao, FlushableCachingDao

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.


Nested Class Summary
 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.
 
Nested classes/interfaces inherited from interface com.atlassian.confluence.pages.persistence.dao.AttachmentDao
AttachmentDao.AttachmentCopier, AttachmentDao.AttachmentMigrator
 
Field Summary
protected  AttachmentDataDao dataDao
           
 
Fields inherited from class com.atlassian.confluence.core.persistence.hibernate.VersionedHibernateObjectDao
cacheFactory
 
Fields inherited from class org.springframework.dao.support.DaoSupport
logger
 
Constructor Summary
AbstractHibernateAttachmentDao()
           
 
Method Summary
 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)
           
 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.
 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
protected  void removeAttachment(Attachment attachment, ContentEntityObject content)
          Severs the connection between attachment and content, and removes the attachment from the database
 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.
 
Methods inherited from class com.atlassian.confluence.core.persistence.hibernate.VersionedHibernateObjectDao
findAllSorted, findLatestVersionsCount, findLatestVersionsIterator, save, setCacheFactory, updateModificationData
 
Methods inherited from class com.atlassian.hibernate.HibernateObjectDao
findAll, findAllSorted, findNamedQuery, findNamedQuery, findNamedQuery, findNamedQueryStringParam, findNamedQueryStringParam, findNamedQueryStringParam, findNamedQueryStringParams, findNamedQueryStringParams, findNamedQueryStringParams, findNamedQueryStringParams, findNamedQueryStringParams, findNamedQueryStringParams, findNamedQueryStringParams, findNamedQueryStringParams, findNamedQueryStringParams, findNamedQueryStringParams, findSingleObject, getByClassId, getCountResult, index, refresh, reIndex, remove, replicate, save, saveRaw, setIndexer, unIndex
 
Methods inherited from class org.springframework.orm.hibernate.support.HibernateDaoSupport
checkDaoConfig, convertHibernateAccessException, createHibernateTemplate, getHibernateTemplate, getSession, getSession, getSessionFactory, releaseSession, setHibernateTemplate, setSessionFactory
 
Methods inherited from class org.springframework.dao.support.DaoSupport
afterPropertiesSet, initDao
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.atlassian.confluence.pages.persistence.dao.AttachmentDao
findAll, findLatestVersionsIterator, removeAttachmentFromServer
 
Methods inherited from interface bucket.core.persistence.ObjectDao
findAll, findAllSorted, refresh, remove, replicate, save, saveRaw
 

Field Detail

dataDao

protected AttachmentDataDao dataDao
Constructor Detail

AbstractHibernateAttachmentDao

public AbstractHibernateAttachmentDao()
Method Detail

getDataDao

public AttachmentDataDao getDataDao()

getInstance

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

getPersistentClass

public Class getPersistentClass()
Specified by:
getPersistentClass in interface ObjectDao

getLatestVersionsOfAttachments

public List<Attachment> getLatestVersionsOfAttachments(ContentEntityObject content)
Description copied from interface: AttachmentDao
Retrieves the latest versions of all attachments to ceo

Specified by:
getLatestVersionsOfAttachments in interface AttachmentDao
Parameters:
content - the content to look up attachments
Returns:
a List of Attachment objects
See Also:
AttachmentDao.countLatestVersionsOfAttachments(com.atlassian.confluence.core.ContentEntityObject)

countLatestVersionsOfAttachments

public int countLatestVersionsOfAttachments(ContentEntityObject content)
Specified by:
countLatestVersionsOfAttachments in interface AttachmentDao
Parameters:
content - the content object
Returns:
the number of current attachments on a content object
See Also:
AttachmentDao.getLatestVersionsOfAttachments(com.atlassian.confluence.core.ContentEntityObject)

getById

public Attachment getById(long id)
Description copied from interface: AttachmentDao
Returns the attachment with the given persistent ID. Returns null if no such attachment exists.

Specified by:
getById in interface AttachmentDao
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.

getAttachment

public Attachment getAttachment(ContentEntityObject content,
                                String fileName,
                                int version)
Description copied from interface: AttachmentDao
Return 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, use AttachmentDao.getLatestAttachment(ContentEntityObject, String).

Specified by:
getAttachment in interface AttachmentDao
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.

getLatestAttachment

public Attachment getLatestAttachment(ContentEntityObject content,
                                      String fileName)
Description copied from interface: AttachmentDao
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.

Specified by:
getLatestAttachment in interface AttachmentDao
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.

getLastAddedVersionsOf

public List<Attachment> getLastAddedVersionsOf(Attachment attachment)
Description copied from interface: AttachmentDao
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.

Specified by:
getLastAddedVersionsOf in interface AttachmentDao
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

public List<Attachment> findAllVersions(Attachment attachment)
Specified by:
findAllVersions in interface AttachmentDao

findAllVersions

public List<Attachment> findAllVersions(Long id)

getAttachmentData

public InputStream getAttachmentData(Attachment attachment)
                              throws AttachmentDataNotFoundException
Description copied from interface: AttachmentDao
Retrieves the InputStream representing the data for attachment

Specified by:
getAttachmentData in interface AttachmentDao
Parameters:
attachment - the attachment whose data will be returned
Returns:
InputStream of the data
Throws:
AttachmentDataNotFoundException - if the data could not be found

saveNewAttachment

public void saveNewAttachment(Attachment attachment,
                              InputStream attachmentData)
Description copied from interface: AttachmentDao
Saves a new attachment

Specified by:
saveNewAttachment in interface AttachmentDao
Parameters:
attachment - the Attachment to be saved
attachmentData - 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:
saveNewAttachmentVersion in interface AttachmentDao
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

moveAttachment

public void moveAttachment(Attachment latestVersion,
                           Attachment oldAttachment,
                           ContentEntityObject newContent)
Description copied from interface: AttachmentDao
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.

Specified by:
moveAttachment in interface AttachmentDao
Parameters:
latestVersion - the Attachment to be moved
oldAttachment - the Attachment before it has been updated
newContent - the new content attachment belongs to

removeAttachment

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

getMigrator

public AttachmentDao.AttachmentMigrator getMigrator(AttachmentDao destinationDao)
Description copied from interface: AttachmentDao
Get a migrator object to migrate attachments between attachment datastores. To be used when switching datastore implementations

Specified by:
getMigrator in interface AttachmentDao
Parameters:
destinationDao - dao to move attachments to
Returns:
A migrator

getCopier

public AttachmentDao.AttachmentCopier getCopier(AttachmentDao destinationDao)
Description copied from interface: AttachmentDao
Get a copier object to copy attachments between data stores The source data store will remain untouched

Specified by:
getCopier in interface AttachmentDao
Parameters:
destinationDao - dao to copy attachments to
Returns:
A copier

prepareForMigrationTo

public void prepareForMigrationTo()
This implementation removes the contents of the table and passes the migration tasks onto the AttachmentDataDao

Specified by:
prepareForMigrationTo in interface AttachmentDao

afterMigrationFrom

public void afterMigrationFrom()
This implementation removes all Attachments and passes the migration tasks onto the AttachmentDataDao

Specified by:
afterMigrationFrom in interface AttachmentDao

replaceAttachmentData

public void replaceAttachmentData(Attachment attachment,
                                  InputStream attachmentData)
Description copied from interface: AttachmentDao
Sets the attachment data for attachment This method will overwrite any existing data for the attachment version.

Specified by:
replaceAttachmentData in interface AttachmentDao
Parameters:
attachment - Attachment the data belongs to
attachmentData - the data to save

flush

public void flush()
This implementation flushes the Hibernate session.

Specified by:
flush in interface FlushableCachingDao
Throws:
RuntimeException - if there was a problem flushing

findLatestVersionIdsIterator

public Iterator<Long> findLatestVersionIdsIterator()

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:
an iterator over the ids of the latest versions of attachments in the requested spaces


Copyright © 2003-2012 Atlassian. All Rights Reserved.