return values.size() > 0 ? values : null;
}
private PageNumber store(Key[] keys, byte[] value, short mode, int level, PageNumber root, KernelContext kContext) throws ChaiDBException {
PageNumber newRoot = null;
if (level == getLayers()) {
newRoot = super.store(keys[level - 1], value, mode, root, kContext);
} else {
BTreePage rootPage = getPage(root);
if (rootPage.getPage() == null) {
rootPage = BTreePage.newPage(btreeSpec, getBuffer(), kContext);
rootPage.setLeaf();
rootPage.setPrevPage(new PageNumber(id, 0, 0)); // root
newRoot = rootPage.pageNumber;
}
BTreePage leafPage = rootPage.getLeaf(keys[level - 1], kContext, BTreePage.INSERT);
//unfix rootPage
getBuffer().releasePage(id, rootPage.pageNumber, false);
//find the next layer root
BTreeNode node = leafPage.search(keys[level - 1], kContext);
if (node != null) root = (PageNumber) convertValue(node.getData(kContext), level);
else root.setPageNumber(BTreeSpec.INVALID_PAGENO);
PageNumber tmpPgNum = store(keys, value, mode, level + 1, root, kContext);
boolean leafPageUpdated = (tmpPgNum != null);
if (tmpPgNum != null)
tmpPgNum = leafPage.insert(keys[level - 1], ByteTool.intToBytes(tmpPgNum.getPageNumber(), btreeSpec.isMsbFirst()), STORE_REPLACE, kContext);
getBuffer().releasePage(id, leafPage.pageNumber, leafPageUpdated);
//remember the new root
if (tmpPgNum != null) newRoot = tmpPgNum;