-1

I’m trying to build a database using Room DB that consists of four entities, I have already create a class for each entity and annotate it with @Entity annotation. Also I have created a DAO for each of the entities. And finally I create the Database abstract class and create an abstract method for each of the DAO interface.

My 1st question is: I want to fill up the table data for the first 3 entities before the user use the application as manually in the code so once the user download the app these tables will be already defined.

My 2nd question Which is better to make a DAO for each entity or make generic DAO?

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115

1 Answers1

0

Answer for 1st question: you can prepopulate the data using this post which explains how to do it clearly.

Answer for 2nd question : well it depends upon how neat you want to get with you code. By neat I meant applylying you object oriented principles, which will help to segregate the logic into generic DAO(if possible) and easy to maintain. This practice will help you in future when you develop big projects (believe me It's very helpful) which have hundred's of classes all doing the similar thing.

itsjwala
  • 106
  • 7
  • also [this](https://android.jlelse.eu/pre-populate-room-database-6920f9acc870) guide could be helpful for prepopulating the tables. – itsjwala Nov 24 '18 at 12:54
  • Thanks for your response I've followed the way in this link https://android.jlelse.eu/pre-populate-room-database-6920f9acc870, and its helped me a lot. – Farah Atieh Nov 24 '18 at 16:14