📄 testmanager.java
字号:
/*
* Created on 23-ene-2005 13:16:09
*
*/
package com.martincuervo.javatest.business.service;
import java.util.Iterator;
import java.util.List;
import com.martincuervo.javatest.business.vo.AnswerVO;
import com.martincuervo.javatest.business.vo.CategoryVO;
import com.martincuervo.javatest.business.vo.QuestionVO;
/**
* @author Jorge Martin Cuervo <jorge@martincuervo.com>
*
*/
public class TestManager extends CommonManager {
/**
* Añade una pregunta y sus respectivas respuestas
*
* @param question
*/
public void addQuestion(QuestionVO question) {
getDAOFactory().getQuestionDAO().addQuestion(question);
List answers = question.getAnswers();
if (answers != null && answers.size() > 0) {
for (Iterator iter = answers.iterator(); iter.hasNext();) {
AnswerVO element = (AnswerVO) iter.next();
getDAOFactory().getAnswerDAO().addAnswer(element, question);
}
}
}
/**
* Elimina una pregunta
*
* En el caso de Oracle, la constraint ya tiene un "on delete cascade" y no
* he codificado el borrado de respuestas.
*
* @param question
*/
public void delQuestion(QuestionVO question) {
getDAOFactory().getQuestionDAO().delQuestion(question);
}
/**
* Modifica la pregunta
*
* TODO ¿que pasa con las respuetas? si las update tambien me puede suceder
* que tenga nuevas. Lo mejor creo que sera borrar e insertar todo.
* @param question
*/
public void modQuestion(QuestionVO question) {
getDAOFactory().getQuestionDAO().modQuestion(question);
}
/**
* Obtiene todas las preguntas y sus respuestas
*
* Que filosofico ha quedao!!
*
* @return
*/
public List getQuestions() {
List questions = getDAOFactory().getQuestionDAO().getQuestions();
for (Iterator iter = questions.iterator(); iter.hasNext();) {
QuestionVO element = (QuestionVO) iter.next();
element.setAnswers(getDAOFactory().getAnswerDAO().getAnswers(element));
element.setCategory(getDAOFactory().getCategoryDAO().getCategory(element.getCategory()));
}
return questions;
}
/**
* Obtiene la pregunta segun el parametro indicado
*
* @param question
* @return
*/
public QuestionVO getQuestion(QuestionVO question) {
QuestionVO q = getDAOFactory().getQuestionDAO().getQuestion(question);
q.setAnswers(getDAOFactory().getAnswerDAO().getAnswers(question));
q.setCategory(getDAOFactory().getCategoryDAO().getCategory(q.getCategory()));
return q;
}
/**
* Retorna la lista de respuesta de una pregunta
*
* @param question
* @return
*/
public List getAnswers(QuestionVO question) {
return getDAOFactory().getAnswerDAO().getAnswers(question);
}
/**
* Elimina una respuesta
*
* @param answer
*/
public void delAnswer(AnswerVO answer) {
getDAOFactory().getAnswerDAO().delAnswer(answer);
}
/**
* Obtiene la pregunta de una respuesta
*
* @param answer
* @return
*/
public QuestionVO getQuestion(AnswerVO answer) {
QuestionVO q = getDAOFactory().getQuestionDAO().getQuestion(answer);
q.setAnswers(getDAOFactory().getAnswerDAO().getAnswers(q));
q.setCategory(getDAOFactory().getCategoryDAO().getCategory(q.getCategory()));
return q;
}
/**
* Añade una respuesta
*
* @param answer
* @param question
*/
public void addAnswer(AnswerVO answer, QuestionVO question) {
getDAOFactory().getAnswerDAO().addAnswer(answer, question);
}
/**
* Añade una categoria
*
* @param category
*/
public void addCategory(CategoryVO category) {
getDAOFactory().getCategoryDAO().addCategory(category);
}
/**
* Modifica una categoria
*
* @param category
*/
public void modCategory(CategoryVO category) {
getDAOFactory().getCategoryDAO().modCategory(category);
}
/**
* Elimina una categoria
*
* @param category
*/
public void delCategory(CategoryVO category) {
getDAOFactory().getCategoryDAO().delCategory(category);
}
/**
* Returna todas las categorias
*
* @return
*/
public List getCategories() {
return getDAOFactory().getCategoryDAO().getCategories();
}
/**
* Obtiene una categoria
*
* @param category
* @return
*/
public CategoryVO getCategory(CategoryVO category) {
return getDAOFactory().getCategoryDAO().getCategory(category);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -