use of com.enonic.xp.blob.BlobKey in project xp by enonic.
the class FileBlobRecordTest method lastModified.
@Test
public void lastModified() throws Exception {
final BlobKey key = BlobKey.from("test");
final Path file = Files.createFile(this.temporaryFolder.resolve("test"));
final FileBlobRecord record = new FileBlobRecord(key, file);
assertEquals(Files.getLastModifiedTime(file).toMillis(), record.lastModified());
}
use of com.enonic.xp.blob.BlobKey in project xp by enonic.
the class FileBlobRecordTest method testAccessors.
@Test
public void testAccessors() throws Exception {
final BlobKey key = BlobKey.from("test");
final Path file = Files.createFile(this.temporaryFolder.resolve("test"));
final FileBlobRecord record = new FileBlobRecord(key, file);
assertSame(key, record.getKey());
assertNotNull(record.getBytes());
assertEquals(0, record.getLength());
}
use of com.enonic.xp.blob.BlobKey in project xp by enonic.
the class FileBlobStoreTest method getRecord.
@Test
public void getRecord() {
final BlobKey key = createRecord("hello").getKey();
final BlobRecord record = this.blobStore.getRecord(this.segment, key);
assertNotNull(record);
}
use of com.enonic.xp.blob.BlobKey in project xp by enonic.
the class AbstractDumpBlobStore method addRecord.
@Override
public BlobKey addRecord(final Segment segment, final ByteSource in) throws BlobStoreException {
try {
final BlobKey blobKey = BlobKey.from(in);
writeRecord(segment, blobKey, in);
return blobKey;
} catch (final IOException e) {
throw new BlobStoreException("Failed to add blob", e);
}
}
use of com.enonic.xp.blob.BlobKey in project xp by enonic.
the class VersionTableVacuumCommand method doProcessRepository.
private void doProcessRepository(final Repository repository) {
int counter = 0;
NodeVersionId lastVersionId = null;
NodeVersionQuery query = createQuery(lastVersionId);
NodeVersionQueryResult versionsResult = nodeService.findVersions(query);
long hits = versionsResult.getHits();
final long totalHits = versionsResult.getTotalHits();
if (listener != null) {
listener.stepBegin(repository.getId().toString(), totalHits);
}
while (hits > 0) {
final List<NodeVersionId> versionsToDelete = new ArrayList<>();
final Set<BlobKey> nodeBlobToCheckSet = new HashSet<>();
final Set<BlobKey> binaryBlobToCheckSet = new HashSet<>();
final NodeVersionsMetadata versions = versionsResult.getNodeVersionsMetadata();
for (NodeVersionMetadata version : versions) {
final boolean toDelete = processVersion(repository, version);
if (toDelete) {
result.deleted();
versionsToDelete.add(version.getNodeVersionId());
nodeBlobToCheckSet.add(version.getNodeVersionKey().getNodeBlobKey());
binaryBlobToCheckSet.addAll(version.getBinaryBlobKeys().getSet());
} else {
result.inUse();
}
lastVersionId = version.getNodeVersionId();
counter++;
}
versionService.delete(versionsToDelete, InternalContext.from(ContextAccessor.current()));
nodeBlobToCheckSet.stream().filter(blobKey -> !isBlobKeyUsed(blobKey, VersionIndexPath.NODE_BLOB_KEY)).forEach(blobKey -> removeNodeBlobRecord(repository.getId(), NodeConstants.NODE_SEGMENT_LEVEL, blobKey));
binaryBlobToCheckSet.stream().filter(blobKey -> !isBlobKeyUsed(blobKey, VersionIndexPath.BINARY_BLOB_KEYS)).forEach(blobKey -> removeNodeBlobRecord(repository.getId(), NodeConstants.BINARY_SEGMENT_LEVEL, blobKey));
query = createQuery(lastVersionId);
versionsResult = nodeService.findVersions(query);
hits = versionsResult.getHits();
}
if (listener != null) {
listener.processed(counter);
}
}
Aggregations