Friday, September 17, 2010

Re: Using the same object at the server and client

Ji Jakob,

yes this is a persisted class. The jdo-annotations, tells
datanucleus to persist this in the datastore.

Yea, I´m sorry but you got me right. I ran into this too, when
I started to work with GWT and GAE.
The solution is quite simple, you already said it.
Make a so called: "DataTransferObject" for each persisted class.
This is a Design Pattern .. the DTO-Pattern.

And yes, it is not a good solution.

If you have time, and good Java-knowledge you can code a
Code-Generator, that generates the DataTransferObjects from
each persisted class. It´s a good solution if you have many
classes, that need DTO´s. Here you can just maintain the
perissted class und regenerate the DTO.

I foun d a nice solution, for me:
I store the object (in your case DTO) in the datastore.
So my persistet class looks like this:


@PersitenceCapable
class LetterDataBaseObject

@Persistent
Key key;

@Persistent
String myID;

@Persistent(serialized = true)
Letter myLetter

...


I generate a searchString, so I can still query my object.


For the beginning I would simple use the DTO-Pattern.


Greets Alex


P.S.: what about your import error?

On 17 Sep., 13:40, Janko <janko.sla...@gmail.com> wrote:
> Hi Alex and Thomas.
>
> This is really fast:D
> I guess the Stock.java is persisted:
> ---
> @PersistenceCapable(identityType = IdentityType.APPLICATION)
> public class Stock {
>
>   @PrimaryKey
>   @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
>   private Long id;
>   @Persistent
>   private User user;
>   @Persistent
>   private String symbol;
>   @Persistent
>   private Date createDate;
> ---
>
> Alex if I get you right I cannot use this object on the client side?
> Is there another way I could move the data to client? Creating a
> similar class on the client side is an option, but it is a relatively
> bad option, because I would need to code both classes... Any ideas?
>
> Thank you,
> janko
>
> On Sep 17, 1:30 pm, Janko <janko.sla...@gmail.com> wrote:
>
> > Thank you for the quick response.
>
> > I now get the 13:25:23.531 [ERROR] [homework] Line 9: The import
> > com.google.appengine cannot be resolved
> > Line 9 is: import com.google.appengine.api.users.User;
>
> > I found I need probably inherit it... in what way? what do I need to
> > do?
>
> > On Sep 17, 1:13 pm, Brett Thomas <brettptho...@gmail.com> wrote:
>
> > > I think you need to move the stock class from the .server. package to
> > > .shared. so the client knows about it
>
> > > On Fri, Sep 17, 2010 at 7:09 AM, Janko <janko.sla...@gmail.com> wrote:
> > > > PS: I get the "did you forget to inherit a required module" error..
>
> > > > --
> > > > You received this message because you are subscribed to the Google Groups
> > > > "Google Web Toolkit" group.
> > > > To post to this group, send email to google-web-toolkit@googlegroups.com.
> > > > To unsubscribe from this group, send email to
> > > > google-web-toolkit+unsubscribe@googlegroups.com<google-web-toolkit%2Bunsubs cribe@googlegroups.com>
> > > > .
> > > > For more options, visit this group at
> > > >http://groups.google.com/group/google-web-toolkit?hl=en.
>
>

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To post to this group, send email to google-web-toolkit@googlegroups.com.
To unsubscribe from this group, send email to google-web-toolkit+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.

No comments:

Post a Comment