Objectbox-java: Option to delete the entire DB

Created on 20 Dec 2017  路  7Comments  路  Source: objectbox/objectbox-java

Hey,
Is there any way i can delete the entire db. i want to clear the db when a user logs out. any single method to achieve this rather than creating a box for each entity and removing the entities?

Most helpful comment

I'm having a similar issue. I am also using dependency injection which works fine with ObjectBox. At a particular point I need to destroy my DI and re-intialise. I need to destroy my instance of ObjectBox before I call my DI. Using the line:

BoxStore.deleteAllFiles(context, null)
won't run as it gives the error

java.lang.IllegalStateException: Cannot delete files: store is still open

BoxStore.close() is not available. I am running ObjectBox 2.3.2 version. Any help would be greatly appreciated :)

All 7 comments

You can close the BoxStore and then just delete the files. That's the most effcient way to do this.

boxStore.close();
boxStore.deleteAllFiles();

There are also static deleteAllFiles(...) methods if you prefer to delete before you open the store (I think that's not what you want, just for the sake of completeness).

Thanks. This worked for me. I somehow missed this in the docs.

This doesn't seem to work for me, Im using the:

boxStore.deleteAllFiles(getContext(), OB_NAME);

OB_NAME being a custom name, and omitting the close as it raises the exception store is closed when user logs back into my app. The data in an entity is still there when logging back in and Im trying to do a simple reset of the database for a user logout and in senario

What am I missing? Cheers

it raises the exception store is closed when user logs back into my app

@dreamcatcha This sounds like your BoxStore instance is not properly cleaned up or the files were not actually deleted. Make sure to close before you delete.
-ut

I'm using dependency injection template and have encountered a problem that I can't use boxStore after boxStore.deleteAllFiles() because it is closed, what solution is there ? how can I delete all data without closing the database?
Best regards

@EspanaMia Deleting the files is the most efficient way to delete all data. Figure out how to do this in your DI framework or drop DI? ;-)

I'm having a similar issue. I am also using dependency injection which works fine with ObjectBox. At a particular point I need to destroy my DI and re-intialise. I need to destroy my instance of ObjectBox before I call my DI. Using the line:

BoxStore.deleteAllFiles(context, null)
won't run as it gives the error

java.lang.IllegalStateException: Cannot delete files: store is still open

BoxStore.close() is not available. I am running ObjectBox 2.3.2 version. Any help would be greatly appreciated :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

greenrobot picture greenrobot  路  17Comments

linguokun1 picture linguokun1  路  18Comments

DJafari picture DJafari  路  29Comments

williamwue picture williamwue  路  18Comments

GerritDeMeulder picture GerritDeMeulder  路  20Comments