[appengine-java] Re: Best method to set up nested classes in Objectify

2010-05-24 Thread Mike
I'm not an expert, but I believe I understand Objectify (and -- you
could post the query on their group as well, the owner is very
responsive and helpful).

The structure would more accurately have been described as:

@Entity
public class A {

private Long id;

@Embeded
private B child;

}

I don't know how big A & B are, and I don't know why you're trying to
conserve bandwidth -- but your #3 should work (but, requires an extra
trip to get an B associated with an A.

There's also a couple of ways of achieving it.  You could either
associate each B to an A by having a Key in each B; or you could
have a Key in each A.

I prefer this layout:


@Entity
public class A {

private Long id;

// Whatever else is in here
}

@Entity
public class B {

private Long id;

private Key parent;
}

Your concerns about "dangling" relationships are concerns about the
GAE Datastore and its capabilities -- not about Objectify.  The GAE
requires that all logic to ensure these valid states must be
implemented in the application layer (its not a SQL DB).  If you're
really worried about that type of consistency, then using the B
embedded in A is the way to go.

Also -- its not true that you can't send less data to the client with
the A contains @Embedded B -- it just means that you would have to
create (and use) some sort of DTO that contained only the data that
you wanted to send to the client, and using that technique is likely
the simplest way for you to achieve your goals (I think).

Cheers
Mike

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine for Java" group.
To post to this group, send email to google-appengine-j...@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine-java+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.



[appengine-java] Re: Best method to set up nested classes in Objectify

2010-05-24 Thread Jake
Hey,

I'll try to answer this, but I'm not an expert - would love to hear an
expert's opinion of my answer.

When you say "inside", it can be a bit misleading to me.  If you're
talking about Embedded classes, the entire object is fetched, so that
wouldn't help for #1 or #2.  If you are just talking about a field
reference to another object, e.g.

public class A {

  private Long id;
  private B child;
}

then I don't believe B will be "fetched" unless explicitly accessed.
At least, that is what the GAE Relationship Documentation for JDO
implies.  I think Objectify is missing some documentation on how this
behavior works (or does it even work?).  Regardless, your concerns
about Option #3 may still exist in Option #1 if Objectify doesn't
support cascading deletes, etc.  I'm pretty sure Option #2 doesn't
work in any scenario.

Anyways, I use Option #3 and it works quite well.  Your concerns are
valid, but can be handled with proper programming.

Jake

On May 22, 3:07 pm, Michael  wrote:
> Hi,
>
> I am new to app engine (using it with GWT).  I have a class with a lot
> of data in it.  nearly 100% of the time my program only needs two of
> the fields.  I want to break it up in to two classes: A (with the data
> needed often) and B (less common data).  Class A is also sent back and
> fourth from the client and server often, so I think it's important
> that I can just send class A and not B to keep bandwidth down. How
> should I set it up, I see a few different ways
> 1 B inside of A
> 2 A Inside of B
> 3 A with a key to B
>
> Method 1 seems bad because I can't send A to the client without
> sending all of B.  I am really new to Objectify, can I fetch just A
> (querying on one of the parameters) using method 2?  Method 3 seems
> the only working way, but then I run the risk of a B with no A
> pointing to it or A pointing to  B that doesn't exist if something
> happens while deleting.  Is there a good way to avoid this?  Or should
> I just keep all of my data in one large class?
>
> What do you think is the best method?
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Google App Engine for Java" group.
> To post to this group, send email to google-appengine-j...@googlegroups.com.
> To unsubscribe from this group, send email to 
> google-appengine-java+unsubscr...@googlegroups.com.
> For more options, visit this group 
> athttp://groups.google.com/group/google-appengine-java?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine for Java" group.
To post to this group, send email to google-appengine-j...@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine-java+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.