Skip to content

Commit 157ec85

Browse files
committed
added panicModeRemoveAllObjects()
1 parent 0d6b4e3 commit 157ec85

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import javax.annotation.concurrent.ThreadSafe;
3030

3131
import io.objectbox.annotation.apihint.Beta;
32+
import io.objectbox.annotation.apihint.Experimental;
3233
import io.objectbox.annotation.apihint.Internal;
3334
import io.objectbox.annotation.apihint.Temporary;
3435
import io.objectbox.exception.DbException;
@@ -468,6 +469,7 @@ public void remove(T object) {
468469
/**
469470
* Removes (deletes) the given Objects in a single transaction.
470471
*/
472+
@SuppressWarnings("Duplicates") // Detected duplicate has different type
471473
public void remove(@Nullable T... objects) {
472474
if (objects == null || objects.length == 0) {
473475
return;
@@ -487,6 +489,7 @@ public void remove(@Nullable T... objects) {
487489
/**
488490
* Removes (deletes) the given Objects in a single transaction.
489491
*/
492+
@SuppressWarnings("Duplicates") // Detected duplicate has different type
490493
public void remove(@Nullable Collection<T> objects) {
491494
if (objects == null || objects.isEmpty()) {
492495
return;
@@ -516,6 +519,17 @@ public void removeAll() {
516519
}
517520
}
518521

522+
/**
523+
* WARNING: this method should generally be avoided as it is not transactional and thus may leave the DB in an
524+
* inconsistent state. It may be the a last resort option to recover from a full DB.
525+
* Like removeAll(), it removes all objects, returns the count of objects removed.
526+
* Logs progress using warning log level.
527+
*/
528+
@Experimental
529+
public long panicModeRemoveAll() {
530+
return store.panicModeRemoveAllObjects(getEntityInfo().getEntityId());
531+
}
532+
519533
/**
520534
* Returns a builder to create queries for Object matching supplied criteria.
521535
*/

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,12 @@ static native void nativeRegisterCustomType(long store, int entityId, int proper
135135
public static native boolean isObjectBrowserAvailable();
136136

137137
public static String getVersion() {
138+
138139
return VERSION;
139140
}
140141

142+
native long nativePanicModeRemoveAllObjects(long store, int entityId);
143+
141144
private final File directory;
142145
private final String canonicalPath;
143146
private final long handle;
@@ -910,4 +913,8 @@ void setDebugFlags(int debugFlags) {
910913
nativeSetDebugFlags(handle, debugFlags);
911914
}
912915

916+
long panicModeRemoveAllObjects(int entityId) {
917+
return nativePanicModeRemoveAllObjects(handle, entityId);
918+
}
919+
913920
}

tests/objectbox-java-test/src/main/java/io/objectbox/BoxTest.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,14 @@ public void testRemoveMany() {
136136
assertEquals(0, box.count());
137137
}
138138

139+
@Test
140+
public void testPanicModeRemoveAllObjects() {
141+
assertEquals(0, box.panicModeRemoveAll());
142+
putTestEntities(7);
143+
assertEquals(7, box.panicModeRemoveAll());
144+
assertEquals(0, box.count());
145+
}
146+
139147
@Test
140148
public void testRunInTx() {
141149
final long[] counts = {0, 0};

0 commit comments

Comments
 (0)