/** * {@inheritDoc} */ public XWikiAttachmentArchive loadArchive(XWikiAttachment attachment, XWikiContext context, boolean transaction) throws XWikiException { XWikiAttachmentArchive archive = attachment.getAttachment_archive(); if (!(archive instanceof VoidAttachmentArchive)) { archive = new VoidAttachmentArchive(attachment); } attachment.setAttachment_archive(archive); return archive; }
@Override public boolean discardEntity(XWikiAttachment entity) { boolean transaction = false; try { transaction = ((XWikiHibernateBaseStore) this.store).beginTransaction(this.context.get()); Session session = ((XWikiHibernateBaseStore) this.store).getSession(this.context.get()); session.delete(entity.getAttachment_content()); session.delete(entity.getAttachment_archive()); this.logger.debug("Deleted attachment [{}] from the database", entity.getReference()); } catch (XWikiException ex) { this.logger.warn("Failed to cleanup attachment from the database: {}", ex.getMessage()); return false; } finally { if (transaction) { ((XWikiHibernateBaseStore) this.store).endTransaction(this.context.get(), transaction); } } return true; }
@Override public boolean discardEntity(XWikiAttachment entity) { boolean transaction = false; try { transaction = ((XWikiHibernateBaseStore) this.store).beginTransaction(this.context.get()); Session session = ((XWikiHibernateBaseStore) this.store).getSession(this.context.get()); session.delete(entity.getAttachment_content()); session.delete(entity.getAttachment_archive()); this.logger.debug("Deleted attachment [{}] from the database", entity.getReference()); } catch (XWikiException ex) { this.logger.warn("Failed to cleanup attachment from the database: {}", ex.getMessage()); return false; } finally { if (transaction) { ((XWikiHibernateBaseStore) this.store).endTransaction(this.context.get(), transaction); } } return true; }
public synchronized Version[] getVersions() { try { return getAttachment_archive().getVersions(); } catch (Exception ex) { LOG.warn(String.format("Cannot retrieve versions of attachment [%s@%s]: %s", getFilename(), getDoc() .getFullName(), ex.getMessage())); return new Version[] {new Version(this.getVersion())}; } }
/** * Clone an attachment but not it's archive.{@link ListAttachmentArchive#clone()} calls {@link * XWikiAttachment#clone()} and if the attachment is associated with an archive it call clone the archive. This * function prevents an infinite loop. * * @param original an attachment to clone. * @return a clone of original which has no XWikiAttachmentArchive attached. */ private static XWikiAttachment cloneAttachment(final XWikiAttachment original) { final XWikiAttachmentArchive arch = original.getAttachment_archive(); try { original.setAttachment_archive(null); return (XWikiAttachment) original.clone(); } finally { original.setAttachment_archive(arch); } }
/** * Clone an attachment but not it's archive.{@link ListAttachmentArchive#clone()} calls {@link * XWikiAttachment#clone()} and if the attachment is associated with an archive it call clone the archive. This * function prevents an infinite loop. * * @param original an attachment to clone. * @return a clone of original which has no XWikiAttachmentArchive attached. */ private static XWikiAttachment cloneAttachment(final XWikiAttachment original) { final XWikiAttachmentArchive arch = original.getAttachment_archive(); try { original.setAttachment_archive(null); return (XWikiAttachment) original.clone(); } finally { original.setAttachment_archive(arch); } }
@Override public XWikiAttachment restoreAttachment(final XWikiAttachment attachment, final XWikiContext context) throws XWikiException { XWikiAttachment result = attachment; if (result != null) { // TODO Add XWikiAttachment#clone(XWikiAttachment) // this toXML does not copy content. result.fromXML(this.attachment.toXML(context)); if (this.attachment.getAttachment_content() != null) { attachment.setAttachment_content((XWikiAttachmentContent) this.attachment.getAttachment_content() .clone()); attachment.getAttachment_content().setAttachment(attachment); } if (this.attachment.getAttachment_archive() != null) { result.setAttachment_archive((XWikiAttachmentArchive) this.attachment.getAttachment_archive().clone()); result.getAttachment_archive().setAttachment(result); } } else { result = (XWikiAttachment) this.attachment.clone(); } result.setDoc(context.getWiki().getDocument(this.attachment.getReference().getDocumentReference(), context)); return result; }
attachment.getAttachment_content().setAttachment(attachment); if (getAttachment_archive() != null) { attachment.setAttachment_archive((XWikiAttachmentArchive) getAttachment_archive().clone()); attachment.getAttachment_archive().setAttachment(attachment);
restoredAttachmentRevision.setAttachment_archive(restoredAttachment.getAttachment_archive()); restoredAttachmentRevision.getAttachment_archive().setAttachment(restoredAttachmentRevision); restoredAttachmentRevision.setVersion(restoredAttachment.getVersion()); restoredAttachmentRevision.setMetaDataDirty(true);
if (attachment.getAttachment_archive() == null) { attachment.loadArchive(context); context.getWiki().getAttachmentVersioningStore().saveArchive(attachment.getAttachment_archive(), context, false);
final XWikiAttachmentArchive archive = attachment.getAttachment_archive(); if (avs instanceof FilesystemAttachmentVersioningStore) { final FilesystemAttachmentVersioningStore favs = (FilesystemAttachmentVersioningStore) avs;
final XWikiAttachmentArchive archive = attachment.getAttachment_archive(); if (avs instanceof FilesystemAttachmentVersioningStore) { final FilesystemAttachmentVersioningStore favs = (FilesystemAttachmentVersioningStore) avs;