throw new TransactionException("Failed to commit the transaction in the defined retries.");
}
public boolean delete(Integer value, Context __transactionContext__){
try{
// System.err.println("\ndelete " + value);
DirectoryManager locator = HyFlow.getLocator();
String next = HEAD;
String prev = null;
boolean right = true;
Node node;
do{
node = (Node)locator.open(next, "s");
if(value > node.getValue(__transactionContext__)){
prev = next;
next = node.getRightChild(__transactionContext__);
right = true;
}else if(value < node.getValue(__transactionContext__)){
prev = next;
next = node.getLeftChild(__transactionContext__);
right = false;
}else{
Node prevNode = (Node)locator.open(prev); //open previous node for write
Node deletedNode = (Node)locator.open(next); //reopen for write to be deleted
String replacement;
if(deletedNode.getLeftChild(__transactionContext__)==null){
// System.err.println("replace with right child");
replacement = deletedNode.getRightChild(__transactionContext__);
}else if(deletedNode.getRightChild(__transactionContext__)==null){
// System.err.println("replace with left child");
replacement = deletedNode.getLeftChild(__transactionContext__);
}else{ // get left most in right tree
// System.err.println("replace with left most in right tree");
String next2 = deletedNode.getRightChild(__transactionContext__);
Node currNode2 = null;
Node prevNode2 = null;
do{
prevNode2 = currNode2;
replacement = next2;
currNode2 = (Node)locator.open(next2, "r");
next2 = currNode2.getLeftChild(__transactionContext__);
}while(next2!=null);
if(prevNode2!=null){ // disconnect replacement node from its parent
Node prevNode2w = (Node)locator.open(prevNode2.getId()); //open previous node for write
prevNode2w.setLeftChild(currNode2.getRightChild(__transactionContext__), __transactionContext__);
}
Node currNode2w = (Node)locator.open(replacement); //replace
currNode2w.setLeftChild(node.getLeftChild(__transactionContext__), __transactionContext__);
if(!replacement.equals(node.getRightChild(__transactionContext__)))
currNode2w.setRightChild(node.getRightChild(__transactionContext__), __transactionContext__);
}
if(right)
prevNode.setRightChild(replacement, __transactionContext__);
else
prevNode.setLeftChild(replacement, __transactionContext__);
locator.delete(deletedNode);
return true;
}
}while(next!=null);
// System.err.println("Nothing to Delete....");
Node last = ((Node)locator.open(node.getId(), "r")); // reopen last node for read
last.getValue(__transactionContext__); // force add to the readset
Logger.debug("Nothing to Delete....");
return false;
} finally{
try {