从现有数据库生成 JDO 对象

发布于 2024-12-02 08:56:48 字数 97 浏览 1 评论 0原文

是否有工具可以从现有数据库生成 JDO 对象?我更喜欢一个看起来很棒的 Eclipse 插件,我可以用它来生成和维护对象,但它似乎目前不存在。是否有其他简单的工具来生成数据库对象?

Is there a tool to generate JDO objects from an existing database? I prefer a awesome looking Eclipse plugin which i could use to generate and maintain the object but it seems that this is currently not existing. Are other, simple tools to generate the database objects?

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

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

发布评论

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

评论(1

习惯成性 2024-12-09 08:56:48

JDO 对象不是数据库行的简单包装器(尽管如果您愿意,您可以将 JDO 对象实现为数据库行的简单包装器)。因此,大多数自动化工具仅通过查看数据库将无法知道如何呈现对象。

例如,像这样的对象:

public class Person {

   private List<PhoneNumber> phoneNumbers;

   ...

   public List<PhoneNumber> getPhoneNumbers() {
     ...
   }

}

可能让 JDO 预取所有电话号码以便直接包含到该对象中。在关系数据库中,这可能是通过在构造 Person 对象时将 PhoneNumber 数据库表与 Person 数据库表连接来完成的。

其他实现可能类似于

public class PhoneNumber {

   public Person getPerson() {
     ...
   }
}

并强制用户在单独的数据库请求中获取某人的电话号码。通用工具不可能预测您希望使用哪种方式。有两种选择(如此处所示),很容易说“使其可配置!”但是,在组合添加八个或更多独立选项后,并不清楚配置类生成是否会更容易(而不是直接编写类)。

更不用说 JDO 并不是为类生成而设计的,事实上,它的设计目的是使您手写的类在不生成的情况下持久存在,因为当时的类生成技术留下了许多可见的缺陷(不合需要的命名模式、暴露的冲突)接口和方法等)。

JDO objects are not simple wrappers around database rows (although you can implement your JDO objects as simple wrappers around database rows if that is what you wish). As such, most automated tools will not know how the object is to be presented by only looking at the database.

For example, an object like:

public class Person {

   private List<PhoneNumber> phoneNumbers;

   ...

   public List<PhoneNumber> getPhoneNumbers() {
     ...
   }

}

might have JDO pre-fetching all the phone numbers for direct inclusion into the object. In the relational database this would probably be done by joining the PhoneNumber database table with the Person database table when constructing the Person object.

Other implementations might look like

public class PhoneNumber {

   public Person getPerson() {
     ...
   }
}

And force the user to fetch a person's phone numbers in a separate database request. It's just not possible for a general purpose tool to predict which manner you wish to use. With two choices (as presented here) it's pretty easy to say "make it configurable!" However, after you add eight or more independent choices in combination, it is not clear that it would be easier to configure the class generation (as opposed to writing the class outright).

Not to mention that JDO wasn't designed for class generation in mind, in fact it was designed to make your hand written classes persistent without generation because the class generation technologies of the day left a lot of visible cruft (undesirable naming patterns, exposed conflicting interfaces and methods, etc).

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