Hi Group,

I'm not sure about how to model my application, therefore I'm going to
ask you, because I think you might know some best practice approach.
Here is the problem.

I have a simple application, maintaining photos and albums. Each photo
can be assigned to one album. One album can contain multiple photos.
Each photo has one (more or less large) set of image data:

public class Photo
    @Persistent
    private String contentType;
    @Persistent
    private Blob data;
    @Persistent
    private String fileName;
    @PrimaryKey
    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
    @Extension(vendorName = "datanucleus", key = "gae.encoded-pk",
value = "true")
    private String id;

...
}

public class Album implements IdObject<String> {
    @PrimaryKey
    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
    @Extension(vendorName = "datanucleus", key = "gae.encoded-pk",
value = "true")
    private String id;
    @Persistent
    private String name;
    @Persistent
    private List<Photo> photos;
...
}

Now, as you can see, every time the application loads an album, it
loads all photos of the album, including the image data. This is easy.
At the moment I'm not experiencing performance problems. But with
increased amount of photos I don't think it will scale very well.
Furthermore, it is not necessary to load the image data every time;
imagine a website which displays all photos of an album: first, a list
of <img> tags is created, including title of the photo etc., but the
data is loaded in a different servlet.

Now I see three options to solve this problem:

1) Use fetch groups
The problem here is, that I am not sure if fetch-groups really solve
the problem - I'm new to JDO.

2) Use "unowned" relationships
Here the question is, if this actually solves the problem. If I
understood correctly, the application itself has to take care about
loading the relationship entities. However I fail to see the benefit I
have, as I have to use the Datastore specific Key class.

3) Use lists of IDs
For this solution, I build my own relationship management. For
example, the Album class contains only a list of photo IDs. This gives
me even more flexibility, as I can use my own ID type, such as Long:

public class Album {
  private List<Long> photoIds;
...
}

What actually is the difference between this and the "unowned"
relationships?

As an extension to this solution, I would separate the photo data from
the actual photo, such as:

public class Photo {
  ... // without the private Blob data member
...
}

public class PhotoData {
  private Long photoId;
  private Blob data;
...
}

I hope this all isn't too confusing. Any help or suggestions are
highly appreciated.

Thank you,
Moritz

-- 
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.

Reply via email to