@Override public String getBlobId(String reference) { if (reference.startsWith(NEW_BLOBSTORE_PREFIX)) { return newBlobStore.getBlobId(reference.substring(NEW_BLOBSTORE_PREFIX.length())); } else if (reference.startsWith(OLD_BLOBSTORE_PREFIX)) { return oldBlobStore.getBlobId(reference.substring(OLD_BLOBSTORE_PREFIX.length())); } else { log.error("Invalid reference: {}", reference); return null; } }
@Override public String getBlobId(String reference) { if (reference.startsWith(NEW_BLOBSTORE_PREFIX)) { return newBlobStore.getBlobId(reference.substring(NEW_BLOBSTORE_PREFIX.length())); } else if (reference.startsWith(OLD_BLOBSTORE_PREFIX)) { return oldBlobStore.getBlobId(reference.substring(OLD_BLOBSTORE_PREFIX.length())); } else { log.error("Invalid reference: {}", reference); return null; } }
@Override public String getBlobId(String reference) { if (reference.startsWith(NEW_BLOBSTORE_PREFIX)) { return newBlobStore.getBlobId(reference.substring(NEW_BLOBSTORE_PREFIX.length())); } else if (reference.startsWith(OLD_BLOBSTORE_PREFIX)) { return oldBlobStore.getBlobId(reference.substring(OLD_BLOBSTORE_PREFIX.length())); } else { log.error("Invalid reference: {}", reference); return null; } }
/** * Returns the {@link Blob} with the given reference. Note that this method is meant to * be used with secure reference obtained from Blob#reference which is different from blobId * * @param reference the reference of the blob. * @return the blob. */ @Override public Blob getBlob(@NotNull String reference) { String blobId = blobStore.getBlobId(reference); if(blobId != null){ return new BlobStoreBlob(blobStore, blobId); } LOG.debug("No blobId found matching reference [{}]", reference); return null; }
@Override public Blob getBlob(@NotNull String reference) { //Use of 'reference' here is bit overloaded. In terms of NodeStore API //a blob reference refers to the secure reference obtained from Blob#getReference() //However in SegmentStore terminology a blob is referred via 'external reference' //That 'external reference' would map to blobId obtained from BlobStore#getBlobId if (blobStore != null) { String blobId = blobStore.getBlobId(reference); if (blobId != null) { return new BlobStoreBlob(blobStore, blobId); } return null; } throw new IllegalStateException("Attempt to read external blob with blobId [" + reference + "] " + "without specifying BlobStore"); }
/** * Returns the {@link Blob} with the given reference. Note that this method is meant to * be used with secure reference obtained from Blob#reference which is different from blobId * * @param reference the reference of the blob. * @return the blob. */ @Override public Blob getBlob(@NotNull String reference) { String blobId = blobStore.getBlobId(reference); if(blobId != null){ return new BlobStoreBlob(blobStore, blobId); } LOG.debug("No blobId found matching reference [{}]", reference); return null; }
@SuppressWarnings("ConstantConditions") @Test(expected = NullPointerException.class) public void getBlobIdShouldThrowAnExceptionWhenNullIsPassed() { given: { final BlobStore blobStore = new LoopbackBlobStore(); when: { blobStore.getBlobId(null); } } }
@Override public String serialize(Blob blob) { if (blob instanceof BlobStoreBlob) { BlobStoreBlob bsb = (BlobStoreBlob) blob; BlobStore bsbBlobStore = bsb.getBlobStore(); //see if the blob has been created from another store if (bsbBlobStore != null && bsbBlobStore.equals(blobStore)) { return bsb.getBlobId(); } } String id; String reference = blob.getReference(); if(reference != null){ id = blobStore.getBlobId(reference); if(id != null){ return id; } } try { id = createBlob(blob.getNewStream()).getBlobId(); } catch (IOException e) { throw new IllegalStateException(e); } return id; } };
@Override public String serialize(Blob blob) { if (blob instanceof BlobStoreBlob) { BlobStoreBlob bsb = (BlobStoreBlob) blob; BlobStore bsbBlobStore = bsb.getBlobStore(); //see if the blob has been created from another store if (bsbBlobStore != null && bsbBlobStore.equals(blobStore)) { return bsb.getBlobId(); } } String id; String reference = blob.getReference(); if(reference != null){ id = blobStore.getBlobId(reference); if(id != null){ return id; } } try { id = createBlob(blob.getNewStream()).getBlobId(); } catch (IOException e) { throw new IllegalStateException(e); } return id; } };
@Test @Parameters(method = "blobIds") public void getBlobIdShouldReturnTheSameValuePassedExceptOfNull( final String blobId) { given: { final BlobStore blobStore = new LoopbackBlobStore(); expect: { assertEquals(blobId, blobStore.getBlobId(blobId)); } } }
private RecordId writeBlob(@NotNull Blob blob) throws IOException { if (sameStore(blob)) { SegmentBlob segmentBlob = (SegmentBlob) blob; if (!isOldGeneration(segmentBlob.getRecordId())) { return segmentBlob.getRecordId(); } if (segmentBlob.isExternal()) { return writeBlobId(segmentBlob.getBlobId()); } } String reference = blob.getReference(); if (reference != null && blobStore != null) { String blobId = blobStore.getBlobId(reference); if (blobId != null) { return writeBlobId(blobId); } else { LOG.debug("No blob found for reference {}, inlining...", reference); } } return writeStream(blob.getNewStream()); }