private boolean checkForInsertion(final GetMode getMode,
final CursorImpl origCursor,
final CursorImpl dupCursor) {
final BIN origBIN = origCursor.getBIN();
final BIN dupBIN = dupCursor.getBIN();
final DBIN origDBIN = origCursor.getDupBIN();
/* If fetchTarget returns null below, a deleted LN was cleaned. */
boolean forward = true;
if (getMode == GetMode.PREV ||
getMode == GetMode.PREV_DUP ||
getMode == GetMode.PREV_NODUP) {
forward = false;
}
boolean ret = false;
if (origBIN != dupBIN) {
/* We jumped to the next BIN during getNext(). */
origCursor.latchBINs();
try {
if (origDBIN == null) {
if (forward) {
if (origBIN.getNEntries() - 1 >
origCursor.getIndex()) {
/*
* We were adjusted to something other than the
* last entry so some insertion happened.
*/
for (int i = origCursor.getIndex() + 1;
i < origBIN.getNEntries();
i++) {
if (!origBIN.isEntryKnownDeleted(i)) {
final Node n = origBIN.fetchTarget(i);
if (n != null && !n.containsDuplicates()) {
final LN ln = (LN) n;
/* See comment above about locking. */
if (!ln.isDeleted()) {
ret = true;
break;
}
}
} else {
/* Need to check the DupCountLN. */
}
}
}
} else {
if (origCursor.getIndex() > 0) {
/*
* We were adjusted to something other than the
* first entry so some insertion happened.
*/
for (int i = 0; i < origCursor.getIndex(); i++) {
if (!origBIN.isEntryKnownDeleted(i)) {
final Node n = origBIN.fetchTarget(i);
if (n != null && !n.containsDuplicates()) {
final LN ln = (LN) n;
/* See comment above about locking. */
if (!ln.isDeleted()) {
ret = true;
break;
}
} else {
/* Need to check the DupCountLN. */
}
}
}
}
}
}
} finally {
origCursor.releaseBINs();
}
return ret;
}
if (origDBIN != dupCursor.getDupBIN() &&
origCursor.getIndex() == dupCursor.getIndex() &&
getMode != GetMode.NEXT_NODUP &&
getMode != GetMode.PREV_NODUP) {
/* Same as above, only for the dupBIN. */
origCursor.latchBINs();
try {
if (forward) {
if (origDBIN.getNEntries() - 1 >
origCursor.getDupIndex()) {
/*
* We were adjusted to something other than the last
* entry so some insertion happened.
*/
for (int i = origCursor.getDupIndex() + 1;
i < origDBIN.getNEntries();
i++) {
if (!origDBIN.isEntryKnownDeleted(i)) {
final Node n = origDBIN.fetchTarget(i);
final LN ln = (LN) n;
/* See comment above about locking. */
if (n != null && !ln.isDeleted()) {
ret = true;
break;
}
}
}
}
} else {
if (origCursor.getDupIndex() > 0) {
/*
* We were adjusted to something other than the first
* entry so some insertion happened.
*/
for (int i = 0; i < origCursor.getDupIndex(); i++) {
if (!origDBIN.isEntryKnownDeleted(i)) {
final Node n = origDBIN.fetchTarget(i);
final LN ln = (LN) n;
/* See comment above about locking. */
if (n != null && !ln.isDeleted()) {
ret = true;
break;