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));
}
Aggregations