Skip to content

Commit 415f6b7

Browse files
Support validate while open.
1 parent f2cd2cc commit 415f6b7

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

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

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -181,11 +181,6 @@ static native void nativeRegisterCustomType(long store, int entityId, int proper
181181

182182
static native boolean nativeIsObjectBrowserAvailable();
183183

184-
/**
185-
* Validates up to {@code pageLimit} pages of the store. Set {@code checkLeafLevel} to check leafs, too.
186-
* Throws StorageException if validation fails.
187-
* Throws DbFileCorruptException or DbPagesCorruptException if the DB is actually inconsistent (corrupt).
188-
*/
189184
native long nativeValidate(long store, long pageLimit, boolean checkLeafLevel);
190185

191186
public static boolean isObjectBrowserAvailable() {
@@ -951,6 +946,19 @@ public String diagnose() {
951946
return nativeDiagnose(handle);
952947
}
953948

949+
/**
950+
* Validates up to {@code pageLimit} pages of the store. Set {@code checkLeafLevel} to check leafs, too.
951+
* Returns the number of pages validated.
952+
* Throws StorageException if validation fails.
953+
* Throws DbFileCorruptException or DbPagesCorruptException if the DB is actually inconsistent (corrupt).
954+
*/
955+
public long validate(long pageLimit, boolean checkLeafLevel) {
956+
if (pageLimit < 0) {
957+
throw new IllegalArgumentException("pageLimit must be zero or positive");
958+
}
959+
return nativeValidate(handle, pageLimit, checkLeafLevel);
960+
}
961+
954962
public int cleanStaleReadTransactions() {
955963
return nativeCleanStaleReadTransactions(handle);
956964
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,4 +215,10 @@ private Callable<String> createTestCallable(final int[] countHolder) {
215215
};
216216
}
217217

218+
@Test
219+
public void validate() {
220+
putTestEntities(10);
221+
long validated = store.validate(0, true);
222+
assertEquals(validated, 2);
223+
}
218224
}

0 commit comments

Comments
 (0)