How to prefill a table in the db and optimize the DAO interface?
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?
java
add a comment |
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?
java
add a comment |
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?
java
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?
java
java
edited Nov 24 '18 at 13:24
Fantômas
32.7k156389
32.7k156389
asked Nov 24 '18 at 12:34
Farah AtiehFarah Atieh
62
62
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
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.
also this guide could be helpful for prepopulating the tables.
– jwala
Nov 24 '18 at 12:54
Thanks for your response I've followed the way in this link android.jlelse.eu/pre-populate-room-database-6920f9acc870, and its helped me a lot.
– Farah Atieh
Nov 24 '18 at 16:14
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53458194%2fhow-to-prefill-a-table-in-the-db-and-optimize-the-dao-interface%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
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.
also this guide could be helpful for prepopulating the tables.
– jwala
Nov 24 '18 at 12:54
Thanks for your response I've followed the way in this link android.jlelse.eu/pre-populate-room-database-6920f9acc870, and its helped me a lot.
– Farah Atieh
Nov 24 '18 at 16:14
add a comment |
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.
also this guide could be helpful for prepopulating the tables.
– jwala
Nov 24 '18 at 12:54
Thanks for your response I've followed the way in this link android.jlelse.eu/pre-populate-room-database-6920f9acc870, and its helped me a lot.
– Farah Atieh
Nov 24 '18 at 16:14
add a comment |
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.
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.
answered Nov 24 '18 at 12:51
jwalajwala
666
666
also this guide could be helpful for prepopulating the tables.
– jwala
Nov 24 '18 at 12:54
Thanks for your response I've followed the way in this link android.jlelse.eu/pre-populate-room-database-6920f9acc870, and its helped me a lot.
– Farah Atieh
Nov 24 '18 at 16:14
add a comment |
also this guide could be helpful for prepopulating the tables.
– jwala
Nov 24 '18 at 12:54
Thanks for your response I've followed the way in this link android.jlelse.eu/pre-populate-room-database-6920f9acc870, and its helped me a lot.
– Farah Atieh
Nov 24 '18 at 16:14
also this guide could be helpful for prepopulating the tables.
– jwala
Nov 24 '18 at 12:54
also this guide could be helpful for prepopulating the tables.
– jwala
Nov 24 '18 at 12:54
Thanks for your response I've followed the way in this link android.jlelse.eu/pre-populate-room-database-6920f9acc870, and its helped me a lot.
– Farah Atieh
Nov 24 '18 at 16:14
Thanks for your response I've followed the way in this link android.jlelse.eu/pre-populate-room-database-6920f9acc870, and its helped me a lot.
– Farah Atieh
Nov 24 '18 at 16:14
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53458194%2fhow-to-prefill-a-table-in-the-db-and-optimize-the-dao-interface%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown