For the sake of comparison, see below for the Twig equivalent
On 10 Mar 2010, at 11:18, Jeff Schnitzer wrote:
class UserSkill {
@Id Long id;
@Parent Key<User> user;
String skill; // could also be Key<Skill> skill if you model
Skill entities
int ability;
}
class UserSkill {
@Parent User user;
String skill
int ability;
}
Note that no key is required and user is referenced directly so your
model has no dependency on the low-level datastore
List<Key<User>> userKeys = new ArrayList<Key<User>>();
for (Key<UserSkill> key: ofy.query(UserSkill.class).filter("skill",
"java").filter("ability >", 5).fetchKeys())
userKeys.add(key.getParent());
Collection<User> users = ofy.get(userKeys).values();
Iterator<User> users = datastore.find()
.type(UserSkill.class)
.addFilter("skill", EQUAL, "java")
.addFilter("ability", GREATER_THAN, 5)
.returnParentsNow();
This is how easy it is to use Relation Index Entities with the new
release of Twig
Note that Twig is the only datastore interface that can do OR queries
- find "java" OR ".net" Users sorted by ability like this:
Iterator<User> users = datastore.find()
.type(UserSkill.class)
.addSort("ability")
.addFilter("ability", GREATER_THAN, 5)
.addChildQuery()
.addFilter("skill", EQUAL, "java")
.addChildQuery()
.addFilter("skill", EQUAL, ".net")
.returnParentsNow();
Behind the scenes two queries are run *in parallel* asynchronously and
then merged together into a single Iterator. Notice also that the two
queries both inherit the common filter and sort on "ability".
Find out more http://code.google.com/p/twig-persist/
John
--
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.