public class ShopDB extends ObjectDB
Constructor and Description |
---|
ShopDB()
Class constructor that fetches the connection to the production database.
|
ShopDB(DatabaseConnection databaseConnection)
Class constructor that stores the given database connection for later use.
|
Modifier and Type | Method and Description |
---|---|
int |
addShop(Shop shop)
Insert a new entry in the table Shop as well as in the table Schedule from
the database.
|
void |
deleteShop(int shopID)
Delete a shop from the database
|
private void |
fillStocks(java.util.List<Shop> shops)
Fills the stocks of a list of shops
|
java.util.List<Shop> |
getAllShops()
Gets all the shops from the database
|
private Schedule |
getScheduleFromResultSet(java.sql.ResultSet resultSet)
Gets the schedule of a shop from a ResultSet
|
void |
insertArticleInShop(int shopID,
Article article)
Inserts an article into a shop in the database
|
private int |
insertEmptyShop(Shop shop)
Inserts the basic information of a shop (no schedule or stock) in the database.
|
private void |
insertSchedule(Shop shop)
Inserts the schedule of a shop in the database
|
private void |
insertStockForEmptyShop(Shop shop)
Inserts the stock of a shop in the database
|
emptyAllTables, getDatabaseConnection
public ShopDB() throws DatabaseConnectionException
DatabaseConnectionException
public ShopDB(DatabaseConnection databaseConnection)
databaseConnection
- public int addShop(Shop shop) throws ShopInsertionException
ATTENTION: the shop ID is set to the ID given by the database.
shop
- ShopInsertionException
private int insertEmptyShop(Shop shop) throws EmptyShopInsertionException
shop
- EmptyShopInsertionException
private void insertSchedule(Shop shop) throws ScheduleInsertionException
shop
- The shop that owns the scheduleScheduleInsertionException
private void insertStockForEmptyShop(Shop shop)
shop
- public void insertArticleInShop(int shopID, Article article) throws ArticleAlreadyInShopException
shopID
- article
- ArticleAlreadyInShopException
public void deleteShop(int shopID) throws java.sql.SQLException
shopID
- The ID of the shop that should be deletedjava.sql.SQLException
public java.util.List<Shop> getAllShops() throws DatabaseException
DatabaseException
private Schedule getScheduleFromResultSet(java.sql.ResultSet resultSet) throws ScheduleFetchException
resultSet
- The resultSetScheduleFetchException
private void fillStocks(java.util.List<Shop> shops) throws StockFillingException
shops
- The list of shopsStockFillingException