java - persisting relationships in datastore - app engine and objectify -


my app using objectify. i'm new nosql .

i have data model this. pay no attention lack of getters , setters, lack of builder pattern, etc. example.

as can see, reallyweirdcar root of quite deep object graph.

now, suppose build reallyweirdcar object in memory using given method.

also, assume datastore empty.

how save object using objectify ?

is ofy().save().entity(rwc1) enough save entire object graph in 1 shot ?

how persist relationships ?

also, consider "good"(performant) model if of time i'm executing queries "find cars solicited customer john"

thx in advance

    @entity     class reallyweirdcar {      @id     public string id;      public string name;      @load     public ref<engine> e1;      @load     public ref<engine> e2;      // reference customer solicited construction of car     @index     @load     public ref<customer> customer;  }      @entity           class customer {      @id     public string id;      public string name; }  @entity class engine {      @id     public string id;      public string name;      @load     public ref<list<carburetor>> ecs;  }  @entity class carburetor {      @id     public string id;      public string name;      @load     public ref<manufacturer> manufacturer;  }  @entity class manufacturer {      @id     public string id;      public string name;  }      // inside service   public buildandpersistcar() {       customer cust1 = new customer("cust1", "customer1");       manufacturer m1 = new manufacturer("m1", "manufacturer1");      carburetor c1 = new carburetor("carb1", "carburetor1", m1);     carburetor c2 = new carburetor("carb2", "carburetor2", m1);     carburetor c3 = new carburetor("carb3", "carburetor3", m1);      carburetor c4 = new carburetor("carb4", "carburetor4", m1);       engine e1 = new engine("e1", "engine1", arrays.aslist(c1,c2));      engine e2 = new engine("e2", "engine2", arrays.aslist(c3,c4)));      reallyweirdcar rwc1 = new reallyweirdcar("rwc1", "reallyweirdcar1", e1, e2, cust1);           // do here ????      // how persist rwc1 ???    } 

there no concept of "cascading save" in objectify. if want save n entities, must save them explicitly. what save save.

from performance perspective, looks suboptimal. gae datastore likes fatter coarse-grained entities; example requires 4 rounds of fetching manufacturer. if genuinely accurate model, may wish live it; 4 rounds of fetching won't kill you, of of entities in memcache. if can denormalize model (say, embedding carburetor in engine), can make faster.

this same problem faced in relational databases (normalize or denormalize). it's easier objectify because objectify smart "rounds" of batch fetching; you'll 4 api calls instead of ~n^4 api calls. still painful load whole engine full of thousands of components.


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -