ischool.info340.teamE
Class Database

java.lang.Object
  extended by ischool.info340.teamE.Database
All Implemented Interfaces:
MediaManager, PlaceManager, TagManager, UserManager

public class Database
extends java.lang.Object
implements TagManager, UserManager, PlaceManager, MediaManager


Method Summary
 java.util.Collection getAllMedia()
           
 java.util.Collection getAllPlaces()
           
 java.util.Collection getAllTags()
           
 java.util.Collection getAllUsers()
          Returns a collection of all users
 java.util.Collection getChildren(int tagId)
          Gets all the children of this tag
 User getCreator(int userId)
          Gets the user who uploaded this media from the storage medium
 java.util.Collection getFavoritePlaces(int userId)
          Gets a collection of places that a user has marked as some of his favorites.
 java.util.Collection getFavoritePlaces(int userId, int offset, int maxReturned)
          Returns a range of the favorites based on a userId
static Database getInstance()
          TO DO
 Media getMedia(int mediaId)
           
 java.util.Collection getMediaForPlace(int placeId)
          Gets all the media associated with a place
 Place getPlace(int placeId)
          Gets the place from the storage medium
 java.util.Collection getPlacesWithTag(int tagId)
          Returns all the places with a given tag
 java.util.Collection getPopularPlaces(int count)
          Returns the top "X" places
 Tag getTag(int tagId)
           
 java.util.Collection getTagsForPlace(int placeId)
          Return all the tags that a given place has been tagged by
 User getUser(int userId)
          Retrieves a user from the storage medium based on their unique id number.
 User getUser(java.lang.String user)
          This doesn't relate to a user, a slightly hacky way to avoid a new manager interface for favorites.
 int getUserCount()
          Returns the number of users that exist in the database
 java.util.Collection getUsers(int offset, int maxReturned)
          Returns a range of the users
 int insertMedia(java.net.URL url, java.lang.String desc, int creatorId, int placeId, java.util.Date dateCaptured)
          Inserts a new piece of media into the storage medium
 int insertPlace(int creatorId, java.lang.String name, java.lang.String descr)
          Inserts a new place into the storage medium
 int insertTag(java.lang.String name, java.lang.String desc, int creatorId, int parentId)
          Inserts a new tag into the storage medium
 int insertUser(java.lang.String username, java.lang.String password, java.lang.String name, java.lang.String interests, java.util.Date dateOfBirth)
          Inserts a new user into the storage medium
 boolean markPlaceWithTag(int placeId, int tagId, int taggedBy)
          Updates the storage medium to reflect the association of a tag with a place
 boolean removeMedia(int mediaId)
          Removes a piece of media from the storage medium
 boolean removePlace(int placeId)
          Removes a place from the storage medium
 boolean removeTag(int tagId)
          Removes a tag from the storage medium
 boolean removeUser(int userId)
          Removes a user from the storage medium
 boolean updateMedia(int mediaId, java.net.URL url, java.lang.String desc, int creatorId, int placeId, java.util.Date dateCaptured)
          Updates the value of a piece of media in the storage medium
 boolean updatePlace(int id, int creatorId, java.lang.String name, java.lang.String descr)
          Updates the value of a piece of media in the storage medium
 boolean updateTag(int tagId, java.lang.String name, java.lang.String desc, int creatorId, int parentId)
          Updates the value of a tag in the storage medium
 boolean updateUser(int id, java.lang.String username, java.lang.String password, java.lang.String name, java.lang.String interests, java.util.Date dateOfBirth)
          Updates a user in the storage medium
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getInstance

public static Database getInstance()
                            throws java.lang.Exception
TO DO

Throws:
java.lang.Exception

getMedia

public Media getMedia(int mediaId)
Specified by:
getMedia in interface MediaManager
Parameters:
mediaId - A unique identifier of a media in the storage medium
Returns:
A media from the storage medium coorisponding to mediaId, null if no matching media can be found.

insertMedia

public int insertMedia(java.net.URL url,
                       java.lang.String desc,
                       int creatorId,
                       int placeId,
                       java.util.Date dateCaptured)
Inserts a new piece of media into the storage medium

Specified by:
insertMedia in interface MediaManager
Parameters:
url - The location where this media is hosted
desc - The description of this media
creatorId - The ID of the user who uploaded this media
placeId - The place that this media represents
dateCaptured - The date that this media was captured at the place
Returns:
The id of the newly inserted media or -1 if there was an error

updateMedia

public boolean updateMedia(int mediaId,
                           java.net.URL url,
                           java.lang.String desc,
                           int creatorId,
                           int placeId,
                           java.util.Date dateCaptured)
Updates the value of a piece of media in the storage medium

Specified by:
updateMedia in interface MediaManager
Parameters:
mediaId - The media to be updated
url - The new location where this media is hosted
desc - The new description of this media
creatorId - The ID of the user who uploaded this media
placeId - The place that this media represents
dateCaptured - The new date that this media was captured at the place
Returns:
true if this operation succedes, false otherwise

removeMedia

public boolean removeMedia(int mediaId)
Removes a piece of media from the storage medium

Specified by:
removeMedia in interface MediaManager
Parameters:
mediaId - The tag to remove
Returns:
True if the tag was successfully removed, false otherwise.

getCreator

public User getCreator(int userId)
Gets the user who uploaded this media from the storage medium

Specified by:
getCreator in interface MediaManager
Specified by:
getCreator in interface PlaceManager
Specified by:
getCreator in interface TagManager
Parameters:
userId - The id of the user to retrieve
Returns:
The user retrieved from the storage medium

getPlace

public Place getPlace(int placeId)
Gets the place from the storage medium

Specified by:
getPlace in interface MediaManager
Specified by:
getPlace in interface PlaceManager
Parameters:
placeId - The id of the place to retrieve
Returns:
The place retrieved or null if there was a error

insertPlace

public int insertPlace(int creatorId,
                       java.lang.String name,
                       java.lang.String descr)
Inserts a new place into the storage medium

Specified by:
insertPlace in interface PlaceManager
Parameters:
creatorId - The unique id of the user who created this place
name - The name of the place
descr - The description that describes this place, can be null
Returns:
The id of the newly inserted media or -1 if there was an error

updatePlace

public boolean updatePlace(int id,
                           int creatorId,
                           java.lang.String name,
                           java.lang.String descr)
Updates the value of a piece of media in the storage medium

Specified by:
updatePlace in interface PlaceManager
Parameters:
id - The unique id for this place in the storage medium
creatorId - The unique id of the user who created this place
name - The name of the place
descr - The description that describes this place, can be null
Returns:
true if this operation succedes, false otherwise

removePlace

public boolean removePlace(int placeId)
Removes a place from the storage medium

Specified by:
removePlace in interface PlaceManager
Parameters:
placeId - The unique id for the place to be removed
Returns:
True if the place was successfully removed, false otherwise.

getTag

public Tag getTag(int tagId)
Specified by:
getTag in interface TagManager
Parameters:
tagId - A unique identifier of a tag in the storage medium
Returns:
A tag from the storage medium coorisponding to tagId, null if no matching tag can be found.

insertTag

public int insertTag(java.lang.String name,
                     java.lang.String desc,
                     int creatorId,
                     int parentId)
Inserts a new tag into the storage medium

Specified by:
insertTag in interface TagManager
Parameters:
name - The name for this tag
desc - Optional description for this tag, null if ommitted.
creatorId - Id of the user who created this tag
parentId - Id of the parent of this tag, or -1 for no parent.
Returns:
The id of the newly inserted tag or -1 if there was an error

updateTag

public boolean updateTag(int tagId,
                         java.lang.String name,
                         java.lang.String desc,
                         int creatorId,
                         int parentId)
Updates the value of a tag in the storage medium

Specified by:
updateTag in interface TagManager
Parameters:
tagId - The tag to be updated
name - The new name for this tag
desc - The new description for this tag, null for no description
creatorId - The new id for user that created this tag
parentId - The new parent id for this tag (or -1 fo no parent)
Returns:
true if this operation succedes, false otherwise

removeTag

public boolean removeTag(int tagId)
Removes a tag from the storage medium

Specified by:
removeTag in interface TagManager
Parameters:
tagId - The tag to remove
Returns:
True if the tag was successfully removed, false otherwise.

getChildren

public java.util.Collection getChildren(int tagId)
Gets all the children of this tag

Specified by:
getChildren in interface TagManager
Parameters:
tagId - Id of the tag whose children should be retrieved or -1 for root tags
Returns:
A collection of all this tags immediate children

getFavoritePlaces

public java.util.Collection getFavoritePlaces(int userId,
                                              int offset,
                                              int maxReturned)
Returns a range of the favorites based on a userId

Specified by:
getFavoritePlaces in interface UserManager
Parameters:
userId - the user to return favorites for
offset - The number of favorites to skip before returning favorites
maxReturned - The maximum number of favorites to return from this query
Returns:
a collection of place objects, null if there is an error

getUser

public User getUser(int userId)
Retrieves a user from the storage medium based on their unique id number.

Specified by:
getUser in interface UserManager
Parameters:
userId - The id of the user to be retrieved
Returns:
The user retrived from the storage medium

removeUser

public boolean removeUser(int userId)
Removes a user from the storage medium

Specified by:
removeUser in interface UserManager
Parameters:
userId - The unique id for the user to remove
Returns:
True if the operation is a success, false otherwise

insertUser

public int insertUser(java.lang.String username,
                      java.lang.String password,
                      java.lang.String name,
                      java.lang.String interests,
                      java.util.Date dateOfBirth)
Inserts a new user into the storage medium

Specified by:
insertUser in interface UserManager
Parameters:
username - The login name for the new user
password - The password for the new user
name - The real name of the new user (optional)
interests - A list of the interests of the new user (optional)
dateOfBirth - the date that the new user was born
Returns:
the id of the newly inserted user or -1 if there was an error

updateUser

public boolean updateUser(int id,
                          java.lang.String username,
                          java.lang.String password,
                          java.lang.String name,
                          java.lang.String interests,
                          java.util.Date dateOfBirth)
Updates a user in the storage medium

Specified by:
updateUser in interface UserManager
Parameters:
id - The id of the user to be updated
username - The new login name for the user
password - The new password for the user
name - The new real name of the user (optional)
interests - A new list of the interests of the user (optional)
dateOfBirth - The new date that the user was born
Returns:
true if the update was successful, false otherwise

getFavoritePlaces

public java.util.Collection getFavoritePlaces(int userId)
Gets a collection of places that a user has marked as some of his favorites.

Specified by:
getFavoritePlaces in interface UserManager
Parameters:
userId - The id of the user whose favorites should be retrieved
Returns:
a collection of the users favorites, or null if there was an error

getUser

public User getUser(java.lang.String user)
Description copied from interface: UserManager
This doesn't relate to a user, a slightly hacky way to avoid a new manager interface for favorites. Returns a user object for the specified username

Specified by:
getUser in interface UserManager
Parameters:
user - The username of this user
Returns:
The user obeject requested

getPopularPlaces

public java.util.Collection getPopularPlaces(int count)
Returns the top "X" places

Specified by:
getPopularPlaces in interface UserManager
Parameters:
count - The number of results to be returned in the collection
Returns:
The collection of popular places.

getAllUsers

public java.util.Collection getAllUsers()
Returns a collection of all users

Specified by:
getAllUsers in interface UserManager
Returns:
a collection of User objects, null if there is an error

getPlacesWithTag

public java.util.Collection getPlacesWithTag(int tagId)
Returns all the places with a given tag

Specified by:
getPlacesWithTag in interface TagManager
Parameters:
tagId - the tagId to retrieve places for
Returns:
A collection of Place objects, null if there is an error

getUsers

public java.util.Collection getUsers(int offset,
                                     int maxReturned)
Returns a range of the users

Specified by:
getUsers in interface UserManager
Parameters:
offset - The number of users to skip before returning users
maxReturned - The maximum number of users to return from this query
Returns:
a collection of user objects, null if there is an error

getUserCount

public int getUserCount()
Returns the number of users that exist in the database

Specified by:
getUserCount in interface UserManager
Returns:
a positive integer or -1 if there is an error

getMediaForPlace

public java.util.Collection getMediaForPlace(int placeId)
Gets all the media associated with a place

Specified by:
getMediaForPlace in interface MediaManager
Parameters:
placeId - The id of the place to get media for
Returns:
A collection of media objects or null if there was an error

getTagsForPlace

public java.util.Collection getTagsForPlace(int placeId)
Return all the tags that a given place has been tagged by

Specified by:
getTagsForPlace in interface TagManager
Parameters:
placeId - the place to get tags for
Returns:
a collection of Tag objects or null if there is an error

getAllMedia

public java.util.Collection getAllMedia()
Specified by:
getAllMedia in interface MediaManager
Returns:
A collection of all media objects from the storage medium, or null if there was an error

getAllPlaces

public java.util.Collection getAllPlaces()
Specified by:
getAllPlaces in interface PlaceManager
Returns:
A collection of all places in the storage medium, or null if there was an error

getAllTags

public java.util.Collection getAllTags()
Specified by:
getAllTags in interface TagManager
Returns:
A collection of all tag objects from the storage medium, or null if there was an error

markPlaceWithTag

public boolean markPlaceWithTag(int placeId,
                                int tagId,
                                int taggedBy)
Updates the storage medium to reflect the association of a tag with a place

Specified by:
markPlaceWithTag in interface PlaceManager
Parameters:
tagId - The tag to add to the place
placeId - the place that was tagged
taggedBy - the id of the user to tagged this place
Returns:
false if there was an error, true otherwise