DBHandlerException - if the database query fails
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectderby.DBHandler
public class DBHandler
The DBHandler acts as the intermediary between the database and the rest of the system. While the DBHandler implements SQL commands, the Database is responsible for the actual execution. The handler acts as a translator, taking SQL commands and converting them into meaningful objects in the model. Rep invarients -Each user may have only one feed for a given URL (Feeds may not be in multiple folders). -Folders may not have any siblings with the same name -No article may list the Trash as their parent feed -FeedID 0 does not exist in the DB; is the root node and all user's top level folders point to the root as their parent -Each user must have at least 3 feeds / folders: Subscribed Feeds, Outbox, and Trash -Min(FeedID) for a user is Subscribed Feeds -Min(FeedID)+1 for a user is the Outbox -Min(FeedID)+2 for a user is the Trash -Trash & outbox may only contain articles -Database may only have 3 tables: Feeds, Atricles, and Users -Every folder must have a distinct feedid -Every feed must have a distinct feedid -Every article must have a distinct articleid -Every user must have a distict username and userid -Only one user may be active at a time
| Field Summary | |
|---|---|
private Feed |
currentOutbox
|
private Folder |
currentSF
|
private Feed |
currentTrash
|
private int |
currentUserID
|
private Database |
db
|
| Constructor Summary | |
|---|---|
DBHandler()
Upon construction, the DBHandler object creates a Database object. |
|
| Method Summary | |
|---|---|
private boolean |
add(Article article,
Feed feed)
Adds an article to the specified feed in the database. |
private void |
add(Feed feed,
Folder folder)
Adds a feed to the specified folder in the database. |
private void |
add(Folder parent,
Folder child)
Adds a subfolder to a folder in the database. |
private boolean |
addArticlestoFeed(java.util.List<Article> list,
Feed f)
Adds a list of articles to a specified feed. |
Feed |
addFeed(Feed feed,
Folder folder)
Adds a feed to a folder in the database. |
Folder |
addFolder(Folder parent,
Folder child)
Adds a folder to another folder in the database. |
boolean |
addUser(java.lang.String userName,
java.lang.String password)
Adds a user to the database |
private Article |
articleUpdate(Article a,
java.lang.String set)
Modifies an article already in the database based on String. |
boolean |
copyArticle(Article source,
Feed destination)
Copies an article into a Feed |
private java.lang.String |
datetoString(java.util.Date d)
Converts a date to a Timestamp friendly string. |
private void |
deleteArticles(Feed f)
Deletes all articles from the specified feed in the database. |
private void |
deleteDB()
Deletes all tables in the database, effectively reseting the DB to its original state. |
private void |
deleteFeed(Feed f)
Deletes a feed from the database. |
boolean |
deleteFolder(Folder f)
Deletes a folder from the database (permanently) |
boolean |
deleteUser(java.lang.String username,
java.lang.String password)
Delete's a user from the database. |
boolean |
emptyTrash()
"Empties" the trash. |
private Feed |
feedUpdate(Feed f,
java.lang.String set)
Updates a field of a feed |
java.util.List<java.lang.String> |
getAllUsers()
Gets a list of all usernames |
private Article |
getArticlebyFeedUAT(java.lang.String url,
java.lang.String author,
java.lang.String title,
Feed feed,
java.lang.String constraint)
Gets an Article based on its URL, title, author, and the feed it's in. |
private Article |
getArticlebyID(int ID)
Gets an Article based on its Article ID. |
Article |
getArticleRandom()
Gets a random, unread article from the database. |
private java.util.List<Article> |
getArticles(java.lang.String constraint)
Returns a list of articles satisfying the constraint. |
java.util.List<Article> |
getArticlesbyFeed(Feed feed)
Retrieves a list of articles from the database that are in the specified feed (based on feedID). |
private int |
getArticlesCount(java.lang.String constraint)
Returns a count of the number of articles in the database which meet the condition of the constraint. |
java.util.List<Feed> |
getChildrenFeeds(Folder f)
Retrieves the Feeds which are children of a specified folder. |
java.util.List<Folder> |
getChildrenFolders(Folder f)
Retrieves the Folders which are children of a specified folder. |
java.lang.String |
getCurrentUser()
Returns the username of the current active user |
int |
getCurrentUserID()
Returns the userid of the active user. |
int |
getCurrentUserView()
Gets the viewid of the view of the current user |
private Feed |
getFeedbyID(int ID)
Gets a Feed based on its Feed ID. |
private Feed |
getFeedbyURL(java.lang.String URL)
Gets a Feed based on its URL. |
private java.util.List<Feed> |
getFeeds(java.lang.String constraint)
Returns a list of Feed objects which satisfy the constraint. |
java.util.List<Feed> |
getFeedsAll()
Gets all Feeds in the database for a given user. |
java.util.List<Feed> |
getFeedstoUpdate()
Gets all the feeds to be updated in a given minute, based on absolute time, not the time since the program was started. |
private Folder |
getFolderbyID(int ID)
Gets a Folder based on its FolderID. |
private java.util.List<Folder> |
getFolders(java.lang.String constraint)
Returns a list of Folder objects which satisfy the constraint. |
int |
getNumberArticles(java.lang.String constraint)
Returns a count of the number of articles in the database whose author, title, or contents contain a substring matching the constraint. |
int |
getNumberOfNewArticles(Feed feed)
Retrieves the number of articles from the database that are unread and belong to the specified feed. |
Feed |
getOutbox()
Gets the outbox feed |
Feed |
getParent(Article a)
Retrieves the Feed which is the parent of the specified Article. |
Folder |
getParent(Feed f)
Retrieves the Folder which is the parent of the specified Feed. |
Folder |
getParent(Folder f)
Retrieves the Folder which is the parent of the specified Folder. |
java.util.List<java.lang.Object> |
getRoot()
Retrieves the list of folders contained by the root folder. |
Folder |
getSubscribedFeeds()
Gets the subscribed feeds folder |
Feed |
getTrash()
Gets the Trash feed |
java.util.List<Article> |
getTrashArticles()
Gets a list of the articles in the trash |
int |
getUserID(java.lang.String username)
Gets a user's userid based on their username. |
private void |
insert(java.util.HashMap<java.lang.String,java.lang.String> values,
java.lang.String table)
Insert builds a string corresponding to a SQL insert of the specified row values into 'table' and executes that query. |
Article |
markRead(Article a)
Set the read status of an article to read |
Article |
markUnread(Article a)
Set the read status of an article to unread |
boolean |
moveFeed(Feed source,
Folder destination)
Moves a Feed from one parent folder to another |
boolean |
moveFolder(Folder source,
Folder destination)
Moves a subfolder from one parent to another |
private boolean |
repOK()
Makes sure that the current state does not violate the representation invarient. |
boolean |
resetDB()
Resets the database to its initial state |
java.util.List<Article> |
searchArticles(boolean byAuthor,
boolean byTitle,
boolean byContent,
Feed feed,
java.lang.String constraint)
Gets a list of articles within a feed based on a search string. |
java.util.List<Article> |
searchArticles(boolean byAuthor,
boolean byTitle,
boolean byContent,
java.lang.String constraint)
Gets a list of articles based on a search string. |
java.util.List<Article> |
searchArticlesOrdered(boolean byAuthor,
boolean byTitle,
boolean byContent,
java.lang.String constraint)
Gets a list of articles based on a search string. |
private java.sql.ResultSet |
select(java.lang.String[] fields,
java.lang.String table,
java.lang.String constraints)
Select compiles a string representing a SQL select query, executes that query, and then returns the ResultSet from that query. |
boolean |
setCurrentUser(java.lang.String userName,
java.lang.String password)
Sets the current, active user |
boolean |
setCurrentUserView(int i)
Set the current user's active view |
Article |
setDelete(Article a)
Permanently delete an article |
Feed |
setFeedTitle(Feed f,
java.lang.String title)
Sets the title a feed |
Feed |
setFeedUpdateInterval(Feed f,
int i)
Sets how often a feed will be automatically updated |
Article |
setRating(Article a,
int i)
Set the rating of an article to int i |
Article |
setReadTime(Article a,
int i)
Set the amount of time you spent reading an article. |
Article |
setTrash(Article a)
Put an article in the Trash |
Article |
setUnTrash(Article a)
Move an article out of the Trash |
private void |
setupDB()
Runs a setup algorithm which creates the feeds, articles, and user tables, as well as the 'Subscribed Feeds' and 'Outbox' folders, which must exist on creation according to the Rep Invariant. |
boolean |
shutdown()
Shuts down the database. |
private void |
startup()
Database startup routine. |
boolean |
unSubscribe(Feed f)
Unsubscribes a feed from the database. |
boolean |
updateAll(java.util.List<Feed> feedList)
This takes a list of feeds and runs update feed for each of them. |
Feed |
updateFeed(Feed f)
Takes a feed from the parser (so it should have its children articles but no id) and updates the database appropriately. |
private boolean |
userUpdate(java.lang.String userName,
java.lang.String password,
java.lang.String set)
Updates a user's profile |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
private Database db
private int currentUserID
private Folder currentSF
private Feed currentOutbox
private Feed currentTrash
| Constructor Detail |
|---|
public DBHandler()
throws DBHandlerException
DBHandlerException - if the database is not properly instantiated,
if it fails to startup, or if it fails to setup.| Method Detail |
|---|
private void setupDB()
throws DBException
DBException - If any part of the setup fails
private void startup()
throws DBHandlerException
DBHandlerException - if DB fails to startup or setup.
public boolean shutdown()
throws DBHandlerException
DBHandlerException
private void deleteDB()
throws DBException
DBException - if any of the database operations fail
public boolean resetDB()
throws DBHandlerException
DBHandlerException - if any ofprivate boolean repOK()
private java.sql.ResultSet select(java.lang.String[] fields,
java.lang.String table,
java.lang.String constraints)
throws DBHandlerException
String[] - fieldsString - tableString - constraints
DBHandlerException - if fields or table are null, or if the
database query corresponding to the select fails for some reason
private void insert(java.util.HashMap<java.lang.String,java.lang.String> values,
java.lang.String table)
throws DBHandlerException
HashMap(String - ColumnName, String Values)String - Table
DBHandlerException - if either the values or table are null, or
if the database query corresponding to the select fails for some reason
private java.util.List<Article> getArticles(java.lang.String constraint)
throws DBHandlerException
String - SQLconstraint (Has "Where"; Requires "AND")
DBHandlerException - if there is an error running the query or
creating the article object
private Article getArticlebyFeedUAT(java.lang.String url,
java.lang.String author,
java.lang.String title,
Feed feed,
java.lang.String constraint)
throws DBHandlerException
String - urlString - authorString - titleint - feedIDString - Constraint
DBHandlerException - if there is an error retrieving the articles
from the database, if more than one article is returned by the search,
or if the feed passed in does not exist in the database
private Article getArticlebyID(int ID)
throws DBHandlerException
int - ID
DBHandlerException - if there is an error retrieving the article
from the database or if more than one article is returned by the search
public java.util.List<Article> getArticlesbyFeed(Feed feed)
throws DBHandlerException
Feed -
DBHandlerException - if there is an error retrieving the articles from
the database or if the Feed provided has no ID
public java.util.List<Article> getTrashArticles()
throws DBHandlerException
DBHandlerException - if the database query fails
public java.util.List<Article> searchArticles(boolean byAuthor,
boolean byTitle,
boolean byContent,
java.lang.String constraint)
throws DBHandlerException
boolean - byAuthorboolean - byTitleboolean - byContentString - searchConstraint
DBHandlerException - if no search fields are selected or if the
database fails while performing the search.
public java.util.List<Article> searchArticles(boolean byAuthor,
boolean byTitle,
boolean byContent,
Feed feed,
java.lang.String constraint)
throws DBHandlerException
boolean - byAuthorboolean - byTitleboolean - byContentfeed - String - searchConstraint
DBHandlerException - if no search fields are selected or if the
database fails while performing the search.
public java.util.List<Article> searchArticlesOrdered(boolean byAuthor,
boolean byTitle,
boolean byContent,
java.lang.String constraint)
throws DBHandlerException
boolean - byAuthorboolean - byTitleboolean - byContentString - searchConstraint
DBHandlerException - if no search fields are selected or if the
database fails while performing the search.
public Article getArticleRandom()
throws DBHandlerException
DBHandlerException - if there is an error retrieving the articles
from the database or if the user has no articles from which to choose a
random one.
private java.util.List<Feed> getFeeds(java.lang.String constraint)
throws DBHandlerException
String - SQLconstraint (Has "Where"; Requires "AND")
DBHandlerException - if there is an error running the query or an
error creating the Feed object
private Feed getFeedbyID(int ID)
throws DBHandlerException
int - FeedID
DBHandlerException - if there is an error retrieving the feed
from the database, if the feedid is not unique, or if a feed with
the specified feedid does not exist.
private Feed getFeedbyURL(java.lang.String URL)
throws DBHandlerException
String - URL
DBHandlerException - if there is an error retrieving the feed
from the database or if a feed with feedurl URL does not exist.
public Feed getParent(Article a)
throws DBHandlerException
Article -
DBHandlerException - if there is an error retrieving the a unique
parent Feed from the database or if an Article with the specified
articleid does not exist in the database.
public java.util.List<Feed> getChildrenFeeds(Folder f)
throws DBHandlerException
Folder -
DBHandlerException - if there is an error retrieving the Feeds
from the database or if there is no Folder with the specified folderid
public java.util.List<Feed> getFeedsAll()
throws DBHandlerException
DBHandlerException - if there is an error retrieving the feeds
from the database.
public java.util.List<Feed> getFeedstoUpdate()
throws DBHandlerException
DBHandlerException - if there is an error retrieving the feeds
from the database.
private java.util.List<Folder> getFolders(java.lang.String constraint)
throws DBHandlerException
String - SQLconstraint (Has "Where"; Requires "AND ")
DBHandlerException - if there is an error running the query or an
error creating the Folder object
private Folder getFolderbyID(int ID)
throws DBHandlerException
int - FolderID
DBHandlerException - if there is an error retrieving the Folder
from the database or if a Folder with the specified FolderID does not
exist.
public Folder getParent(Feed f)
throws DBHandlerException
Feed -
DBHandlerException - if there is an error retrieving the a unique
parent Folder from the database or if a Feed the specified feedid does
not exist in the database.
public Folder getParent(Folder f)
throws DBHandlerException
Folder -
DBHandlerException - if there is an error retrieving the a unique
parent Folder from the database or if a Folder the specified feedid does
not exist in the database.
public java.util.List<Folder> getChildrenFolders(Folder f)
throws DBHandlerException
Folder -
DBHandlerException - if there is an error retrieving the Folders
from the database or if a Folder with folderid FolderID does not exist.
public java.util.List<java.lang.Object> getRoot()
throws DBHandlerException
DBHandlerException - or if there is an error retrieving the
Subscribed Feeds Folder, Outbox Feed, or Trash Feed from the database
public Folder getSubscribedFeeds()
throws DBHandlerException
DBHandlerException - if the database query fails or if the folder
is not unique for the user
public Feed getOutbox()
throws DBHandlerException
DBHandlerException - if the database query fails or if the feed
is not unique for the user
public Feed getTrash()
throws DBHandlerException
DBHandlerException - if the database query fails or if the feed
is not unique for the user
public int getUserID(java.lang.String username)
throws DBHandlerException
String - username
DBHandlerException - if the database query fails, or if there is
more than one or no user with the specified username
public java.lang.String getCurrentUser()
throws DBHandlerException
DBHandlerException - if the database query fails, or if there is
more than one or no active
public int getCurrentUserID()
throws DBHandlerException
DBHandlerException - if the database query fails, or if there is
more than one or no user with the specified username or userid
public java.util.List<java.lang.String> getAllUsers()
throws DBHandlerException
DBHandlerException - if the database query fails
public int getCurrentUserView()
throws DBHandlerException
DBHandlerException - if the database query fails or if there is
more than one active user
private int getArticlesCount(java.lang.String constraint)
throws DBException
String - constraint
DBException - if the database query fails
public int getNumberArticles(java.lang.String constraint)
throws DBHandlerException
String - constraint
DBHandlerException - if the database query fails or if the
contraint is empty
public int getNumberOfNewArticles(Feed feed)
throws DBHandlerException
feed -
DBHandlerException - if there is an error retrieving the articles from the
database or if the Feed provided has no ID
private boolean add(Article article,
Feed feed)
throws DBHandlerException
Article - Feed -
DBHandlerException - if the database query corresponding to the
insert fails or if the feed isn't in the database.
private boolean addArticlestoFeed(java.util.List<Article> list,
Feed f)
throws DBHandlerException
List - (Article)Feed -
DBHandlerException - if the database query fails or if the destination
feed does not exist
public boolean copyArticle(Article source,
Feed destination)
throws DBHandlerException
Article - Feed - destination
DBHandlerException - if the destination Feed does not exist, or if the
database operation fails
private void add(Feed feed,
Folder folder)
throws DBHandlerException
Feed - Folder -
DBHandlerException - if the database query corresponding to the
insert fails or if the destination folder doesn't exist in the database.
public Feed addFeed(Feed feed,
Folder folder)
throws DBHandlerException
Feed - Folder -
DBHandlerException - if the feed already exists in the database, if the
feed is not successfully added, or if the feed does not contain any
articles
private void add(Folder parent,
Folder child)
throws DBHandlerException
Folder - parentFolder - child
DBHandlerException - if the database query corresponding to the
insert fails or if the parent isn't in the database.
public Folder addFolder(Folder parent,
Folder child)
throws DBHandlerException
Folder - parentFolder - child
DBHandlerException - if the parent does not exist, if the
database addition fails, or if the folder has the same name as a
potential sibling (Folder at the same depth).
public boolean addUser(java.lang.String userName,
java.lang.String password)
throws DBHandlerException
String - userNameString - password
DBHandlerException - if the user is already in the DB or if the DB
inserts fail
private Article articleUpdate(Article a,
java.lang.String set)
throws DBHandlerException
Article - aString - (includs "set"; requires 'field = value')
DBHandlerException - if article a does not exist or is non-unique
in the database, or if the database update operation fails
public Article markRead(Article a)
throws DBHandlerException
Article - a
DBHandlerException - if article a does not exist or is non-unique
in the database, or if the database update operation fails
public Article markUnread(Article a)
throws DBHandlerException
Article - a
DBHandlerException - if article a does not exist or is non-unique
in the database, or if the database update operation fails
public Article setRating(Article a,
int i)
throws DBHandlerException
Article - a
DBHandlerException - if article a does not exist or is non-unique
in the database, or if the database update operation fails
public Article setReadTime(Article a,
int i)
throws DBHandlerException
Article - aint - i The read time (amount of time spent reading article).
DBHandlerException - if article a does not exist or is non-unique
in the database, or if the database update operation fails
public Article setTrash(Article a)
throws DBHandlerException
Article - a
DBHandlerException - if article a does not exist or is non-unique
in the database, or if the database update operation fails
public Article setUnTrash(Article a)
throws DBHandlerException
Article - a
DBHandlerException - if article a does not exist or is non-unique
in the database, or if the database update operation fails
public Article setDelete(Article a)
throws DBHandlerException
Article - a
DBHandlerException - if article a does not exist or is non-unique
in the database, or if the database update operation fails
public boolean emptyTrash()
throws DBHandlerException
DBHandlerException - if there is an error running the query to
empty the trash or an error getting the contents of the Trash after
emptying it.
private Feed feedUpdate(Feed f,
java.lang.String set)
throws DBHandlerException
Feed - fString - set (includs "set"; requires 'field = value')
DBHandlerException - of the feed does not exist in the DB or if
the DB operation fails
public Feed setFeedUpdateInterval(Feed f,
int i)
throws DBHandlerException
Feed - fint - updateInterval (minutes)
DBHandlerException
public Feed setFeedTitle(Feed f,
java.lang.String title)
throws DBHandlerException
Feed - fString - newTitle
DBHandlerException
public boolean moveFeed(Feed source,
Folder destination)
throws DBHandlerException
Feed - sourceFolder - destination
DBHandlerException - if the source Feed or destination Folder
does not exist, or if the database update operation fails
public Feed updateFeed(Feed f)
throws DBHandlerException
Feed - f
DBHandlerException - if the feed being updated is not already in
the DB, if there is a problem adding the new articles to the DB, or if
there is a problem getting the new feed after the update
public boolean updateAll(java.util.List<Feed> feedList)
throws DBHandlerException
List(Feed) - feedList
DBHandlerException - if there is a problem updating any feed in
the list of feeds (including attempting to update a non-existant feed).
public boolean moveFolder(Folder source,
Folder destination)
throws DBHandlerException
Folder - sourceFolder - destination
DBHandlerException - if the source or destination Folders do not
exist, or if the database update operation fails
private boolean userUpdate(java.lang.String userName,
java.lang.String password,
java.lang.String set)
throws DBHandlerException
String - userNameString - passwordString - set (includs "set"; requires 'field = value')
DBHandlerException - if the user is not in the database or if the
DB update fails
public boolean setCurrentUser(java.lang.String userName,
java.lang.String password)
throws DBHandlerException
String - userNameString - password
DBHandlerException - if the user does not exist or if the DB
operation fails
public boolean setCurrentUserView(int i)
throws DBHandlerException
int - viewid
DBHandlerException - if the user is not in the database or if
the DB update operation fails
private void deleteArticles(Feed f)
throws DBHandlerException
Feed - f
DBHandlerException - if the database operation fails, or if the
feed has no valid ID
private void deleteFeed(Feed f)
throws DBHandlerException
Feed - f
DBHandlerException - if the database operation fails, if the feed
has no valid ID, or if the feed the user is trying to delete is
Subscribed Feeds, the outbox, or the trash
public boolean unSubscribe(Feed f)
throws DBHandlerException
Feed -
DBHandlerException - if the feed does not exist, or if there is a
error performing the database operation
public boolean deleteFolder(Folder f)
throws DBHandlerException
Folder -
DBHandlerException - if the folder is not in the database, if
the database operation fails, or if the folder passed is the
'Subscribed Feeds' folder
public boolean deleteUser(java.lang.String username,
java.lang.String password)
throws DBHandlerException
String - usernameString - password
DBHandlerException - if the user does not exist or if the DB
deletion operations failprivate java.lang.String datetoString(java.util.Date d)
Date -
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||