@Test public void saveTwoOfSameAttachmentInOneTransactionTest() throws Exception { final File storeFile = this.fileTools.getAttachmentFileProvider(this.mockAttachReference).getAttachmentContentFile(); Assert.assertFalse(this.storeFile.exists()); getMockery().checking(new Expectations() { { oneOf(mockAttachVersionStore).saveArchive(mockArchive, mockContext, false); oneOf(mockAttachVersionStore).saveArchive(mockArchive, mockContext, false); } }); final List<XWikiAttachment> attachments = new ArrayList<XWikiAttachment>(); attachments.add(this.mockAttach); attachments.add(this.mockAttach); this.attachStore.saveAttachmentsContent(attachments, this.doc, false, this.mockContext, false); Assert.assertTrue("The attachment file was not created.", this.storeFile.exists()); Assert.assertEquals("The attachment file contained the wrong content", HELLO, FileUtils.readFileToString(storeFile, StandardCharsets.UTF_8)); }
@Override public void saveAttachmentsContent(final List<XWikiAttachment> attachments, final XWikiDocument doc, final boolean updateDocument, final XWikiContext context, final boolean bTransaction) throws XWikiException { if (attachments == null || attachments.isEmpty()) { return; } try { final XWikiHibernateTransaction transaction = new XWikiHibernateTransaction(context); for (XWikiAttachment attach : attachments) { this.getAttachmentContentSaveRunnable(attach, false, context).runIn(transaction); } if (updateDocument) { new TransactionRunnable<XWikiHibernateTransaction>() { @Override protected void onRun() throws Exception { context.getWiki().getStore().saveXWikiDoc(doc, context, false); } }.runIn(transaction); } transaction.start(); } catch (XWikiException e) { throw e; } catch (Exception e) { throw new XWikiException(XWikiException.MODULE_XWIKI_STORE, XWikiException.ERROR_XWIKI_STORE_HIBERNATE_SAVING_ATTACHMENT, "Exception while saving attachments", e); } }
FilesystemAttachmentStore implements XWikiAttachmentStoreInterface { @Override public void saveAttachmentsContent(final List<XWikiAttachment> attachments, final XWikiDocument doc, final boolean updateDocument, final XWikiContext context, final boolean bTransaction) throws XWikiException { if (attachments == null || attachments.isEmpty()) { return; } try { final XWikiHibernateTransaction transaction = new XWikiHibernateTransaction(context); for (XWikiAttachment attach : attachments) { this.getAttachmentContentSaveRunnable(attach, false, context).runIn(transaction); } if (updateDocument) { new TransactionRunnable<XWikiHibernateTransaction>() { @Override protected void onRun() throws Exception { context.getWiki().getStore().saveXWikiDoc(doc, context, false); } }.runIn(transaction); } transaction.start(); } catch (XWikiException e) { throw e; } catch (Exception e) { throw new XWikiException(XWikiException.MODULE_XWIKI_STORE, XWikiException.ERROR_XWIKI_STORE_HIBERNATE_SAVING_ATTACHMENT, "Exception while saving attachments", e); } } }
FilesystemAttachmentStore implements XWikiAttachmentStoreInterface { @Override public void saveAttachmentsContent(final List<XWikiAttachment> attachments, final XWikiDocument doc, final boolean updateDocument, final XWikiContext context, final boolean bTransaction) throws XWikiException { if (attachments == null || attachments.isEmpty()) { return; } try { final XWikiHibernateTransaction transaction = new XWikiHibernateTransaction(context); for (XWikiAttachment attach : attachments) { this.getAttachmentContentSaveRunnable(attach, false, context).runIn(transaction); } if (updateDocument) { new TransactionRunnable<XWikiHibernateTransaction>() { @Override protected void onRun() throws Exception { context.getWiki().getStore().saveXWikiDoc(doc, context, false); } }.runIn(transaction); } transaction.start(); } catch (XWikiException e) { throw e; } catch (Exception e) { throw new XWikiException(XWikiException.MODULE_XWIKI_STORE, XWikiException.ERROR_XWIKI_STORE_HIBERNATE_SAVING_ATTACHMENT, "Exception while saving attachments", e); } }  }
FilesystemAttachmentStore implements XWikiAttachmentStoreInterface { @Override public void saveAttachmentsContent(final List<XWikiAttachment> attachments, final XWikiDocument doc, final boolean updateDocument, final XWikiContext context, final boolean bTransaction) throws XWikiException { if (attachments == null || attachments.isEmpty()) { return; } try { final XWikiHibernateTransaction transaction = new XWikiHibernateTransaction(context); for (XWikiAttachment attach : attachments) { this.getAttachmentContentSaveRunnable(attach, false, context).runIn(transaction); } if (updateDocument) { new TransactionRunnable<XWikiHibernateTransaction>() { @Override protected void onRun() throws Exception { context.getWiki().getStore().saveXWikiDoc(doc, context, false); } }.runIn(transaction); } transaction.start(); } catch (XWikiException e) { throw e; } catch (Exception e) { throw new XWikiException(XWikiException.MODULE_XWIKI_STORE, XWikiException.ERROR_XWIKI_STORE_HIBERNATE_SAVING_ATTACHMENT, "Exception while saving attachments", e); } }  @Override String getHint(); @Override void saveAttachmentContent(final XWikiAttachment attachment, final XWikiContext context,
        final boolean bTransaction); @Override void saveAttachmentContent(final XWikiAttachment attachment, final boolean updateDocument,
        final XWikiContext context, final boolean bTransaction); @Override void saveAttachmentsContent(final List<XWikiAttachment> attachments, final XWikiDocument doc,
        final boolean updateDocument, final XWikiContext context, final boolean bTransaction); @Override void loadAttachmentContent(final XWikiAttachment attachment, final XWikiContext context,
        final boolean bTransaction); @Override void deleteXWikiAttachment(final XWikiAttachment attachment, final XWikiContext context,
        final boolean bTransaction); @Override void deleteXWikiAttachment(final XWikiAttachment attachment, final boolean parentUpdate,
        final XWikiContext context, final boolean bTransaction); @Override void cleanUp(XWikiContext context); }
FilesystemAttachmentStore implements XWikiAttachmentStoreInterface { @Override public void saveAttachmentsContent(final List<XWikiAttachment> attachments, final XWikiDocument doc, final boolean updateDocument, final XWikiContext context, final boolean bTransaction) throws XWikiException { if (attachments == null || attachments.isEmpty()) { return; } try { final XWikiHibernateTransaction transaction = new XWikiHibernateTransaction(context); for (XWikiAttachment attach : attachments) { this.getAttachmentContentSaveRunnable(attach, false, context).runIn(transaction); } if (updateDocument) { new TransactionRunnable<XWikiHibernateTransaction>() { @Override protected void onRun() throws Exception { context.getWiki().getStore().saveXWikiDoc(doc, context, false); } }.runIn(transaction); } transaction.start(); } catch (XWikiException e) { throw e; } catch (Exception e) { throw new XWikiException(XWikiException.MODULE_XWIKI_STORE, XWikiException.ERROR_XWIKI_STORE_HIBERNATE_SAVING_ATTACHMENT, "Exception while saving attachments", e); } }  @Override String getHint(); @Override void saveAttachmentContent(final XWikiAttachment attachment, final XWikiContext context,
        final boolean bTransaction); @Override void saveAttachmentContent(final XWikiAttachment attachment, final boolean updateDocument,
        final XWikiContext context, final boolean bTransaction); @Override void saveAttachmentsContent(final List<XWikiAttachment> attachments, final XWikiDocument doc,
        final boolean updateDocument, final XWikiContext context, final boolean bTransaction); @Override void loadAttachmentContent(final XWikiAttachment attachment, final XWikiContext context,
        final boolean bTransaction); @Override void deleteXWikiAttachment(final XWikiAttachment attachment, final XWikiContext context,
        final boolean bTransaction); @Override void deleteXWikiAttachment(final XWikiAttachment attachment, final boolean parentUpdate,
        final XWikiContext context, final boolean bTransaction); @Override void cleanUp(XWikiContext context);  }