使用文档我使用'Chunk'列表存储我的BLOB 它们存储在名为default的群集中,ID为3。
如果我要求这样的大块 从#3:1中选择计数(*)我得到1
然后我申请 从#3:1删除它返回0
再一次 从#3中选择计数(*):1我返回1
如何删除此文档以及为什么删除不适用?
创建块:
private ODocument save(OrientGraph graph, byte[] content) throws IOException {
graph.getRawGraph().declareIntent(new OIntentMassiveInsert());
List<ORID> chunks = new ArrayList<ORID>();
InputStream in = new BufferedInputStream(new ByteArrayInputStream(content));
while (in.available() > 0) {
final ORecordBytes chunk = new ORecordBytes();
chunk.fromInputStream(in, BLOCK_SIZE);
graph.getRawGraph().save(chunk);
chunks.add(chunk.getIdentity());
}
ODocument record = new ODocument();
record.field(Resource.RESOURCE_FIELD_CHUNKS, chunks);
log.debug("Splitted file to {}", chunks.size());
graph.getRawGraph().save(record);
graph.getRawGraph().declareIntent(null);
return record;
}
然后阅读就可以了
ORecordLazyList blocks = doc.field(Resource.RESOURCE_FIELD_CONTENT);
if (blocks == null) {
log.error("No data content for {}", rid);
return;
}
for (OIdentifiable id : (List<OIdentifiable>) blocks) {
ORecordBytes chunk = (ORecordBytes) id.getRecord();
chunk.toOutputStream(out);
chunk.unload();
}
但是删除使用SQL创建删除命令会返回0 并尝试迭代返回一个空对象
String selectChunks = String.format("select %s from %s ",
Resource.RESOURCE_FIELD_CONTENT, resourceID);
Get(selectChunks, graph).forEach(ids -> {
OrientVertex rs = (OrientVertex) ids.getProperty(Resource.RESOURCE_FIELD_CONTENT);
OrientElementIterable chunks = rs.getProperty(Resource.RESOURCE_FIELD_CHUNKS);
chunks.forEach( chunk -> {
CHUNK IS NULL !!!! no delete()
});
});
使用
String selectChunks = String.format("select %s.@rid.asString() from %s ",
Resource.RESOURCE_FIELD_CONTENT + "." + Resource.RESOURCE_FIELD_CHUNKS, resourceID);
将返回id但与SQL命令结合返回0个已修改的条目。