Java Code Examples for org.sonatype.nexus.repository.storage.StorageTx#findComponentWithProperty()

The following examples show how to use org.sonatype.nexus.repository.storage.StorageTx#findComponentWithProperty() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AptSnapshotFacetSupport.java    From nexus-repository-apt with Eclipse Public License 1.0 6 votes vote down vote up
@Transactional(retryOn = { ONeedRetryException.class })
@Override
public Content getSnapshotFile(String id, String path) throws IOException {
  StorageTx tx = UnitOfWork.currentTx();
  Bucket bucket = tx.findBucket(getRepository());
  Component component = tx.findComponentWithProperty(P_NAME, id, bucket);
  if (component == null) {
    return null;
  }

  final Asset asset = tx.findAssetWithProperty(P_NAME, createAssetPath(id, path), component);
  if (asset == null) {
    return null;
  }

  final Blob blob = tx.requireBlob(asset.requireBlobRef());
  return FacetHelper.toContent(asset, blob);
}
 
Example 2
Source File: RawContentFacetImpl.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@Override
@TransactionalTouchMetadata
public void setCacheInfo(final String path, final Content content, final CacheInfo cacheInfo) throws IOException {
  StorageTx tx = UnitOfWork.currentTx();
  Bucket bucket = tx.findBucket(getRepository());

  // by EntityId
  Asset asset = Content.findAsset(tx, bucket, content);
  if (asset == null) {
    // by format coordinates
    Component component = tx.findComponentWithProperty(P_NAME, path, bucket);
    if (component != null) {
      asset = tx.firstAsset(component);
    }
  }
  if (asset == null) {
    log.debug("Attempting to set cache info for non-existent raw component {}", path);
    return;
  }

  log.debug("Updating cacheInfo of {} to {}", path, cacheInfo);
  CacheInfo.applyToAsset(asset, cacheInfo);
  tx.saveAsset(asset);
}
 
Example 3
Source File: AptSnapshotFacetSupport.java    From nexus-repository-apt with Eclipse Public License 1.0 5 votes vote down vote up
@Transactional(retryOn = { ONeedRetryException.class })
@Override
public void deleteSnapshot(String id) throws IOException {
  StorageTx tx = UnitOfWork.currentTx();
  Bucket bucket = tx.findBucket(getRepository());
  Component component = tx.findComponentWithProperty(P_NAME, id, bucket);
  if (component == null) {
    return;
  }
  tx.deleteComponent(component);
}
 
Example 4
Source File: RawContentFacetImpl.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@TransactionalStoreMetadata
public Asset getOrCreateAsset(final Repository repository, final String componentName, final String componentGroup,
                              final String assetName) {
  final StorageTx tx = UnitOfWork.currentTx();

  final Bucket bucket = tx.findBucket(getRepository());
  Component component = tx.findComponentWithProperty(P_NAME, componentName, bucket);
  Asset asset;
  if (component == null) {
    // CREATE
    component = tx.createComponent(bucket, getRepository().getFormat())
        .group(componentGroup)
        .name(componentName);

    tx.saveComponent(component);

    asset = tx.createAsset(bucket, component);
    asset.name(assetName);
  }
  else {
    // UPDATE
    asset = tx.firstAsset(component);
    asset = asset != null ? asset : tx.createAsset(bucket, component).name(assetName);
  }

  return asset;
}
 
Example 5
Source File: RawContentFacetImpl.java    From nexus-public with Eclipse Public License 1.0 4 votes vote down vote up
private Component findComponent(StorageTx tx, Bucket bucket, String path) {
  return tx.findComponentWithProperty(P_NAME, path, bucket);
}