|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.cutunes.server.DatabaseController
Contains all logic for connecting/querying/updating the top40db database. Written as a Java singleton so only a single database connection can be opened by an application at any given time.
Methods mainly called through the RequestHandler in response to XML-RPC messages. A couple methods, updateTop40Caches() and updatePlayCountWeek() are called by cron jobs on a regular basis.
Method Summary | |
void |
bulkLoadHasSongData(int userID,
java.lang.String hasSongsFile)
Uses MySQL's load data function to bulk load a file full of information into the has_songs table. |
void |
bulkLoadSongData(int userID,
java.lang.String songsFile)
Uses MySQL's load data function to bulk load a file full of information into the songs table. |
void |
clearTable(java.lang.String table)
Clear a table |
int |
countForArtist(java.lang.String query)
|
java.util.Vector |
getArtistsLike(java.lang.String artist)
Gets artists that are similar to another artist |
java.util.Vector |
getArtistsOfUser(int userID,
int myUserID,
int limit)
Get the top artists of a user that another user has |
static DatabaseController |
getInstance()
Java singleton getInstance() method. |
java.sql.Timestamp |
getLastSync(int userID,
java.lang.String version)
Queries database to get the last time a user synced. |
java.util.Vector |
getSongsForArtist(java.lang.String artist,
int userID,
int numItems)
Gets songs of a given artist that a user has |
int |
getUserID(java.lang.String user,
java.lang.String password)
Queries database with username and password to find the unique ID for a given user. |
java.util.Vector |
getUserIDFor(java.lang.String query)
Get a the name and ID of a user given a query. |
void |
loadDataIntoTable(java.lang.String file,
java.lang.String table,
boolean isLocal)
Load data from a file into a table |
void |
logMessage(boolean error,
java.lang.String function,
java.lang.String message)
Logs messages into the message_logs table of the database. |
static void |
main(java.lang.String[] args)
Simple main method used for testing the database controller. |
void |
setLastSync(int userID,
java.lang.String version)
Sets the last sync time for a user to the current time in UTC, and logs the sync in the sync_logs table. |
void |
updateForFirstSync(int userID,
java.lang.String version)
Adds 1 to the this week play count of every song that was played in the last week |
void |
updateHasSong(int userID,
java.util.Date lastSyncDate,
java.util.Vector songGroup)
Method updates the playcount/last_played information in the has_song table for a given user. |
void |
updatePlayCountWeek()
Automatically 'decays' the play_count_week field for all rows in the has_songs table. |
void |
updateTop40Caches()
Caches the Top40 artists, albums, songs (both week and all-time views) in extra table in the database (called top_songs, top_artists, etc). |
Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
public static DatabaseController getInstance()
public void logMessage(boolean error, java.lang.String function, java.lang.String message)
error
- Boolean error is true is message is an error, false if just
a friendly messagefunction
- String describing method/function issuing messagemessage
- String with message to be loggedpublic int getUserID(java.lang.String user, java.lang.String password)
user
- String usernamepassword
- String password
public java.sql.Timestamp getLastSync(int userID, java.lang.String version)
userID
- Unique ID identifying userversion
- String version of client used
public void setLastSync(int userID, java.lang.String version)
userID
- Unique ID identifying userversion
- String version of client softwarepublic void updateHasSong(int userID, java.util.Date lastSyncDate, java.util.Vector songGroup)
Three steps are involved in updated this information:
We have attempted to optimize this method so it runs as fast as possible, and prepared statements are used to keep things quick
userID
- Unique ID identifying userlastSyncDate
- Timestamp of user's last syncsongGroup
- Vector of songs to update has_song information forpublic void bulkLoadSongData(int userID, java.lang.String songsFile)
userID
- Unique ID identifying usersongsFile
- String with path to file to bulk loadpublic void bulkLoadHasSongData(int userID, java.lang.String hasSongsFile)
userID
- Unique ID identifying userhasSongsFile
- String with path to file to bulk loadpublic void updateTop40Caches()
public void updatePlayCountWeek()
public void updateForFirstSync(int userID, java.lang.String version)
public void loadDataIntoTable(java.lang.String file, java.lang.String table, boolean isLocal)
file
- table
- public void clearTable(java.lang.String table)
table
- public java.util.Vector getArtistsLike(java.lang.String artist)
artist
-
public java.util.Vector getSongsForArtist(java.lang.String artist, int userID, int numItems)
artist
- userID
- numItems
-
public java.util.Vector getArtistsOfUser(int userID, int myUserID, int limit)
userID
- myUserID
- limit
-
public java.util.Vector getUserIDFor(java.lang.String query)
query
-
public int countForArtist(java.lang.String query)
query
-
public static void main(java.lang.String[] args)
args
- No command line args are needed.
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |