Search in sources :

Example 1 with TransactionRunnable

use of org.xwiki.store.TransactionRunnable in project xwiki-platform by xwiki.

the class FilesystemAttachmentStore method getAttachmentContentSaveRunnable.

/**
 * Get a TransactionRunnable for saving the attachment content. If {@link XWikiAttachment#getAttachment_content()}
 * yields null, this runnable will do nothing.
 *
 * @param attachment the XWikiAttachment whose content should be saved.
 * @param updateDocument whether or not to update the document at the same time.
 * @param context the XWikiContext for the request.
 * @return a TransactionRunnable for saving the attachment content in an XWikiHibernateTransaction.
 * @throws XWikiException if thrown by AttachmentSaveTransactionRunnable()
 */
private TransactionRunnable<XWikiHibernateTransaction> getAttachmentContentSaveRunnable(final XWikiAttachment attachment, final boolean updateDocument, final XWikiContext context) throws XWikiException {
    final XWikiAttachmentContent content = attachment.getAttachment_content();
    if (content == null) {
        // If content does not exist we should not blank the attachment.
        return new TransactionRunnable<>();
    }
    // This is the permanent location where the attachment content will go.
    final File attachFile = this.fileTools.getAttachmentFileProvider(attachment.getReference()).getAttachmentContentFile();
    return new AttachmentSaveTransactionRunnable(attachment, updateDocument, context, attachFile, this.fileTools.getTempFile(attachFile), this.fileTools.getBackupFile(attachFile), this.fileTools.getLockForFile(attachFile));
}
Also used : File(java.io.File) XWikiAttachmentContent(com.xpn.xwiki.doc.XWikiAttachmentContent) TransactionRunnable(org.xwiki.store.TransactionRunnable) FileDeleteTransactionRunnable(org.xwiki.store.FileDeleteTransactionRunnable) FileSaveTransactionRunnable(org.xwiki.store.FileSaveTransactionRunnable)

Aggregations

XWikiAttachmentContent (com.xpn.xwiki.doc.XWikiAttachmentContent)1 File (java.io.File)1 FileDeleteTransactionRunnable (org.xwiki.store.FileDeleteTransactionRunnable)1 FileSaveTransactionRunnable (org.xwiki.store.FileSaveTransactionRunnable)1 TransactionRunnable (org.xwiki.store.TransactionRunnable)1