简体   繁体   English

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

[英]Java web application & database design

I have developed a work flow web application in Java with an Oracle backend. 我已经开发了一个带有Oracle后端的Java工作流Web应用程序。 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. 我使用每个检查表2个表开始了该项目-一个表用于存储问题,另一个表用于存储答案。

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. 我正在重构整个应用程序,因为它没有遵循MVC方法。 Now is the time to correct any database deign issues. 现在是纠正任何数据库设计问题的时候了。

Here is my new approach: 这是我的新方法:

tables: 表格:

CHECKLIST_CLASS - store a type of checklist ie Quality Audit Checklist, Process Audit Checklist CHECKLIST_CLASS存储CHECKLIST_CLASS类型,即质量审核清单,过程审核清单
CHECKLIST_INSTANCE - the users checklist being worked. CHECKLIST_INSTANCE正在使用的用户清单。 store FK of the checklist_class_id, work_flow_id 存储checklist_class_id,work_flow_id的FK
CHECKLIST_ANSWER - stores the check_list_instance_id, FK of the question_id, multiple choice answer CHECKLIST_ANSWER存储check_list_instance_id,question_id的FK,多选答案
CHECKLIST_QUESTION - stores the question_id, FK of the checklist_class_id CHECKLIST_QUESTION存储question_id,checklist_class_id的FK

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. 我认为,一旦我编写了代表各种清单的所有javabean模型,就可以清理工作。 I just want to feel like I am on the right path during this refactoring job. 我只想感觉自己在进行重构工作时走上了正确的道路。

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. 对于选项2和3,一个子选项是考虑使用视图。

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. 我显然不知道您在什么时间范围内工作,但是如果您有时间的话,我强烈建议您创建POJO来存储结果,而不是将它们放在哈希图中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM