Skip to content

Commit

Permalink
minor: reduced manual cursor creations
Browse files Browse the repository at this point in the history
  • Loading branch information
penemue committed Jul 23, 2015
1 parent abd6d7b commit 9eb1262
Showing 1 changed file with 8 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,7 @@ public void put(@NotNull final PersistentStoreTransaction txn,
if (oldValue == null) {
success = allPropsIndex.put(envTxn, IntegerBinding.intToCompressedEntry(propertyId), secondaryValue);
} else {
success = deleteFromCursorAndClose(
valueIdx.openCursor(envTxn), secondaryValue, createSecondaryKeys(store.getPropertyTypes(), oldValue, type));
success = deleteFromStore(envTxn, valueIdx, secondaryValue, createSecondaryKeys(store.getPropertyTypes(), oldValue, type));
}
if (success) {
for (final ByteIterable secondaryKey : createSecondaryKeys(store.getPropertyTypes(), value, type)) {
Expand All @@ -118,10 +117,9 @@ public boolean deleteNoFail(@NotNull final PersistentStoreTransaction txn,
final Transaction envTxn = txn.getEnvironmentTransaction();
final ByteIterable secondaryValue = LongBinding.longToCompressedEntry(localId);
return primaryStore.delete(envTxn, key) &&
deleteFromCursorAndClose(getOrCreateValueIndex(txn, propertyId).openCursor(envTxn),
deleteFromStore(envTxn, getOrCreateValueIndex(txn, propertyId),
secondaryValue, createSecondaryKeys(store.getPropertyTypes(), value, type)) &&
deleteFromCursorAndClose(allPropsIndex.openCursor(envTxn),
secondaryValue, IntegerBinding.intToCompressedEntry(propertyId));
deleteFromStore(envTxn, allPropsIndex, secondaryValue, IntegerBinding.intToCompressedEntry(propertyId));
}

public Store getPrimaryIndex() {
Expand Down Expand Up @@ -196,10 +194,11 @@ private String valueIndexName(final int propertyId) {
return name + PROP_VALUE_IDX + propertyId;
}

private static boolean deleteFromCursorAndClose(@NotNull final Cursor cursor,
@NotNull final ByteIterable value,
@NotNull final ByteIterable... keys) {
try {
private static boolean deleteFromStore(@NotNull final Transaction txn,
@NotNull final Store store,
@NotNull final ByteIterable value,
@NotNull final ByteIterable... keys) {
try (Cursor cursor = store.openCursor(txn)) {
for (final ByteIterable key : keys) {
if (!cursor.getSearchBoth(key, value)) {
// repeat for debugging
Expand All @@ -213,8 +212,6 @@ private static boolean deleteFromCursorAndClose(@NotNull final Cursor cursor,
}
}
return true;
} finally {
cursor.close();
}
}

Expand Down

0 comments on commit 9eb1262

Please sign in to comment.