Search in sources :

Example 6 with BlobStore

use of org.exist.storage.blob.BlobStore in project exist by eXist-db.

the class NativeBroker method removeCollectionBinary.

private void removeCollectionBinary(final Txn transaction, final BinaryDocument doc) throws IOException {
    final BlobStore blobStore = pool.getBlobStore();
    blobStore.remove(transaction, doc.getBlobId());
}
Also used : BlobStore(org.exist.storage.blob.BlobStore)

Example 7 with BlobStore

use of org.exist.storage.blob.BlobStore in project exist by eXist-db.

the class NativeBroker method doCopyDocument.

/**
 * Creates a new Document object for the destination document
 * - copies the nodes from the source document to the destination document
 * - if no existing document in the destination:
 *      - adds the destination document to the destination collection
 *   else, switches the existing document object for the new document in the destination collection
 *
 *   asynchronously deletes the nodes of the old existing document
 */
private void doCopyDocument(final Txn transaction, final DocumentTrigger trigger, final DocumentImpl sourceDocument, final Collection targetCollection, final XmldbURI newDocName, @EnsureLocked(mode = LockMode.WRITE_LOCK) @Nullable final DocumentImpl oldDoc, final PreserveType preserve) throws TriggerException, LockException, PermissionDeniedException, IOException, EXistException {
    final XmldbURI sourceDocumentUri = sourceDocument.getURI();
    final XmldbURI targetCollectionUri = targetCollection.getURI();
    final XmldbURI targetDocumentUri = targetCollectionUri.append(newDocName);
    trigger.beforeCopyDocument(this, transaction, sourceDocument, targetDocumentUri);
    final DocumentImpl newDocument;
    final LockManager lockManager = getBrokerPool().getLockManager();
    try (final ManagedDocumentLock newDocLock = lockManager.acquireDocumentWriteLock(targetDocumentUri)) {
        final int copiedDocId = getNextResourceId(transaction);
        if (sourceDocument.getResourceType() == DocumentImpl.BINARY_FILE) {
            final BinaryDocument newDoc;
            if (oldDoc != null) {
                newDoc = new BinaryDocument(copiedDocId, oldDoc);
            } else {
                newDoc = new BinaryDocument(getBrokerPool(), targetCollection, copiedDocId, newDocName);
            }
            newDoc.copyOf(this, sourceDocument, oldDoc);
            if (preserveOnCopy(preserve)) {
                copyResource_preserve(this, sourceDocument, newDoc, oldDoc != null);
            }
            copyBinaryResource(transaction, (BinaryDocument) sourceDocument, newDoc);
            newDocument = newDoc;
        } else {
            final DocumentImpl newDoc;
            if (oldDoc != null) {
                newDoc = new DocumentImpl(copiedDocId, oldDoc);
            } else {
                newDoc = new DocumentImpl(pool, targetCollection, copiedDocId, newDocName);
            }
            newDoc.copyOf(this, sourceDocument, oldDoc);
            copyXMLResource(transaction, sourceDocument, newDoc);
            if (preserveOnCopy(preserve)) {
                copyResource_preserve(this, sourceDocument, newDoc, oldDoc != null);
            }
            newDocument = newDoc;
        }
        /*
             * Stores the document entry for newDstDoc,
             * or overwrites the document entry for currentDstDoc with
             * the entry for newDstDoc, in collections.dbx.
             */
        storeXMLResource(transaction, newDocument);
        // must be the last action (before cleanup), as this will make newDstDoc available to other threads!
        targetCollection.addDocument(transaction, this, newDocument);
        // cleanup the old destination doc (if present)
        if (oldDoc != null) {
            if (oldDoc.getResourceType() == DocumentImpl.XML_FILE) {
                // drop the index and dom nodes of the old document
                dropIndex(transaction, oldDoc);
                dropDomNodes(transaction, oldDoc);
            } else {
                // remove the blob of the old document
                final BlobStore blobStore = pool.getBlobStore();
                blobStore.remove(transaction, ((BinaryDocument) oldDoc).getBlobId());
            }
            // remove oldDoc entry from collections.dbx
            removeResourceMetadata(transaction, oldDoc);
            // TODO(AR) do we need a freeId flag to control this?
            // recycle the id
            collectionsDb.freeResourceId(oldDoc.getDocId());
        // The Collection object oldDstDoc is now an empty husk which is
        // not available or referenced from anywhere, it will be subject
        // to garbage collection
        }
    }
    trigger.afterCopyDocument(this, transaction, newDocument, sourceDocumentUri);
}
Also used : XmldbURI(org.exist.xmldb.XmldbURI) BlobStore(org.exist.storage.blob.BlobStore)

Aggregations

BlobStore (org.exist.storage.blob.BlobStore)7 IOException (java.io.IOException)2 Path (java.nio.file.Path)2 BlobId (org.exist.storage.blob.BlobId)2 XmldbURI (org.exist.xmldb.XmldbURI)2 TaggedTryUnchecked (com.evolvedbinary.j8fu.Try.TaggedTryUnchecked)1 Long2ObjectOpenHashMap (it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap)1 FileNotFoundException (java.io.FileNotFoundException)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 UnsynchronizedByteArrayOutputStream (org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream)1 LogManager (org.apache.logging.log4j.LogManager)1 Logger (org.apache.logging.log4j.Logger)1 QName (org.exist.dom.QName)1 BinaryDocument (org.exist.dom.persistent.BinaryDocument)1 LockedDocument (org.exist.dom.persistent.LockedDocument)1 PermissionDeniedException (org.exist.security.PermissionDeniedException)1 Source (org.exist.source.Source)1