derby
Class DBHandler

java.lang.Object
  extended by derby.DBHandler

public class DBHandler
extends java.lang.Object

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

Author:
zozer

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

db

private Database db

currentUserID

private int currentUserID

currentSF

private Folder currentSF

currentOutbox

private Feed currentOutbox

currentTrash

private Feed currentTrash
Constructor Detail

DBHandler

public DBHandler()
          throws DBHandlerException
Upon construction, the DBHandler object creates a Database object. This Database is where all data for the system is stored, and serves as the ultimate repository of information. The DBHandler automatically starts the DB on instantiation.

Throws:
DBHandlerException - if the database is not properly instantiated, if it fails to startup, or if it fails to setup.
Method Detail

setupDB

private void setupDB()
              throws DBException
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.

Throws:
DBException - If any part of the setup fails

startup

private void startup()
              throws DBHandlerException
Database startup routine. Requires that the database be instantiated, however, this is taken care of when the DBHandler is instantiated.

Throws:
DBHandlerException - if DB fails to startup or setup.

shutdown

public boolean shutdown()
                 throws DBHandlerException
Shuts down the database.

Returns:
true if runs to completion
Throws:
DBHandlerException

deleteDB

private void deleteDB()
               throws DBException
Deletes all tables in the database, effectively reseting the DB to its original state.

Throws:
DBException - if any of the database operations fail

resetDB

public boolean resetDB()
                throws DBHandlerException
Resets the database to its initial state

Returns:
true if the database is successfully reset
Throws:
DBHandlerException - if any of

repOK

private boolean repOK()
Makes sure that the current state does not violate the representation invarient.

Returns:
true if none of the representation invarient conditions are violated

select

private java.sql.ResultSet select(java.lang.String[] fields,
                                  java.lang.String table,
                                  java.lang.String constraints)
                           throws DBHandlerException
Select compiles a string representing a SQL select query, executes that query, and then returns the ResultSet from that query. The fields array should be strings of the column names to be returned.

Parameters:
String[] - fields
String - table
String - constraints
Returns:
ResultSet (Never null)
Throws:
DBHandlerException - if fields or table are null, or if the database query corresponding to the select fails for some reason

insert

private void insert(java.util.HashMap<java.lang.String,java.lang.String> values,
                    java.lang.String table)
             throws DBHandlerException
Insert builds a string corresponding to a SQL insert of the specified row values into 'table' and executes that query.

Parameters:
HashMap(String - ColumnName, String Values)
String - Table
Throws:
DBHandlerException - if either the values or table are null, or if the database query corresponding to the select fails for some reason

getArticles

private java.util.List<Article> getArticles(java.lang.String constraint)
                                     throws DBHandlerException
Returns a list of articles satisfying the constraint. If no constraint is specified, all articles will be returned.

Parameters:
String - SQLconstraint (Has "Where"; Requires "AND")
Returns:
List(Article) (never null)
Throws:
DBHandlerException - if there is an error running the query or creating the article object

getArticlebyFeedUAT

private Article getArticlebyFeedUAT(java.lang.String url,
                                    java.lang.String author,
                                    java.lang.String title,
                                    Feed feed,
                                    java.lang.String constraint)
                             throws DBHandlerException
Gets an Article based on its URL, title, author, and the feed it's in. To search in all folders, 0 (the root node) should be passed as the last term, the FeedID. NOTE: inactive, deleted articles will be returned.

Parameters:
String - url
String - author
String - title
int - feedID
String - Constraint
Returns:
Article, unless no article is found, in which case the result is null
Throws:
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

getArticlebyID

private Article getArticlebyID(int ID)
                        throws DBHandlerException
Gets an Article based on its Article ID.

Parameters:
int - ID
Returns:
Article
Throws:
DBHandlerException - if there is an error retrieving the article from the database or if more than one article is returned by the search

getArticlesbyFeed

public java.util.List<Article> getArticlesbyFeed(Feed feed)
                                          throws DBHandlerException
Retrieves a list of articles from the database that are in the specified feed (based on feedID). Only active, non-deleted articles are returned.

Parameters:
Feed -
Returns:
List(Article)
Throws:
DBHandlerException - if there is an error retrieving the articles from the database or if the Feed provided has no ID

getTrashArticles

public java.util.List<Article> getTrashArticles()
                                         throws DBHandlerException
Gets a list of the articles in the trash

Returns:
List

searchArticles

public java.util.List<Article> searchArticles(boolean byAuthor,
                                              boolean byTitle,
                                              boolean byContent,
                                              java.lang.String constraint)
                                       throws DBHandlerException
Gets a list of articles based on a search string. The search looks for the string in the author, title, and content of the article, depending on the flags set by the booleans. Only active, non-deleted articles are returned.

Parameters:
boolean - byAuthor
boolean - byTitle
boolean - byContent
String - searchConstraint
Returns:
List (articles) matching the constraint in the fields specified
Throws:
DBHandlerException - if no search fields are selected or if the database fails while performing the search.

searchArticles

public java.util.List<Article> searchArticles(boolean byAuthor,
                                              boolean byTitle,
                                              boolean byContent,
                                              Feed feed,
                                              java.lang.String constraint)
                                       throws DBHandlerException
Gets a list of articles within a feed based on a search string. The search looks for the string in the author, title, and content of the article, depending on the flags set by the booleans. Only active, non-deleted articles are returned.

Parameters:
boolean - byAuthor
boolean - byTitle
boolean - byContent
feed -
String - searchConstraint
Returns:
List (articles) matching the constraint in the fields specified
Throws:
DBHandlerException - if no search fields are selected or if the database fails while performing the search.

searchArticlesOrdered

public java.util.List<Article> searchArticlesOrdered(boolean byAuthor,
                                                     boolean byTitle,
                                                     boolean byContent,
                                                     java.lang.String constraint)
                                              throws DBHandlerException
Gets a list of articles based on a search string. The search looks for the string in the author, title, and content of the article, depending on the flags set by the booleans. Only active, non-deleted articles are returned.

Parameters:
boolean - byAuthor
boolean - byTitle
boolean - byContent
String - searchConstraint
Returns:
List (articles) matching the constraint in the fields specified
Throws:
DBHandlerException - if no search fields are selected or if the database fails while performing the search.

getArticleRandom

public Article getArticleRandom()
                         throws DBHandlerException
Gets a random, unread article from the database. Only active, non-deleted articles are returned.

Returns:
Article
Throws:
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.

getFeeds

private java.util.List<Feed> getFeeds(java.lang.String constraint)
                               throws DBHandlerException
Returns a list of Feed objects which satisfy the constraint. If no constraint is specified, all Feeds will be returned.

Parameters:
String - SQLconstraint (Has "Where"; Requires "AND")
Returns:
List(Feed) (never null)
Throws:
DBHandlerException - if there is an error running the query or an error creating the Feed object

getFeedbyID

private Feed getFeedbyID(int ID)
                  throws DBHandlerException
Gets a Feed based on its Feed ID.

Parameters:
int - FeedID
Returns:
Feed
Throws:
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.

getFeedbyURL

private Feed getFeedbyURL(java.lang.String URL)
                   throws DBHandlerException
Gets a Feed based on its URL.

Parameters:
String - URL
Returns:
Feed
Throws:
DBHandlerException - if there is an error retrieving the feed from the database or if a feed with feedurl URL does not exist.

getParent

public Feed getParent(Article a)
               throws DBHandlerException
Retrieves the Feed which is the parent of the specified Article.

Parameters:
Article -
Returns:
Feed
Throws:
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.

getChildrenFeeds

public java.util.List<Feed> getChildrenFeeds(Folder f)
                                      throws DBHandlerException
Retrieves the Feeds which are children of a specified folder.

Parameters:
Folder -
Returns:
List(Feed)
Throws:
DBHandlerException - if there is an error retrieving the Feeds from the database or if there is no Folder with the specified folderid

getFeedsAll

public java.util.List<Feed> getFeedsAll()
                                 throws DBHandlerException
Gets all Feeds in the database for a given user.

Returns:
List(Feed)
Throws:
DBHandlerException - if there is an error retrieving the feeds from the database.

getFeedstoUpdate

public java.util.List<Feed> getFeedstoUpdate()
                                      throws DBHandlerException
Gets all the feeds to be updated in a given minute, based on absolute time, not the time since the program was started.

Returns:
List(Feed)
Throws:
DBHandlerException - if there is an error retrieving the feeds from the database.

getFolders

private java.util.List<Folder> getFolders(java.lang.String constraint)
                                   throws DBHandlerException
Returns a list of Folder objects which satisfy the constraint. If no constraint is specified, all Folders will be returned.

Parameters:
String - SQLconstraint (Has "Where"; Requires "AND ")
Returns:
List(Folder) (never null)
Throws:
DBHandlerException - if there is an error running the query or an error creating the Folder object

getFolderbyID

private Folder getFolderbyID(int ID)
                      throws DBHandlerException
Gets a Folder based on its FolderID.

Parameters:
int - FolderID
Returns:
Folder
Throws:
DBHandlerException - if there is an error retrieving the Folder from the database or if a Folder with the specified FolderID does not exist.

getParent

public Folder getParent(Feed f)
                 throws DBHandlerException
Retrieves the Folder which is the parent of the specified Feed.

Parameters:
Feed -
Returns:
Folder
Throws:
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.

getParent

public Folder getParent(Folder f)
                 throws DBHandlerException
Retrieves the Folder which is the parent of the specified Folder.

Parameters:
Folder -
Returns:
Folder
Throws:
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.

getChildrenFolders

public java.util.List<Folder> getChildrenFolders(Folder f)
                                          throws DBHandlerException
Retrieves the Folders which are children of a specified folder.

Parameters:
Folder -
Returns:
List(Folder)
Throws:
DBHandlerException - if there is an error retrieving the Folders from the database or if a Folder with folderid FolderID does not exist.

getRoot

public java.util.List<java.lang.Object> getRoot()
                                         throws DBHandlerException
Retrieves the list of folders contained by the root folder.

Returns:
List(Objcect)
Throws:
DBHandlerException - or if there is an error retrieving the Subscribed Feeds Folder, Outbox Feed, or Trash Feed from the database

getSubscribedFeeds

public Folder getSubscribedFeeds()
                          throws DBHandlerException
Gets the subscribed feeds folder

Returns:
Folder outbox
Throws:
DBHandlerException - if the database query fails or if the folder is not unique for the user

getOutbox

public Feed getOutbox()
               throws DBHandlerException
Gets the outbox feed

Returns:
Folder outbox
Throws:
DBHandlerException - if the database query fails or if the feed is not unique for the user

getTrash

public Feed getTrash()
              throws DBHandlerException
Gets the Trash feed

Returns:
Feed trash
Throws:
DBHandlerException - if the database query fails or if the feed is not unique for the user

getUserID

public int getUserID(java.lang.String username)
              throws DBHandlerException
Gets a user's userid based on their username.

Parameters:
String - username
Returns:
int Userid
Throws:
DBHandlerException - if the database query fails, or if there is more than one or no user with the specified username

getCurrentUser

public java.lang.String getCurrentUser()
                                throws DBHandlerException
Returns the username of the current active user

Returns:
String username
Throws:
DBHandlerException - if the database query fails, or if there is more than one or no active

getCurrentUserID

public int getCurrentUserID()
                     throws DBHandlerException
Returns the userid of the active user.

Returns:
int userid
Throws:
DBHandlerException - if the database query fails, or if there is more than one or no user with the specified username or userid

getAllUsers

public java.util.List<java.lang.String> getAllUsers()
                                             throws DBHandlerException
Gets a list of all usernames

Returns:
List(String username) (never null)
Throws:
DBHandlerException - if the database query fails

getCurrentUserView

public int getCurrentUserView()
                       throws DBHandlerException
Gets the viewid of the view of the current user

Returns:
int viewid
Throws:
DBHandlerException - if the database query fails or if there is more than one active user

getArticlesCount

private int getArticlesCount(java.lang.String constraint)
                      throws DBException
Returns a count of the number of articles in the database which meet the condition of the constraint.

Parameters:
String - constraint
Returns:
int Count(Articles)
Throws:
DBException - if the database query fails

getNumberArticles

public int getNumberArticles(java.lang.String constraint)
                      throws DBHandlerException
Returns a count of the number of articles in the database whose author, title, or contents contain a substring matching the constraint.

Parameters:
String - constraint
Returns:
int Count(Articles) that meet the constraint
Throws:
DBHandlerException - if the database query fails or if the contraint is empty

getNumberOfNewArticles

public int getNumberOfNewArticles(Feed feed)
                           throws DBHandlerException
Retrieves the number of articles from the database that are unread and belong to the specified feed.

Parameters:
feed -
Returns:
int
Throws:
DBHandlerException - if there is an error retrieving the articles from the database or if the Feed provided has no ID

add

private boolean add(Article article,
                    Feed feed)
             throws DBHandlerException
Adds an article to the specified feed in the database.

Parameters:
Article -
Feed -
Returns:
boolean true if runs to completion
Throws:
DBHandlerException - if the database query corresponding to the insert fails or if the feed isn't in the database.

addArticlestoFeed

private boolean addArticlestoFeed(java.util.List<Article> list,
                                  Feed f)
                           throws DBHandlerException
Adds a list of articles to a specified feed.

Parameters:
List - (Article)
Feed -
Returns:
boolean true if runs to completion
Throws:
DBHandlerException - if the database query fails or if the destination feed does not exist

copyArticle

public boolean copyArticle(Article source,
                           Feed destination)
                    throws DBHandlerException
Copies an article into a Feed

Parameters:
Article -
Feed - destination
Returns:
true if the article is successfully added; false otherwise
Throws:
DBHandlerException - if the destination Feed does not exist, or if the database operation fails

add

private void add(Feed feed,
                 Folder folder)
          throws DBHandlerException
Adds a feed to the specified folder in the database.

Parameters:
Feed -
Folder -
Throws:
DBHandlerException - if the database query corresponding to the insert fails or if the destination folder doesn't exist in the database.

addFeed

public Feed addFeed(Feed feed,
                    Folder folder)
             throws DBHandlerException
Adds a feed to a folder in the database.

Parameters:
Feed -
Folder -
Returns:
Feed (with ID)
Throws:
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

add

private void add(Folder parent,
                 Folder child)
          throws DBHandlerException
Adds a subfolder to a folder in the database.

Parameters:
Folder - parent
Folder - child
Throws:
DBHandlerException - if the database query corresponding to the insert fails or if the parent isn't in the database.

addFolder

public Folder addFolder(Folder parent,
                        Folder child)
                 throws DBHandlerException
Adds a folder to another folder in the database.

Parameters:
Folder - parent
Folder - child
Returns:
Updated Folder parent
Throws:
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).

addUser

public boolean addUser(java.lang.String userName,
                       java.lang.String password)
                throws DBHandlerException
Adds a user to the database

Parameters:
String - userName
String - password
Returns:
ture if runs to completion
Throws:
DBHandlerException - if the user is already in the DB or if the DB inserts fail

articleUpdate

private Article articleUpdate(Article a,
                              java.lang.String set)
                       throws DBHandlerException
Modifies an article already in the database based on String.

Parameters:
Article - a
String - (includs "set"; requires 'field = value')
Returns:
Updated Article a
Throws:
DBHandlerException - if article a does not exist or is non-unique in the database, or if the database update operation fails

markRead

public Article markRead(Article a)
                 throws DBHandlerException
Set the read status of an article to read

Parameters:
Article - a
Returns:
Updated Article a
Throws:
DBHandlerException - if article a does not exist or is non-unique in the database, or if the database update operation fails

markUnread

public Article markUnread(Article a)
                   throws DBHandlerException
Set the read status of an article to unread

Parameters:
Article - a
Returns:
Updated Article a
Throws:
DBHandlerException - if article a does not exist or is non-unique in the database, or if the database update operation fails

setRating

public Article setRating(Article a,
                         int i)
                  throws DBHandlerException
Set the rating of an article to int i

Parameters:
Article - a
Returns:
Updated Article a
Throws:
DBHandlerException - if article a does not exist or is non-unique in the database, or if the database update operation fails

setReadTime

public Article setReadTime(Article a,
                           int i)
                    throws DBHandlerException
Set the amount of time you spent reading an article.

Parameters:
Article - a
int - i The read time (amount of time spent reading article).
Returns:
Updated Article a
Throws:
DBHandlerException - if article a does not exist or is non-unique in the database, or if the database update operation fails

setTrash

public Article setTrash(Article a)
                 throws DBHandlerException
Put an article in the Trash

Parameters:
Article - a
Returns:
Updated Article a
Throws:
DBHandlerException - if article a does not exist or is non-unique in the database, or if the database update operation fails

setUnTrash

public Article setUnTrash(Article a)
                   throws DBHandlerException
Move an article out of the Trash

Parameters:
Article - a
Returns:
Updated Article a
Throws:
DBHandlerException - if article a does not exist or is non-unique in the database, or if the database update operation fails

setDelete

public Article setDelete(Article a)
                  throws DBHandlerException
Permanently delete an article

Parameters:
Article - a
Returns:
Updated Article a
Throws:
DBHandlerException - if article a does not exist or is non-unique in the database, or if the database update operation fails

emptyTrash

public boolean emptyTrash()
                   throws DBHandlerException
"Empties" the trash. Articles remain in the database (but are invisible) until cleanup() is run. Should return a List(Article) with no elements if it runs to completetion

Returns:
boolean True if runs to completion
Throws:
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.

feedUpdate

private Feed feedUpdate(Feed f,
                        java.lang.String set)
                 throws DBHandlerException
Updates a field of a feed

Parameters:
Feed - f
String - set (includs "set"; requires 'field = value')
Returns:
updatedFeed f
Throws:
DBHandlerException - of the feed does not exist in the DB or if the DB operation fails

setFeedUpdateInterval

public Feed setFeedUpdateInterval(Feed f,
                                  int i)
                           throws DBHandlerException
Sets how often a feed will be automatically updated

Parameters:
Feed - f
int - updateInterval (minutes)
Returns:
updatedFeed f
Throws:
DBHandlerException

setFeedTitle

public Feed setFeedTitle(Feed f,
                         java.lang.String title)
                  throws DBHandlerException
Sets the title a feed

Parameters:
Feed - f
String - newTitle
Returns:
updatedFeed f
Throws:
DBHandlerException

moveFeed

public boolean moveFeed(Feed source,
                        Folder destination)
                 throws DBHandlerException
Moves a Feed from one parent folder to another

Parameters:
Feed - source
Folder - destination
Returns:
boolean true if runs to completion
Throws:
DBHandlerException - if the source Feed or destination Folder does not exist, or if the database update operation fails

updateFeed

public Feed updateFeed(Feed f)
                throws DBHandlerException
Takes a feed from the parser (so it should have its children articles but no id) and updates the database appropriately. Returns a new feed object that has been updated appropriately.

Parameters:
Feed - f
Returns:
UpdatedFeed f
Throws:
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

updateAll

public boolean updateAll(java.util.List<Feed> feedList)
                  throws DBHandlerException
This takes a list of feeds and runs update feed for each of them. List(Feed) feedList should come from the parser, and each feed must return true for knowsChildren to ensure that update to work properly.

Parameters:
List(Feed) - feedList
Returns:
boolean true if runs to completion
Throws:
DBHandlerException - if there is a problem updating any feed in the list of feeds (including attempting to update a non-existant feed).

moveFolder

public boolean moveFolder(Folder source,
                          Folder destination)
                   throws DBHandlerException
Moves a subfolder from one parent to another

Parameters:
Folder - source
Folder - destination
Returns:
boolean true if runs to completion
Throws:
DBHandlerException - if the source or destination Folders do not exist, or if the database update operation fails

userUpdate

private boolean userUpdate(java.lang.String userName,
                           java.lang.String password,
                           java.lang.String set)
                    throws DBHandlerException
Updates a user's profile

Parameters:
String - userName
String - password
String - set (includs "set"; requires 'field = value')
Returns:
true if runs to completion
Throws:
DBHandlerException - if the user is not in the database or if the DB update fails

setCurrentUser

public boolean setCurrentUser(java.lang.String userName,
                              java.lang.String password)
                       throws DBHandlerException
Sets the current, active user

Parameters:
String - userName
String - password
Returns:
true if runs to completion
Throws:
DBHandlerException - if the user does not exist or if the DB operation fails

setCurrentUserView

public boolean setCurrentUserView(int i)
                           throws DBHandlerException
Set the current user's active view

Parameters:
int - viewid
Returns:
true if runs to completion
Throws:
DBHandlerException - if the user is not in the database or if the DB update operation fails

deleteArticles

private void deleteArticles(Feed f)
                     throws DBHandlerException
Deletes all articles from the specified feed in the database.

Parameters:
Feed - f
Throws:
DBHandlerException - if the database operation fails, or if the feed has no valid ID

deleteFeed

private void deleteFeed(Feed f)
                 throws DBHandlerException
Deletes a feed from the database.

Parameters:
Feed - f
Throws:
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

unSubscribe

public boolean unSubscribe(Feed f)
                    throws DBHandlerException
Unsubscribes a feed from the database. Deletes the specified feed and all its articles.

Parameters:
Feed -
Returns:
boolean true if both the articles and feed are successfully removed
Throws:
DBHandlerException - if the feed does not exist, or if there is a error performing the database operation

deleteFolder

public boolean deleteFolder(Folder f)
                     throws DBHandlerException
Deletes a folder from the database (permanently)

Parameters:
Folder -
Returns:
boolean true if runs to completion
Throws:
DBHandlerException - if the folder is not in the database, if the database operation fails, or if the folder passed is the 'Subscribed Feeds' folder

deleteUser

public boolean deleteUser(java.lang.String username,
                          java.lang.String password)
                   throws DBHandlerException
Delete's a user from the database. as well as their feeds, folders, and articles

Parameters:
String - username
String - password
Returns:
true if runs to completion
Throws:
DBHandlerException - if the user does not exist or if the DB deletion operations fail

datetoString

private java.lang.String datetoString(java.util.Date d)
Converts a date to a Timestamp friendly string.

Parameters:
Date -
Returns:
Timestamp(Date) --> String