if (putMode != PutMode.CURRENT && key == null) {
throw new IllegalArgumentException
("put passed a null DatabaseEntry arg");
}
CursorImpl original = null;
OperationStatus status = OperationStatus.NOTFOUND;
CursorImpl dup = null;
try {
/* Latch and clone. */
original = cursorImpl;
if (putMode == PutMode.CURRENT) {
/* Call addCursor for putCurrent. */
dup = original.cloneCursor(true);
} else {
/*
* Do not call addCursor when inserting. Copy the position of
* nextKeyCursor if available.
*/
dup = original.cloneCursor(false, nextKeyCursor);
}
/* Perform operation. */
if (putMode == PutMode.CURRENT) {
status = dup.putCurrent(data, key, returnOldData);
} else if (putMode == PutMode.OVERWRITE) {
status = dup.put(key, data, returnOldData);
} else if (putMode == PutMode.NOOVERWRITE) {
status = dup.putNoOverwrite(key, data);
} else if (putMode == PutMode.NODUP) {
status = dup.putNoDupData(key, data);
} else {
throw new InternalException("unknown PutMode");
}
return status;
} finally {
if (original != null) {
original.releaseBINs();
}
boolean success = (status == OperationStatus.SUCCESS);
if (cursorImpl == dup) {
if (!success) {
cursorImpl.reset();
}
} else {
if (success) {
original.close();
cursorImpl = dup;
} else {
if (dup != null) {
dup.close();
}
}
}
}
}