lecturequiz.server.main
Class MySQLDB

java.lang.Object
  extended by lecturequiz.server.main.MySQLDB
All Implemented Interfaces:
DBInterface

public class MySQLDB
extends java.lang.Object
implements DBInterface

Implements a DB backend to MySQL


Constructor Summary
MySQLDB()
          Private singleton constructor
 
Method Summary
 User authenticateUser(java.lang.String username, java.lang.String password)
          Tries to authenticate a user against the database.
 FullQuestionInfo getQuestion(int id)
          Returns all information on the question with the supplied id
 java.util.List<FullQuestionInfo> getQuestionList()
          Returns a list of all available questions.
 Quiz getQuiz(int id)
          Returns the quiz with the given ID from the database
 java.util.ArrayList<QuizInfo> getQuizList()
          Returns a list of all available quizzes
 User getUser(int id)
          Returns a user from the database with the supplied ID.
 int saveQuiz(FullQuizInfo fqi, User user)
          Saves a quiz to the database
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MySQLDB

public MySQLDB()
Private singleton constructor

Method Detail

getQuizList

public java.util.ArrayList<QuizInfo> getQuizList()
Returns a list of all available quizzes

Specified by:
getQuizList in interface DBInterface
Returns:
A list of QuizInfo objects containing information about a quiz or null if an error occurs.

authenticateUser

public User authenticateUser(java.lang.String username,
                             java.lang.String password)
Tries to authenticate a user against the database.

Specified by:
authenticateUser in interface DBInterface
Parameters:
username - Username sent to the database.
password - Password sent to the database.
Returns:
User object with the authenticated user. null if authentication fails

getUser

public User getUser(int id)
Returns a user from the database with the supplied ID.

Specified by:
getUser in interface DBInterface
Parameters:
id - ID of the user to retrieve
Returns:
A User-object with teh requested user, or null if the user was not found

getQuiz

public Quiz getQuiz(int id)
Returns the quiz with the given ID from the database

Specified by:
getQuiz in interface DBInterface
Parameters:
id - ID of the quiz
Returns:
Quiz with the given ID

getQuestionList

public java.util.List<FullQuestionInfo> getQuestionList()
Returns a list of all available questions. The list will only contain the correct answer of a question

Specified by:
getQuestionList in interface DBInterface
Returns:
A list of FullQuestionInfo objects containing the information for all questions

getQuestion

public FullQuestionInfo getQuestion(int id)
Returns all information on the question with the supplied id

Specified by:
getQuestion in interface DBInterface
Parameters:
id - ID of the question to retrieve
Returns:
A FullQuestionInfo object with all information, or null on error

saveQuiz

public int saveQuiz(FullQuizInfo fqi,
                    User user)
Saves a quiz to the database

Specified by:
saveQuiz in interface DBInterface
Parameters:
fqi - All information of the quiz to be saved. If the ID of a quiz is 0 the quiz will be created. If any questions have the ID 0 they will be created and answers of this question should be give ID's of 0-n and correctAnswer should point to one of these IDs.
user - The user trying to save the quiz. If this is not done by a logged in user this can be null.
Returns:
Error codes:
0 - Success
1 - No such quiz
2 - Invalid data
3 - Access denied
4 - Other error