public class JDBCRatingDAO extends Object implements EventDAO, UserEventDAO, ItemEventDAO, UserDAO, ItemDAO
Rating DAO backed by a JDBC connection. This DAO can only store rating data; no other events are supported.
Modifier and Type | Field and Description |
---|---|
protected boolean |
closeConnection |
static int |
COL_ITEM_ID
Item ID column number.
|
static int |
COL_RATING
Rating column number.
|
static int |
COL_TIMESTAMP
Timestamp column number.
|
static int |
COL_USER_ID
User ID column number.
|
protected Connection |
connection |
protected org.slf4j.Logger |
logger |
Constructor and Description |
---|
JDBCRatingDAO(Connection dbc,
SQLStatementFactory sfac)
Deprecated.
Use
newBuilder() . |
JDBCRatingDAO(Connection dbc,
SQLStatementFactory sfac,
boolean close)
Deprecated.
Use
newBuilder() . |
Modifier and Type | Method and Description |
---|---|
void |
close()
Close the connection and all open statements.
|
List<Event> |
getEventsForItem(long itemId)
Get the events for a specific item.
|
<E extends Event> |
getEventsForItem(long iid,
Class<E> type)
Get the events for a specific item, filtering by type.
|
UserHistory<Event> |
getEventsForUser(long userId)
Get the events for a specific user.
|
<E extends Event> |
getEventsForUser(long uid,
Class<E> type)
Get the events for a specific user, filtering by type.
|
protected LongSet |
getIdSet(PreparedStatement s) |
LongSet |
getItemIds()
Get all known item IDs.
|
LongSet |
getUserIds()
Get all known user IDs.
|
LongSet |
getUsersForItem(long item)
Get the users who have interacted with an item.
|
static JDBCRatingDAOBuilder |
newBuilder()
Create a new JDBC DAO builder.
|
ObjectStream<Event> |
streamEvents()
Stream all events.
|
<E extends Event> |
streamEvents(Class<E> type)
Stream all events of a given type.
|
<E extends Event> |
streamEvents(Class<E> type,
SortOrder order)
Stream all events of a given type in a specified order.
|
ObjectStream<ItemEventCollection<Event>> |
streamEventsByItem()
Stream events grouped by item.
|
<E extends Event> |
streamEventsByItem(Class<E> type)
Stream events grouped by item.
|
ObjectStream<UserHistory<Event>> |
streamEventsByUser()
Stream events grouped by user.
|
<E extends Event> |
streamEventsByUser(Class<E> type)
Stream events grouped by user.
|
public static final int COL_USER_ID
User ID column number.
public static final int COL_ITEM_ID
Item ID column number.
public static final int COL_RATING
Rating column number.
public static final int COL_TIMESTAMP
Timestamp column number.
protected final org.slf4j.Logger logger
protected final Connection connection
protected final boolean closeConnection
@Deprecated public JDBCRatingDAO(@WillCloseWhenClosed Connection dbc, SQLStatementFactory sfac)
newBuilder()
.Create a new JDBC rating DAO. The resulting DAO will be uncached.
dbc
- The database connection. The connection will be closed when the DAO is closed.sfac
- The statement factory.@Deprecated public JDBCRatingDAO(Connection dbc, SQLStatementFactory sfac, boolean close)
newBuilder()
.Create a new JDBC rating DAO. The resulting DAO will be uncached.
dbc
- The database connection.sfac
- The statement factory.close
- Whether to close the database connection when the DAO is closed.public static JDBCRatingDAOBuilder newBuilder()
Create a new JDBC DAO builder.
public void close()
Close the connection and all open statements.
protected LongSet getIdSet(PreparedStatement s) throws SQLException
SQLException
public LongSet getUserIds()
UserDAO
Get all known user IDs.
getUserIds
in interface UserDAO
public LongSet getItemIds()
ItemDAO
Get all known item IDs.
getItemIds
in interface ItemDAO
public ObjectStream<Event> streamEvents()
EventDAO
Stream all events.
streamEvents
in interface EventDAO
public <E extends Event> ObjectStream<E> streamEvents(Class<E> type)
EventDAO
Stream all events of a given type.
streamEvents
in interface EventDAO
type
- The event type.public <E extends Event> ObjectStream<E> streamEvents(Class<E> type, SortOrder order)
EventDAO
Stream all events of a given type in a specified order.
streamEvents
in interface EventDAO
type
- The event type.order
- The order.public UserHistory<Event> getEventsForUser(long userId)
UserEventDAO
Get the events for a specific user.
getEventsForUser
in interface UserEventDAO
userId
- The user ID.null
if the user is unknown.public <E extends Event> UserHistory<E> getEventsForUser(long uid, Class<E> type)
UserEventDAO
Get the events for a specific user, filtering by type.
getEventsForUser
in interface UserEventDAO
uid
- The user ID.type
- The type of events to retrieve.null
if the user is unknown.public List<Event> getEventsForItem(long itemId)
ItemEventDAO
Get the events for a specific item.
getEventsForItem
in interface ItemEventDAO
itemId
- The item ID.null
if the item is unknown.public <E extends Event> List<E> getEventsForItem(long iid, Class<E> type)
ItemEventDAO
Get the events for a specific item, filtering by type.
getEventsForItem
in interface ItemEventDAO
iid
- The item ID.type
- The type of events to retrieve.null
if the item is unknown.public LongSet getUsersForItem(long item)
ItemEventDAO
Get the users who have interacted with an item.
getUsersForItem
in interface ItemEventDAO
item
- The item ID.null
if the item is unknown.public ObjectStream<UserHistory<Event>> streamEventsByUser()
UserEventDAO
Stream events grouped by user.
streamEventsByUser
in interface UserEventDAO
public <E extends Event> ObjectStream<UserHistory<E>> streamEventsByUser(Class<E> type)
UserEventDAO
Stream events grouped by user.
streamEventsByUser
in interface UserEventDAO
type
- The type of item to look for.type
. If a user exists, but does not have any history, they may or may not be included depending on the DAO implementation.public ObjectStream<ItemEventCollection<Event>> streamEventsByItem()
ItemEventDAO
Stream events grouped by item.
streamEventsByItem
in interface ItemEventDAO
public <E extends Event> ObjectStream<ItemEventCollection<E>> streamEventsByItem(Class<E> type)
ItemEventDAO
Stream events grouped by item.
streamEventsByItem
in interface ItemEventDAO
type
- The type of item to look for.type
from all items. If an item exists but does not have any events, it may or may not be included depending on the DAO implementation.