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 Connection
s 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, lookupDataSource
public 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 JDBCDataModel
DataSource
that this instance is usingpublic String getPreferenceTable()
public String getUserIDColumn()
public String getItemIDColumn()
public String getPreferenceColumn()
public LongPrimitiveIterator getUserIDs() throws TasteException
getUserIDs
in interface DataModel
TasteException
public PreferenceArray getPreferencesFromUser(long userID) throws TasteException
getPreferencesFromUser
in interface DataModel
NoSuchUserException
- if there is no such userTasteException
public FastByIDMap<PreferenceArray> exportWithPrefs() throws TasteException
exportWithPrefs
in interface JDBCDataModel
TasteException
public FastByIDMap<FastIDSet> exportWithIDsOnly() throws TasteException
exportWithIDsOnly
in interface JDBCDataModel
TasteException
public FastIDSet getItemIDsFromUser(long userID) throws TasteException
getItemIDsFromUser
in interface DataModel
NoSuchUserException
- if there is no such userTasteException
public Float getPreferenceValue(long userID, long itemID) throws TasteException
getPreferenceValue
in interface DataModel
TasteException
public Long getPreferenceTime(long userID, long itemID) throws TasteException
getPreferenceTime
in interface DataModel
TasteException
public LongPrimitiveIterator getItemIDs() throws TasteException
getItemIDs
in interface DataModel
TasteException
public PreferenceArray getPreferencesForItem(long itemID) throws TasteException
getPreferencesForItem
in interface DataModel
TasteException
protected List<Preference> doGetPreferencesForItem(long itemID) throws TasteException
TasteException
public int getNumItems() throws TasteException
getNumItems
in interface DataModel
TasteException
public int getNumUsers() throws TasteException
getNumUsers
in interface DataModel
TasteException
public int getNumUsersWithPreferenceFor(long itemID) throws TasteException
getNumUsersWithPreferenceFor
in interface DataModel
TasteException
public int getNumUsersWithPreferenceFor(long itemID1, long itemID2) throws TasteException
getNumUsersWithPreferenceFor
in interface DataModel
TasteException
public void setPreference(long userID, long itemID, float value) throws TasteException
setPreference
in interface DataModel
TasteException
public void removePreference(long userID, long itemID) throws TasteException
removePreference
in interface DataModel
TasteException
public void refresh(Collection<Refreshable> alreadyRefreshed)
refresh
in interface Refreshable
public boolean hasPreferenceValues()
hasPreferenceValues
in interface DataModel
public float getMaxPreference()
getMaxPreference
in interface DataModel
public float getMinPreference()
getMinPreference
in interface DataModel
protected Preference buildPreference(ResultSet rs) throws SQLException
SQLException
protected long getLongColumn(ResultSet rs, int position) throws SQLException
IDMigrator
to perform
translation.SQLException
protected void setLongParameter(PreparedStatement stmt, int position, long value) throws SQLException
IDMigrator
to perform
translation.SQLException
Copyright © 2008–2017 The Apache Software Foundation. All rights reserved.