cafe.database
Interface Database

All Known Implementing Classes:
DBCommunication

public interface Database

This interface provides methods for accessing the database component.

Version:
1.0
Author:
Markus Penttila

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)
          updates product balance for group and for user.
 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
 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
 boolean reconnectDatabase()
          Method tries to reconnect to database if connection is lost for some reason
 void removeAlert(ImportProduct product)
          Removes alert from a product
 int saveFingerprint(FPData data)
          Inserts a new fingerprint into database
 void saveUser(UserInfo user)
          Saves userInfo into database.
 

Method Detail

loadUser

UserInfo loadUser(int id)
                  throws DBConLostException
Method for loading user by id, if user not found, returns NULL

Parameters:
id -
Returns:
UserInfo
Throws:
DBConLostException

loadUser

UserInfo loadUser(java.lang.String username)
                  throws DBConLostException
Returns UserInfo, if given username is not valid returns NULL

Parameters:
username -
Returns:
UserInfo
Throws:
DBConLostException

saveUser

void saveUser(UserInfo user)
              throws DBConLostException
Saves userInfo into database. If user exists, update information, else insert a new user

Parameters:
user - userInfo bean
Throws:
DBConLostException

exportProduct

void exportProduct(UserInfo user,
                   ExportProduct product)
                   throws ProductNotFoundException,
                          DBConLostException
updates product balance for group and for user. Logs new export into database

Parameters:
user - user who is exporting product
product - what product we are exporting
Throws:
ProductNotFoundException
DBConLostException

cancelProductExport

CancelProduct cancelProductExport(UserInfo user)
                                  throws DBConLostException,
                                         java.net.SocketException
Method cancels the last product "takeout" in the productout table

Parameters:
user - user who is cancelling last action
Returns:
CancelProduct, product which is cancelled
Throws:
DBConLostException - or SocketException when databese is not responding
java.net.SocketException

importProduct

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

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

getProductList

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

Returns:
exportproducts
Throws:
DBConLostException

insertAlert

void insertAlert(ImportProduct product)
                 throws ProductNotFoundException,
                        DBConLostException
Method inserts a alert for a product, if alert is already "valid", keeps the alert as valid

Parameters:
product - which we are adding alert to
Throws:
ProductNotFoundException
DBConLostException

removeAlert

void removeAlert(ImportProduct product)
                 throws DBConLostException
Removes alert from a product

Parameters:
product -
Throws:
DBConLostException

getAlerts

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

Returns:
ImportProduct[] list of products
Throws:
DBConLostException

saveFingerprint

int saveFingerprint(FPData data)
                    throws DBConLostException
Inserts a new fingerprint into 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

getProductGroups

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

Returns:
ProductGroup[] list of productgroups
Throws:
DBConLostException

getFingerprintData

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

Returns:
FPData[], list of fingerprints
Throws:
DBConLostException

deleteFingerprint

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

Parameters:
id - Primary Key of fingerprint to be deleted
Throws:
DBConLostException

reconnectDatabase

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

Returns:
true if connection is got. If connection failes returns false