use of com.enonic.xp.blob.Segment in project xp by enonic.
the class BinaryServiceImpl method store.
@Override
public AttachedBinary store(final RepositoryId repositoryId, final BinaryAttachment binaryAttachment) {
final Segment segment = RepositorySegmentUtils.toSegment(repositoryId, NodeConstants.BINARY_SEGMENT_LEVEL);
final BlobRecord blob = this.blobStore.addRecord(segment, binaryAttachment.getByteSource());
return new AttachedBinary(binaryAttachment.getReference(), blob.getKey().toString());
}
use of com.enonic.xp.blob.Segment in project xp by enonic.
the class AbstractDumpReader method getBinary.
@Override
public ByteSource getBinary(final RepositoryId repositoryId, final String blobKey) {
final Segment segment = RepositorySegmentUtils.toSegment(repositoryId, DumpConstants.DUMP_BINARY_SEGMENT_LEVEL);
final DumpBlobRecord record = this.dumpBlobStore.getRecord(segment, BlobKey.from(blobKey));
if (record == null) {
throw new RepoLoadException("Cannot find referred blob id " + blobKey + " in dump");
}
return record.getBytes();
}
use of com.enonic.xp.blob.Segment in project xp by enonic.
the class AbstractDumpWriter method writeBinaryBlob.
@Override
public void writeBinaryBlob(final RepositoryId repositoryId, final BlobKey blobKey) {
final Segment dumpSegment = RepositorySegmentUtils.toSegment(repositoryId, DumpConstants.DUMP_BINARY_SEGMENT_LEVEL);
final BlobRecord binaryRecord = blobStore.getRecord(dumpSegment, blobKey);
if (binaryRecord == null) {
throw new RepoDumpException("Cannot write binary with key [" + blobKey + "], not found in blobStore");
}
final Segment segment = RepositorySegmentUtils.toSegment(repositoryId, NodeConstants.BINARY_SEGMENT_LEVEL);
this.dumpBlobStore.addRecord(segment, binaryRecord.getBytes());
}
use of com.enonic.xp.blob.Segment in project xp by enonic.
the class AbstractDumpWriter method writeNodeVersionBlobs.
@Override
public void writeNodeVersionBlobs(final RepositoryId repositoryId, final NodeVersionKey nodeVersionKey) {
final Segment nodeDumpSegment = RepositorySegmentUtils.toSegment(repositoryId, DumpConstants.DUMP_NODE_SEGMENT_LEVEL);
final BlobRecord existingNodeBlobRecord = blobStore.getRecord(nodeDumpSegment, nodeVersionKey.getNodeBlobKey());
if (existingNodeBlobRecord == null) {
throw new RepoDumpException("Cannot write node blob with key [" + nodeVersionKey.getNodeBlobKey() + "], not found in blobStore");
}
final Segment indexConfigDumpSegment = RepositorySegmentUtils.toSegment(repositoryId, DumpConstants.DUMP_INDEX_CONFIG_SEGMENT_LEVEL);
final BlobRecord existingIndexConfigBlobRecord = blobStore.getRecord(indexConfigDumpSegment, nodeVersionKey.getIndexConfigBlobKey());
if (existingIndexConfigBlobRecord == null) {
throw new RepoDumpException("Cannot write index config blob with key [" + nodeVersionKey.getIndexConfigBlobKey() + "], not found in blobStore");
}
final Segment accessControlDumpSegment = RepositorySegmentUtils.toSegment(repositoryId, DumpConstants.DUMP_ACCESS_CONTROL_SEGMENT_LEVEL);
final BlobRecord existingAccessControlBlobRecord = blobStore.getRecord(accessControlDumpSegment, nodeVersionKey.getAccessControlBlobKey());
if (existingAccessControlBlobRecord == null) {
throw new RepoDumpException("Cannot write access control blob with key [" + nodeVersionKey.getAccessControlBlobKey() + "], not found in blobStore");
}
final Segment nodeSegment = RepositorySegmentUtils.toSegment(repositoryId, NodeConstants.NODE_SEGMENT_LEVEL);
this.dumpBlobStore.addRecord(nodeSegment, existingNodeBlobRecord.getBytes());
final Segment indexConfigSegment = RepositorySegmentUtils.toSegment(repositoryId, NodeConstants.INDEX_CONFIG_SEGMENT_LEVEL);
this.dumpBlobStore.addRecord(indexConfigSegment, existingIndexConfigBlobRecord.getBytes());
final Segment accessControlSegment = RepositorySegmentUtils.toSegment(repositoryId, NodeConstants.ACCESS_CONTROL_SEGMENT_LEVEL);
this.dumpBlobStore.addRecord(accessControlSegment, existingAccessControlBlobRecord.getBytes());
}
use of com.enonic.xp.blob.Segment in project xp by enonic.
the class NodeVersionServiceImpl method getFromBlob.
private NodeVersion getFromBlob(final NodeVersionKey nodeVersionKey, final InternalContext context) {
final Segment nodeSegment = RepositorySegmentUtils.toSegment(context.getRepositoryId(), NodeConstants.NODE_SEGMENT_LEVEL);
final BlobRecord nodeBlobRecord = blobStore.getRecord(nodeSegment, nodeVersionKey.getNodeBlobKey());
if (nodeBlobRecord == null) {
throw new IllegalArgumentException("Cannot get node blob with blobKey: " + nodeVersionKey.getNodeBlobKey() + ": blob is null");
}
final Segment indexConfigSegment = RepositorySegmentUtils.toSegment(context.getRepositoryId(), NodeConstants.INDEX_CONFIG_SEGMENT_LEVEL);
final BlobRecord indexConfigBlobRecord = blobStore.getRecord(indexConfigSegment, nodeVersionKey.getIndexConfigBlobKey());
if (indexConfigBlobRecord == null) {
throw new IllegalArgumentException("Cannot get index config blob with blobKey: " + nodeVersionKey.getIndexConfigBlobKey() + ": blob is null");
}
final Segment accessControlSegment = RepositorySegmentUtils.toSegment(context.getRepositoryId(), NodeConstants.ACCESS_CONTROL_SEGMENT_LEVEL);
final BlobRecord accessControlBlobRecord = blobStore.getRecord(accessControlSegment, nodeVersionKey.getAccessControlBlobKey());
if (accessControlBlobRecord == null) {
throw new IllegalArgumentException("Cannot get access control blob with blobKey: " + nodeVersionKey.getAccessControlBlobKey() + ": blob is null");
}
try {
final byte[] nodeString = nodeBlobRecord.getBytes().read();
final byte[] indexConfigString = indexConfigBlobRecord.getBytes().read();
final byte[] accessControlString = accessControlBlobRecord.getBytes().read();
return this.nodeVersionJsonSerializer.toNodeVersion(nodeString, indexConfigString, accessControlString);
} catch (IOException e) {
if (blobStore instanceof CachingBlobStore) {
((CachingBlobStore) blobStore).invalidate(indexConfigSegment, nodeBlobRecord.getKey());
((CachingBlobStore) blobStore).invalidate(indexConfigSegment, indexConfigBlobRecord.getKey());
((CachingBlobStore) blobStore).invalidate(indexConfigSegment, accessControlBlobRecord.getKey());
}
throw new RuntimeException("Failed to load blobs with keys: " + nodeBlobRecord.getKey() + ", " + indexConfigBlobRecord.getKey() + ", " + accessControlBlobRecord.getKey(), e);
}
}
Aggregations