"Java EE Learning Day 71st" "Data acquisition system third Day" "Analysis answer entity" "Delete question" "Delete page" "Delete Survey" "Clear Survey" "Open/Close survey"

Source: Internet
Author: User

I. Analytical answer entity

Analysis of the answer entity is mainly related to the design of the problem, the technical point is almost no. You first need to determine the format of the answer in order to finalize what attributes are required in the answer entity.

The design of the answer format is very important, the current design format is as follows:

The information that needs to be provided in the form has a name value and a value, and the name value is actually used only to echo and save the answer, and only one question ID is required to save the answer, but in fact the value of name is more complex for a matrix radio button. The reason for the complication is that it is convenient for Echo. But there is only one problem ID that needs to be saved in the answer entity.

Answer format for type 1-4 questions (single, multiple, with other items):

If it is a radio type or a checkbox type of form: Name= ' Q ' +qid,value= the index value of the problem, such as problem type 1, then the answer is Q1, here does not consider to see the answer question has been done, assuming a one-time commit.

If there is a "other" topic, first use a form of type Chekbox to determine if there are other types of options, which are of type Boolean, name= ' Q ' +qid, but the value is fixed "other"

If there are other types of topics, then you also need to determine which type of other types of topics, it is assumed that the other types of topics have two types, one is a text box type, one is a drop-down list type.

Two other types of answers name= ' q ' +qid+ ' other ', for the answer to a text box type in the first year, the answer to the question is to save just a string, which is also an indexed value for the problem.

Type 5 answer to the question (drop-down list): Name= ' Q ' +qid,value= the index value of the problem;

Type 6 answer to question (text box): name= ' Q ' +qid,value= filled in the string;

Type 7 question Answer (Matrix radio button): Name= ' Q ' +qid+ ' _ ' + line coordinates + ' _ ' + column coordinates, value= line coordinates + ' _ ' + ordinate.

Type 8 question Answer (Matrix check box button): Name= ' q ' +qid,value= ' line coordinates ' + ' _ ' + ordinate.

Type 9 question Answer (matrix drop-down list): Name= ' Q ' +qid,value= line coordinates + ' _ ' + ordinate + ' _ ' + index value of drop-down list box.

To summarize, the answer to the entity needs to save the answer mainly has two is the answer index value string Answerindexs, a otheranswer with other answers to save other answers. Plus an answer time answertime, you need to be aware of the question of whether you need to associate to the question object. Do you first need to get all the answers to the question based on question? There has to be this need, but it's foolish to get all the answers using an association, because the number of people involved in the survey is very large, probably tens of thousands of or hundreds of thousands of, and if the question object is passed on to the front page as you like, a lot of the data (answer) is saved to the session, The server will soon be paralyzed so quesiton must not be associated to the answers object. But here also need to answer object and question object have contact, otherwise simply save the answer is meaningless. So we add a QuestionID property to the answer object to identify the problem. Also for convenience, we use a redundant field Surveyid to identify which survey is.

  

Second, delete the problem, delete the page, delete the survey

Above three delete no matter which one you delete, you must first be sure to delete all the corresponding answers.

Delete question: Delete the answer first and then delete the question

1  Public void deletequestion (Question Question) {2         String hql= "Delete from Answer a where a.questionid=?" ; 3         questiondao.batchentitybyhql (HQL, Question.getquestionid ()); 4         5         Hql= "Delete from Question Q where q.questionid=?" ; 6          This . QUESTIONDAO.BATCHENTITYBYHQL (HQL, Question.getquestionid ()); 7     }

Delete page: Delete the answer first, then delete the question, then delete the page

 Public voiddeletepage (Page page) {page=Pagedao.getentitybyid (Page.getpageid ()); Set<Question> questions=page.getquestions (); //Remove all questions and answers from the page firstString hql= "Delete from Answer a where a.questionid=?";  for(Question question:questions) {answerdao.batchentitybyhql (HQL, Question.getquestionid ()); }        //Remove All issuesHql= "Delete from Question Q where page.pageid=?";        QUESTIONDAO.BATCHENTITYBYHQL (HQL, Page.getpageid ()); //Delete the current pagehql= "Delete from page p where p.pageid=?";    PAGEDAO.BATCHENTITYBYHQL (HQL, Page.getpageid ()); }

Delete a survey: Delete the answer first, then delete the question, delete the page, and finally delete the survey.

1  Public voidDeletesurvey (Survey Survey) {2survey= This. Surveydao.getentitybyid (Survey.getsurveyid ());3 String hql;4set<page>pages=survey.getpages ();5          for(Page page:pages) {6set<question>questions=page.getquestions ();7             //first Remove all questions from all the pages in the current survey8              for(Question question:questions) {9Hql= "Delete from Answer a where a.questionid=?";Ten answerdao.batchentitybyhql (HQL, Question.getquestionid ()); One             } A             //then remove all the issues from all the pages in the current survey -Hql= "Delete from Question where page.pageid=?"; - questiondao.batchentitybyhql (HQL, Page.getpageid ()); the         } -         //then delete all the pages in the current survey -hql= "Delete from page where survey.surveyid=?"; - pagedao.batchentitybyhql (HQL, Survey.getsurveyid ()); +         //finally delete the survey object itself -Hql= "Delete from Survey s where s.surveyid=?"; + surveydao.batchentitybyhql (HQL, Survey.getsurveyid ()); A}

Third, clear the investigation, that is, delete their own participation in the investigation, a little.

Iv. Open and close investigations

This feature can affect which surveys can be displayed when participating in a survey. This requires adding a new property to the survey object closed, if the value of the property is true, indicating that the status of the survey has been closed, that it cannot be displayed in the list of participating surveys, and if False indicates that it has not been closed, it can be displayed in the list.

Relatively simple, slightly.

"Java EE Learning Day 71st" "Data acquisition system third Day" "Analysis answer entity" "Delete question" "Delete page" "Delete Survey" "Clear Survey" "Open/Close survey"

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.