if (node.isLeafNode())
{
K expectedKey = nodeDef.getKey();
if (expectedKey != null && (!node.getRecords().get(0).getKey().equals(nodeDef.getKey())))
{
throw new DatabaseException("Expected first key " + expectedKey + ". Got " + node.getRecords().get(0).getKey());
}
if (m_nodeRepository.leafNodeHasPointersToAdjacentLeafNodes())
{
BPlusTreeLeafNode<K, V> lnode = (BPlusTreeLeafNode<K, V>) node;
if (lnode.getLeafNodeToTheLeftPointer() != null)
{
BPlusTreeLeafNode<K, V> nodeToTheLeft = (BPlusTreeLeafNode<K, V>) m_nodeRepository.readNode(lnode.getLeafNodeToTheLeftPointer().longValue(), null);
List<KeyAndValue<K, V>> lrecords = nodeToTheLeft.getRecords();
K leftNodeLastKey = lrecords.get(lrecords.size() - 1).getKey();
K thisNodeFirstKey = lnode.getRecords().get(0).getKey();
if (compareKeys(thisNodeFirstKey, leftNodeLastKey) <= 0)
{
throw new DatabaseException("The first key of node at position " + node.getPosition() + ", " + thisNodeFirstKey + ", was less than the last key of node at position " + nodeToTheLeft.getPosition() + ", " + leftNodeLastKey);
}
if (nodeToTheLeft.getLeafNodeToTheRightPointer().longValue() != node.getPosition())
{
throw new DatabaseException("Adjacent node pointer error for node to the left: (this node) -> (node to the left) -> (this node): " + node.getPosition() + " -> " + lnode.getLeafNodeToTheLeftPointer() + " -> " + nodeToTheLeft.getLeafNodeToTheRightPointer());
}
}
if (lnode.getLeafNodeToTheRightPointer() != null)
{
BPlusTreeLeafNode<K, V> nodeToTheRight = (BPlusTreeLeafNode<K, V>) m_nodeRepository.readNode(lnode.getLeafNodeToTheRightPointer().longValue(), null);
K rightNodeFirstKey = nodeToTheRight.getRecords().get(0).getKey();
K thisNodeLastKey = lnode.getRecords().get(lnode.getRecords().size() - 1).getKey();
if (compareKeys(thisNodeLastKey, rightNodeFirstKey) >= 0)
{
throw new DatabaseException("The last key of node at position " + node.getPosition() + ", " + thisNodeLastKey + ", was greater than the first key of node at position " + nodeToTheRight.getPosition() + ", " + rightNodeFirstKey);
}
if (nodeToTheRight.getLeafNodeToTheLeftPointer().longValue() != node.getPosition())
{
throw new DatabaseException("Adjacent node pointer error for node to the right: (this node) -> (node to the right) -> (this node): " + node.getPosition() + " -> " + lnode.getLeafNodeToTheRightPointer() + " -> " + nodeToTheRight.getLeafNodeToTheLeftPointer());
}
}
}
}
else
{
BPlusTreeNonLeafNode<K> nlNode = (BPlusTreeNonLeafNode<K>) node;
if (!(first || nlNode.getKeyForFirstPointer() != null))
{
throw new DatabaseException("The key to the first pointer was null in a non-leaf node that was not the leftmost node: " + node);
}
nextLevelNodes.add(new KeyAndValue<K, Long>(nlNode.getKeyForFirstPointer(), nlNode.getFirstPointer(), m_keyComparator));
for (KeyAndValue<K, Long> hap : nlNode.getRecords())
{
nextLevelNodes.add(hap);