Search in sources :

Example 1 with PreserveType

use of org.exist.storage.DBBroker.PreserveType 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);
                    }
                }
            });
        }
    }));
}
Also used : XMLDBException(org.xmldb.api.base.XMLDBException) Tuple2(com.evolvedbinary.j8fu.tuple.Tuple2) ManagedDocumentLock(org.exist.storage.lock.ManagedDocumentLock) LockedDocument(org.exist.dom.persistent.LockedDocument) BrokerPool(org.exist.storage.BrokerPool) Date(java.util.Date) URISyntaxException(java.net.URISyntaxException) ManagedCollectionLock(org.exist.storage.lock.ManagedCollectionLock) PreserveType(org.exist.storage.DBBroker.PreserveType) LockException(org.exist.util.LockException) Subject(org.exist.security.Subject) Optional(java.util.Optional) DocumentImpl(org.exist.dom.persistent.DocumentImpl) EXistException(org.exist.EXistException) TriggerException(org.exist.collections.triggers.TriggerException) ErrorCodes(org.xmldb.api.base.ErrorCodes) Lock(org.exist.storage.lock.Lock) Nullable(javax.annotation.Nullable) Collection(org.xmldb.api.base.Collection) ManagedDocumentLock(org.exist.storage.lock.ManagedDocumentLock) LockedDocument(org.exist.dom.persistent.LockedDocument) XMLDBException(org.xmldb.api.base.XMLDBException) EXistException(org.exist.EXistException) DocumentImpl(org.exist.dom.persistent.DocumentImpl)

Example 2 with PreserveType

use of org.exist.storage.DBBroker.PreserveType in project exist by eXist-db.

the class LocalCollectionManagementService method copy.

private void copy(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).apply((source, b1, t1) -> modify(b1, t1, destPath).apply((destination, b2, t2) -> {
        try {
            b2.copyCollection(t2, source, destination, newName, preserve);
            return null;
        } catch (final EXistException e) {
            throw new XMLDBException(ErrorCodes.VENDOR_ERROR, "failed to move collection " + srcPath, e);
        }
    })));
}
Also used : XMLDBException(org.xmldb.api.base.XMLDBException) Tuple2(com.evolvedbinary.j8fu.tuple.Tuple2) ManagedDocumentLock(org.exist.storage.lock.ManagedDocumentLock) LockedDocument(org.exist.dom.persistent.LockedDocument) BrokerPool(org.exist.storage.BrokerPool) Date(java.util.Date) URISyntaxException(java.net.URISyntaxException) ManagedCollectionLock(org.exist.storage.lock.ManagedCollectionLock) PreserveType(org.exist.storage.DBBroker.PreserveType) LockException(org.exist.util.LockException) Subject(org.exist.security.Subject) Optional(java.util.Optional) DocumentImpl(org.exist.dom.persistent.DocumentImpl) EXistException(org.exist.EXistException) TriggerException(org.exist.collections.triggers.TriggerException) ErrorCodes(org.xmldb.api.base.ErrorCodes) Lock(org.exist.storage.lock.Lock) Nullable(javax.annotation.Nullable) Collection(org.xmldb.api.base.Collection) XMLDBException(org.xmldb.api.base.XMLDBException) EXistException(org.exist.EXistException)

Aggregations

Tuple2 (com.evolvedbinary.j8fu.tuple.Tuple2)2 URISyntaxException (java.net.URISyntaxException)2 Date (java.util.Date)2 Optional (java.util.Optional)2 Nullable (javax.annotation.Nullable)2 EXistException (org.exist.EXistException)2 TriggerException (org.exist.collections.triggers.TriggerException)2 DocumentImpl (org.exist.dom.persistent.DocumentImpl)2 LockedDocument (org.exist.dom.persistent.LockedDocument)2 Subject (org.exist.security.Subject)2 BrokerPool (org.exist.storage.BrokerPool)2 PreserveType (org.exist.storage.DBBroker.PreserveType)2 Lock (org.exist.storage.lock.Lock)2 ManagedCollectionLock (org.exist.storage.lock.ManagedCollectionLock)2 ManagedDocumentLock (org.exist.storage.lock.ManagedDocumentLock)2 LockException (org.exist.util.LockException)2 Collection (org.xmldb.api.base.Collection)2 ErrorCodes (org.xmldb.api.base.ErrorCodes)2 XMLDBException (org.xmldb.api.base.XMLDBException)2