具有 Objectify 数据结构的 App 引擎

发布于 2024-12-12 17:20:10 字数 1933 浏览 3 评论 0原文

真的很喜欢 objectify,尽管仍在努力寻找在我的应用程序中构建数据的最佳方法。我将很快推出一个新的应用程序,并且不想陷入可能无法正常运行或执行速度非常慢的结构。

该应用程序将位于 HRD 上,并且将具有大量实体类型。出于说明目的,我将制作一些示例实体。假设该应用程序适用于快餐店。每个连锁店都是一个实体(例如麦当劳、温迪店等)。每个特定的特许经营权或地点也将是一个实体。员工、订单、菜单、时间表等也将是实体。

我想最大的问题是如何建立这些实体之间的关系?我通过将数据存储 ID 作为长整型存储在每个实体中来存储关系。例如,每个员工实体都会有一个长值,该值是他们工作地点的数据存储 ID,以及他们所属链的成员。

通过这种结构,我可以使用以下语句查询特定餐厅的所有订单:

  Long restaurantId =restaurant.getId();
  Query<Order> q=ofy.query(Order.class).filter("location", resturantId);

只是好奇以这种方式使用数据存储/对象化是否存在任何问题。任何输入都会很棒!我一直在小规模地使用类似的东西,并且似乎工作得很好。理想情况下,我想要最有效的结构,并且我意识到这可能需要一些测试。然而,一旦部署了应用程序,就很难更改......

@Entity
public class Chain {

  @Id
  @GeneratedValue(strategy = GenerationType.IDENTITY)
  private Long id;

  private String name;
  private String type;

  //getters & setters, etc
  }

@Entity
public class Location {

  @Id
  @GeneratedValue(strategy = GenerationType.IDENTITY)
  private Long id;

  private Long chain;  //which resturant chain the location belongs to (mcdonalds, wendy's,     etc)

  private String address;
  private String owner;
  private String phoneNumber;

  //getters & setters, etc
  }

@Entity
public class Employee {

  @Id
  @GeneratedValue(strategy = GenerationType.IDENTITY)
  private Long id;

  private Long location;  //which location the employee works for
  private Long chain;  //which resturant chain the location belongs to (mcdonalds, wendy's,     etc)

  private String name;
  private String position;

  //getters & setters, etc
  }

@Entity
public class Order {

  @Id
  @GeneratedValue(strategy = GenerationType.IDENTITY)
  private Long id;

  private Long chain;  //which resturant chain the location belongs to (mcdonalds, wendy's,     etc)
  private Long location;
  private Long employee; //employee that took order

  private Order order;
  private String time;

   //getters & setters, etc
   }

Really like objectify, although still struggling with what is the best way to structure my data in my app. I will be launching a new app soon and do not want to get stuck with a structure that may not function right, or would perform very slowly.

The app will be on the HRD and will have a large number of entity types. For illustrative purposes I will make up some example entities. Suppose the app is for fast food restaurants. Each chain will be an entity(for example McDonalds, Wendy's, etc.). Each specific franchise or location will be an entity as well. Employees, Orders, Menus, Timesheets, and so on will also be entities.

I guess by biggest question is how to setup the relationships between these entities? I have been store relationships by storing the datastore ID as a long in each entity. For example each employee entity would have a long value that is the datastore ID for the location they work at, as well as for which chain they are a member of.

With this structure I can query for all of the orders from a specific restaurant with a statement such as:

  Long restaurantId =restaurant.getId();
  Query<Order> q=ofy.query(Order.class).filter("location", resturantId);

Just curious if there is any issue with using the datastore/objectify in this manner. Any input would be great! I have been using something similar on a small scale and seems to work fine. Ideally I would like the most efficient structure, and i realize this may take some testing. However once may app is deployed it may be very difficult to change...

@Entity
public class Chain {

  @Id
  @GeneratedValue(strategy = GenerationType.IDENTITY)
  private Long id;

  private String name;
  private String type;

  //getters & setters, etc
  }

@Entity
public class Location {

  @Id
  @GeneratedValue(strategy = GenerationType.IDENTITY)
  private Long id;

  private Long chain;  //which resturant chain the location belongs to (mcdonalds, wendy's,     etc)

  private String address;
  private String owner;
  private String phoneNumber;

  //getters & setters, etc
  }

@Entity
public class Employee {

  @Id
  @GeneratedValue(strategy = GenerationType.IDENTITY)
  private Long id;

  private Long location;  //which location the employee works for
  private Long chain;  //which resturant chain the location belongs to (mcdonalds, wendy's,     etc)

  private String name;
  private String position;

  //getters & setters, etc
  }

@Entity
public class Order {

  @Id
  @GeneratedValue(strategy = GenerationType.IDENTITY)
  private Long id;

  private Long chain;  //which resturant chain the location belongs to (mcdonalds, wendy's,     etc)
  private Long location;
  private Long employee; //employee that took order

  private Order order;
  private String time;

   //getters & setters, etc
   }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

三五鸿雁 2024-12-19 17:20:10

这是标准做法。前进吧!

Objectify 很棒 - 我们已经使用它大约 6 个月了,我们对它非常满意。

This is standard practice. Go forth!

Objectify is great - we've been using it for about 6 months and we're very happy with it.

余厌 2024-12-19 17:20:10

Key是类型安全的,Long 则不是。文档中不鼓励使用 Long。

参考:https://github.com/objectify/objectify/wiki/Entities#relationships< /a>

我鼓励您阅读整个页面,这是值得花时间的。我现在拥有一个在各处使用 Ref的类型安全结构。

Key<Object> is type safe, Long is not. Using Long is discouraged in the documentation.

Reference: https://github.com/objectify/objectify/wiki/Entities#relationships

I'd encourage you to read through that entire page, it's worth the time. I now have a type-safe structure using Ref<Object> everywhere.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文