public final class ReloadFromJDBCDataModel extends Object implements DataModel
DataModel
which loads, and can re-load, data from a JDBC-backed JDBCDataModel
into memory, as a
GenericDataModel
or GenericBooleanPrefDataModel
. It is intended to provide the speed
advantage of in-memory representation but be able to update periodically to pull in new data from a database source.Constructor and Description |
---|
ReloadFromJDBCDataModel(JDBCDataModel delegate) |
Modifier and Type | Method and Description |
---|---|
JDBCDataModel |
getDelegate() |
DataModel |
getDelegateInMemory() |
LongPrimitiveIterator |
getItemIDs() |
FastIDSet |
getItemIDsFromUser(long id) |
float |
getMaxPreference() |
float |
getMinPreference() |
int |
getNumItems() |
int |
getNumUsers() |
int |
getNumUsersWithPreferenceFor(long itemID) |
int |
getNumUsersWithPreferenceFor(long itemID1,
long itemID2) |
PreferenceArray |
getPreferencesForItem(long itemID) |
PreferenceArray |
getPreferencesFromUser(long id) |
Long |
getPreferenceTime(long userID,
long itemID)
Retrieves the time at which a preference value from a user and item was set, if known.
|
Float |
getPreferenceValue(long userID,
long itemID)
Retrieves the preference value for a single user and item.
|
LongPrimitiveIterator |
getUserIDs() |
boolean |
hasPreferenceValues() |
void |
refresh(Collection<Refreshable> alreadyRefreshed)
Triggers "refresh" -- whatever that means -- of the implementation.
|
void |
removePreference(long userID,
long itemID)
Removes a particular preference for a user.
|
void |
setPreference(long userID,
long itemID,
float value)
Sets a particular preference (item plus rating) for a user.
|
public ReloadFromJDBCDataModel(JDBCDataModel delegate) throws TasteException
TasteException
public void refresh(Collection<Refreshable> alreadyRefreshed)
Refreshable
Triggers "refresh" -- whatever that means -- of the implementation. The general contract is that any
Refreshable
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
- Refreshable
s that are known to have already been
refreshed as a result of an initial call to a {#refresh(Collection)} method on some
object. This ensure that objects in a refresh dependency graph aren't refreshed twice
needlessly.public JDBCDataModel getDelegate()
public DataModel getDelegateInMemory()
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 forNoSuchUserException
- if the user does not existTasteException
- if an error occurs while accessing the datapublic FastIDSet getItemIDsFromUser(long id) throws TasteException
getItemIDsFromUser
in interface DataModel
id
- ID of user to get prefs forNoSuchUserException
- if the user does not existTasteException
- if an error occurs while accessing the datapublic 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 forNoSuchUserException
- if the user does not existTasteException
- if an error occurs while accessing the datapublic 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 questionNoSuchUserException
- if the user does not existTasteException
- 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 orderTasteException
- if an error occurs while accessing the datapublic PreferenceArray getPreferencesForItem(long itemID) throws TasteException
getPreferencesForItem
in interface DataModel
itemID
- item IDPreference
s expressed for that item, ordered by user ID, as an arrayNoSuchItemException
- if the item does not existTasteException
- if an error occurs while accessing the datapublic 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 itemID) throws TasteException
getNumUsersWithPreferenceFor
in interface DataModel
itemID
- item ID to check forTasteException
- if an error occurs while accessing the datapublic int getNumUsersWithPreferenceFor(long itemID1, long itemID2) throws TasteException
getNumUsersWithPreferenceFor
in interface DataModel
itemID1
- first item ID to check foritemID2
- second item ID to check forTasteException
- 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 valueNoSuchItemException
- if the item does not existNoSuchUserException
- if the user does not existTasteException
- 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 forNoSuchItemException
- if the item does not existNoSuchUserException
- if the user does not existTasteException
- if an error occurs while accessing the datapublic 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()
Copyright © 2008–2017 The Apache Software Foundation. All rights reserved.