|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.mahout.cf.taste.impl.common.jdbc.AbstractJDBCComponent
org.apache.mahout.cf.taste.impl.model.jdbc.AbstractJDBCDataModel
public abstract class AbstractJDBCDataModel
An abstract superclass for JDBCDataModel
implementations, providing most of the common
functionality that any such implementation would need.
Performance will be a concern with any JDBCDataModel
. There are going to be lots of
simultaneous reads and some writes to one table. Make sure the table is set up optimally -- for example,
you'll want to establish indexes.
You'll also want to use connection pooling of some kind. Most J2EE containers like Tomcat provide
connection pooling, so make sure the DataSource
it exposes is using pooling. Outside a J2EE
container, you can use packages like Jakarta's DBCP
to create a DataSource
on top of your database whose Connection
s are pooled.
Field Summary | |
---|---|
static java.lang.String |
DEFAULT_ITEM_ID_COLUMN
|
static java.lang.String |
DEFAULT_PREFERENCE_COLUMN
|
static java.lang.String |
DEFAULT_PREFERENCE_TABLE
|
static java.lang.String |
DEFAULT_PREFERENCE_TIME_COLUMN
|
static java.lang.String |
DEFAULT_USER_ID_COLUMN
|
Fields inherited from class org.apache.mahout.cf.taste.impl.common.jdbc.AbstractJDBCComponent |
---|
DEFAULT_DATASOURCE_NAME |
Constructor Summary | |
---|---|
protected |
AbstractJDBCDataModel(javax.sql.DataSource dataSource,
java.lang.String getPreferenceSQL,
java.lang.String getPreferenceTimeSQL,
java.lang.String getUserSQL,
java.lang.String getAllUsersSQL,
java.lang.String getNumItemsSQL,
java.lang.String getNumUsersSQL,
java.lang.String setPreferenceSQL,
java.lang.String removePreferenceSQL,
java.lang.String getUsersSQL,
java.lang.String getItemsSQL,
java.lang.String getPrefsForItemSQL,
java.lang.String getNumPreferenceForItemSQL,
java.lang.String getNumPreferenceForItemsSQL,
java.lang.String getMaxPreferenceSQL,
java.lang.String getMinPreferenceSQL)
|
protected |
AbstractJDBCDataModel(javax.sql.DataSource dataSource,
java.lang.String preferenceTable,
java.lang.String userIDColumn,
java.lang.String itemIDColumn,
java.lang.String preferenceColumn,
java.lang.String getPreferenceSQL,
java.lang.String getPreferenceTimeSQL,
java.lang.String getUserSQL,
java.lang.String getAllUsersSQL,
java.lang.String getNumItemsSQL,
java.lang.String getNumUsersSQL,
java.lang.String setPreferenceSQL,
java.lang.String removePreferenceSQL,
java.lang.String getUsersSQL,
java.lang.String getItemsSQL,
java.lang.String getPrefsForItemSQL,
java.lang.String getNumPreferenceForItemSQL,
java.lang.String getNumPreferenceForItemsSQL,
java.lang.String getMaxPreferenceSQL,
java.lang.String getMinPreferenceSQL)
|
Method Summary | |
---|---|
protected Preference |
buildPreference(java.sql.ResultSet rs)
|
protected java.util.List<Preference> |
doGetPreferencesForItem(long itemID)
|
FastByIDMap<FastIDSet> |
exportWithIDsOnly()
|
FastByIDMap<PreferenceArray> |
exportWithPrefs()
Hmm, should this exist elsewhere? seems like most relevant for a DB implementation, which is not in memory, which might want to export to memory. |
javax.sql.DataSource |
getDataSource()
|
java.lang.String |
getItemIDColumn()
|
LongPrimitiveIterator |
getItemIDs()
|
FastIDSet |
getItemIDsFromUser(long id)
|
protected long |
getLongColumn(java.sql.ResultSet rs,
int position)
Subclasses may wish to override this if ID values in the file are not numeric. |
float |
getMaxPreference()
|
float |
getMinPreference()
|
int |
getNumItems()
|
int |
getNumUsers()
|
int |
getNumUsersWithPreferenceFor(long... itemIDs)
|
java.lang.String |
getPreferenceColumn()
|
PreferenceArray |
getPreferencesForItem(long itemID)
|
PreferenceArray |
getPreferencesFromUser(long id)
|
java.lang.String |
getPreferenceTable()
|
java.lang.Long |
getPreferenceTime(long userID,
long itemID)
Retrieves the time at which a preference value from a user and item was set, if known. |
java.lang.Float |
getPreferenceValue(long userID,
long itemID)
Retrieves the preference value for a single user and item. |
java.lang.String |
getUserIDColumn()
|
LongPrimitiveIterator |
getUserIDs()
|
boolean |
hasPreferenceValues()
|
void |
refresh(java.util.Collection<Refreshable> alreadyRefreshed)
Triggers "refresh" -- whatever that means -- of the implementation. |
void |
removePreference(long userID,
long itemID)
Removes a particular preference for a user. |
protected void |
setLongParameter(java.sql.PreparedStatement stmt,
int position,
long value)
Subclasses may wish to override this if ID values in the file are not numeric. |
void |
setPreference(long userID,
long itemID,
float value)
Sets a particular preference (item plus rating) for a user. |
Methods inherited from class org.apache.mahout.cf.taste.impl.common.jdbc.AbstractJDBCComponent |
---|
advanceResultSet, checkNotNullAndLog, checkNotNullAndLog, getFetchSize, lookupDataSource |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final java.lang.String DEFAULT_PREFERENCE_TABLE
public static final java.lang.String DEFAULT_USER_ID_COLUMN
public static final java.lang.String DEFAULT_ITEM_ID_COLUMN
public static final java.lang.String DEFAULT_PREFERENCE_COLUMN
public static final java.lang.String DEFAULT_PREFERENCE_TIME_COLUMN
Constructor Detail |
---|
protected AbstractJDBCDataModel(javax.sql.DataSource dataSource, java.lang.String getPreferenceSQL, java.lang.String getPreferenceTimeSQL, java.lang.String getUserSQL, java.lang.String getAllUsersSQL, java.lang.String getNumItemsSQL, java.lang.String getNumUsersSQL, java.lang.String setPreferenceSQL, java.lang.String removePreferenceSQL, java.lang.String getUsersSQL, java.lang.String getItemsSQL, java.lang.String getPrefsForItemSQL, java.lang.String getNumPreferenceForItemSQL, java.lang.String getNumPreferenceForItemsSQL, java.lang.String getMaxPreferenceSQL, java.lang.String getMinPreferenceSQL)
protected AbstractJDBCDataModel(javax.sql.DataSource dataSource, java.lang.String preferenceTable, java.lang.String userIDColumn, java.lang.String itemIDColumn, java.lang.String preferenceColumn, java.lang.String getPreferenceSQL, java.lang.String getPreferenceTimeSQL, java.lang.String getUserSQL, java.lang.String getAllUsersSQL, java.lang.String getNumItemsSQL, java.lang.String getNumUsersSQL, java.lang.String setPreferenceSQL, java.lang.String removePreferenceSQL, java.lang.String getUsersSQL, java.lang.String getItemsSQL, java.lang.String getPrefsForItemSQL, java.lang.String getNumPreferenceForItemSQL, java.lang.String getNumPreferenceForItemsSQL, java.lang.String getMaxPreferenceSQL, java.lang.String getMinPreferenceSQL)
Method Detail |
---|
public javax.sql.DataSource getDataSource()
getDataSource
in interface JDBCDataModel
DataSource
that this instance is usingpublic java.lang.String getPreferenceTable()
public java.lang.String getUserIDColumn()
public java.lang.String getItemIDColumn()
public java.lang.String getPreferenceColumn()
public LongPrimitiveIterator getUserIDs() throws TasteException
getUserIDs
in interface DataModel
TasteException
- if an error occurs while accessing the datapublic PreferenceArray getPreferencesFromUser(long id) throws TasteException
getPreferencesFromUser
in interface DataModel
id
- ID of user to get prefs for
NoSuchUserException
- if there is no such user
TasteException
- if an error occurs while accessing the datapublic FastByIDMap<PreferenceArray> exportWithPrefs() throws TasteException
JDBCDataModel
exportWithPrefs
in interface JDBCDataModel
TasteException
public FastByIDMap<FastIDSet> exportWithIDsOnly() throws TasteException
exportWithIDsOnly
in interface JDBCDataModel
TasteException
public FastIDSet getItemIDsFromUser(long id) throws TasteException
getItemIDsFromUser
in interface DataModel
id
- ID of user to get prefs for
NoSuchUserException
- if there is no such user
TasteException
- if an error occurs while accessing the datapublic java.lang.Float getPreferenceValue(long userID, long itemID) throws TasteException
DataModel
getPreferenceValue
in interface DataModel
userID
- user ID to get pref value fromitemID
- item ID to get pref value for
NoSuchUserException
- if the user does not exist
TasteException
- if an error occurs while accessing the datapublic java.lang.Long getPreferenceTime(long userID, long itemID) throws TasteException
DataModel
getPreferenceTime
in interface DataModel
userID
- user ID for preference in questionitemID
- item ID for preference in question
NoSuchUserException
- if the user does not exist
TasteException
- if an error occurs while accessing the datapublic LongPrimitiveIterator getItemIDs() throws TasteException
getItemIDs
in interface DataModel
LongPrimitiveIterator
of all item IDs in the model, in order
TasteException
- if an error occurs while accessing the datapublic PreferenceArray getPreferencesForItem(long itemID) throws TasteException
getPreferencesForItem
in interface DataModel
itemID
- item ID
Preference
s expressed for that item, ordered by user ID, as an array
NoSuchItemException
- if the item does not exist
TasteException
- if an error occurs while accessing the dataprotected java.util.List<Preference> doGetPreferencesForItem(long itemID) throws TasteException
TasteException
public int getNumItems() throws TasteException
getNumItems
in interface DataModel
TasteException
- if an error occurs while accessing the datapublic int getNumUsers() throws TasteException
getNumUsers
in interface DataModel
TasteException
- if an error occurs while accessing the datapublic int getNumUsersWithPreferenceFor(long... itemIDs) throws TasteException
getNumUsersWithPreferenceFor
in interface DataModel
itemIDs
- item IDs to check for
TasteException
- if an error occurs while accessing the datapublic void setPreference(long userID, long itemID, float value) throws TasteException
DataModel
Sets a particular preference (item plus rating) for a user.
setPreference
in interface DataModel
userID
- user to set preference foritemID
- item to set preference forvalue
- preference value
NoSuchItemException
- if the item does not exist
NoSuchUserException
- if the user does not exist
TasteException
- if an error occurs while accessing the datapublic void removePreference(long userID, long itemID) throws TasteException
DataModel
Removes a particular preference for a user.
removePreference
in interface DataModel
userID
- user from which to remove preferenceitemID
- item to remove preference for
NoSuchItemException
- if the item does not exist
NoSuchUserException
- if the user does not exist
TasteException
- if an error occurs while accessing the datapublic void refresh(java.util.Collection<Refreshable> alreadyRefreshed)
Refreshable
Triggers "refresh" -- whatever that means -- of the implementation. The general contract is that any should always leave itself in a consistent, operational state, and that the refresh atomically updates internal state from old to new.
refresh
in interface Refreshable
alreadyRefreshed
- s that are known to have already been
refreshed as a result of an initial call to a method on some
object. This ensure that objects in a refresh dependency graph aren't refreshed twice
needlessly.public boolean hasPreferenceValues()
hasPreferenceValues
in interface DataModel
public float getMaxPreference()
getMaxPreference
in interface DataModel
Recommender
may estimate a preference value above 5.0, it
isn't "fair" to consider that the system is actually suggesting an impossible rating of, say, 5.4 stars.
In practice the application would cap this estimate to 5.0. Since evaluators evaluate
the difference between estimated and actual value, this at least prevents this effect from unfairly
penalizing a Recommender
public float getMinPreference()
getMinPreference
in interface DataModel
DataModel.getMaxPreference()
protected Preference buildPreference(java.sql.ResultSet rs) throws java.sql.SQLException
java.sql.SQLException
protected long getLongColumn(java.sql.ResultSet rs, int position) throws java.sql.SQLException
IDMigrator
to perform
translation.
java.sql.SQLException
protected void setLongParameter(java.sql.PreparedStatement stmt, int position, long value) throws java.sql.SQLException
IDMigrator
to perform
translation.
java.sql.SQLException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |