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