fi.paatti.paattidatabaseutils.dbservice
Class PaattiDBService

java.lang.Object
  extended by fi.paatti.paattidatabaseutils.dbservice.PaattiDBService
All Implemented Interfaces:
PaattiMobileDBService, PaattiResearchDBService, Serializable

public class PaattiDBService
extends Object
implements PaattiResearchDBService, PaattiMobileDBService, Serializable

The implementation of the interfaces PaattiResearchDBService and PaattiMobileDBService.

TODO: Remove system.out messages and add logging.

Author:
Lauri Satokangas, lauri.n.satokangas@student.jyu.fi, Tapio Keränen, t.tapio.keranen@student.jyu.fi, Toni Salminen, toni.a.j.salminen@student.jyu.fi, Jari Salokangas, jari.p.t.salokangas@student.jyu.fi
See Also:
Serialized Form
 

Constructor Summary
PaattiDBService(String dbAddress, String dbName, String userName, String password)
          Constructor.
 
Method Summary
 boolean addScheduleToGroup(Object groupID, Object scheduleID)
          Adds the schedule to the group.
 boolean addUserToGroup(Object groupId, Object userId)
          Adds the user to the group.
 Object createGroup(String name, String description, Object role, Object research, int editor, Object groupID)
          Saves the group's information to the database.
 Object createResearch(String name, String description, Object researchID)
          Saves the research's information to the database.
 Object createSchedule(String description, Date zeroTime, Object scheduleID, com.vaadin.data.util.IndexedContainer scheduledEvents)
          Creates a new schedule.
 Object createUser(Object userID, String userName, String firstName, String lastName, String userPassword, String userDescription)
          Saves user's information to the database.
 Object getCellValueFromTable(String tableName, String columnName, String idColumn, Object rowId)
          Returns the value of the given column.
 com.vaadin.data.util.sqlcontainer.SQLContainer getChoiceContainer(Object eventId)
          Returns all the choices that belong to the event with the given id.
 ChoiceContainer getChoiceContainerWithListener(Object eventId)
          Returns the ChoiceContainer containing all the choices from the given event.
 com.vaadin.data.util.sqlcontainer.SQLContainer getEventsInSchedule(Object scheduleId)
          Returns all the events that belong to the schedule with the given id.
 com.vaadin.data.util.sqlcontainer.SQLContainer getGroupResearch(Object groupId)
          Returns all the researches that belong to the group with the given id.
 com.vaadin.data.util.sqlcontainer.SQLContainer getGroupRole(Object groupId)
          Returns the role of the given group.
 com.vaadin.data.util.sqlcontainer.SQLContainer getGroupSchedules(Object groupId)
          Returns all the schedules that belong to the group with the given id.
 com.vaadin.data.util.sqlcontainer.SQLContainer getGroupUsers(Object groupId)
          Returns all the users that belong to the group with the given id.
 com.vaadin.data.util.sqlcontainer.SQLContainer getResearchGroups(Object researchId)
          Returns all the groups that belong to the research with the given id.
 com.vaadin.data.util.sqlcontainer.SQLContainer getSQLContainerFromDBTable(String tableName, String nameOfIdColumn, boolean noDeletedRows)
          Queries the database for the given table and returns an SQLContainer containing the query results.
 com.vaadin.data.util.sqlcontainer.SQLContainer getSQLContainerFromDBTableFiltered(String tableName, String nameOfIdColumn, boolean noDeletedRows, com.vaadin.data.Container.Filter filter)
          Queries the database for the given table and returns an SQLContainer containing the query results.
 com.vaadin.data.util.sqlcontainer.SQLContainer getTaskContainer(Object eventId)
          Returns all the tasks that belong to the event with the given id.
 TaskContainer getTaskContainerWithListener(Object eventId)
          Returns the TaskContainer containing all the tasks from the given event.
 com.vaadin.data.util.sqlcontainer.SQLContainer getUserEventData(Object userId)
          Returns all the event data that belongs to the user with the given id.
 com.vaadin.data.util.sqlcontainer.SQLContainer getUserGroups(Object userId)
          Returns all the groups that belong to the user with the given id.
 com.vaadin.data.util.sqlcontainer.SQLContainer getUserGroupsdRolesAndResearches(Integer userID)
          Returns the roles and researches of the user's groups.
 com.vaadin.data.util.sqlcontainer.SQLContainer getUserUnfinishedEvents(Object userId)
          Returns all the available events for the user.
 com.vaadin.data.util.sqlcontainer.SQLContainer getUserVoluntaryEvents(Object userID)
          Returns all the voluntary events that are assigned to the user.
 boolean removeRowFromTable(Object itemID, String tableName, String idColumnName)
          Removes the row from the table.
 boolean removeUserFromGroup(Object groupId, Object userId)
          Removes the user from the group.
 boolean saveEventTaskData(Object userID, Stack<TaskData> taskDataStack)
          Saves all the data from a single event.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PaattiDBService

public PaattiDBService(String dbAddress,
                       String dbName,
                       String userName,
                       String password)
Constructor.

Parameters:
dbAddress - The address of the database.
dbName - The name of the database.
userName - The username that should be used for logging.
password - The password that should be used for logging.
Method Detail

getSQLContainerFromDBTable

public com.vaadin.data.util.sqlcontainer.SQLContainer getSQLContainerFromDBTable(String tableName,
                                                                                 String nameOfIdColumn,
                                                                                 boolean noDeletedRows)
Queries the database for the given table and returns an SQLContainer containing the query results.

Specified by:
getSQLContainerFromDBTable in interface PaattiMobileDBService
Specified by:
getSQLContainerFromDBTable in interface PaattiResearchDBService
Parameters:
tableName - the name of the database table.
nameOfIdColumn - the name of the id column.
noDeletedRows - whether to filter deleted rows or not.
Returns:
The SQLContainer if successful, otherwise null.

getSQLContainerFromDBTableFiltered

public com.vaadin.data.util.sqlcontainer.SQLContainer getSQLContainerFromDBTableFiltered(String tableName,
                                                                                         String nameOfIdColumn,
                                                                                         boolean noDeletedRows,
                                                                                         com.vaadin.data.Container.Filter filter)
Queries the database for the given table and returns an SQLContainer containing the query results. The given filter (if any) will be applied to the SQLContainer to exclude rows from the results.

A word of warning: filtered SQLContainers are immutable, so don't use this if you're planning on modifying the container later.

Specified by:
getSQLContainerFromDBTableFiltered in interface PaattiMobileDBService
Specified by:
getSQLContainerFromDBTableFiltered in interface PaattiResearchDBService
Parameters:
tableName - the name of the database table.
nameOfIdColumn - the name of the id column.
noDeletedRows - whether to filter deleted rows or not.
filter - the filter that is applied to the search results.
Returns:
The filtered SQLContaner if successful, otherwise null.

getTaskContainer

public com.vaadin.data.util.sqlcontainer.SQLContainer getTaskContainer(Object eventId)
Returns all the tasks that belong to the event with the given id.

Specified by:
getTaskContainer in interface PaattiMobileDBService
Specified by:
getTaskContainer in interface PaattiResearchDBService
Parameters:
eventId - the event's id.
Returns:
SQLContainer containing all the tasks of the event.

getTaskContainerWithListener

public TaskContainer getTaskContainerWithListener(Object eventId)
Returns the TaskContainer containing all the tasks from the given event. The TaskContainer is an extended version of SQLContainer. A listener can be added to it for getting the new row ID after a successful insertion to the database.

Specified by:
getTaskContainerWithListener in interface PaattiResearchDBService
Parameters:
eventId - the ID of the event.
Returns:
All the tasks of the event.

getChoiceContainer

public com.vaadin.data.util.sqlcontainer.SQLContainer getChoiceContainer(Object eventId)
Returns all the choices that belong to the event with the given id.

Specified by:
getChoiceContainer in interface PaattiMobileDBService
Specified by:
getChoiceContainer in interface PaattiResearchDBService
Parameters:
eventId - the event's id.
Returns:
SQLContainer containing all the choices of the event.

getChoiceContainerWithListener

public ChoiceContainer getChoiceContainerWithListener(Object eventId)
Returns the ChoiceContainer containing all the choices from the given event. The ChoiceContainer is an extended version of SQLContainer. A listener can be added to it for getting the new row ID after a successful insertion to the database.

Specified by:
getChoiceContainerWithListener in interface PaattiResearchDBService
Parameters:
eventId - the ID of the event.
Returns:
All the choices of the event.

getUserGroups

public com.vaadin.data.util.sqlcontainer.SQLContainer getUserGroups(Object userId)
Returns all the groups that belong to the user with the given id.

Specified by:
getUserGroups in interface PaattiResearchDBService
Parameters:
userId - the user's id.
Returns:
SQLContainer containing all groups of the user.

getGroupUsers

public com.vaadin.data.util.sqlcontainer.SQLContainer getGroupUsers(Object groupId)
Returns all the users that belong to the group with the given id.

Specified by:
getGroupUsers in interface PaattiMobileDBService
Specified by:
getGroupUsers in interface PaattiResearchDBService
Parameters:
groupId - the group's id.
Returns:
SQLContainer containing the members of the group.

getGroupSchedules

public com.vaadin.data.util.sqlcontainer.SQLContainer getGroupSchedules(Object groupId)
Returns all the schedules that belong to the group with the given id.

Specified by:
getGroupSchedules in interface PaattiResearchDBService
Parameters:
groupId - the group's id.
Returns:
SQLContainer containing the schedules of the group.

getGroupResearch

public com.vaadin.data.util.sqlcontainer.SQLContainer getGroupResearch(Object groupId)
Returns all the researches that belong to the group with the given id.

Specified by:
getGroupResearch in interface PaattiResearchDBService
Parameters:
groupId - the group's id.
Returns:
SQLContainer containing all the researches of the group.

getResearchGroups

public com.vaadin.data.util.sqlcontainer.SQLContainer getResearchGroups(Object researchId)
Returns all the groups that belong to the research with the given id.

Specified by:
getResearchGroups in interface PaattiResearchDBService
Parameters:
researchId - the research's id.
Returns:
SQLContainer containing all the groups of the research.

getUserEventData

public com.vaadin.data.util.sqlcontainer.SQLContainer getUserEventData(Object userId)
Returns all the event data that belongs to the user with the given id.

Specified by:
getUserEventData in interface PaattiMobileDBService
Specified by:
getUserEventData in interface PaattiResearchDBService
Parameters:
userId - the user's id.
Returns:
SQLContainer containing all the event data of the user.

getUserUnfinishedEvents

public com.vaadin.data.util.sqlcontainer.SQLContainer getUserUnfinishedEvents(Object userId)
Returns all the available events for the user.

Specified by:
getUserUnfinishedEvents in interface PaattiMobileDBService
Parameters:
userId - the ID of the user.
Returns:
SQLContainer containing all the available events.

getGroupRole

public com.vaadin.data.util.sqlcontainer.SQLContainer getGroupRole(Object groupId)
Returns the role of the given group.

Specified by:
getGroupRole in interface PaattiResearchDBService
Parameters:
groupId - the id of the group.
Returns:
The SQLContainer containing the group's role info.

createUser

public Object createUser(Object userID,
                         String userName,
                         String firstName,
                         String lastName,
                         String userPassword,
                         String userDescription)
Saves user's information to the database. If the user with the given id already exists in the database, the existing name and description values are replaced. If no user was found, a new row is created to the database with the given values.

Specified by:
createUser in interface PaattiResearchDBService
Parameters:
userID - the id of the user.
userName - the user name of the user.
firstName - the first name of the user.
lastName - the last name of the user.
userPassword - the password of the user.
userDescription - the description of the user.
Returns:
True if successful and no exception was thrown, otherwise false.

removeRowFromTable

public boolean removeRowFromTable(Object itemID,
                                  String tableName,
                                  String idColumnName)
Removes the row from the table. Removing means setting the row's row status to 'DELETED'.

Specified by:
removeRowFromTable in interface PaattiResearchDBService
Parameters:
itemID - the id of the row to be removed.
tableName - the name of the table containing the row
idColumnName - the id column of the table
Returns:
True if successful and no exception was thrown, otherwise false.

createResearch

public Object createResearch(String name,
                             String description,
                             Object researchID)
Saves the research's information to the database. If the research with the given id already exists in the database, the existing name and description values are replaced. If no research was found, a new row is created to the database with the given values.

Specified by:
createResearch in interface PaattiResearchDBService
Parameters:
name - the name of the research.
description - the description of the research.
researchID - the id of the research.
Returns:
RowId if successful and no exception was thrown; otherwise null.

createGroup

public Object createGroup(String name,
                          String description,
                          Object role,
                          Object research,
                          int editor,
                          Object groupID)
Saves the group's information to the database. If a group with the given id already exists in the database, the existing name, description, role, and editor values are replaced. If no group was found, a new row is created to the database with the given values.

Specified by:
createGroup in interface PaattiResearchDBService
Parameters:
name - the name of ther group.
description - the description of the group.
role - the role of the group.
research - the id of the research this group belong to.
editor - the id of the editor.
groupID - the id of the group.
Returns:
RowId if successful and no exception was thrown, otherwise null.

getCellValueFromTable

public Object getCellValueFromTable(String tableName,
                                    String columnName,
                                    String idColumn,
                                    Object rowId)
Returns the value of the given column.

Specified by:
getCellValueFromTable in interface PaattiMobileDBService
Specified by:
getCellValueFromTable in interface PaattiResearchDBService
Parameters:
tableName - the name of the table the column belongs to.
columnName - the name of the column.
idColumn - the ID column of the table.
rowId - the ID of the row where the value will be taken from.
Returns:
The found value or null if none found.

saveEventTaskData

public boolean saveEventTaskData(Object userID,
                                 Stack<TaskData> taskDataStack)
Saves all the data from a single event.

Specified by:
saveEventTaskData in interface PaattiMobileDBService
Parameters:
userID - the ID of the user.
taskDataStack - the list of TaskData items.
Returns:
True if successful, otherwise false.

addUserToGroup

public boolean addUserToGroup(Object groupId,
                              Object userId)
Adds the user to the group. If the user already belongs to the group, the rowstatus of the BELONGS table is set to 'ACTIVE'. If no row is found in the table, a new row is created with the given values.

Specified by:
addUserToGroup in interface PaattiResearchDBService
Parameters:
groupId - the id of the group
userId - the id of the user
Returns:
True if successful and no exception was thrown, otherwise false.

removeUserFromGroup

public boolean removeUserFromGroup(Object groupId,
                                   Object userId)
Removes the user from the group. Removing the user from the group means setting the row status in BELONGS table to 'DELETED'.

Specified by:
removeUserFromGroup in interface PaattiResearchDBService
Parameters:
groupId - the ID of the user's group.
userId - the ID of the user.
Returns:
True if successful, otherwise false.

getEventsInSchedule

public com.vaadin.data.util.sqlcontainer.SQLContainer getEventsInSchedule(Object scheduleId)
Returns all the events that belong to the schedule with the given id.

Specified by:
getEventsInSchedule in interface PaattiResearchDBService
Parameters:
scheduleId - the schedule's id.
Returns:
SQLContainer containing all the events of the schedule.

getUserVoluntaryEvents

public com.vaadin.data.util.sqlcontainer.SQLContainer getUserVoluntaryEvents(Object userID)
Returns all the voluntary events that are assigned to the user.

Specified by:
getUserVoluntaryEvents in interface PaattiMobileDBService
Parameters:
userID - the ID of the user.
Returns:
SQLContainer containing the voluntary events.

getUserGroupsdRolesAndResearches

public com.vaadin.data.util.sqlcontainer.SQLContainer getUserGroupsdRolesAndResearches(Integer userID)
Returns the roles and researches of the user's groups. These properties can be accessed with the values from PaattiColumnNames.

Specified by:
getUserGroupsdRolesAndResearches in interface PaattiResearchDBService
Parameters:
userID - the ID of the user.
Returns:
The SQLContainer containing the user's role and research info.

createSchedule

public Object createSchedule(String description,
                             Date zeroTime,
                             Object scheduleID,
                             com.vaadin.data.util.IndexedContainer scheduledEvents)
Creates a new schedule.

Specified by:
createSchedule in interface PaattiResearchDBService
Parameters:
description - the description of the schedule.
zeroTime - the start date of the schedule.
scheduleID - the id of the schedule.
scheduledEvents - the list of events that belong to the schedule.
Returns:
The row id of the schedule if successful, otherwise null.

addScheduleToGroup

public boolean addScheduleToGroup(Object groupID,
                                  Object scheduleID)
Adds the schedule to the group.

Specified by:
addScheduleToGroup in interface PaattiResearchDBService
Parameters:
groupID - the id of the group.
scheduleID - the id of the schedule.
Returns:
True if succesful and no exception was thrown, otherwise false.


Copyright © 2012. All Rights Reserved.