How to correctly implements model insertion with foreign key?Java Class that implements Map and keeps insertion order?How to update a value, given a key in a java hashmap?How to implement onBackPressed() in Fragments?How should a model be structured in MVC?How to preserve insertion order in HashMap?Once for all, how to correctly save instance state of Fragments in back stack?android MVP - How should the network layer be called , from model?Android Room Persistence Library: UpsertLoopback - how to get id of user and insert into related model? (hasMany)Kill Network Service Discovery from AsyncTask when done without leaks
Does the "6 seconds per round" rule apply to speaking/roleplaying during combat situations?
Do manufacturers try make their components as close to ideal ones as possible?
Java guess the number
On the Twin Paradox Again
Funtion to extract float from different price patterns
Dynamically loading CSS files based on URL or URI in PHP
Movie where a boy is transported into the future by an alien spaceship
What is the right way to float a home lab?
Is the decompression of compressed and encrypted data without decryption also theoretically impossible?
Does the growth of home value benefit from compound interest?
Removing applications from Show Applications without uninstalling
What are the words for people who cause trouble believing they know better?
How can I instantiate a lambda closure type in C++11/14?
Why is c4 bad when playing the London against a King's Indian?
Smooth switching between 12v batteries, with toggle switch
Importance sampling estimation of power function
Building a road to escape Earth's gravity by making a pyramid on Antartica
Are the AT-AT's from Empire Strikes back a deliberate reference to Mecha
Credit card offering 0.5 miles for every cent rounded up. Too good to be true?
How is it possible that Gollum speaks Westron?
Incremental Ranges!
What's the correct term describing the action of sending a brand-new ship out into its first seafaring trip?
Short story written from alien perspective with this line: "It's too bright to look at, so they don't"
How to decline physical affection from a child whose parents are pressuring them?
How to correctly implements model insertion with foreign key?
Java Class that implements Map and keeps insertion order?How to update a value, given a key in a java hashmap?How to implement onBackPressed() in Fragments?How should a model be structured in MVC?How to preserve insertion order in HashMap?Once for all, how to correctly save instance state of Fragments in back stack?android MVP - How should the network layer be called , from model?Android Room Persistence Library: UpsertLoopback - how to get id of user and insert into related model? (hasMany)Kill Network Service Discovery from AsyncTask when done without leaks
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
i'm making a basic app following clean architecture to learn it, and i'm not sure about how implementing model insertion when an order in insertion is needed.
I have "Event", "Artist", "Advert" entity.
- Event have one or more artist.
- Artist have one or more Event.
- Advert have one Event and/or artist.
I get data from a Json file online then my adapter map the data for my model of my data layer.
Now i have the data that i need to insert but for example when i insert an advert that reference an artist i need the artist to be inserted first so the foreign key of advert can reference the artist and my question is :
if i want to insert or upsert all the data at the same moment how respect the insertion order to avoid foreign key error?
My app shows a list of advert as the first view. I manage to do it by having a insertTask in my artistRepository (in domain layer) that call Insert method of my advertRepository in onPostExecute but it surely is the wrong way since i call method of a repo from another repo.
public class upsertFromServerAsync extends AsyncTask<Void, Void, JsonResponse>
//My mapper
JsonResponse myResponse;
@Override
protected JsonResponse doInBackground(Void... voids)
retrofit = RetrofitClient.getInstance();
apiService = retrofit.create(ApiService.class);
Call<JsonResponse> call = apiService.getJsonFromServer("yh4ra");
try
//Getting my data
myResponse = call.execute().body();
//Inserting events
List<Event> events = myResponse.getEvents();
for (Event event : events)
upsertEvent(event);
//Inserting artists
List<Artist> artists = myResponse.getArtists();
for (Artist artist : artists)
upsertArtist(artist);
catch (IOException e)
e.printStackTrace();
return myResponse;
@Override
protected void onPostExecute(JsonResponse myResponse)
super.onPostExecute(myResponse);
AsyncTask.execute(() ->
List<Advert> advertsFromJson = jsonAdapter.getAdvertsFromJson(myResponse);
for (Advert advert : advertsFromJson)
Log.d("test", advert.getArtistName() + "");
upsertAdvert(advert);
);
this solution is a mess, i ended up having an upsertArtist and upsertAdvert method in my EventRepo. What is the good way for achieving this following the clean arch?
Maybe i need to use an interactor that can call several repo to upsert my model?
Thanks
java
add a comment |
i'm making a basic app following clean architecture to learn it, and i'm not sure about how implementing model insertion when an order in insertion is needed.
I have "Event", "Artist", "Advert" entity.
- Event have one or more artist.
- Artist have one or more Event.
- Advert have one Event and/or artist.
I get data from a Json file online then my adapter map the data for my model of my data layer.
Now i have the data that i need to insert but for example when i insert an advert that reference an artist i need the artist to be inserted first so the foreign key of advert can reference the artist and my question is :
if i want to insert or upsert all the data at the same moment how respect the insertion order to avoid foreign key error?
My app shows a list of advert as the first view. I manage to do it by having a insertTask in my artistRepository (in domain layer) that call Insert method of my advertRepository in onPostExecute but it surely is the wrong way since i call method of a repo from another repo.
public class upsertFromServerAsync extends AsyncTask<Void, Void, JsonResponse>
//My mapper
JsonResponse myResponse;
@Override
protected JsonResponse doInBackground(Void... voids)
retrofit = RetrofitClient.getInstance();
apiService = retrofit.create(ApiService.class);
Call<JsonResponse> call = apiService.getJsonFromServer("yh4ra");
try
//Getting my data
myResponse = call.execute().body();
//Inserting events
List<Event> events = myResponse.getEvents();
for (Event event : events)
upsertEvent(event);
//Inserting artists
List<Artist> artists = myResponse.getArtists();
for (Artist artist : artists)
upsertArtist(artist);
catch (IOException e)
e.printStackTrace();
return myResponse;
@Override
protected void onPostExecute(JsonResponse myResponse)
super.onPostExecute(myResponse);
AsyncTask.execute(() ->
List<Advert> advertsFromJson = jsonAdapter.getAdvertsFromJson(myResponse);
for (Advert advert : advertsFromJson)
Log.d("test", advert.getArtistName() + "");
upsertAdvert(advert);
);
this solution is a mess, i ended up having an upsertArtist and upsertAdvert method in my EventRepo. What is the good way for achieving this following the clean arch?
Maybe i need to use an interactor that can call several repo to upsert my model?
Thanks
java
add a comment |
i'm making a basic app following clean architecture to learn it, and i'm not sure about how implementing model insertion when an order in insertion is needed.
I have "Event", "Artist", "Advert" entity.
- Event have one or more artist.
- Artist have one or more Event.
- Advert have one Event and/or artist.
I get data from a Json file online then my adapter map the data for my model of my data layer.
Now i have the data that i need to insert but for example when i insert an advert that reference an artist i need the artist to be inserted first so the foreign key of advert can reference the artist and my question is :
if i want to insert or upsert all the data at the same moment how respect the insertion order to avoid foreign key error?
My app shows a list of advert as the first view. I manage to do it by having a insertTask in my artistRepository (in domain layer) that call Insert method of my advertRepository in onPostExecute but it surely is the wrong way since i call method of a repo from another repo.
public class upsertFromServerAsync extends AsyncTask<Void, Void, JsonResponse>
//My mapper
JsonResponse myResponse;
@Override
protected JsonResponse doInBackground(Void... voids)
retrofit = RetrofitClient.getInstance();
apiService = retrofit.create(ApiService.class);
Call<JsonResponse> call = apiService.getJsonFromServer("yh4ra");
try
//Getting my data
myResponse = call.execute().body();
//Inserting events
List<Event> events = myResponse.getEvents();
for (Event event : events)
upsertEvent(event);
//Inserting artists
List<Artist> artists = myResponse.getArtists();
for (Artist artist : artists)
upsertArtist(artist);
catch (IOException e)
e.printStackTrace();
return myResponse;
@Override
protected void onPostExecute(JsonResponse myResponse)
super.onPostExecute(myResponse);
AsyncTask.execute(() ->
List<Advert> advertsFromJson = jsonAdapter.getAdvertsFromJson(myResponse);
for (Advert advert : advertsFromJson)
Log.d("test", advert.getArtistName() + "");
upsertAdvert(advert);
);
this solution is a mess, i ended up having an upsertArtist and upsertAdvert method in my EventRepo. What is the good way for achieving this following the clean arch?
Maybe i need to use an interactor that can call several repo to upsert my model?
Thanks
java
i'm making a basic app following clean architecture to learn it, and i'm not sure about how implementing model insertion when an order in insertion is needed.
I have "Event", "Artist", "Advert" entity.
- Event have one or more artist.
- Artist have one or more Event.
- Advert have one Event and/or artist.
I get data from a Json file online then my adapter map the data for my model of my data layer.
Now i have the data that i need to insert but for example when i insert an advert that reference an artist i need the artist to be inserted first so the foreign key of advert can reference the artist and my question is :
if i want to insert or upsert all the data at the same moment how respect the insertion order to avoid foreign key error?
My app shows a list of advert as the first view. I manage to do it by having a insertTask in my artistRepository (in domain layer) that call Insert method of my advertRepository in onPostExecute but it surely is the wrong way since i call method of a repo from another repo.
public class upsertFromServerAsync extends AsyncTask<Void, Void, JsonResponse>
//My mapper
JsonResponse myResponse;
@Override
protected JsonResponse doInBackground(Void... voids)
retrofit = RetrofitClient.getInstance();
apiService = retrofit.create(ApiService.class);
Call<JsonResponse> call = apiService.getJsonFromServer("yh4ra");
try
//Getting my data
myResponse = call.execute().body();
//Inserting events
List<Event> events = myResponse.getEvents();
for (Event event : events)
upsertEvent(event);
//Inserting artists
List<Artist> artists = myResponse.getArtists();
for (Artist artist : artists)
upsertArtist(artist);
catch (IOException e)
e.printStackTrace();
return myResponse;
@Override
protected void onPostExecute(JsonResponse myResponse)
super.onPostExecute(myResponse);
AsyncTask.execute(() ->
List<Advert> advertsFromJson = jsonAdapter.getAdvertsFromJson(myResponse);
for (Advert advert : advertsFromJson)
Log.d("test", advert.getArtistName() + "");
upsertAdvert(advert);
);
this solution is a mess, i ended up having an upsertArtist and upsertAdvert method in my EventRepo. What is the good way for achieving this following the clean arch?
Maybe i need to use an interactor that can call several repo to upsert my model?
Thanks
java
java
edited Mar 24 at 15:01
Sree
937922
937922
asked Mar 24 at 14:22
Loic BchLoic Bch
86
86
add a comment |
add a comment |
0
active
oldest
votes
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%2f55324780%2fhow-to-correctly-implements-model-insertion-with-foreign-key%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
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%2f55324780%2fhow-to-correctly-implements-model-insertion-with-foreign-key%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