On Tuesday, October 22, 2013 6:12:36 PM UTC+2, Nermin wrote: > > OK Thomas, I will go for Objectify. > > The only problem is that I cannot find a really good tutorial for using it > with Requestfactory. > > http://code.google.com/p/objectify-appengine/wiki/ObjectifyWithGWT > For example, their official GWT-Tutorial is totally confusing (see link > above), they state: "Make sure your entity classes are part of your GWT > module (typically in a .client package)." ...... Now I get totally > confused! Is this really true????? >
They use GWT-RPC, so yes (your entities would be used on the client-side, so they'd have to be in .client or .shared – assuming you follow GWT's naming conventions here). It's not the case when you use RequestFactory. Have you looked at http://turbomanage.wordpress.com/2011/03/25/using-gwt-requestfactory-with-objectify/ ? (linked at the bottom of the above-linked page) (from memory, it's a bit old, back in the days when Objectify didn't have a request-scoped cache, so it could break depending on the requests you made; but Objectify now has a request-scoped cache, so it should Just Work™; just beware of this: https://code.google.com/p/objectify-appengine/wiki/Caching#Transactions_and_the_Session_Cache, but if I understand correctly there are relatively few cases where it would break with RequestFactory). I have played today wit it a bit with Objectify, and I have managed it to > create an simple working example. > Can you please tell me if this is the right way of working with the > Objectify 4 and the RequestFactory? > Heh, I never used Objectify either (I never worked with AppEngine), but I'll do my best. > The code works but I am somehow not really sure if I am on the right > track. Here is my code: > Btw: I have all my entities on server side. > > *@Entity > public class EntityOne* { > @Id > private Long id; > private Integer version = 0; > private String name; > private Key<EntityTwo> entityTwoKey; //This is the Key for the > EntityTwo (Using this you will know how to lad it) > @Ignore > private EntityTwo entityTwo; //Transient field (not saved in the > Datastore) it is a real representation of the entityt > > @OnSave > void onPersist() { > version++; // Increase the Version > } > > // ========= HANDLER METHODS ==========// > public static EntityOne findEntityOne(Long id) { > return ofy().load().type(EntityOne.class).id(id).now(); > } > > public void persist() { > ofy().save().entity(this).now(); > } > > .... > public Key<EntityTwo> getEntityTwoKey() { > return entityTwoKey; > } > public void setEntityTwoKey(Key<EntityTwo> entityTwoKey) { > this.entityTwoKey = entityTwoKey; > } > > public EntityTwo getEntityTwo() { > //Load entity using its Key > this.entityTwo = ofy().load().key(getEntityTwoKey()).now(); > return this.entityTwo; > } > public void setEntityTwo(EntityTwo entityTwo) { > //Step1: Set the key (This will make sure it be saved into the DB) > this.entityTwoKey = Key.create(EntityTwo.class, entityTwo.getId()); > //Step2: Set entity > this.entityTwo = entityTwo; > } > } > > > *@Entity > public class EntityTwo* { > @Id > private Long id; > private Integer version = 0; > > private String name; > > @OnSave > void onPersist() { > version++; // Increase the Version > } > > // ========= HANDLER METHODS ==========// > public static EntityTwo findEntityTwo(Long id) { > return ofy().load().type(EntityTwo.class).id(id).now(); > } > > public EntityTwo persist() { > ofy().save().entity(this).now(); > return this; > } > ... Get/set > } > > *@ProxyFor(EntityOne.class) > public interface EntityOneProxy extends EntityProxy {* > Long getId(); > Integer getVersion(); > void setVersion(Integer version); > Do you really want to get/set the version on the client-side? (OK, get the version maybe, but set it?) > String getName(); > void setName(String name); > > EntityTwoProxy getEntityTwo(); > void setEntityTwo(EntityTwoProxy entityTwo); > } > > *@ProxyFor(EntityTwo.class) > public interface EntityTwoProxy extends EntityProxy {* > Long getId(); > Integer getVersion(); > void setVersion(Integer version); > String getName(); > void setName(String name); > } > > ... And registering to my RequestFactory interface ... etc. > > Is this code OK?? > It looks OK to me. > > If I understood correctly, I do not need to care about OSIV etc. > Yes, except https://code.google.com/p/objectify-appengine/wiki/Caching#Transactions_and_the_Session_Cache as already mentioned. > All I need to do is to register ObjectifyFilter. Right? > It seems so. -- You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/google-web-toolkit. For more options, visit https://groups.google.com/groups/opt_out.
