简体   繁体   中英

How do you use list properties in Google App Engine datastore in Java?

An object to be placed in the datastore will have a set of tags.

public class Model 
{
    List<String> tagList
    ...
}

In Python, the Google App Engine has the notion of list properties. What is the equivalent notion in Java (if it exists) and how would you use list properties in Java, in JPA and/or in JDO?

See my blog post exactly on this: Efficient Keyword Search with Relation Index Entities and Objectify for Google Datastore . It talks about implementing search with list properties using Relation Index Entities and Objectify.

To summarize:

  Query<DocumentKeywords> query = ofy.query(DocumentKeywords.class);
  for (String keyword : keywords) {
    query = query.filter("keywords", keyword);
  }

  Set<Key<Document>> keys = query.<Document>fetchParentKeys();

  Collection<Document> documents = ofy.get(keys).values();

where DocumentKeywords contains a list property (collection) of all keywords for its Document entity, and Document entity is a parent for DocumentKeywords .

In JDO use

@Persistent
private List<ContactInfo> contactInfoSets;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM