cafe.database
Class DBCommunication

java.lang.Object
  extended by cafe.database.DBCommunication
All Implemented Interfaces:
Database

public class DBCommunication
extends java.lang.Object
implements Database

This class communicates data from the database to other components.

Version:
0.03 Parts made by Veli-Pekka Kestilä (vpk) Copyright(C) Veli-Pekka Kestilä Parts made by others Copyright(C) University of Helsinki Following notice currently only concerns parts written by Veli-Pekka Kestilä. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Author:
Lauri Holmas, vpk

Constructor Summary
DBCommunication(DBSettings settings)
           
 
Method Summary
 CancelProduct cancelProductExport(UserInfo user)
          Method cancels the last product "takeout" in the productout table
 void deleteFingerprint(int id)
          Method removes a fingerprint from db
 void exportProduct(UserInfo user, ExportProduct product)
          Method returns exportproducts in a list
 ImportProduct[] getAlerts()
          Method returns products in a list, where the products have alerts
 FPData[] getFingerprintData()
          Method returns all the fingerprint data in database in a list
 ProductGroup[] getProductGroups()
          method returns groups in database and their balance in ProductGroup beans in a list
 ExportProduct[] getProductList()
          Method returns exportproducts in a list
 void importProduct(UserInfo user, ImportProduct product, double amount)
          Method for importing new products
 void insertAlert(ImportProduct product)
          Method inserts a alert for a product, if alert is already "valid", keeps the alert as valid if proiduct id found in db, sets the alert for it, if not found, no rows are updated
 UserInfo loadUser(int id)
          Method for loading user by id, if user not found, returns NULL.
 UserInfo loadUser(java.lang.String username)
          Returns UserInfo, if given username is not valid returns NULL else returns all the data found in database in UserInfo bean.
 boolean reconnectDatabase()
          Method tries to reconnect to database if connection is lost for some reason
 void removeAlert(ImportProduct product)
          Removes alert from a product if productId in db, updates that row, if no product found, does not update any rows
 int saveFingerprint(FPData data)
          Inserts a new fingerprint into database
 void saveUser(UserInfo user)
          Saves userInfo into database.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DBCommunication

public DBCommunication(DBSettings settings)
                throws DBConLostException
Parameters:
settings -
Throws:
DBConLostException
Method Detail

cancelProductExport

public CancelProduct cancelProductExport(UserInfo user)
                                  throws DBConLostException
Description copied from interface: Database
Method cancels the last product "takeout" in the productout table

Specified by:
cancelProductExport in interface Database
Parameters:
user - user who is cancelling last action
Returns:
CancelProduct, product which is cancelled
Throws:
DBConLostException - or SocketException when databese is not responding

deleteFingerprint

public void deleteFingerprint(int id)
                       throws DBConLostException
Method removes a fingerprint from db

Specified by:
deleteFingerprint in interface Database
Parameters:
id - Primary Key of fingerprint to be deleted
Throws:
DBConLostException

exportProduct

public void exportProduct(UserInfo user,
                          ExportProduct product)
                   throws ProductNotFoundException,
                          DBConLostException
Method returns exportproducts in a list

Specified by:
exportProduct in interface Database
Parameters:
user - user who is exporting product
product - of which we are exporting
Throws:
DBConLostException
ProductNotFoundException

getAlerts

public ImportProduct[] getAlerts()
                          throws DBConLostException
Method returns products in a list, where the products have alerts

Specified by:
getAlerts in interface Database
Returns:
ImportProduct[], list of products
Throws:
DBConLostException

getFingerprintData

public FPData[] getFingerprintData()
                            throws DBConLostException
Method returns all the fingerprint data in database in a list

Specified by:
getFingerprintData in interface Database
Returns:
FPData[], list of fingerprints
Throws:
DBConLostException

getProductGroups

public ProductGroup[] getProductGroups()
                                throws DBConLostException
method returns groups in database and their balance in ProductGroup beans in a list

Specified by:
getProductGroups in interface Database
Returns:
ProductGroup[] list of productgroups
Throws:
DBConLostException

getProductList

public ExportProduct[] getProductList()
                               throws DBConLostException
Method returns exportproducts in a list

Specified by:
getProductList in interface Database
Returns:
exportproducts
Throws:
DBConLostException

importProduct

public void importProduct(UserInfo user,
                          ImportProduct product,
                          double amount)
                   throws ProductNotFoundException,
                          DBConLostException
Method for importing new products

Specified by:
importProduct in interface Database
Parameters:
user - user who is importing products into system
product - product which we are importing
amount - amount of goods which we are importing. For example a coffee package is worth 20 cups -> amount 20
Throws:
ProductNotFoundException
DBConLostException

insertAlert

public void insertAlert(ImportProduct product)
                 throws ProductNotFoundException,
                        DBConLostException
Method inserts a alert for a product, if alert is already "valid", keeps the alert as valid if proiduct id found in db, sets the alert for it, if not found, no rows are updated

Specified by:
insertAlert in interface Database
Parameters:
product - which we are adding alert to
Throws:
ProductNotFoundException
DBConLostException

loadUser

public UserInfo loadUser(int id)
                  throws DBConLostException
Method for loading user by id, if user not found, returns NULL. Loads username from db, if username found, uses loadUser(username) method to handle the loading, else returns null

Specified by:
loadUser in interface Database
Parameters:
id -
Returns:
UserInfo
Throws:
DBConLostException

loadUser

public UserInfo loadUser(java.lang.String username)
                  throws DBConLostException
Returns UserInfo, if given username is not valid returns NULL else returns all the data found in database in UserInfo bean.

Specified by:
loadUser in interface Database
Parameters:
username -
Returns:
UserInfo
Throws:
DBConLostException

reconnectDatabase

public boolean reconnectDatabase()
Method tries to reconnect to database if connection is lost for some reason

Specified by:
reconnectDatabase in interface Database
Returns:
true if connection is got. If connection failes returns false

removeAlert

public void removeAlert(ImportProduct product)
                 throws DBConLostException
Removes alert from a product if productId in db, updates that row, if no product found, does not update any rows

Specified by:
removeAlert in interface Database
Parameters:
product -
Throws:
DBConLostException

saveFingerprint

public int saveFingerprint(FPData data)
                    throws DBConLostException
Inserts a new fingerprint into database

Specified by:
saveFingerprint in interface Database
Parameters:
data - griaule produced data to be inserted into database
Returns:
int, the integer that matches the Primary Key (PK) of fingerprint in database
Throws:
DBConLostException

saveUser

public void saveUser(UserInfo user)
              throws DBConLostException
Saves userInfo into database. If user exists, update information, else insert a new user userInfo bean: getRegularportion() must be valid (finalproduct_id should be in db) if regularPortion not valid saving failes

Specified by:
saveUser in interface Database
Parameters:
user - userInfo bean
Throws:
DBConLostException