public abstract class AbstractJDBCDataModel extends AbstractJDBCComponent implements JDBCDataModel
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 Connections are pooled.
| Modifier and Type | Field and Description |
|---|---|
static String |
DEFAULT_ITEM_ID_COLUMN |
static String |
DEFAULT_PREFERENCE_COLUMN |
static String |
DEFAULT_PREFERENCE_TABLE |
static String |
DEFAULT_PREFERENCE_TIME_COLUMN |
static String |
DEFAULT_USER_ID_COLUMN |
DEFAULT_DATASOURCE_NAME| Modifier | Constructor and Description |
|---|---|
protected |
AbstractJDBCDataModel(DataSource dataSource,
String getPreferenceSQL,
String getPreferenceTimeSQL,
String getUserSQL,
String getAllUsersSQL,
String getNumItemsSQL,
String getNumUsersSQL,
String setPreferenceSQL,
String removePreferenceSQL,
String getUsersSQL,
String getItemsSQL,
String getPrefsForItemSQL,
String getNumPreferenceForItemSQL,
String getNumPreferenceForItemsSQL,
String getMaxPreferenceSQL,
String getMinPreferenceSQL) |
protected |
AbstractJDBCDataModel(DataSource dataSource,
String preferenceTable,
String userIDColumn,
String itemIDColumn,
String preferenceColumn,
String getPreferenceSQL,
String getPreferenceTimeSQL,
String getUserSQL,
String getAllUsersSQL,
String getNumItemsSQL,
String getNumUsersSQL,
String setPreferenceSQL,
String removePreferenceSQL,
String getUsersSQL,
String getItemsSQL,
String getPrefsForItemSQL,
String getNumPreferenceForItemSQL,
String getNumPreferenceForItemsSQL,
String getMaxPreferenceSQL,
String getMinPreferenceSQL) |
checkNotNullAndLog, checkNotNullAndLog, getFetchSize, lookupDataSourcepublic static final String DEFAULT_PREFERENCE_TABLE
public static final String DEFAULT_USER_ID_COLUMN
public static final String DEFAULT_ITEM_ID_COLUMN
public static final String DEFAULT_PREFERENCE_COLUMN
public static final String DEFAULT_PREFERENCE_TIME_COLUMN
protected AbstractJDBCDataModel(DataSource dataSource, String getPreferenceSQL, String getPreferenceTimeSQL, String getUserSQL, String getAllUsersSQL, String getNumItemsSQL, String getNumUsersSQL, String setPreferenceSQL, String removePreferenceSQL, String getUsersSQL, String getItemsSQL, String getPrefsForItemSQL, String getNumPreferenceForItemSQL, String getNumPreferenceForItemsSQL, String getMaxPreferenceSQL, String getMinPreferenceSQL)
protected AbstractJDBCDataModel(DataSource dataSource, String preferenceTable, String userIDColumn, String itemIDColumn, String preferenceColumn, String getPreferenceSQL, String getPreferenceTimeSQL, String getUserSQL, String getAllUsersSQL, String getNumItemsSQL, String getNumUsersSQL, String setPreferenceSQL, String removePreferenceSQL, String getUsersSQL, String getItemsSQL, String getPrefsForItemSQL, String getNumPreferenceForItemSQL, String getNumPreferenceForItemsSQL, String getMaxPreferenceSQL, String getMinPreferenceSQL)
public DataSource getDataSource()
getDataSource in interface JDBCDataModelDataSource that this instance is usingpublic String getPreferenceTable()
public String getUserIDColumn()
public String getItemIDColumn()
public String getPreferenceColumn()
public LongPrimitiveIterator getUserIDs() throws TasteException
getUserIDs in interface DataModelTasteExceptionpublic PreferenceArray getPreferencesFromUser(long userID) throws TasteException
getPreferencesFromUser in interface DataModelNoSuchUserException - if there is no such userTasteExceptionpublic FastByIDMap<PreferenceArray> exportWithPrefs() throws TasteException
exportWithPrefs in interface JDBCDataModelTasteExceptionpublic FastByIDMap<FastIDSet> exportWithIDsOnly() throws TasteException
exportWithIDsOnly in interface JDBCDataModelTasteExceptionpublic FastIDSet getItemIDsFromUser(long userID) throws TasteException
getItemIDsFromUser in interface DataModelNoSuchUserException - if there is no such userTasteExceptionpublic Float getPreferenceValue(long userID, long itemID) throws TasteException
getPreferenceValue in interface DataModelTasteExceptionpublic Long getPreferenceTime(long userID, long itemID) throws TasteException
getPreferenceTime in interface DataModelTasteExceptionpublic LongPrimitiveIterator getItemIDs() throws TasteException
getItemIDs in interface DataModelTasteExceptionpublic PreferenceArray getPreferencesForItem(long itemID) throws TasteException
getPreferencesForItem in interface DataModelTasteExceptionprotected List<Preference> doGetPreferencesForItem(long itemID) throws TasteException
TasteExceptionpublic int getNumItems()
throws TasteException
getNumItems in interface DataModelTasteExceptionpublic int getNumUsers()
throws TasteException
getNumUsers in interface DataModelTasteExceptionpublic int getNumUsersWithPreferenceFor(long itemID)
throws TasteException
getNumUsersWithPreferenceFor in interface DataModelTasteExceptionpublic int getNumUsersWithPreferenceFor(long itemID1,
long itemID2)
throws TasteException
getNumUsersWithPreferenceFor in interface DataModelTasteExceptionpublic void setPreference(long userID,
long itemID,
float value)
throws TasteException
setPreference in interface DataModelTasteExceptionpublic void removePreference(long userID,
long itemID)
throws TasteException
removePreference in interface DataModelTasteExceptionpublic void refresh(Collection<Refreshable> alreadyRefreshed)
refresh in interface Refreshablepublic boolean hasPreferenceValues()
hasPreferenceValues in interface DataModelpublic float getMaxPreference()
getMaxPreference in interface DataModelpublic float getMinPreference()
getMinPreference in interface DataModelprotected Preference buildPreference(ResultSet rs) throws SQLException
SQLExceptionprotected long getLongColumn(ResultSet rs, int position) throws SQLException
IDMigrator to perform
translation.SQLExceptionprotected void setLongParameter(PreparedStatement stmt, int position, long value) throws SQLException
IDMigrator to perform
translation.SQLExceptionCopyright © 2008–2013 The Apache Software Foundation. All rights reserved.