fi.helsinki.cs.lohtu.model
Class UserDAO

java.lang.Object
  |
  +--fi.helsinki.cs.lohtu.model.UserDAO

public class UserDAO
extends java.lang.Object

This class handles all database connections and creates appropriate classes resembling database table rows.

Author:
Kimmo Airamaa

Constructor Summary
protected UserDAO(java.sql.Connection conn)
          Protected constructor.
 
Method Summary
protected  void finalize()
          Finalizes UserDAO.
 java.util.Iterator getProjectUserIterator(int projectId)
          This method returns an iterator to users filling the specified criteria (the project matches the parameter).
 UserVO getUser(java.lang.String userName)
          Searches for desired username and returns respective VO object or throws some kind of exception.
 void saveUser(UserVO user)
          When changes have been made, new VO is created and needs to be saved or object needs to be deleted, this method is invoked.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

UserDAO

protected UserDAO(java.sql.Connection conn)
           throws java.lang.IllegalArgumentException
Protected constructor. Used to create instances from this DAO. Access is restricted inside this package.

Parameters:
conn - Connection to the database.
Throws:
java.lang.IllegalArgumentException - when no viable connection is passed.
Method Detail

getProjectUserIterator

public java.util.Iterator getProjectUserIterator(int projectId)
                                          throws LohdutonException
This method returns an iterator to users filling the specified criteria (the project matches the parameter).

Parameters:
projectId - Project from which users are to be fetched.
Returns:
Iterator to fetched users.
Throws:
LohdutonException - When database query fails real bad.

saveUser

public void saveUser(UserVO user)
              throws java.lang.Exception
When changes have been made, new VO is created and needs to be saved or object needs to be deleted, this method is invoked.

Parameters:
user - UserVO class that is to be saved/updated/deleted.
Throws:
java.lang.Exception - When parameter isn't valid or sql operations fail.

getUser

public UserVO getUser(java.lang.String userName)
               throws java.lang.Exception
Searches for desired username and returns respective VO object or throws some kind of exception.

Parameters:
userName - Name of the user to be found.
Returns:
UserVO object of user.
Throws:
java.lang.Exception - When something devious happens or no viable parameter is received.

finalize

protected void finalize()
                 throws LohdutonException
Finalizes UserDAO. Closes all the preparedstatements and connection.

Overrides:
finalize in class java.lang.Object
Throws:
LohdutonException - when something fails to shut down.