Skip to content

Commit a8884fb

Browse files
committed
JavaDocs, minor
1 parent 697131c commit a8884fb

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

objectbox-java/src/main/java/io/objectbox/Box.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import java.util.HashMap;
2424
import java.util.List;
2525
import java.util.Map;
26+
import java.util.concurrent.Callable;
2627

2728
import javax.annotation.Nullable;
2829
import javax.annotation.concurrent.ThreadSafe;
@@ -169,6 +170,9 @@ void txCommitted(Transaction tx) {
169170
}
170171
}
171172

173+
/**
174+
* Called by {@link BoxStore#callInReadTx(Callable)} - does not throw so caller does not need try/finally.
175+
*/
172176
void readTxFinished(Transaction tx) {
173177
Cursor<T> cursor = activeTxCursor.get();
174178
if (cursor != null && cursor.getTx() == tx) {

objectbox-java/src/main/java/io/objectbox/BoxStore.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -603,10 +603,17 @@ public void runInReadTx(Runnable runnable) {
603603
}
604604
}
605605

606+
/**
607+
* Calls {@link #callInReadTx(Callable)} and retries in case a DbException is thrown.
608+
* If the given amount of attempts is reached, the last DbException will be thrown.
609+
* Experimental: API might change.
610+
*/
606611
@Experimental
607612
public <T> T callInReadTxWithRetry(Callable<T> callable, int attempts, int initialBackOffInMs, boolean logAndHeal) {
608613
if (attempts == 1) {
609614
return callInReadTx(callable);
615+
} else if (attempts < 1) {
616+
throw new IllegalArgumentException("Illegal value of attempts: " + attempts);
610617
}
611618
long backoffInMs = initialBackOffInMs;
612619
DbException lastException = null;
@@ -648,9 +655,9 @@ public <T> T callInReadTxWithRetry(Callable<T> callable, int attempts, int initi
648655
* This allows multiple read operations (gets) using a single consistent state of data.
649656
* Also, for a high number of read operations (thousands, e.g. in loops),
650657
* it is advised to run them in a single read transaction for efficiency reasons.
651-
* Note that any exception thrown by the given Callable will be wrapped in a RuntimeException.
658+
* Note that an exception thrown by the given Callable will be wrapped in a RuntimeException, if the exception is
659+
* not a RuntimeException itself.
652660
*/
653-
654661
public <T> T callInReadTx(Callable<T> callable) {
655662
Transaction tx = this.activeTx.get();
656663
// Only if not already set, allowing to call it recursively with first (outer) TX
@@ -659,7 +666,7 @@ public <T> T callInReadTx(Callable<T> callable) {
659666
activeTx.set(tx);
660667
try {
661668
return callable.call();
662-
} catch (DbException e) {
669+
} catch (RuntimeException e) {
663670
throw e;
664671
} catch (Exception e) {
665672
throw new RuntimeException("Callable threw exception", e);

0 commit comments

Comments
 (0)