JPA 和装饰器模式

发布于 2024-10-24 12:20:58 字数 484 浏览 7 评论 0原文

我正在尝试创建一个部分依赖于人口普查部 TIGER/Lines 数据 Shapefile 的应用程序,该文件具有此处定义的记录布局:

http://www.census.gov/geo/www/tiger/tgrshp2010/TGRSHP10AA.pdf

我的想法是使用装饰器模式来拥有一个基本要素类,其中包含以下常见字段所有数据类型,然后通过各个要素类型(州、县、国会选区等)的装饰器模式对其进行扩展。但是,我计划使用 Google App Engine 进行托管,因此我必须通过 JDO 或 JPA 来执行此操作。我更喜欢 JPA。

我可以映射装饰对象吗?我的想法是,基本要素类将使用 @Entity 进行注释,然后扩展将包含特定于装饰对象的映射字段。由于 GAE 数据存储不是 RDBMS,我想我可以摆脱它。

I am trying to create an application which will be partially dependent on the Census Department TIGER/Lines data Shapefiles, which have a record layout defined here:

http://www.census.gov/geo/www/tiger/tgrshp2010/TGRSHP10AA.pdf

My idea is to use the Decorator pattern to have a base Feature class with the fields common to all the data types, then extend it via the decorator pattern for the individual feature types (States, Counties, Congressional Districts, etc). However, I plan to use Google App Engine for hosting, so I have to do this via either JDO or JPA. I would much prefer JPA.

Can I map a decorated object? My idea is that the base feature class would be annotated with @Entity, then the extensions would contain the mapped fields specific to the decorated object. Since the GAE datastore is NOT an RDBMS, I'm thinking I can get away with it.

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

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

发布评论

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

评论(1

抽个烟儿 2024-10-31 12:20:58

如果你使用Decorator模式,就意味着你使用了组合。所以你能做的就是将你想要装饰的类标记为 可嵌入并在装饰器中将装饰类标记为 嵌入

如果您更喜欢使用继承,那么您的基类不是一个实体,因为您想要继承的东西只是数据库,而不是存储本身。要创建将从其他真实实体继承的基类,有一个注释: @MappedSuperclass

根据GAE 文档,两者均受支持。

希望有帮助!

If you use the Decorator pattern, it means that you use the composition. So what you can do is just mark the class you want to decorate as Embeddable and in your decorator, mark your decorated class as Embedded.

If you prefer to use the inheritance, your base class is not an entity since is just something you want to inherit and not store itself is the DB. To create a base classe which will be inherited from other real entities, there is an annotation for that : @MappedSuperclass

According the GAE docs, both are supported.

Hope it helps!

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