Skip to content

Commit a0f171b

Browse files
InternalAccess: sanction their use, annotate all methods as internal
1 parent 6aea0f4 commit a0f171b

File tree

3 files changed

+20
-16
lines changed

3 files changed

+20
-16
lines changed

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

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,12 @@
2222
import io.objectbox.sync.SyncClient;
2323

2424
/**
25-
* This is a workaround to access internal APIs, notably for tests.
26-
* <p>
27-
* To avoid this, future APIs should be exposed via interfaces with an internal implementation that can be used by
28-
* tests.
25+
* Exposes internal APIs to tests and code in other packages.
2926
*/
3027
@Internal
3128
public class InternalAccess {
3229

30+
@Internal
3331
public static Transaction getActiveTx(BoxStore boxStore) {
3432
Transaction tx = boxStore.activeTx.get();
3533
if (tx == null) {
@@ -39,31 +37,43 @@ public static Transaction getActiveTx(BoxStore boxStore) {
3937
return tx;
4038
}
4139

40+
@Internal
4241
public static long getHandle(Transaction tx) {
4342
return tx.internalHandle();
4443
}
4544

45+
@Internal
4646
public static void setSyncClient(BoxStore boxStore, @Nullable SyncClient syncClient) {
4747
boxStore.setSyncClient(syncClient);
4848
}
4949

50+
@Internal
5051
public static <T> Cursor<T> getWriter(Box<T> box) {
5152
return box.getWriter();
5253
}
5354

55+
@Internal
5456
public static <T> Cursor<T> getActiveTxCursor(Box<T> box) {
5557
return box.getActiveTxCursor();
5658
}
5759

60+
@Internal
5861
public static <T> long getActiveTxCursorHandle(Box<T> box) {
5962
return box.getActiveTxCursor().internalHandle();
6063
}
6164

65+
@Internal
6266
public static <T> void commitWriter(Box<T> box, Cursor<T> writer) {
6367
box.commitWriter(writer);
6468
}
6569

66-
/** Makes creation more expensive, but lets Finalizers show the creation stack for dangling resources. */
70+
/**
71+
* Makes creation more expensive, but lets Finalizers show the creation stack for dangling resources.
72+
* <p>
73+
* Currently used by integration tests.
74+
*/
75+
@SuppressWarnings("unused")
76+
@Internal
6777
public static void enableCreationStackTracking() {
6878
Transaction.TRACK_CREATION_STACK = true;
6979
Cursor.TRACK_CREATION_STACK = true;

objectbox-java/src/main/java/io/objectbox/query/InternalQueryAccess.java renamed to objectbox-java/src/main/java/io/objectbox/query/InternalAccess.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,12 @@
1919
import io.objectbox.annotation.apihint.Internal;
2020

2121
/**
22-
* This is a workaround to access internal APIs for tests.
23-
* <p>
24-
* To avoid this, future APIs should be exposed via interfaces with an internal implementation that can be used by
25-
* tests.
22+
* Exposes internal APIs to tests and code in other packages.
2623
*/
2724
@Internal
28-
public class InternalQueryAccess {
25+
public class InternalAccess {
2926

30-
/**
31-
* For testing only.
32-
*/
27+
@Internal
3328
public static <T> void nativeFindFirst(Query<T> query, long cursorHandle) {
3429
query.nativeFindFirst(query.handle, cursorHandle);
3530
}

tests/objectbox-java-test/src/test/java/io/objectbox/TransactionTest.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
import io.objectbox.exception.DbException;
3737
import io.objectbox.exception.DbExceptionListener;
3838
import io.objectbox.exception.DbMaxReadersExceededException;
39-
import io.objectbox.query.InternalQueryAccess;
4039
import io.objectbox.query.Query;
4140

4241

@@ -339,15 +338,15 @@ public void nativeCallInTx_storeIsClosed_throws() throws InterruptedException {
339338
Box<TestEntity> box = store.boxFor(TestEntity.class);
340339
Query<TestEntity> query = box.query().build();
341340
// Obtain Cursor handle before closing the Store as getActiveTxCursor() has a closed check
342-
long cursorHandle = io.objectbox.InternalAccess.getActiveTxCursorHandle(box);
341+
long cursorHandle = InternalAccess.getActiveTxCursorHandle(box);
343342

344343
callableIsReady.countDown();
345344
try {
346345
if (!storeIsClosed.await(5, TimeUnit.SECONDS)) {
347346
throw new IllegalStateException("Store did not close within 5 seconds");
348347
}
349348
// Call native query API within the transaction (opened by callInReadTx below)
350-
InternalQueryAccess.nativeFindFirst(query, cursorHandle);
349+
io.objectbox.query.InternalAccess.nativeFindFirst(query, cursorHandle);
351350
query.close();
352351
} catch (Exception e) {
353352
callableException.set(e);

0 commit comments

Comments
 (0)