Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 951
onejigtwojig Avatar asked Apr 25 '11 13:04

onejigtwojig


People also ask

How does Google's Datastore work?

Datastore is a highly scalable NoSQL database for your applications. Datastore automatically handles sharding and replication, providing you with a highly available and durable database that scales automatically to handle your applications' load.

What is the data store used by Google App Engine?

Datastore is a NoSQL document database built for automatic scaling, high performance, and ease of application development. Datastore features include: Atomic transactions.

How do I add entities to Google Datastore?

In Java, you create a new entity by constructing an instance of class Entity , supplying the entity's kind as an argument to the Entity() constructor. After populating the entity's properties if necessary, you save it to the datastore by passing it as an argument to the DatastoreService. put() method.


2 Answers

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.

like image 106
topchef Avatar answered Oct 26 '22 22:10

topchef


In JDO use

@Persistent
private List<ContactInfo> contactInfoSets;
like image 38
Stan Kurilin Avatar answered Oct 26 '22 23:10

Stan Kurilin