net.sourceforge.jsurveyor
Class DataAccess

java.lang.Object
  extended bynet.sourceforge.jsurveyor.DataAccess

public class DataAccess
extends java.lang.Object

This class handles the interaction with the underlying storage technology. The set of methods defined here, provides persistence transparency for all other classes within this application. It encapsulates all persistence methods in one single class.

Version:
1.0
Author:
Claus Methmann Christensen, Anders Spliid Hansen, Esben Iversen Hansen, Lars H Jensen, Marcus Overheu, Thomas Ramdal, Peter Thomsen

Constructor Summary
DataAccess()
           
 
Method Summary
static void deleteAnswer(int answerID)
          Deletes the row containing the representation of the Answer object, with the AnswerID passed as argument.
static void deleteEvaluation(int evaluationID)
          Deletes the row containing the representation of the Evaluation object with the evaluationID passed as argument, along with all answers corresponding to this evaluation.
static void deleteEvaluationsForQuestionnaire(int questionnaireID)
          Deletes all evaluations generated from the Questionnaire with questionnaireID, by using the method deleteEvaluation(int evaluationID) recursively.
static void deleteQuestion(int questionID)
          Deletes the row containing the representation of the Question object, with the QuestionID passed as argument.
static void deleteQuestionnaire(int questionnaireID)
          Deletes the row containing the representation of the Questionnaire object with the QuestionnaireID passed as argument, along with all QuestionPages corresponding to this Questionnaire.
static void deleteQuestionPage(int questionPageID)
          Deletes the row containing the representation of the QuestionPage object, with the QuestionPageID passed as argument.
static void deleteUser(java.lang.String key)
          Deletes the row containing the representation of the User object, and updates all UserGroups which the User was a member of.
static void deleteUserGroup(int groupID)
          Deletes the row containing the representation of the UserGroup object, and updates all Users and UserGroups which the UserGroup was affected with.
static boolean existsUser(java.lang.String key)
          Method to test for existance of a User object representation in database.
static boolean existsUserGroup(java.lang.String key)
          Method to test for existance of a UserGroup object representation in database.
static java.util.ArrayList fetchQuestionnaires(User usr)
          Fetch all Questionnaire objects which the User passed as argument may answer.
static java.util.ArrayList retrieveAllEvaluations(int questionnaireID)
          Retrieves all evaluations corresponding to the Questionnaire with QuestionnaireID passed as argument, from the database.
static java.util.ArrayList retrieveAllRootUserGroups()
          Retrieves all UserGroup objects which has no parents, from the database.
static java.util.ArrayList retrieveAllUserGroups()
          Retrieves all UserGroup objects from the database.
static java.util.ArrayList retrieveAllUsers()
          Retrieves all Users from database, except those of UserType root.
static net.sourceforge.jsurveyor.Answer retrieveAnswer(int answerID)
          Retrieves an Answer object from the corresponding Answer SQL-table.
static Evaluation retrieveEvaluation(int evaluationID)
          Retrieves a Evaluation object from the database.
static net.sourceforge.jsurveyor.Question retrieveQuestion(int questionID)
          Retrieves a Question object from the database.
static Questionnaire retrieveQuestionnaire(int key)
          Retrieves a Questionnaire object from the database.
static java.util.ArrayList retrieveQuestionnairesForOwner(User usr)
          Retrieves all Questionnaire objects from the database with User usr as owner.
static QuestionPage retrieveQuestionPage(int key)
          Retrieves a QuestionPage object from the database.
static User retrieveUser(java.lang.String key)
          Retrieves a User object from the database.
static UserGroup retrieveUserGroup(int groupID)
          Retrieves a UserGroup object from the database.
static void storeAnswer(net.sourceforge.jsurveyor.Answer answer)
          Stores the passed Answer object in the corresponding Answer SQL-table.
static void storeEvaluation(Evaluation evaluation)
          Stores the passed Evaluation object in the corresponding Evaluation SQL-table.
static void storeQuestion(net.sourceforge.jsurveyor.Question question)
          Stores the passed Question object in the corresponding Question SQL-table.
static void storeQuestionnaire(Questionnaire questionnaire)
          Stores the passed Questionnaire object in the corresponding Questionnaire SQL-table.
static void storeQuestionPage(QuestionPage questionPage)
          Stores the passed QuestionPage object in the corresponding QuestionPage SQL-table.
static void storeUser(User usr)
          Stores the passed User object in the corresponding User SQL-table
static void storeUserGroup(UserGroup group)
          Stores the passed UserGroup object in the corresponding UserGroup SQL-table.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DataAccess

public DataAccess()
Method Detail

storeUser

public static void storeUser(User usr)
Stores the passed User object in the corresponding User SQL-table

Parameters:
usr - User
PRE condition:
User usr has the attribute Username set.
POST condition:
The User object has been stored or updated as a row in the database.

storeUserGroup

public static void storeUserGroup(UserGroup group)
Stores the passed UserGroup object in the corresponding UserGroup SQL-table.

Parameters:
group - UserGroup
PRE condition:
none
POST condition:
The UserGroup object has been stored as a row in the database. For a new object, an integer UserGroupID was attached to the object passed as an argument. If the object already was in the database, the row was updated.

storeAnswer

public static void storeAnswer(net.sourceforge.jsurveyor.Answer answer)
Stores the passed Answer object in the corresponding Answer SQL-table. Differs between the two types of answers, AnswerFreeText and AnswerMultipleChoice, with a null in the choice- or freetext-field, respectively.

Parameters:
answer - Answer
PRE condition:
none
POST condition:
The Answer object has been stored as a row in the database. For a new object, an integer AnswerID was attached to the object passed as an argument. If the object already was in the database, the row was updated.

storeEvaluation

public static void storeEvaluation(Evaluation evaluation)
Stores the passed Evaluation object in the corresponding Evaluation SQL-table.

Parameters:
evaluation - Evaluation
PRE condition:
none
POST condition:
The Evaluation object has been stored as a row in the database. For a new object, an integer EvaluationID was attached to the object passed as an argument. If the object already was in the database, the row was updated.

storeQuestionnaire

public static void storeQuestionnaire(Questionnaire questionnaire)
Stores the passed Questionnaire object in the corresponding Questionnaire SQL-table.

Parameters:
questionnaire - Questionnaire
PRE condition:
none
POST condition:
The Questionnaire object has been stored as a row in the database. For a new object, an integer QuestionnaireID was attached to the object passed as an argument. If the object already was in the database, the row was updated.

storeQuestionPage

public static void storeQuestionPage(QuestionPage questionPage)
Stores the passed QuestionPage object in the corresponding QuestionPage SQL-table.

Parameters:
questionPage - QuestionPage
PRE condition:
none
POST condition:
The QuestionPage object has been stored as a row in the database. For a new object, an integer QuestionPageID was attached to the object passed as an argument. If the object already was in the database, the row was updated.

storeQuestion

public static void storeQuestion(net.sourceforge.jsurveyor.Question question)
Stores the passed Question object in the corresponding Question SQL-table. Differs between the two types of questions, QuestionFreeText and QuestionMultipleChoice, with a null in the choices-field.

Parameters:
question - Question
PRE condition:
none
POST condition:
The Question object has been stored as a row in the database. For a new object, an integer QuestionID was attached to the object passed as an argument. If the object already was in the database, the row was updated.

deleteEvaluation

public static void deleteEvaluation(int evaluationID)
Deletes the row containing the representation of the Evaluation object with the evaluationID passed as argument, along with all answers corresponding to this evaluation.

Parameters:
evaluationID -
PRE condition:
the row in the Evaluation table with EvaluationID passed as argument, exists.
POST condition:
the row containing the representation of the Evaluation object, along with the rows from the Answer table containing all attached answers, has been deleted.

deleteEvaluationsForQuestionnaire

public static void deleteEvaluationsForQuestionnaire(int questionnaireID)
Deletes all evaluations generated from the Questionnaire with questionnaireID, by using the method deleteEvaluation(int evaluationID) recursively.

Parameters:
questionnaireID -
PRE condition:
none
POST condition:
the rows containing the representation of the evaluations generated from the Questionnaire with the questionnaireID passed as argument, has been deleted.

deleteQuestionnaire

public static void deleteQuestionnaire(int questionnaireID)
Deletes the row containing the representation of the Questionnaire object with the QuestionnaireID passed as argument, along with all QuestionPages corresponding to this Questionnaire.

Parameters:
questionnaireID -
PRE condition:
the row in the Questionnaire table with QuestionnaireID passed as argument, exists.
POST condition:
the row containing the representation of the Evaluation object, along with the rows from the Answer table containing all attached answers, has been deleted.

deleteQuestionPage

public static void deleteQuestionPage(int questionPageID)
Deletes the row containing the representation of the QuestionPage object, with the QuestionPageID passed as argument.

Parameters:
questionPageID - int
PRE condition:
none
POST condition:
the row containing the representation of the QuestionPage object has been deleted.

deleteQuestion

public static void deleteQuestion(int questionID)
Deletes the row containing the representation of the Question object, with the QuestionID passed as argument.

Parameters:
questionID - int
PRE condition:
none
POST condition:
the row containing the representation of the Question object has been deleted.

deleteAnswer

public static void deleteAnswer(int answerID)
Deletes the row containing the representation of the Answer object, with the AnswerID passed as argument.

Parameters:
answerID - int
PRE condition:
none
POST condition:
the row containing the representation of the Answer object has been deleted.

deleteUser

public static void deleteUser(java.lang.String key)
Deletes the row containing the representation of the User object, and updates all UserGroups which the User was a member of.

Parameters:
key - String
PRE condition:
the row in the User table with UserName key passed as argument, exists.
POST condition:
the row containing the representation of the User object has been deleted, and all affected UserGroups has been updated.

deleteUserGroup

public static void deleteUserGroup(int groupID)
Deletes the row containing the representation of the UserGroup object, and updates all Users and UserGroups which the UserGroup was affected with.

Parameters:
groupID - int
PRE condition:
the row in the UserGroup table with UserGroupID passed as argument, exists.
POST condition:
the row containing the representation of the UserGroup object has been deleted, and all affected Users and UserGroups has been updated.

retrieveAnswer

public static net.sourceforge.jsurveyor.Answer retrieveAnswer(int answerID)
Retrieves an Answer object from the corresponding Answer SQL-table.

Parameters:
answerID - int
Returns:
AnswerFreeText or AnswerMultipleChoice
PRE condition:
none
POST condition:
if the Answer didn't exist in the database, an AnswerFreeText object with IDs and choice set to -1 is returned.

retrieveAllUsers

public static java.util.ArrayList retrieveAllUsers()
Retrieves all Users from database, except those of UserType root.

Returns:
ArrayList of Users
PRE condition:
none

retrieveAllEvaluations

public static java.util.ArrayList retrieveAllEvaluations(int questionnaireID)
Retrieves all evaluations corresponding to the Questionnaire with QuestionnaireID passed as argument, from the database.

Parameters:
questionnaireID - int
Returns:
ArrayList of Evaluation
PRE condition:
none

retrieveEvaluation

public static Evaluation retrieveEvaluation(int evaluationID)
Retrieves a Evaluation object from the database.

Parameters:
evaluationID - int
Returns:
Evaluation
PRE condition:
none
POST condition:
if the Evaluation didn't exist, a Evaluation object with IDs set to -1 is returned.

retrieveQuestionnaire

public static Questionnaire retrieveQuestionnaire(int key)
Retrieves a Questionnaire object from the database.

Parameters:
key - int
Returns:
Questionnaire
PRE condition:
none
POST condition:
if the Questionnaire didn't exist, a Questionnaire object with ID set to 0 is returned.

retrieveQuestionPage

public static QuestionPage retrieveQuestionPage(int key)
Retrieves a QuestionPage object from the database.

Parameters:
key - int
Returns:
QuestionPage
PRE condition:
none
POST condition:
if the QuestionPage didn't exist, a QuestionPage object with ID set to 0 is returned.

retrieveUser

public static User retrieveUser(java.lang.String key)
Retrieves a User object from the database.

Parameters:
key - String
Returns:
User
PRE condition:
none
POST condition:
if the User didn't exist, a User object with all fields set to empty strings, is returned.

retrieveUserGroup

public static UserGroup retrieveUserGroup(int groupID)
Retrieves a UserGroup object from the database.

Parameters:
groupID - int
Returns:
UserGroup
PRE condition:
none
POST condition:
if the UserGroup didn't exist, a UserGroup object with ID set to -1 and all textfields set to empty strings, is returned.

retrieveAllUserGroups

public static java.util.ArrayList retrieveAllUserGroups()
Retrieves all UserGroup objects from the database.

Returns:
UserGroup ArrayList
PRE condition:
none

retrieveAllRootUserGroups

public static java.util.ArrayList retrieveAllRootUserGroups()
Retrieves all UserGroup objects which has no parents, from the database.

Returns:
UserGroup ArrayList
PRE condition:
none

retrieveQuestion

public static net.sourceforge.jsurveyor.Question retrieveQuestion(int questionID)
Retrieves a Question object from the database.

Parameters:
questionID - int
Returns:
Question
PRE condition:
none
POST condition:
if the Question object didn't exist, a Question object with ID set to -1 and all textfields set to empty strings, is returned.

retrieveQuestionnairesForOwner

public static java.util.ArrayList retrieveQuestionnairesForOwner(User usr)
Retrieves all Questionnaire objects from the database with User usr as owner.

Parameters:
usr - User
Returns:
ArrayList
PRE condition:
none
POST condition:
if the User passed as argument doesn't exist, an empty ArrayList is returned.

fetchQuestionnaires

public static java.util.ArrayList fetchQuestionnaires(User usr)
Fetch all Questionnaire objects which the User passed as argument may answer.

Parameters:
usr - User
Returns:
ArrayList
PRE condition:
none
POST condition:
if the User passed as argument doesn't exist, a empty ArrayList is returned.

existsUser

public static boolean existsUser(java.lang.String key)
Method to test for existance of a User object representation in database.

Parameters:
key - String
Returns:
boolean
PRE condition:
none
POST condition:
returns true if the User exist in database, otherwise false.

existsUserGroup

public static boolean existsUserGroup(java.lang.String key)
Method to test for existance of a UserGroup object representation in database.

Parameters:
key - String
Returns:
boolean
PRE condition:
none
POST condition:
returns true if the UserGroup exist in database, otherwise false.