com.neatech.climbplan.dataaccess
Class DatabaseImpl

java.lang.Object
  extended by com.neatech.climbplan.dataaccess.DatabaseImpl
All Implemented Interfaces:
Database

public class DatabaseImpl
extends Object
implements Database


Field Summary
private  Connection con
           
private static org.apache.log4j.Logger logger
           
 
Constructor Summary
DatabaseImpl()
           
 
Method Summary
 void addMountaineerToTeam(TeamModel team, MountaineerModel mountaineer)
          This method adds a mountaineer to a team.
 void changePassword(OrganizerModel organizer, String password)
          This method changes the password of an organizer.
 OrganizerModel checkAuthorization(String userName, String passwd)
          This method checks whether a supplied user name and password belongs to an organizer
private  void closeConnection(Connection con)
           
private  Connection connectToDatabase()
           
 void deleteMap(MapModel map)
          This method deletes a MapModel from the database.
 void deleteMountaineer(MountaineerModel mountaineer)
          This method deletes a MountaineerModel from the database.
private  boolean deleteMountaineer(MountaineerModel mountaineer, Connection con)
           
 void deleteMountaineerFromTeam(TeamModel team, MountaineerModel mountaineer)
          This method deletes a mountaineer from a team.
 void deleteOrganizer(OrganizerModel organizer)
          This method deletes a OrganizerModel from the database.
 void deleteTeam(TeamModel team)
          This method deletes a TeamModel from the database.
 void getAllMaps(List<MapModel> maps)
          This method returns all the maps stored in the database as a list of MapModel by filling the list of MapModel given as a parameter.
 void getAllMountaineers(List<MountaineerModel> mountaineers)
          This method returns all the mountaineers stored in the database in a single list by filling the list of MountaineerModel given as a parameter.
 void getAllOrganizers(List<MountaineerModel> mountaineers)
          This method returns all the organizers stored in the database in a single list by filling the list of MountaineerModel given as a parameter.
 void getAllTeams(List<TeamModel> teams, List<MountaineerModel> mountaineers)
          This methods returns all the teams stored in the database as a list of TeamModel by filling the list of TeamModel given as a parameter.
private  void insertLayer(MapModel map, Layer layer)
           
 void insertMap(MapModel map)
          This method inserts a MapModel to the database by filling the given list of MapModel as a parameter.
 void insertMountaineer(MountaineerModel mountaineer)
          This method inserts a MountaineerModel to the database.
private  boolean insertMountaineer(MountaineerModel mountaineer, Connection con)
           
 void insertOrganizer(OrganizerModel organizer)
          This method inserts a OrganizerModel to the database.
 void insertTeam(TeamModel team)
          This method inserts a TeamModel to the database.
private  void updateLayer(MapModel map, Layer layer)
           
 void updateMap(MapModel map)
          This method updates a MapModel by storing the data to the database if necessary.
 void updateMountaineer(MountaineerModel mountaineer)
          This method updates a MountaineerModel by storing the data to the database if necessary.
private  boolean updateMountaineer(MountaineerModel mountaineer, Connection con)
           
 void updateOrganizer(OrganizerModel organizer)
          This method updates a OrganizerModel by storing the data to the database if necessary.
 void updateTeam(TeamModel team)
          This method updates a TeamModel by storing the data to the database if necessary.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

private static final org.apache.log4j.Logger logger

con

private Connection con
Constructor Detail

DatabaseImpl

public DatabaseImpl()
Method Detail

connectToDatabase

private Connection connectToDatabase()
                              throws DatabaseException
Throws:
DatabaseException

closeConnection

private void closeConnection(Connection con)
                      throws DatabaseException
Throws:
DatabaseException

checkAuthorization

public OrganizerModel checkAuthorization(String userName,
                                         String passwd)
                                  throws DatabaseException
Description copied from interface: Database
This method checks whether a supplied user name and password belongs to an organizer

Specified by:
checkAuthorization in interface Database
Parameters:
userName - of the organizer
passwd - of the organizer
Returns:
an OrganizerModel if the login info is correct else null
Throws:
DatabaseException

changePassword

public void changePassword(OrganizerModel organizer,
                           String password)
                    throws DatabaseException
Description copied from interface: Database
This method changes the password of an organizer.

Specified by:
changePassword in interface Database
Parameters:
organizer - whose password is to be changed
password - new password to be set
Throws:
DatabaseException

deleteMap

public void deleteMap(MapModel map)
               throws DatabaseException
Description copied from interface: Database
This method deletes a MapModel from the database.

Specified by:
deleteMap in interface Database
Parameters:
map - a MapModel to delete from the database
Throws:
DatabaseException

deleteMountaineer

private boolean deleteMountaineer(MountaineerModel mountaineer,
                                  Connection con)

deleteMountaineer

public void deleteMountaineer(MountaineerModel mountaineer)
                       throws DatabaseException
Description copied from interface: Database
This method deletes a MountaineerModel from the database.

Specified by:
deleteMountaineer in interface Database
Parameters:
mountaineer - a MountaineerModel to delete from the database
Throws:
DatabaseException

deleteOrganizer

public void deleteOrganizer(OrganizerModel organizer)
                     throws DatabaseException
Description copied from interface: Database
This method deletes a OrganizerModel from the database.

Specified by:
deleteOrganizer in interface Database
Parameters:
organizer - a OrganizerModel to delete from the database
Throws:
DatabaseException

deleteTeam

public void deleteTeam(TeamModel team)
                throws DatabaseException
Description copied from interface: Database
This method deletes a TeamModel from the database.

Specified by:
deleteTeam in interface Database
Parameters:
team - a TeamModel to delete from the database
Throws:
DatabaseException

getAllMaps

public void getAllMaps(List<MapModel> maps)
                throws DatabaseException
Description copied from interface: Database
This method returns all the maps stored in the database as a list of MapModel by filling the list of MapModel given as a parameter.

Specified by:
getAllMaps in interface Database
Parameters:
maps - a list of MapModel to be filled
Throws:
DatabaseException

getAllMountaineers

public void getAllMountaineers(List<MountaineerModel> mountaineers)
                        throws DatabaseException
Description copied from interface: Database
This method returns all the mountaineers stored in the database in a single list by filling the list of MountaineerModel given as a parameter.

Specified by:
getAllMountaineers in interface Database
Parameters:
mountaineers - a list of MountaineerModel to be filled
Throws:
DatabaseException

getAllOrganizers

public void getAllOrganizers(List<MountaineerModel> mountaineers)
                      throws DatabaseException
Description copied from interface: Database
This method returns all the organizers stored in the database in a single list by filling the list of MountaineerModel given as a parameter. Note: OrganizerModel must be cast to MountaineerModel and added to the list.

Specified by:
getAllOrganizers in interface Database
Parameters:
mountaineers - a list of MountaineerModel to be filled
Throws:
DatabaseException

getAllTeams

public void getAllTeams(List<TeamModel> teams,
                        List<MountaineerModel> mountaineers)
                 throws DatabaseException
Description copied from interface: Database
This methods returns all the teams stored in the database as a list of TeamModel by filling the list of TeamModel given as a parameter. TeamModel contains a list of MountaineerModel; this list must be filled from the given parameter, list of MountaineerModel. The following procedure may be implemented (pseudo-code): For each mountaineerId in TeamModel team // find the index of the mountaineer // having id = mountaineerId from mountaineers index = mountaineers.indexOf(mountaineerId); teams.mountaineers.add(mountaineers.get(index));

Specified by:
getAllTeams in interface Database
Parameters:
teams - a list of TeamModel to be filled
mountaineers - the mountaineer models to be used
Throws:
DatabaseException

insertMap

public void insertMap(MapModel map)
               throws DatabaseException
Description copied from interface: Database
This method inserts a MapModel to the database by filling the given list of MapModel as a parameter.

Specified by:
insertMap in interface Database
Throws:
DatabaseException

insertLayer

private void insertLayer(MapModel map,
                         Layer layer)
                  throws SQLException
Throws:
SQLException

insertMountaineer

private boolean insertMountaineer(MountaineerModel mountaineer,
                                  Connection con)

insertMountaineer

public void insertMountaineer(MountaineerModel mountaineer)
                       throws DatabaseException
Description copied from interface: Database
This method inserts a MountaineerModel to the database.

Specified by:
insertMountaineer in interface Database
Parameters:
mountaineer - a MountaineerModel to insert to the database
Throws:
DatabaseException

insertOrganizer

public void insertOrganizer(OrganizerModel organizer)
                     throws DatabaseException
Description copied from interface: Database
This method inserts a OrganizerModel to the database.

Specified by:
insertOrganizer in interface Database
Parameters:
organizer - a OrganizerModel to insert to the database
Throws:
DatabaseException

insertTeam

public void insertTeam(TeamModel team)
                throws DatabaseException
Description copied from interface: Database
This method inserts a TeamModel to the database.

Specified by:
insertTeam in interface Database
Parameters:
team - a TeamModel to insert to the database
Throws:
DatabaseException

updateMap

public void updateMap(MapModel map)
               throws DatabaseException
Description copied from interface: Database
This method updates a MapModel by storing the data to the database if necessary.

Specified by:
updateMap in interface Database
Parameters:
map - a MapModel to update from the database
Throws:
DatabaseException

updateLayer

private void updateLayer(MapModel map,
                         Layer layer)
                  throws SQLException
Throws:
SQLException

updateMountaineer

private boolean updateMountaineer(MountaineerModel mountaineer,
                                  Connection con)

updateMountaineer

public void updateMountaineer(MountaineerModel mountaineer)
                       throws DatabaseException
Description copied from interface: Database
This method updates a MountaineerModel by storing the data to the database if necessary.

Specified by:
updateMountaineer in interface Database
Parameters:
mountaineer - a MountaineerModel to update to the database
Throws:
DatabaseException

updateOrganizer

public void updateOrganizer(OrganizerModel organizer)
                     throws DatabaseException
Description copied from interface: Database
This method updates a OrganizerModel by storing the data to the database if necessary.

Specified by:
updateOrganizer in interface Database
Parameters:
organizer - a OrganizerModel to update to the database
Throws:
DatabaseException

addMountaineerToTeam

public void addMountaineerToTeam(TeamModel team,
                                 MountaineerModel mountaineer)
                          throws DatabaseException
Description copied from interface: Database
This method adds a mountaineer to a team.

Specified by:
addMountaineerToTeam in interface Database
Parameters:
team - a TeamModel to add to
mountaineer - a MountaineerModel to add
Throws:
DatabaseException

deleteMountaineerFromTeam

public void deleteMountaineerFromTeam(TeamModel team,
                                      MountaineerModel mountaineer)
                               throws DatabaseException
Description copied from interface: Database
This method deletes a mountaineer from a team.

Specified by:
deleteMountaineerFromTeam in interface Database
Parameters:
team - a TeamModel to delete from
mountaineer - a MountaineerModel to delete
Throws:
DatabaseException

updateTeam

public void updateTeam(TeamModel team)
                throws DatabaseException
Description copied from interface: Database
This method updates a TeamModel by storing the data to the database if necessary.

Specified by:
updateTeam in interface Database
Parameters:
team - a TeamModel to update from the database
Throws:
DatabaseException