Posts

Showing posts with the label android-room

Cascade delete based on @ForeignKey in Android Rooms ORM

Cascade delete based on @ForeignKey in Android Rooms ORM I have two entities DBList adnd DBListContent . With one to many relationship between DBList and DBListContent . DBList DBListContent DBList DBListContent Here is the DBList class DBList @Entity(tableName = "lists") public class DBList { @PrimaryKey private String listId; private String title; private String createdDateTime; } Here is the DBListContent DBListContent @Entity(tableName = "listContents") public class DBListContent { @PrimaryKey public String listContentId; public String content; public String lastEditedBy; public String lastEditedDateTime; @ForeignKey(entity = DBList.class, parentColumns = "listId", childColumns = "dbListId", onDelete = CASCADE) public String dbListId; } When I delete a row in lists table, the corresponding rows in the listContents table are not deleted. lists listContents I deleted the rows using the following ...

Room running very slow

Room running very slow I'm trying to get/store data using the Room Persistence Library. The calls to get all data from a table is really slow, and I timed it using nanoTime to be about 1800ms, which I think is too slow. What could be going wrong? nanoTime Here's some more info: nanoTime AsyncTask The query is defined in DbDao as @Query("SELECT * FROM events") List<Event> getAllEvents(); 1 Answer 1 Async task is not good for handling Room database. I would suggest you to use executor and make a singleton class using this. Code is as follows. import android.os.Looper; import android.support.annotation.NonNull; import java.util.concurrent.Executor; import java.util.concurrent.Executors; public class AppExecutor { private static final Object LOCK = new Object(); private static AppExecutor sInstance; private final Executor diskIO; private final Executor mainThread; private final ...