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

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.pages.persistence.dao.hibernate.HibernateAttachmentDataDao
All Implemented Interfaces:
ObjectDao, AttachmentDataDao, TransactionalAttachmentDataDao, org.springframework.beans.factory.InitializingBean

public class HibernateAttachmentDataDao
extends HibernateObjectDao
implements TransactionalAttachmentDataDao

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.


Field Summary
 
Fields inherited from class org.springframework.dao.support.DaoSupport
logger
 
Constructor Summary
HibernateAttachmentDataDao()
           
 
Method Summary
 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.
 java.util.List findAll()
          Find all objects of the class provided by getPersistentClass()
 java.util.List findAllSorted(java.lang.String s)
          Find all objects currently persisted of a particular type and sort results by named property.
protected  AttachmentData getAttachmentDataForAttachment(Attachment attachment)
          Retrieves the attachment data object for a given attachment.
 java.io.InputStream getDataForAttachment(Attachment attachment)
          Grabs the AttachmentData object for an Attachment
 AttachmentDataStream getDataForAttachment(Attachment attachment, AttachmentDataStreamType dataStreamType)
          Grabs the AttachmentData object for an Attachment
 java.lang.Class getPersistentClass()
           
 AttachmentDataStorageType getStorageType()
          Returns the storage type.
 boolean isAttachmentPresent(Attachment attachment)
          Check that an attachment exists
 void moveAttachment(Attachment attachment, Attachment oldAttachment, ContentEntityObject newContent)
          Moves an attachment to a new file name or content object
 void moveDataForAttachmentVersion(Attachment sourceAttachmentVersion, Attachment targetAttachmentVersion)
          Moves the attachment data from one AbstractVersionedEntityObject.getVersion() to the other.
 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 removeDataForAttachmentVersion(Attachment attachment, ContentEntityObject originalContent)
          Removes the attachment data for the given attachment version.
 void replaceDataForAttachment(Attachment attachment, AttachmentDataStream dataStream)
          Sets the data for attachment This method will overwrite any existing data for the attachment.
 void replaceDataForAttachment(Attachment attachment, java.io.InputStream data)
          Sets the data for attachment This method will overwrite any existing data for the attachment.
 void save(com.atlassian.core.bean.EntityObject objectToSave)
          Save an object.
 void saveDataForAttachment(Attachment attachment, AttachmentDataStream dataStream)
          Saves data to the attachment data store
 void saveDataForAttachment(Attachment attachment, java.io.InputStream data)
          Saves data to the attachment data store
 void saveDataForAttachmentVersion(Attachment attachment, Attachment previousVersion, AttachmentDataStream dataStream)
          Saves data to the attachment data store, for an attachment that has been updated.
 void saveDataForAttachmentVersion(Attachment attachment, Attachment previousVersion, java.io.InputStream data)
          Saves data to the attachment data store, for an attachment that has been updated.
 
Methods inherited from class com.atlassian.hibernate.HibernateObjectDao
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, saveRaw, setIndexer, unIndex, uniqueResult, updateModificationData
 
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
 

Constructor Detail

HibernateAttachmentDataDao

public HibernateAttachmentDataDao()
Method Detail

findAll

public java.util.List findAll()
Description copied from class: HibernateObjectDao
Find all objects of the class provided by getPersistentClass()

Specified by:
findAll in interface ObjectDao
Overrides:
findAll in class HibernateObjectDao
Returns:
a list of all objects of the appropriate class, or the empty list if no objects are found

findAllSorted

public java.util.List findAllSorted(java.lang.String s)
Description copied from interface: ObjectDao
Find all objects currently persisted of a particular type and sort results by named property.

Specified by:
findAllSorted in interface ObjectDao
Overrides:
findAllSorted in class HibernateObjectDao
Parameters:
s - the name of the property to be sorted on. This should be null if no sorting is required.

save

public void save(com.atlassian.core.bean.EntityObject objectToSave)
Description copied from class: HibernateObjectDao
Save an object. The object's last-modified time will be updated, and if the object is searchable it will be indexed.

Specified by:
save in interface ObjectDao
Overrides:
save in class HibernateObjectDao

getPersistentClass

public java.lang.Class getPersistentClass()
Specified by:
getPersistentClass in interface ObjectDao

getAttachmentDataForAttachment

protected AttachmentData getAttachmentDataForAttachment(Attachment attachment)
                                                 throws AttachmentDataNotFoundException
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
org.springframework.dao.IncorrectResultSizeDataAccessException - if the database contains more than one data object associated with the given attachment

getDataForAttachment

public java.io.InputStream getDataForAttachment(Attachment attachment)
                                         throws AttachmentDataNotFoundException
Description copied from interface: AttachmentDataDao
Grabs the AttachmentData object for an Attachment

Specified by:
getDataForAttachment in interface AttachmentDataDao
Parameters:
attachment - the Attachment representing the data
Returns:
an AttachmentData object
Throws:
AttachmentDataNotFoundException - if no data was found

removeDataForAttachment

public void removeDataForAttachment(Attachment attachment,
                                    ContentEntityObject originalContent)
Description copied from interface: AttachmentDataDao
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.

Specified by:
removeDataForAttachment in interface AttachmentDataDao
Parameters:
attachment - the latest version of the attachment for which the data should be removed
originalContent - the content the attachment belongs to

removeDataForAttachmentVersion

public void removeDataForAttachmentVersion(Attachment attachment,
                                           ContentEntityObject originalContent)
Description copied from interface: AttachmentDataDao
Removes the attachment data for the given attachment version.

Specified by:
removeDataForAttachmentVersion in interface AttachmentDataDao
Parameters:
attachment - the version of the attachment for which the data should be removed
originalContent - the content the attachment belongs to

moveDataForAttachmentVersion

public void moveDataForAttachmentVersion(Attachment sourceAttachmentVersion,
                                         Attachment targetAttachmentVersion)
Description copied from interface: AttachmentDataDao
Moves the attachment data from one AbstractVersionedEntityObject.getVersion() to the other.

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

Specified by:
moveDataForAttachmentVersion in interface AttachmentDataDao
Parameters:
sourceAttachmentVersion - the attachment
See Also:
AttachmentDataDao.moveAttachment(Attachment, Attachment, ContentEntityObject)

saveDataForAttachment

public void saveDataForAttachment(Attachment attachment,
                                  java.io.InputStream data)
Description copied from interface: AttachmentDataDao
Saves data to the attachment data store

Specified by:
saveDataForAttachment in interface AttachmentDataDao
Parameters:
attachment - the Attachment the data belongs to
data - the InputStream to be written

saveDataForAttachmentVersion

public void saveDataForAttachmentVersion(Attachment attachment,
                                         Attachment previousVersion,
                                         java.io.InputStream data)
Description copied from interface: AttachmentDataDao
Saves data to the attachment data store, for an attachment that has been updated.

This method assumes that the attachment has already been saved.

Specified by:
saveDataForAttachmentVersion in interface AttachmentDataDao
Parameters:
attachment - the new version of the attachment
previousVersion - the previous version of the attachment
data - the InputStream representing the data

replaceDataForAttachment

public void replaceDataForAttachment(Attachment attachment,
                                     java.io.InputStream data)
Description copied from interface: AttachmentDataDao
Sets the data for attachment This method will overwrite any existing data for the attachment.

Specified by:
replaceDataForAttachment in interface AttachmentDataDao
Parameters:
attachment - Attachment the data belongs to
data - the data to be saved

isAttachmentPresent

public boolean isAttachmentPresent(Attachment attachment)
Description copied from interface: AttachmentDataDao
Check that an attachment exists

Specified by:
isAttachmentPresent in interface AttachmentDataDao
Parameters:
attachment - the Attachment to be checked

moveAttachment

public void moveAttachment(Attachment attachment,
                           Attachment oldAttachment,
                           ContentEntityObject newContent)
Description copied from interface: AttachmentDataDao
Moves an attachment to a new file name or content object

Specified by:
moveAttachment in interface AttachmentDataDao
Parameters:
attachment - the Attachment to be moved
oldAttachment - the original version of the attachment
newContent - the new content the Attachment belongs to

prepareForMigrationTo

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.

Specified by:
prepareForMigrationTo in interface AttachmentDataDao

afterMigrationFrom

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.

Specified by:
afterMigrationFrom in interface AttachmentDataDao

getStorageType

public AttachmentDataStorageType getStorageType()
Description copied from interface: AttachmentDataDao
Returns the storage type.

The client code should be storage agnostic in general. Thus this method should only be used in rare cases in order to hide operations which are known to be not implemented for the specific type.

Specified by:
getStorageType in interface AttachmentDataDao
Returns:
the storage type

getDataForAttachment

public AttachmentDataStream getDataForAttachment(Attachment attachment,
                                                 AttachmentDataStreamType dataStreamType)
                                          throws AttachmentDataNotFoundException
Description copied from interface: AttachmentDataDao
Grabs the AttachmentData object for an Attachment

Specified by:
getDataForAttachment in interface AttachmentDataDao
Parameters:
attachment - the Attachment representing the data
Returns:
an AttachmentData object
Throws:
AttachmentDataNotFoundException - if no data was found

saveDataForAttachment

public void saveDataForAttachment(Attachment attachment,
                                  AttachmentDataStream dataStream)
Description copied from interface: AttachmentDataDao
Saves data to the attachment data store

Specified by:
saveDataForAttachment in interface AttachmentDataDao
Parameters:
attachment - the Attachment the data belongs to
dataStream - the data stream to be written

saveDataForAttachmentVersion

public void saveDataForAttachmentVersion(Attachment attachment,
                                         Attachment previousVersion,
                                         AttachmentDataStream dataStream)
Description copied from interface: AttachmentDataDao
Saves data to the attachment data store, for an attachment that has been updated.

This method assumes that the attachment has already been saved.

Specified by:
saveDataForAttachmentVersion in interface AttachmentDataDao
Parameters:
attachment - the new version of the attachment
previousVersion - the previous version of the attachment
dataStream - the InputStream representing the data

replaceDataForAttachment

public void replaceDataForAttachment(Attachment attachment,
                                     AttachmentDataStream dataStream)
Description copied from interface: AttachmentDataDao
Sets the data for attachment This method will overwrite any existing data for the attachment.

Specified by:
replaceDataForAttachment in interface AttachmentDataDao
Parameters:
attachment - Attachment the data belongs to
dataStream - the data to be saved


Copyright © 2003-2014 Atlassian. All Rights Reserved.