@Override public DocumentWriter removeChild( String id ) { EditableArray children = federatedDocument.getArray(DocumentTranslator.CHILDREN); if (children != null) { for (int i = 0; i != children.size(); ++i) { Object val = children.get(i); if (val instanceof Document) { Document child = (Document)val; if (child.getString(DocumentTranslator.KEY).equals(id)) { children.remove(i); return this; } } } } return this; }
@Override public DocumentWriter removeChild( String id ) { EditableArray children = federatedDocument.getArray(DocumentTranslator.CHILDREN); if (children != null) { for (int i = 0; i != children.size(); ++i) { Object val = children.get(i); if (val instanceof Document) { Document child = (Document)val; if (child.getString(DocumentTranslator.KEY).equals(id)) { children.remove(i); return this; } } } } return this; }
protected void removeFederatedSegments( EditableDocument federatedDocument, Set<String> externalNodeKeys ) { if (!federatedDocument.containsField(FEDERATED_SEGMENTS)) { return; } EditableArray federatedSegments = federatedDocument.getArray(FEDERATED_SEGMENTS); for (int i = 0; i < federatedSegments.size(); i++) { Object federatedSegment = federatedSegments.get(i); assert federatedSegment instanceof Document; String segmentKey = getKey((Document)federatedSegment); if (externalNodeKeys.contains(segmentKey)) { federatedSegments.remove(i); } } if (federatedSegments.isEmpty()) { federatedDocument.remove(FEDERATED_SEGMENTS); } }
protected void removeFederatedSegments( EditableDocument federatedDocument, Set<String> externalNodeKeys ) { if (!federatedDocument.containsField(FEDERATED_SEGMENTS)) { return; } EditableArray federatedSegments = federatedDocument.getArray(FEDERATED_SEGMENTS); for (int i = 0; i < federatedSegments.size(); i++) { Object federatedSegment = federatedSegments.get(i); assert federatedSegment instanceof Document; String segmentKey = getKey((Document)federatedSegment); if (externalNodeKeys.contains(segmentKey)) { federatedSegments.remove(i); } } if (federatedSegments.isEmpty()) { federatedDocument.remove(FEDERATED_SEGMENTS); } }
for (int i = 0; i < providers.size(); i++) { providerPosition = i; Document document = (Document)providers.get(i);
assert tolerance < targetCountPerBlock; int total = children.size(); int numFullBlocks = total / targetCountPerBlock; EditableDocument blockDoc = Schematic.newDocument(); EditableDocument childInfo = blockDoc.setDocument(CHILDREN_INFO); childInfo.setNumber(BLOCK_SIZE, blockChildren.size()); if (nextBlockKey != null) { childInfo.setString(NEXT_BLOCK, nextBlockKey); childInfo = document.setDocument(CHILDREN_INFO); childInfo.setNumber(BLOCK_SIZE, newChildren.size()); childInfo.setString(NEXT_BLOCK, firstNewBlockKey);
assert tolerance < targetCountPerBlock; int total = children.size(); int numFullBlocks = total / targetCountPerBlock; EditableDocument blockDoc = Schematic.newDocument(); EditableDocument childInfo = blockDoc.setDocument(CHILDREN_INFO); childInfo.setNumber(BLOCK_SIZE, blockChildren.size()); if (nextBlockKey != null) { childInfo.setString(NEXT_BLOCK, nextBlockKey); childInfo = document.setDocument(CHILDREN_INFO); childInfo.setNumber(BLOCK_SIZE, newChildren.size()); childInfo.setString(NEXT_BLOCK, firstNewBlockKey);
if (selfContained) { int total = children.size(); if (total < targetCountPerBlock + tolerance) { String nextKey = docInfo != null ? docInfo.getString(NEXT_BLOCK) : null; children = doc.getArray(CHILDREN); int count = children.size(); boolean isFirst = doc == document; if (count > (targetCountPerBlock + tolerance)) {
if (selfContained) { int total = children.size(); if (total < targetCountPerBlock + tolerance) { String nextKey = docInfo != null ? docInfo.getString(NEXT_BLOCK) : null; children = doc.getArray(CHILDREN); int count = children.size(); boolean isFirst = doc == document; if (count > (targetCountPerBlock + tolerance)) {
lastDocInfo.setNumber(BLOCK_SIZE, lastChildren.size());
lastDocInfo.setNumber(BLOCK_SIZE, lastChildren.size());
@Test public void shouldMergeDocumentWithTooSmallChildReferencesSegmentInFirstBlock() throws Exception { NodeKey key = new NodeKey("source1works1-childB"); transactions().begin(); EditableDocument doc = workspaceCache.documentStore().edit(key.toString(), true); EditableArray children = doc.getArray(DocumentTranslator.CHILDREN); String nextBlock = doc.getDocument(DocumentTranslator.CHILDREN_INFO).getString(DocumentTranslator.NEXT_BLOCK); optimizer.mergeChildren(key, doc, children, true, nextBlock); transactions().commit(); // Refetch the document, which should no longer be segmented ... transactions().begin(); doc = workspaceCache.documentStore().edit(key.toString(), true); assertInfo(key.toString(), 2, null, null, true, 0); children = doc.getArray(DocumentTranslator.CHILDREN); transactions().commit(); assertThat(children.size(), is(2)); assertChildren(doc, name("childC"), name("childD")); print(false); print(doc); }