IndexItem addRoot(IndexManager containerIndexManager,
ContainerId key) throws IOException {
if (map.containsKey(key)) {
removeRoot(containerIndexManager, key);
}
StoreLocation data = dataManager.storeDataItem(ROOT_MARSHALLER, key);
IndexItem newRoot = indexManager.createNewIndex();
newRoot.setKeyData(data);
IndexItem containerRoot = containerIndexManager.createNewIndex();
containerIndexManager.storeIndex(containerRoot);
newRoot.setValueOffset(containerRoot.getOffset());
IndexItem last = list.isEmpty() ? null : (IndexItem)list.getLast();
last = last == null ? root : last;
long prev = last.getOffset();
newRoot.setPreviousItem(prev);
indexManager.storeIndex(newRoot);
last.setNextItem(newRoot.getOffset());
indexManager.storeIndex(last);
map.put(key, newRoot);
list.add(newRoot);
return containerRoot;
}
|