Search in sources :

Example 1 with AddDocumentRevision

use of com.zimbra.cs.redolog.op.AddDocumentRevision in project zm-mailbox by Zimbra.

the class Mailbox method addDocumentRevision.

public Document addDocumentRevision(OperationContext octxt, int docId, ParsedDocument pd) throws IOException, ServiceException {
    StoreManager sm = StoreManager.getInstance();
    StagedBlob staged = sm.stage(pd.getBlob(), this);
    AddDocumentRevision redoRecorder = new AddDocumentRevision(mId, pd.getDigest(), pd.getSize(), 0);
    boolean success = false;
    try {
        beginTransaction("addDocumentRevision", octxt, redoRecorder);
        Document doc = getDocumentById(docId);
        redoRecorder.setDocument(pd);
        redoRecorder.setDocId(docId);
        redoRecorder.setItemType(doc.getType());
        // TODO: simplify the redoRecorder by not subclassing from CreateMessage
        // Get the redolog data from the mailbox blob.  This is less than ideal in the
        // HTTP store case because it will result in network access, and possibly an
        // extra write to local disk.  If this becomes a problem, we should update the
        // ParsedDocument constructor to take a DataSource instead of an InputStream.
        MailboxBlob mailboxBlob = doc.setContent(staged, pd);
        redoRecorder.setMessageBodyInfo(new MailboxBlobDataSource(mailboxBlob), mailboxBlob.getSize());
        index.add(doc);
        success = true;
        return doc;
    } catch (IOException ioe) {
        throw ServiceException.FAILURE("error writing document blob", ioe);
    } finally {
        endTransaction(success);
        sm.quietDelete(staged);
    }
}
Also used : StagedBlob(com.zimbra.cs.store.StagedBlob) MailboxBlob(com.zimbra.cs.store.MailboxBlob) MailboxBlobDataSource(com.zimbra.cs.store.MailboxBlobDataSource) AddDocumentRevision(com.zimbra.cs.redolog.op.AddDocumentRevision) IOException(java.io.IOException) ParsedDocument(com.zimbra.cs.mime.ParsedDocument) IndexDocument(com.zimbra.cs.index.IndexDocument) SaveDocument(com.zimbra.cs.redolog.op.SaveDocument) StoreManager(com.zimbra.cs.store.StoreManager)

Aggregations

IndexDocument (com.zimbra.cs.index.IndexDocument)1 ParsedDocument (com.zimbra.cs.mime.ParsedDocument)1 AddDocumentRevision (com.zimbra.cs.redolog.op.AddDocumentRevision)1 SaveDocument (com.zimbra.cs.redolog.op.SaveDocument)1 MailboxBlob (com.zimbra.cs.store.MailboxBlob)1 MailboxBlobDataSource (com.zimbra.cs.store.MailboxBlobDataSource)1 StagedBlob (com.zimbra.cs.store.StagedBlob)1 StoreManager (com.zimbra.cs.store.StoreManager)1 IOException (java.io.IOException)1