Java(NetBeans 平台)RCP 中的数据类和业务对象以及查看器类的体系结构

发布于 2025-01-08 00:50:23 字数 1098 浏览 3 评论 0原文

我有一些编程经验,但我仍然是一个业余爱好者。我浏览了许多 NB 平台和 IDE 教程并阅读了一些书籍,但它对我如何使用数据库组织我的 RCP 应用程序(Derby 嵌入,而不是外部服务器)没有帮助。

我有什么?

  1. 实体类(由NB IDE从数据库生成,用于JPA)和JPA(使用EclipseLink
  2. 一些视图对象,例如TopComponent、Explorer等节点
  3. 基本现实世界的“对象”:书籍、书中的章节、章节中的人物

我想,我还应该为所有对象使用一些DAO类三个现实世界的对象,它们将创建和发送查询到数据库并返回数据。 当然,我会为业务逻辑构建一些业务对象。可能是“书籍”、“章节”、“人物”,例如,章节实例的属性包含指向章节来源的书籍实例的链接。

但是如何进行基本操作,例如:

  1. 获取所有书籍/字符或特定书籍的章节的集合以在某些视图中显示?
  2. 所有业务对象的基本 CRUD 操作? 等等?

我的意思是,我不能直接从我的业务对象(例如从 Chapters)调用 DAO 来请求查询所有字符,这些字符在 Chapters 表中的 FK 等于此 Chapters 实例的 ID,可以吗?我的业务逻辑和特定的数据库系统(在 DAO 中)连接得太紧密了。 要求 Book 实例返回所有书籍是没有意义的。我应该为此创建一些静态方法和可能的属性(集合)吗? 或者我应该创建一些适配器类,它会调用特定的 DAO 方法并从中创建特定的业务对象并返回它们?

所以我的一般问题是:

  • A) 如何获取数据集合?在哪里保存它们的一些收藏?
  • B) 如何获取个人数据?当我编辑某些字符(例如其名称)时,我更改了业务对象属性,但如何将此更改获取到数据库中?业务对象本身是否应该以某种方式调用 DAO,或者我应该在视图/控制器中不仅更新业务对象,而且还更新数据对象(可能通过某些适配器类)?

我将不胜感激任何帮助。我感到完全迷失了,但我无法创建一些应用程序来让它工作,我需要一些好的设计(这是一种大学工作)。

I have some experience with programming, but I am still quite an amateur. I went through many NB platform and IDE tutorials and read through some book, but it have not helped me, how to organise my RCP application with database (Derby embbed, not an external server).

What I have got?

  1. entity classes (generated by NB IDE from database, for JPA) and JPA (using EclipseLink)
  2. some view objects like TopComponent, Explorer etc. and Nodes
  3. basic real world "objects": books, chapters in book, characters in chapters

I guess, I should also use some DAO class for all three real world objects, which would create and send queries to database and return the data.
And of course, I would build some business objects for business logic. Probably "Books", "Chapters", "Characters", where for example instance of Chapter has attribute containing link to instance of Book, where the chapter is from.

But how to make basic operations like:

  1. Getting collection of all books/characters or chapters of particular book for displaying in some view?
  2. Basic CRUD operations with all business objects?
    and so on?

I mean, I can't call directly the DAO from my business object, for example from Chapters, to ask query for all characters, which have the FK in chapters table equal to the ID of this Chapters instance, can I? It would be too connected, my business logic and particular database system (in DAO).
And it makes no sense, to ask instance of Book to return all books. Should I make some static methods and probably attributes (collections) for this?
Or should I create some adapter class, which would call the particular DAO's methods and create from them particular business objects and return them?

So my general questions are:

  • A) How to get collections of data? Where to maintain some collection of them?
  • B) How to get individual data? When I edit some Character, for example its name, I change the business object attribute, but how do I get this change into database? Should the business object itself call the DAO somehow, or should I do in my view/controller not only update business object, but also the data object (probably via some adapter class)?

I would appreciate any help. I feel totally lost, but I can't create some app just so it works, I need a bit good design (it is kind of university work).

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

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

发布评论

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

评论(1

夜雨飘雪 2025-01-15 00:50:23

考虑使用像 grails 或 roo 这样的框架。这些将免费为您提供粗品。他们将为您的应用程序提供一些结构(模型-视图-控制器)。

consider using a framework like grails, or roo. these will get you crud for free. and they will give some structure (model-view-controller) for your app.

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