I probably have a naive understanding of what you're doing, maybe
explain a little more, but to me it looks like this:
class TagCounter {
int count;
String label; // primary key, unique tag name.
}
class Entity {
String tag;
String foo;
}
whenever the user creates a new entity, record its tag(s), then
increment the appropriate TagCounter instance. Keeping counters like
this introduces a bottleneck and goes against what you want to be
doing for a highly scalable web service, so you may want to shard them
(imagine you have thousands of users all trying to increment a single
tag counter at once). Since the above two classes won't be in the
same entity group, you wouldn't be able to perform both operations in
a single transaction. You can either accept the fact that your tag
count may be out of sync with the actual number of entities with that
tag, or you can have a multistep process and clean up dangling tag
counts with a task (eventual consistency might be the term here). I'm
referring to Nick Johnson's article on distributed transactions which
I think you can modify to do what you're looking for:
http://blog.notdot.net/2009/9/Distributed-Transactions-on-App-Engine
I'm still learning app engine so take the above with a big grain of
salt. To me, it seems that if you want to write a highly scalable web
service, you need to accept that you may lose some data precision, or
you have to put in additional work to get what you want (compared to
assuming a single mysql instance etc).
Anyway, after you implement something like the above, your original
two queries should be easy to do. You probably want to define how many
tags an Entity can have. If an Entity can have more than one tag, I'd
explicitly state what that max is. Write out everything you need when
the user submits an entity, so that your reads will be fast as other
users browse the site.
Mark
On Jul 19, 9:16 am, planetjones <[email protected]> wrote:
> Hi,
> I'm looking to store entities using GAE Java which have 1-many tags.
> I
> would like to display a tag cloud, so will need to know how many
> times
> each tag occurs (can't use aggregate functions and group by on GAE to
> do this like I would in SQL). And when I click a tag I would like to
> retrieve all entities with the selected tag.
> Does anyone have any examples of what my Classes should look like to
> do this optimally and efficiently? Sample JPA code would be great
> too.
> Cheers - Jonathan
--
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 [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-appengine-java?hl=en.