/** * Check if a record for the given identifier exists in the primary data * store. If not found there it will be returned from the archive data * store. If no record exists, this method returns null. * * @param identifier * data identifier * @return the record if found, and null if not */ public DataRecord getRecordIfStored(DataIdentifier identifier) throws DataStoreException { if (moveDataTaskRunning) { moveDataTaskLock.lock(); } try { DataRecord dataRecord = primaryDataStore.getRecordIfStored(identifier); if (dataRecord == null) { dataRecord = archiveDataStore.getRecordIfStored(identifier); } return dataRecord; } finally { if (moveDataTaskRunning) { moveDataTaskLock.unlock(); } } }
/** * Check if a record for the given identifier exists in the primary data * store. If not found there it will be returned from the archive data * store. If no record exists, this method returns null. * * @param identifier * data identifier * @return the record if found, and null if not */ public DataRecord getRecordIfStored(DataIdentifier identifier) throws DataStoreException { if (moveDataTaskRunning) { moveDataTaskLock.lock(); } try { DataRecord dataRecord = primaryDataStore.getRecordIfStored(identifier); if (dataRecord == null) { dataRecord = archiveDataStore.getRecordIfStored(identifier); } return dataRecord; } finally { if (moveDataTaskRunning) { moveDataTaskLock.unlock(); } } }
/** * Check if a record for the given identifier exists in the primary data * store. If not found there it will be returned from the archive data * store. If no record exists, this method returns null. * * @param identifier * data identifier * @return the record if found, and null if not */ public DataRecord getRecordIfStored(DataIdentifier identifier) throws DataStoreException { if (moveDataTaskRunning) { moveDataTaskLock.lock(); } try { DataRecord dataRecord = primaryDataStore.getRecordIfStored(identifier); if (dataRecord == null) { dataRecord = archiveDataStore.getRecordIfStored(identifier); } return dataRecord; } finally { if (moveDataTaskRunning) { moveDataTaskLock.unlock(); } } }
@Override public String getReference(@NotNull String encodedBlobId) { checkNotNull(encodedBlobId); String blobId = extractBlobId(encodedBlobId); //Reference are not created for in memory record if (InMemoryDataRecord.isInstance(blobId)) { return null; } DataRecord record; try { record = delegate.getRecordIfStored(new DataIdentifier(blobId)); if (record != null) { return record.getReference(); } else { log.debug("No blob found for id [{}]", blobId); } } catch (DataStoreException e) { log.warn("Unable to access the blobId for [{}]", blobId, e); } return null; }
@Override public String getReference(@NotNull String encodedBlobId) { checkNotNull(encodedBlobId); String blobId = extractBlobId(encodedBlobId); //Reference are not created for in memory record if (InMemoryDataRecord.isInstance(blobId)) { return null; } DataRecord record; try { record = delegate.getRecordIfStored(new DataIdentifier(blobId)); if (record != null) { return record.getReference(); } else { log.debug("No blob found for id [{}]", blobId); } } catch (DataStoreException e) { log.warn("Unable to access the blobId for [{}]", blobId, e); } return null; }
@Override public String getReference(@NotNull String encodedBlobId) { checkNotNull(encodedBlobId); String blobId = extractBlobId(encodedBlobId); //Reference are not created for in memory record if (InMemoryDataRecord.isInstance(blobId)) { return null; } DataRecord record; try { record = delegate.getRecordIfStored(new DataIdentifier(blobId)); if (record != null) { return record.getReference(); } else { log.debug("No blob found for id [{}]", blobId); } } catch (DataStoreException e) { log.warn("Unable to access the blobId for [{}]", blobId, e); } return null; }
@Override public String getReference(@NotNull String encodedBlobId) { checkNotNull(encodedBlobId); String blobId = extractBlobId(encodedBlobId); //Reference are not created for in memory record if (InMemoryDataRecord.isInstance(blobId)) { return null; } DataRecord record; try { record = delegate.getRecordIfStored(new DataIdentifier(blobId)); if (record != null) { return record.getReference(); } else { log.debug("No blob found for id [{}]", blobId); } } catch (DataStoreException e) { log.warn("Unable to access the blobId for [{}]", blobId, e); } return null; }
@Override public DataRecord getRecordIfStored(DataIdentifier identifier) throws DataStoreException { if (isInMemoryRecord(identifier)) { return getDataRecord(identifier.toString()); } return delegate.getRecordIfStored(identifier); }
@Override protected DataRecord getDataRecord(String blobId) throws DataStoreException { DataRecord id; if (InMemoryDataRecord.isInstance(blobId)) { id = InMemoryDataRecord.getInstance(blobId); } else { id = delegate.getRecordIfStored(new DataIdentifier(blobId)); } return id; } }
@Override public String getReference(@Nonnull String encodedBlobId) { checkNotNull(encodedBlobId); String blobId = extractBlobId(encodedBlobId); //Reference are not created for in memory record if (InMemoryDataRecord.isInstance(blobId)) { return null; } DataRecord record; try { record = delegate.getRecordIfStored(new DataIdentifier(blobId)); if (record != null) { return record.getReference(); } else { log.debug("No blob found for id [{}]", blobId); } } catch (DataStoreException e) { log.warn("Unable to access the blobId for [{}]", blobId, e); } return null; }
@Override public DataRecord getRecordIfStored(DataIdentifier identifier) throws DataStoreException { if (isInMemoryRecord(identifier)) { return getDataRecord(identifier.toString()); } return delegate.getRecordIfStored(identifier); }
@Override public DataRecord getRecordIfStored(DataIdentifier identifier) throws DataStoreException { if (isInMemoryRecord(identifier)) { return getDataRecord(identifier.toString()); } return delegate.getRecordIfStored(identifier); }
@Override protected DataRecord getDataRecord(String blobId) throws DataStoreException { DataRecord id; if (InMemoryDataRecord.isInstance(blobId)) { id = InMemoryDataRecord.getInstance(blobId); } else { id = delegate.getRecordIfStored(new DataIdentifier(blobId)); } return id; } }
@Override public DataRecord getRecordIfStored(DataIdentifier dataIdentifier) throws DataStoreException { if (existingMappings.containsKey(dataIdentifier.toString())) { return new DelegateDataRecord(this, dataIdentifier, existingMappings); } else if (newMappings.containsKey(dataIdentifier.toString())) { return new DelegateDataRecord(this, dataIdentifier, newMappings); } DataRecord result = getDelegate().getRecordIfStored(dataIdentifier); addNewMapping(result); return result; }
@Override public DataRecord getRecordIfStored(DataIdentifier dataIdentifier) throws DataStoreException { if (existingMappings.containsKey(dataIdentifier.toString())) { return new DelegateDataRecord(this, dataIdentifier, existingMappings); } else if (newMappings.containsKey(dataIdentifier.toString())) { return new DelegateDataRecord(this, dataIdentifier, newMappings); } DataRecord result = getDelegate().getRecordIfStored(dataIdentifier); addNewMapping(result); return result; }
/** * Get the internal value for this blob. * * @param identifier the identifier * @param store the data store * @param verify verify if the record exists, and return null if not * @return the internal value or null */ static InternalValue getInternalValue(DataIdentifier identifier, DataStore store, boolean verify) throws DataStoreException { if (verify) { if (store.getRecordIfStored(identifier) == null) { return null; } } else { // access the record to ensure it is not garbage collected store.getRecord(identifier); } // it exists - so we don't need to stream it again // but we need to create a new object because the original // one might be in a different data store (repository) BLOBFileValue blob = BLOBInDataStore.getInstance(store, identifier); return new InternalValue(blob); }
/** * Get the internal value for this blob. * * @param identifier the identifier * @param store the data store * @param verify verify if the record exists, and return null if not * @return the internal value or null */ static InternalValue getInternalValue(DataIdentifier identifier, DataStore store, boolean verify) throws DataStoreException { if (verify) { if (store.getRecordIfStored(identifier) == null) { return null; } } else { // access the record to ensure it is not garbage collected store.getRecord(identifier); } // it exists - so we don't need to stream it again // but we need to create a new object because the original // one might be in a different data store (repository) BLOBFileValue blob = BLOBInDataStore.getInstance(store, identifier); return new InternalValue(blob); }
/** * Test {@link MultiDataStoreAware#deleteRecord(DataIdentifier)}. */ protected void doDeleteRecordTest() throws Exception { Random random = randomGen; byte[] data1 = new byte[dataLength]; random.nextBytes(data1); DataRecord rec1 = ds.addRecord(new ByteArrayInputStream(data1)); byte[] data2 = new byte[dataLength]; random.nextBytes(data2); DataRecord rec2 = ds.addRecord(new ByteArrayInputStream(data2)); byte[] data3 = new byte[dataLength]; random.nextBytes(data3); DataRecord rec3 = ds.addRecord(new ByteArrayInputStream(data3)); ((MultiDataStoreAware)ds).deleteRecord(rec1.getIdentifier()); assertNull("rec1 should be null", ds.getRecordIfStored(rec1.getIdentifier())); assertEquals(new ByteArrayInputStream(data2), ds.getRecord(rec2.getIdentifier()).getStream()); assertEquals(new ByteArrayInputStream(data3), ds.getRecord(rec3.getIdentifier()).getStream()); }
@Test public void testReference() throws DataStoreException, IOException { String reference = "testReference"; String blobId = "test"; DataIdentifier testDI = new DataIdentifier(blobId); DataRecord testDR = new ByteArrayDataRecord("foo".getBytes(), testDI, reference); DataStore mockedDS = mock(DataStore.class); when(mockedDS.getRecordFromReference(reference)).thenReturn(testDR); when(mockedDS.getRecord(testDI)).thenReturn(testDR); when(mockedDS.getRecordIfStored(testDI)).thenReturn(testDR); DataStoreBlobStore ds = new DataStoreBlobStore(mockedDS); assertEquals(reference,ds.getReference(blobId)); assertEquals(blobId, BlobId.of(ds.getBlobId(reference)).blobId); assertEquals(BlobId.of(testDR).encodedValue(),ds.getBlobId(reference)); String inMemBlobId = InMemoryDataRecord.getInstance("foo".getBytes()) .getIdentifier().toString(); //For in memory record the reference should be null assertNull(ds.getReference(inMemBlobId)); }
/** * Test {@link MultiDataStoreAware#deleteRecord(DataIdentifier)}. */ protected void doDeleteRecordTest() throws Exception { ds = createDataStore(); Random random = randomGen; byte[] data1 = new byte[dataLength]; random.nextBytes(data1); DataRecord rec1 = ds.addRecord(new ByteArrayInputStream(data1)); byte[] data2 = new byte[dataLength]; random.nextBytes(data2); DataRecord rec2 = ds.addRecord(new ByteArrayInputStream(data2)); byte[] data3 = new byte[dataLength]; random.nextBytes(data3); DataRecord rec3 = ds.addRecord(new ByteArrayInputStream(data3)); ((MultiDataStoreAware)ds).deleteRecord(rec2.getIdentifier()); assertNull("rec2 should be null", ds.getRecordIfStored(rec2.getIdentifier())); assertEquals(new ByteArrayInputStream(data1), ds.getRecord(rec1.getIdentifier()).getStream()); assertEquals(new ByteArrayInputStream(data3), ds.getRecord(rec3.getIdentifier()).getStream()); ds.close(); }