LoginSignup
2
1

More than 5 years have passed since last update.

EmbeddedEntity

Posted at

Who

Google App Engine (GAE/J)
Datastore API

What

EntityにプロパティMapを埋め込む。
プロパティMapはEntityとしてDatastoreに登録する必要はない。
EntityからEmbeddedEntityへとその逆の変換が用意されている。
EntityのIDを関連付けるのではなく、Entityのプロパティ自体を持つ。

When, Where

サーバーサイド

Why

EntityのプロパティにEntityを指定するために使用する。

How

employee EntityにContact Infoを埋め込む。

public class EmbeddedEntitySample {
  static final DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();

  void execute() {
    final Entity employee = new Entity("employee");
    employee.setProperty("firstName", "Antonio");
    employee.setProperty("lastName", "Salieri");

    final EmbeddedEntity embeddedContactInfo = new EmbeddedEntity();

    embeddedContactInfo.setProperty("homeAddress", "XXX-XXXX");
    embeddedContactInfo.setProperty("phoneNumber", "XXXXXXXX");
    embeddedContactInfo.setProperty("emailAddress", "xxx@gmail.com");

    employee.setProperty("contactInfo", embeddedContactInfo);

    datastore.put(employee);

    final Entity contactInfo = new Entity("contactInfo");
    contactInfo.setPropertiesFrom(embeddedContactInfo);
    datastore.put(contactInfo);
  }
}
2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1