Question

I have a Course entity which contains a Set of Keys to my Tag entity. How would I go about creating a query to get a list of courses with a specific tag? For example, I want to find all the courses tagged with java.

Here are my entities:

@PersistenceCapable(identityType = IdentityType.APPLICATION, detachable="true")
 public class Course{

 @PrimaryKey
 @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
 private Key key;

 @Persistent private Set<Key>       tags;
 //etc
 }

@PersistenceCapable(identityType = IdentityType.APPLICATION, detachable="true")
public class Tag{

    @PrimaryKey
    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
    private Key key;

    @Persistent private String tagText;
}
Was it helpful?

Solution

Tag tag = getTagFromString("java");
Key tagKey = tag.getKey();  // i will assume you have a getKey() method

PersistenceManger pm = PMF.get().getPersistenceManager();
Query q = pm.newQuery(Course.class);
q.setFilter("tags == :tagParam");

List<Course> coursesTaggedWithJava = (List<Course>) q.execute(tagKey);

OTHER TIPS

I don't think this is possible. Google DataStore does not allow to use Join queries. But I may be mistaken.

Here and here is the website where you can find more information about GQL.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top