Java Web 应用程序和数据库设计

发布于 2024-10-12 04:46:00 字数 2721 浏览 2 评论 0原文

我用 Java 开发了一个带有 Oracle 后端的工作流 Web 应用程序。该工作流程要求用户完成一系列检查表。
我开始这个项目时,每个清单使用 2 个表 - 一个表用于存储问题,另一个表用于存储答案。

但管理层一直要求提供更多清单,所以我改变了我的数据库方法(如下)。我想知道这种方法是否好,或者我会给自己带来麻烦。我正在重构整个应用程序,因为它没有遵循 MVC 方法。现在是纠正任何数据库设计问题的时候了。

这是我的新方法:

表:

CHECKLIST_CLASS - 存储一种类型的清单,即质量审核清单、流程审核清单
CHECKLIST_INSTANCE - 正在处理的用户清单。存储checklist_class_id、work_flow_id的FK
CHECKLIST_ANSWER - 存储 check_list_instance_id、question_id 的 FK、多项选择答案
CHECKLIST_QUESTION - 存储 Question_id、checklist_class_id 的 FK

我喜欢这种方法,因为我可以动态添加新的检查列表,而无需添加另一个数据库表。
但它使得查询确定工作流程中每个清单的状态变得有点复杂。

 SELECT TO_CHAR(CALCDATEREQUIRED, 'MM/DD/YYYY') as CALCDATEREQUIRED, 
        TO_CHAR(CALCAPPROVEIPRDATE, 'MM/DD/YYYY') as CALCAPPROVEIPRDATE, 
        (SELECT SECTION_I_STATE FROM TPQOT_CALC_MODEL WHERE CHECKLIST_INSTANCE_ID = 
            SELECT MAX(TPQOT_CHECKLIST_INSTANCE.CHECKLIST_INSTANCE_ID) FROM TPQOT_CHECKLIST_INSTANCE 
            WHERE TPQOT_CHECKLIST_INSTANCE.CHECKLIST_CLASS_ID='1257877690209' AND 
            TPQOT_CHECKLIST_INSTANCE.CALC_ID=CALCID AND 
            TPQOT_CHECKLIST_INSTANCE.CALC_REV=CALCREV)  ) AS SECTION_I_STATE, 
        (SELECT CHECKLIST_STATE AS FINALIZE_CHECKLIST_STATUS FROM TPQOT_CHECKLIST_INSTANCE WHERE CHECKLIST_INSTANCE_ID = 
            (SELECT MAX(TPQOT_CHECKLIST_INSTANCE.CHECKLIST_INSTANCE_ID) FROM TPQOT_CHECKLIST_INSTANCE 
            WHERE TPQOT_CHECKLIST_INSTANCE.CHECKLIST_CLASS_ID='1257877690209' AND 
            TPQOT_CHECKLIST_INSTANCE.CALC_ID=CALCID AND 
            TPQOT_CHECKLIST_INSTANCE.CALC_REV=CALCREV)  ) AS DI4630901_STATE, 
        (SELECT CHECKLIST_STATE AS FINALIZE_CHECKLIST_STATUS FROM TPQOT_CHECKLIST_INSTANCE WHERE CHECKLIST_INSTANCE_ID = 
            (SELECT MAX(TPQOT_CHECKLIST_INSTANCE.CHECKLIST_INSTANCE_ID) FROM TPQOT_CHECKLIST_INSTANCE 
            WHERE TPQOT_CHECKLIST_INSTANCE.CHECKLIST_CLASS_ID='1257877670188' AND 
            TPQOT_CHECKLIST_INSTANCE.CALC_ID=CALCID AND 
            TPQOT_CHECKLIST_INSTANCE.CALC_REV=CALCREV)  ) AS OPC_STATE, 
        (SELECT phonebook.lname FROM phonebook WHERE phonebook.badge = xtbl463Calc.CalcOriginator) AS OrigName, 
        (SELECT phonebook.lname FROM phonebook WHERE phonebook.badge = xtbl463Calc.CalcChecker) AS CheckName, 
        (SELECT phonebook.lname FROM phonebook WHERE phonebook.badge = xtbl463Calc.CalcReviewer) AS ReviewName, 
        (SELECT phonebook.lname FROM phonebook WHERE phonebook.badge = xtbl463Calc.CalcApprover) AS ApproveName 
        FROM xtbl463Calc ORDER BY CALCID;

该查询的结果集进入哈希图的数组列表并发送到我的视图。我应该继续这种 4 表方法吗?我需要重构我的查询吗?我想一旦我编码了代表各种清单的所有 javabean 模型,我就可以清理这些东西。我只是想在这次重构工作中感觉自己走在正确的道路上。

I have developed a work flow web application in Java with an Oracle backend. The workflow requires the user to complete a series of checklists.
I started the project using 2 tables per checklist - one table to store the questions and another to store the answers.

But management keeps asking for more checklists so I changed my db approach (below). I'd like to know if this approach is good or I am setting myself up for trouble down the road. I am in the process of refactoring the whole application because it did not follow an MVC approach. Now is the time to correct any database deign issues.

Here is my new approach:

tables:

CHECKLIST_CLASS - store a type of checklist i.e. Quality Audit Checklist, Process Audit Checklist
CHECKLIST_INSTANCE - the users checklist being worked. store FK of the checklist_class_id, work_flow_id
CHECKLIST_ANSWER - stores the check_list_instance_id, FK of the question_id, multiple choice answer
CHECKLIST_QUESTION - stores the question_id, FK of the checklist_class_id

I like this approach because I can dynamically add a new check list without adding another db table.
but it makes queries a little complicated looking for determining the status of each checklist in the workflow.

 SELECT TO_CHAR(CALCDATEREQUIRED, 'MM/DD/YYYY') as CALCDATEREQUIRED, 
        TO_CHAR(CALCAPPROVEIPRDATE, 'MM/DD/YYYY') as CALCAPPROVEIPRDATE, 
        (SELECT SECTION_I_STATE FROM TPQOT_CALC_MODEL WHERE CHECKLIST_INSTANCE_ID = 
            SELECT MAX(TPQOT_CHECKLIST_INSTANCE.CHECKLIST_INSTANCE_ID) FROM TPQOT_CHECKLIST_INSTANCE 
            WHERE TPQOT_CHECKLIST_INSTANCE.CHECKLIST_CLASS_ID='1257877690209' AND 
            TPQOT_CHECKLIST_INSTANCE.CALC_ID=CALCID AND 
            TPQOT_CHECKLIST_INSTANCE.CALC_REV=CALCREV)  ) AS SECTION_I_STATE, 
        (SELECT CHECKLIST_STATE AS FINALIZE_CHECKLIST_STATUS FROM TPQOT_CHECKLIST_INSTANCE WHERE CHECKLIST_INSTANCE_ID = 
            (SELECT MAX(TPQOT_CHECKLIST_INSTANCE.CHECKLIST_INSTANCE_ID) FROM TPQOT_CHECKLIST_INSTANCE 
            WHERE TPQOT_CHECKLIST_INSTANCE.CHECKLIST_CLASS_ID='1257877690209' AND 
            TPQOT_CHECKLIST_INSTANCE.CALC_ID=CALCID AND 
            TPQOT_CHECKLIST_INSTANCE.CALC_REV=CALCREV)  ) AS DI4630901_STATE, 
        (SELECT CHECKLIST_STATE AS FINALIZE_CHECKLIST_STATUS FROM TPQOT_CHECKLIST_INSTANCE WHERE CHECKLIST_INSTANCE_ID = 
            (SELECT MAX(TPQOT_CHECKLIST_INSTANCE.CHECKLIST_INSTANCE_ID) FROM TPQOT_CHECKLIST_INSTANCE 
            WHERE TPQOT_CHECKLIST_INSTANCE.CHECKLIST_CLASS_ID='1257877670188' AND 
            TPQOT_CHECKLIST_INSTANCE.CALC_ID=CALCID AND 
            TPQOT_CHECKLIST_INSTANCE.CALC_REV=CALCREV)  ) AS OPC_STATE, 
        (SELECT phonebook.lname FROM phonebook WHERE phonebook.badge = xtbl463Calc.CalcOriginator) AS OrigName, 
        (SELECT phonebook.lname FROM phonebook WHERE phonebook.badge = xtbl463Calc.CalcChecker) AS CheckName, 
        (SELECT phonebook.lname FROM phonebook WHERE phonebook.badge = xtbl463Calc.CalcReviewer) AS ReviewName, 
        (SELECT phonebook.lname FROM phonebook WHERE phonebook.badge = xtbl463Calc.CalcApprover) AS ApproveName 
        FROM xtbl463Calc ORDER BY CALCID;

The result set for this query goes into an array list of hashmaps and sent to my view. Should I continue with this 4 table approach? Do I need to refactor my query? I think once I code all my javabean models representing the various checklists I can clean things up. I just want to feel like I am on the right path during this refactoring job.

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

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

发布评论

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

评论(1

暖风昔人 2024-10-19 04:46:00

我看不出表结构有多大问题,如果我正确理解你的描述,它存储它应该存储的结构。

另一方面,查询看起来确实太复杂了。

查询中的查询中有很多查询都是不正确的。我可以看到这里打开了三个选项:

  1. 检查您是否需要此查询。您真的必须同时显示所有内容的详细状态吗?
  2. 检查是否可以以某种方式简化查询,消除或合并部分查询,用联接替换内部选择,等等。查询中有相当多的重复,因此绝对可以简化。
  3. 将查询分解为几个较小的查询,然后依次执行。例如,查询的电话簿部分几乎肯定可以与主查询分开运行。

对于选项 2 和 3,一​​个子选项是考虑使用视图。

最后,还有将结果放入哈希映射列表的问题。我显然不知道您工作的时间限制,但如果您有时间的话,我强烈建议您创建 POJO 来存储结果,而不是将它们放入哈希图中。

I can't see much wrong with the table structure, if I understood your description correctly, it stores the structure it is supposed to store.

The query on the other hand does look way too complicated.

There are a lot of queries iwthin queries within queries which just can't be right. I can see three options open here:

  1. Check whether you need this query at all. Do you really have to display the detailed status of everything at the same time?
  2. Check whether you can simplify your query in some way, eliminate or merge parts of it, replace inner selects with joins, anything. There is considerable repetition in the query, so it can definitely be simplified.
  3. Break the query down into several smaller queries that are executed one after the other. For example, the phonebook part of the query can almost certainly be run separately from the main query.

With options 2 and 3 a sub-option is to consider the use of views.

And finally, there's the question of putting the result in a list of hashmaps. I obviously don't know the time constraints within which you're working but if you can afford the time, I'd strongly recommend creating POJOs for storing the results instead of putting them in a hashmap.

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