use of org.exist.storage.lock.ManagedDocumentLock in project exist by eXist-db.
the class LocalCollectionManagementService method copyResource.
private void copyResource(final XmldbURI src, final XmldbURI dest, final XmldbURI name, final PreserveType preserve) throws XMLDBException {
final XmldbURI srcPath = resolve(src);
final XmldbURI destPath = dest == null ? srcPath.removeLastSegment() : resolve(dest);
final XmldbURI newName;
if (name == null) {
newName = srcPath.lastSegment();
} else {
newName = name;
}
withDb((broker, transaction) -> read(broker, transaction, srcPath.removeLastSegment()).apply((sourceCol, b1, t1) -> {
try (final LockedDocument lockedSource = sourceCol.getDocumentWithLock(b1, srcPath.lastSegment(), Lock.LockMode.READ_LOCK)) {
final DocumentImpl source = lockedSource == null ? null : lockedSource.getDocument();
if (source == null) {
// NOTE: early release of Collection lock inline with Asymmetrical Locking scheme
sourceCol.close();
throw new XMLDBException(ErrorCodes.NO_SUCH_RESOURCE, "Resource " + srcPath + " not found");
}
return modify(b1, t1, destPath).apply((destinationCol, b2, t2) -> {
try (final ManagedDocumentLock lockedDestination = b2.getBrokerPool().getLockManager().acquireDocumentWriteLock(destinationCol.getURI().append(newName))) {
try {
b2.copyResource(t2, source, destinationCol, newName, preserve);
// NOTE: early release of Collection locks inline with Asymmetrical Locking scheme
destinationCol.close();
sourceCol.close();
return null;
} catch (final EXistException e) {
throw new XMLDBException(ErrorCodes.VENDOR_ERROR, "failed to copy resource " + srcPath, e);
}
}
});
}
}));
}
use of org.exist.storage.lock.ManagedDocumentLock in project exist by eXist-db.
the class NewArrayNodeSet method lock.
@Override
public ManagedLocks<ManagedDocumentLock> lock(final DBBroker broker, final boolean exclusive) throws LockException {
sort();
final LockManager lockManager = broker.getBrokerPool().getLockManager();
final ManagedDocumentLock[] managedDocumentLocks = new ManagedDocumentLock[documentCount];
try {
for (int idx = 0; idx < documentCount; idx++) {
final DocumentImpl doc = nodes[documentNodesOffset[idx]].getOwnerDocument();
final ManagedDocumentLock managedDocumentLock;
if (exclusive) {
managedDocumentLock = lockManager.acquireDocumentWriteLock(doc.getURI());
} else {
managedDocumentLock = lockManager.acquireDocumentReadLock(doc.getURI());
}
managedDocumentLocks[idx] = managedDocumentLock;
}
return new ManagedLocks<>(managedDocumentLocks);
} catch (final LockException e) {
// unlock any previously locked documents
new ManagedLocks<>(managedDocumentLocks).close();
throw e;
}
}
use of org.exist.storage.lock.ManagedDocumentLock in project exist by eXist-db.
the class ExtArrayNodeSet method lock.
@Override
public ManagedLocks<ManagedDocumentLock> lock(final DBBroker broker, final boolean exclusive) throws LockException {
final LockManager lockManager = broker.getBrokerPool().getLockManager();
final ManagedDocumentLock[] managedDocumentLocks = new ManagedDocumentLock[partCount];
try {
for (int i = 0; i < partCount; i++) {
final DocumentImpl doc = parts[i].getOwnerDocument();
final ManagedDocumentLock docLock;
if (exclusive) {
docLock = lockManager.acquireDocumentWriteLock(doc.getURI());
} else {
docLock = lockManager.acquireDocumentReadLock(doc.getURI());
}
managedDocumentLocks[i] = docLock;
}
return new ManagedLocks<>(managedDocumentLocks);
} catch (final LockException e) {
// unlock any previously locked documents
new ManagedLocks<>(managedDocumentLocks).close();
throw e;
}
}
Aggregations