public class BasicSQLStatementFactory extends Object implements SQLStatementFactory
Constructor and Description |
---|
BasicSQLStatementFactory() |
Modifier and Type | Method and Description |
---|---|
String |
getItemColumn()
Get the name of the item ID column in the rating table.
|
String |
getRatingColumn()
Get the name of the rating column in the rating table.
|
String |
getTableName()
Get the name of the rating table.
|
String |
getTimestampColumn()
Get the name of the timestamp column in the rating table (or
null if there is no
timestamp column). |
String |
getUserColumn()
Get the name of the user ID column in the rating table.
|
String |
prepareEvents(SortOrder order)
Prepare a statement to satisfy
EventDAO.streamEvents(Class, SortOrder) . |
String |
prepareItemEvents()
Prepare a statement to satisfy
ItemEventDAO.getEventsForItem(long) . |
String |
prepareItems()
Prepare a statement to satisfy
ItemDAO.getItemIds() . |
String |
prepareItemUsers()
Prepare a statement to satisfy
ItemEventDAO.getUsersForItem(long) . |
String |
prepareUserEvents()
Prepare a statement to satisfy
UserEventDAO.getEventsForUser(long) . |
String |
prepareUsers()
Prepare a statement to satisfy
UserDAO.getUserIds() . |
protected void |
rqAddOrder(StringBuilder query,
SortOrder order)
Add an ORDER BY clause to a query.
|
protected void |
rqAddSelectFrom(StringBuilder query)
Add the SELECT and FROM clauses to the query.
|
protected void |
rqFinish(StringBuilder query)
Finish a query (append a semicolon).
|
void |
setItemColumn(String col)
Set the name of the item ID column in the rating table.
|
void |
setRatingColumn(String col)
Set the name of the rating column in the rating table.
|
void |
setTableName(String name)
Set the name of the rating table.
|
void |
setTimestampColumn(String col)
Set the name of the timestamp column in the rating table.
|
void |
setUserColumn(String col)
Set the name of the user ID column in the rating table.
|
@Nonnull public String getTableName()
public void setTableName(@Nonnull String name)
name
- The name of the rating table. This table name is used without escaping to build
SQL queries, so include whatever escaping or quotations are needed to make the
name valid in the backing DBMS in the name here.@Nonnull public String getUserColumn()
public void setUserColumn(@Nonnull String col)
col
- The name of the user column. This column name is used without escaping to build
SQL queries, so include whatever escaping or quotations are needed to make the
name valid in the backing DBMS in the name here.@Nonnull public String getItemColumn()
public void setItemColumn(@Nonnull String col)
col
- The name of the item column. This column name is used without escaping to build
SQL queries, so include whatever escaping or quotations are needed to make the
name valid in the backing DBMS in the name here.@Nonnull public String getRatingColumn()
public void setRatingColumn(@Nonnull String col)
col
- The name of the rating column. This column name is used without escaping to build
SQL queries, so include whatever escaping or quotations are needed to make the
name valid in the backing DBMS in the name here.@Nullable public String getTimestampColumn()
null
if there is no
timestamp column).null
if no timestamp is used.public void setTimestampColumn(@Nullable String col)
null
if there is no
timestamp column.col
- The name of the timestamp column, or null
. This column name is used
without escaping to build SQL queries, so include whatever escaping or quotations
are needed to make the name valid in the backing DBMS in the name here.public String prepareUsers()
SQLStatementFactory
UserDAO.getUserIds()
.
Querying the statement should return one column per row containing the
numeric user ID.prepareUsers
in interface SQLStatementFactory
public String prepareItems()
SQLStatementFactory
ItemDAO.getItemIds()
.
Querying the statement should return one column per row containing the
numeric item ID.prepareItems
in interface SQLStatementFactory
protected void rqAddSelectFrom(StringBuilder query)
query
- The query accumulator.protected void rqAddOrder(StringBuilder query, SortOrder order)
query
- The query accumulatororder
- The sort order.protected void rqFinish(StringBuilder query)
query
- The query accumulatorpublic String prepareEvents(SortOrder order)
SQLStatementFactory
EventDAO.streamEvents(Class, SortOrder)
. Each row should contain
three or four columns: the user ID, the item ID, the rating,
and (optionally) the timestamp. The timestamp column is allowed to
contain NULL values or to be omitted entirely. User, item, and rating
columns must be non-null.prepareEvents
in interface SQLStatementFactory
order
- The sort orderpublic String prepareUserEvents()
SQLStatementFactory
UserEventDAO.getEventsForUser(long)
. The returned rows should be
as in SQLStatementFactory.prepareEvents(SortOrder)
, and the prepared
statement should take a single parameter for the user ID.prepareUserEvents
in interface SQLStatementFactory
public String prepareItemEvents()
SQLStatementFactory
ItemEventDAO.getEventsForItem(long)
.
The returned rows should be as in SQLStatementFactory.prepareEvents(SortOrder)
, and the prepared
statement should take a single parameter for the item ID.prepareItemEvents
in interface SQLStatementFactory
public String prepareItemUsers()
SQLStatementFactory
ItemEventDAO.getUsersForItem(long)
.
The returned rows should each contain a user ID as their only column, and the statement
should take a single parameter for the item ID.prepareItemUsers
in interface SQLStatementFactory