Search in sources :

Example 6 with StorageTx

use of org.sonatype.nexus.repository.storage.StorageTx in project nexus-repository-r by sonatype-nexus-community.

the class RHostedFacetImpl method getStoredContent.

@Override
@TransactionalTouchBlob
public Content getStoredContent(final String contentPath) {
    checkNotNull(contentPath);
    StorageTx tx = UnitOfWork.currentTx();
    Asset asset = findAsset(tx, tx.findBucket(getRepository()), contentPath);
    if (asset == null) {
        return null;
    }
    if (asset.markAsDownloaded()) {
        tx.saveAsset(asset);
    }
    return toContent(asset, tx.requireBlob(asset.requireBlobRef()));
}
Also used : StorageTx(org.sonatype.nexus.repository.storage.StorageTx) RFacetUtils.saveAsset(org.sonatype.nexus.repository.r.internal.util.RFacetUtils.saveAsset) RFacetUtils.findAsset(org.sonatype.nexus.repository.r.internal.util.RFacetUtils.findAsset) Asset(org.sonatype.nexus.repository.storage.Asset) TransactionalTouchBlob(org.sonatype.nexus.repository.transaction.TransactionalTouchBlob)

Example 7 with StorageTx

use of org.sonatype.nexus.repository.storage.StorageTx in project nexus-repository-r by sonatype-nexus-community.

the class RHostedFacetImpl method buildAndPutPackagesGz.

@Override
@TransactionalTouchMetadata
public Content buildAndPutPackagesGz(final String basePath) throws IOException {
    checkNotNull(basePath);
    StorageTx tx = UnitOfWork.currentTx();
    RPackagesBuilder packagesBuilder = new RPackagesBuilder();
    Iterable<Asset> archiveAssets = browseAllAssetsByKind(tx, tx.findBucket(getRepository()), ARCHIVE);
    // packageInfoBuilder doesn't support multithreading
    StreamSupport.stream(archiveAssets.spliterator(), false).filter(asset -> basePath.equals(getBasePath(asset.name()))).forEach(packagesBuilder::append);
    byte[] packagesBytes = packagesBuilder.buildPackagesGz();
    StorageFacet storageFacet = getRepository().facet(StorageFacet.class);
    try (InputStream is = new ByteArrayInputStream(packagesBytes)) {
        TempBlob tempPackagesGz = storageFacet.createTempBlob(is, RFacetUtils.HASH_ALGORITHMS);
        return doPutPackagesGz(tx, basePath, tempPackagesGz);
    }
}
Also used : StorageFacet(org.sonatype.nexus.repository.storage.StorageFacet) ARCHIVE(org.sonatype.nexus.repository.r.internal.AssetKind.ARCHIVE) RFacetUtils.saveAsset(org.sonatype.nexus.repository.r.internal.util.RFacetUtils.saveAsset) RFacet(org.sonatype.nexus.repository.r.RFacet) RFacetUtils(org.sonatype.nexus.repository.r.internal.util.RFacetUtils) RFacetUtils.toContent(org.sonatype.nexus.repository.r.internal.util.RFacetUtils.toContent) Component(org.sonatype.nexus.repository.storage.Component) UnitOfWork(org.sonatype.nexus.transaction.UnitOfWork) ByteArrayInputStream(java.io.ByteArrayInputStream) RHostedFacet(org.sonatype.nexus.repository.r.RHostedFacet) Map(java.util.Map) Payload(org.sonatype.nexus.repository.view.Payload) StreamSupport(java.util.stream.StreamSupport) PACKAGES_GZ_FILENAME(org.sonatype.nexus.repository.r.internal.util.RPathUtils.PACKAGES_GZ_FILENAME) Named(javax.inject.Named) TransactionalStoreBlob(org.sonatype.nexus.repository.transaction.TransactionalStoreBlob) RDescriptionUtils.extractDescriptionFromArchive(org.sonatype.nexus.repository.r.internal.util.RDescriptionUtils.extractDescriptionFromArchive) TempBlob(org.sonatype.nexus.repository.storage.TempBlob) RPathUtils.getBasePath(org.sonatype.nexus.repository.r.internal.util.RPathUtils.getBasePath) TransactionalTouchBlob(org.sonatype.nexus.repository.transaction.TransactionalTouchBlob) FacetSupport(org.sonatype.nexus.repository.FacetSupport) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) RFacetUtils.findAsset(org.sonatype.nexus.repository.r.internal.util.RFacetUtils.findAsset) IOException(java.io.IOException) StorageTx(org.sonatype.nexus.repository.storage.StorageTx) Asset(org.sonatype.nexus.repository.storage.Asset) Content(org.sonatype.nexus.repository.view.Content) TransactionalTouchMetadata(org.sonatype.nexus.repository.transaction.TransactionalTouchMetadata) RFacetUtils.browseAllAssetsByKind(org.sonatype.nexus.repository.r.internal.util.RFacetUtils.browseAllAssetsByKind) RPathUtils.buildPath(org.sonatype.nexus.repository.r.internal.util.RPathUtils.buildPath) InputStream(java.io.InputStream) TempBlob(org.sonatype.nexus.repository.storage.TempBlob) StorageTx(org.sonatype.nexus.repository.storage.StorageTx) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) RFacetUtils.saveAsset(org.sonatype.nexus.repository.r.internal.util.RFacetUtils.saveAsset) RFacetUtils.findAsset(org.sonatype.nexus.repository.r.internal.util.RFacetUtils.findAsset) Asset(org.sonatype.nexus.repository.storage.Asset) StorageFacet(org.sonatype.nexus.repository.storage.StorageFacet) TransactionalTouchMetadata(org.sonatype.nexus.repository.transaction.TransactionalTouchMetadata)

Example 8 with StorageTx

use of org.sonatype.nexus.repository.storage.StorageTx in project nexus-repository-r by sonatype-nexus-community.

the class RProxyFacetImpl method getAsset.

@TransactionalTouchBlob
protected Content getAsset(final String name) {
    StorageTx tx = UnitOfWork.currentTx();
    Asset asset = findAsset(tx, tx.findBucket(getRepository()), name);
    if (asset == null) {
        return null;
    }
    if (asset.markAsDownloaded()) {
        tx.saveAsset(asset);
    }
    return toContent(asset, tx.requireBlob(asset.requireBlobRef()));
}
Also used : StorageTx(org.sonatype.nexus.repository.storage.StorageTx) RFacetUtils.saveAsset(org.sonatype.nexus.repository.r.internal.util.RFacetUtils.saveAsset) RFacetUtils.findAsset(org.sonatype.nexus.repository.r.internal.util.RFacetUtils.findAsset) Asset(org.sonatype.nexus.repository.storage.Asset) TransactionalTouchBlob(org.sonatype.nexus.repository.transaction.TransactionalTouchBlob)

Example 9 with StorageTx

use of org.sonatype.nexus.repository.storage.StorageTx in project nexus-repository-r by sonatype-nexus-community.

the class RProxyFacetImpl method setCacheInfo.

@TransactionalTouchMetadata
public void setCacheInfo(final Content content, final CacheInfo cacheInfo) {
    StorageTx tx = UnitOfWork.currentTx();
    Asset asset = Content.findAsset(tx, tx.findBucket(getRepository()), content);
    if (asset == null) {
        log.debug("Attempting to set cache info for non-existent R asset {}", content.getAttributes().require(Asset.class));
        return;
    }
    log.debug("Updating cacheInfo of {} to {}", asset, cacheInfo);
    CacheInfo.applyToAsset(asset, cacheInfo);
    tx.saveAsset(asset);
}
Also used : StorageTx(org.sonatype.nexus.repository.storage.StorageTx) RFacetUtils.saveAsset(org.sonatype.nexus.repository.r.internal.util.RFacetUtils.saveAsset) RFacetUtils.findAsset(org.sonatype.nexus.repository.r.internal.util.RFacetUtils.findAsset) Asset(org.sonatype.nexus.repository.storage.Asset) TransactionalTouchMetadata(org.sonatype.nexus.repository.transaction.TransactionalTouchMetadata)

Example 10 with StorageTx

use of org.sonatype.nexus.repository.storage.StorageTx in project nexus-repository-r by sonatype-nexus-community.

the class RProxyFacetImpl method getAsset.

@TransactionalTouchBlob
protected Content getAsset(final String name) {
    StorageTx tx = UnitOfWork.currentTx();
    Asset asset = findAsset(tx, tx.findBucket(getRepository()), name);
    if (asset == null) {
        return null;
    }
    if (asset.markAsDownloaded()) {
        tx.saveAsset(asset);
    }
    return toContent(asset, tx.requireBlob(asset.requireBlobRef()));
}
Also used : StorageTx(org.sonatype.nexus.repository.storage.StorageTx) RFacetUtils.findAsset(org.sonatype.nexus.repository.r.internal.RFacetUtils.findAsset) RFacetUtils.saveAsset(org.sonatype.nexus.repository.r.internal.RFacetUtils.saveAsset) Asset(org.sonatype.nexus.repository.storage.Asset) TransactionalTouchBlob(org.sonatype.nexus.repository.transaction.TransactionalTouchBlob)

Aggregations

Asset (org.sonatype.nexus.repository.storage.Asset)17 StorageTx (org.sonatype.nexus.repository.storage.StorageTx)17 RFacetUtils.findAsset (org.sonatype.nexus.repository.r.internal.RFacetUtils.findAsset)7 RFacetUtils.saveAsset (org.sonatype.nexus.repository.r.internal.RFacetUtils.saveAsset)7 RFacetUtils.findAsset (org.sonatype.nexus.repository.r.internal.util.RFacetUtils.findAsset)7 RFacetUtils.saveAsset (org.sonatype.nexus.repository.r.internal.util.RFacetUtils.saveAsset)7 Component (org.sonatype.nexus.repository.storage.Component)7 TransactionalStoreBlob (org.sonatype.nexus.repository.transaction.TransactionalStoreBlob)7 InputStream (java.io.InputStream)6 TransactionalTouchBlob (org.sonatype.nexus.repository.transaction.TransactionalTouchBlob)6 RFacet (org.sonatype.nexus.repository.r.RFacet)5 TransactionalTouchMetadata (org.sonatype.nexus.repository.transaction.TransactionalTouchMetadata)4 Bucket (org.sonatype.nexus.repository.storage.Bucket)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 IOException (java.io.IOException)2 Map (java.util.Map)2 RFacetUtils.findComponent (org.sonatype.nexus.repository.r.internal.RFacetUtils.findComponent)2 Content (org.sonatype.nexus.repository.view.Content)2 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1