|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.araneaframework.backend.list.helper.BaseListSqlHelper
This class provides an SQL based implementation of the list. It takes care of the filtering, ordering and returning data to the web components. Implementations should override abstract methods noted in those methods.
Note, that all operations on items are made on the list of "processed", that is ordered and filtered items.
| Nested Class Summary | |
class |
BaseListSqlHelper.BeanResultReader
Resultset reader that uses beanToResultSetMapping in
ListSqlHelper to construct a given type of Bean list. |
class |
BaseListSqlHelper.CountSqlCallback
The total count query callback. |
class |
BaseListSqlHelper.ItemRangeSqlCallback
The itme range query callback that returns List of items. |
static class |
BaseListSqlHelper.ListItemsDataCallback
The item range and total count querites callback that returns ListItemsData object. |
| Field Summary | |
protected static Long |
DEFAULT_RANGE_START
|
protected DataSource |
ds
|
protected Fields |
fields
|
protected Expression |
filterExpr
|
protected SqlExpression |
filterSqlExpr
|
protected Long |
itemRangeCount
|
protected Long |
itemRangeStart
|
protected NamingStrategy |
namingStrategy
|
protected ComparatorExpression |
orderExpr
|
protected SqlExpression |
orderSqlExpr
|
protected ResultSetColumnReader |
resultSetColumnReader
|
protected ValueConverter |
valueConverter
|
protected VariableResolver |
variableResolver
|
| Constructor Summary | |
BaseListSqlHelper()
Creates ListSqlHelper without initializing any fields. |
|
BaseListSqlHelper(DataSource dataSource)
Creates ListSqlHelper and provides it with the
DataSource. |
|
BaseListSqlHelper(DataSource dataSource,
ListQuery query)
Creates ListSqlHelper initializing the appropriate fields
and providing it with the DataSource. |
|
BaseListSqlHelper(ListQuery query)
Creates ListSqlHelper initializing the appropriate fields. |
|
| Method Summary | |
abstract void |
addNullParam(int valueType)
Adds a NULL PreparedStatement parameter for
later setting. |
abstract void |
addStatementParam(Object param)
Adds a PreparedStatement parameter for later setting. |
abstract void |
addStatementParams(List params)
Adds PreparedStatement parameters for later setting. |
ResultReader |
createBeanResultReader(Class itemClass)
Returns Bean ResultSet reader. |
protected VariableResolver |
createExpressionBuilderResolver()
Creates the VariableResolver for SqlExpressionBuilder that converts Variable names to their Database Field names according to the naming strategy. |
protected StandardExpressionToSqlExprBuilder |
createFilterSqlExpressionBuilder()
Creates new filtering SQL Expression builder. |
protected StandardCompExprToSqlExprBuilder |
createOrderSqlExpressionBuilder()
Creates new ordering SQL Expression builder. |
protected static RuntimeException |
createQueryFailedException(String QueryString,
List queryParams,
SQLException nestedException)
Returns query failed Exception that contains query String and params. |
ListItemsData |
execute(Class itemClass)
Executes SQL queries that should retrieve 1) the total count of items in the list and 2) a range of items from the list ListSqlHelper's BeanResultReader is used
to convert the ResultSet into a List. |
Object |
execute(ConnectionCallback action)
Execute a JDBC data access operation, implemented as callback action working on a JDBC Connection. |
ListItemsData |
execute(ResultReader reader)
Executes SQL queries that should retrieve 1) the total count of items in the list and 2) a range of items from the list Provided ResultReader is used to convert the
ResultSet into a List. |
Long |
executeCountSql()
Executes a SQL query that should retrieve the total count of items in the list. |
List |
executeItemRangeSql(Class itemClass)
Executes a SQL query that should retrieve a range of items from the list. |
List |
executeItemRangeSql(ResultReader reader)
Executes a SQL query that should retrieve a range of items from the list. |
ConnectionCallback |
getCountSqlCallback()
Returns the total count query callback. |
protected abstract SqlStatement |
getCountSqlStatement()
Returns the total count SQL query String and parameters. |
String |
getDatabaseFields()
Returns the database fields list seperated by commas, which can be used in "SELECT" clause. |
String |
getDatabaseFilter()
Returns the filter database condition, which can be used in "WHERE" clause. |
List |
getDatabaseFilterParams()
Returns the List of parameters that should be set in the
PreparedStatement that
belong to the filter database conditions. |
String |
getDatabaseFilterWith(String prefix,
String suffix)
Returns the database filter query with prefix added before and
suffix after it if the query is not empty. |
String |
getDatabaseOrder()
Returns the order database representation, which can be used in "ORDER BY" clause. |
List |
getDatabaseOrderParams()
Returns the List of parameters that should be set in the
PreparedStatement that belong to the order database representation. |
String |
getDatabaseOrderWith(String prefix,
String suffix)
Returns the database order query with prefix added before and
suffix after it if the query is not empty. |
Fields |
getFields()
|
protected SqlExpression |
getFieldsSqlExpression()
Returns the fields SqlExpression, which can be used in
"SELECT" clause. |
protected SqlExpression |
getFilterSqlExpression()
Returns the filter SqlExpression, which can be used in
"WHERE" clause. |
ConnectionCallback |
getItemRangeSqlCallback(ResultReader reader)
Returns the item range query callback. |
ConnectionCallback |
getListItemsDataCallback(ResultReader reader)
Returns the total count and item ragne queries callback. |
NamingStrategy |
getNamingStrategy()
|
protected SqlExpression |
getOrderSqlExpression()
Returns the order SqlExpression, which can be used in
"ORDER BY" clause. |
protected abstract SqlStatement |
getRangeSqlStatement()
Returns the itme range SQL query String and parameters. |
ResultSetColumnReader |
getResultSetColumnReader()
|
ValueConverter |
getValueConverter()
|
protected void |
init()
|
abstract void |
setCountSqlQuery(String countSqlQuery)
Sets the SQL query used to count the items in the database. |
void |
setDataSource(DataSource ds)
Stores the DataSource. |
void |
setFields(Fields fields)
|
void |
setFilterExpression(Expression filterExpr)
Sets the filter expression saving it for later automatic SQL query creation. |
void |
setItemRangeCount(Long itemRangeCount)
Sets the count of items in the range. |
void |
setItemRangeStart(Long itemRangeStart)
Sets the (0-based) starting index of the item range. |
void |
setListQuery(ListQuery query)
Sets the starting index and count of items in the range and filtering and ordering expressions. |
void |
setNamingStrategy(NamingStrategy namingStrategy)
|
void |
setOrderExpression(ComparatorExpression orderExpr)
Sets the order expression saving it for later automatic SQL query creation. |
void |
setResultSetColumnReader(ResultSetColumnReader resultSetColumnReader)
|
void |
setSimpleSqlQuery(String fromSql)
Sets the SQL query (with arguments) that will be used to retrieve the item range from the list and count the items. |
void |
setSimpleSqlQuery(String fromSql,
String customWhereSql,
Object[] customWhereArgs)
Sets the SQL query (with arguments) that will be used to retrieve the item range from the list and count the items. |
void |
setSimpleSqlQuery(String fromSql,
String customWhereSql,
Object[] customWhereArgs,
String customOrderbySql,
Object[] customOrderbyArgs)
Sets the SQL query (with arguments) that will be used to retrieve the item range from the list and count the items. |
abstract void |
setSqlQuery(String sqlQuery)
Sets the SQL query that will be used to retrieve the item range from the list and count the items. |
void |
setValueConverter(ValueConverter valueConverter)
|
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
protected static final Long DEFAULT_RANGE_START
protected Fields fields
protected NamingStrategy namingStrategy
protected ValueConverter valueConverter
protected ResultSetColumnReader resultSetColumnReader
protected Expression filterExpr
protected ComparatorExpression orderExpr
protected VariableResolver variableResolver
protected SqlExpression filterSqlExpr
protected SqlExpression orderSqlExpr
protected Long itemRangeStart
protected Long itemRangeCount
protected DataSource ds
| Constructor Detail |
public BaseListSqlHelper()
ListSqlHelper without initializing any fields.
public BaseListSqlHelper(DataSource dataSource)
ListSqlHelper and provides it with the
DataSource.
public BaseListSqlHelper(ListQuery query)
ListSqlHelper initializing the appropriate fields.
public BaseListSqlHelper(DataSource dataSource,
ListQuery query)
ListSqlHelper initializing the appropriate fields
and providing it with the DataSource.
| Method Detail |
protected void init()
public void setListQuery(ListQuery query)
public void setOrderExpression(ComparatorExpression orderExpr)
getDatabaseOrder(),
getDatabaseOrderWith(String, String),
getDatabaseOrderParams()public void setFilterExpression(Expression filterExpr)
getDatabaseFilter(),
getDatabaseFilterWith(String, String),
getDatabaseFilterParams()public void setItemRangeStart(Long itemRangeStart)
public void setItemRangeCount(Long itemRangeCount)
public Fields getFields()
public void setFields(Fields fields)
public NamingStrategy getNamingStrategy()
public void setNamingStrategy(NamingStrategy namingStrategy)
public void setValueConverter(ValueConverter valueConverter)
public ValueConverter getValueConverter()
public void setResultSetColumnReader(ResultSetColumnReader resultSetColumnReader)
public ResultSetColumnReader getResultSetColumnReader()
protected SqlExpression getFieldsSqlExpression()
SqlExpression, which can be used in
"SELECT" clause.
SqlExpression, which can be used in
"SELECT" clause.protected SqlExpression getOrderSqlExpression()
SqlExpression, which can be used in
"ORDER BY" clause.
SqlExpression, which can be used in
"ORDER BY" clause.protected SqlExpression getFilterSqlExpression()
SqlExpression, which can be used in
"WHERE" clause.
SqlExpression, which can be used in
"WHERE" clause.protected StandardCompExprToSqlExprBuilder createOrderSqlExpressionBuilder()
protected StandardExpressionToSqlExprBuilder createFilterSqlExpressionBuilder()
public String getDatabaseFields()
public String getDatabaseFilter()
getDatabaseFilterWith(String, String),
getDatabaseFilterParams()
public String getDatabaseFilterWith(String prefix,
String suffix)
prefix added before and
suffix after it if the query is not empty.
prefix - Prefix added before the expression.suffix - Suffix added after the expression.
prefix added before and
suffix after it if the query is not empty.getDatabaseFilter(),
getDatabaseFilterParams()public List getDatabaseFilterParams()
List of parameters that should be set in the
PreparedStatement that
belong to the filter database conditions.
List of parameters that should be set in the
PreparedStatement that
belong to the filter database conditions.getDatabaseFilter(),
getDatabaseFilterWith(String, String)public String getDatabaseOrder()
getDatabaseOrderWith(String, String),
getDatabaseOrderParams()
public String getDatabaseOrderWith(String prefix,
String suffix)
prefix added before and
suffix after it if the query is not empty.
prefix - Prefix added before the expression.suffix - Suffix added after the expression.
prefix added before and
suffix after it if the query is not empty.getDatabaseOrder(),
getDatabaseOrderParams()public List getDatabaseOrderParams()
List of parameters that should be set in the
PreparedStatement that belong to the order database representation.
List of parameters that should be set in the
PreparedStatement that belong to the order database representation.getDatabaseOrder(),
getDatabaseOrderWith(String, String)public void setSimpleSqlQuery(String fromSql)
ListQuery filter and order conditions are used
automatically.
To use additional custom filter (and order) conditions,
use setSimpleSqlQuery(String, String, Object[]) or
setSimpleSqlQuery(String, String, Object[], String, Object[])
method. To use more complex query, use setSqlQuery(String)
method.
The constrcuted SQL query format is following
(LQ =
SELECT (fromSql) [WHERE (LQ filter conditions)]
[ORDER BY (LQ order conditions)]
fromSql - FROM clause String.
public void setSimpleSqlQuery(String fromSql,
String customWhereSql,
Object[] customWhereArgs)
ListQuery filter and order conditions are used automatically
and they must not be added to this metohd's arguments.
This method's Where arguments are only for additional
conditions that are not contained in ListQuery already.
In simpler cases, use setSimpleSqlQuery(String) method.
To use also custom order by conditions, use
setSimpleSqlQuery(String, String, Object[], String, Object[]) method.
To use more complex query, use setSqlQuery(String) method.
The constrcuted SQL query format is following
(LQ =
SELECT (fromSql) [WHERE (customWhereSql) AND (LQ filter conditions)]
[ORDER BY (customOrderbySql), (LQ order conditions)]
fromSql - FROM clause String.customWhereSql - custom WHERE clause String.customWhereArgs - custom WHERE clause arguments.
public void setSimpleSqlQuery(String fromSql,
String customWhereSql,
Object[] customWhereArgs,
String customOrderbySql,
Object[] customOrderbyArgs)
ListQuery filter and order conditions are used automatically
and they must not be added to this metohd's arguments.
This method's Where and Order by arguments are only for additional
conditions that are not contained in ListQuery already.
In simpler cases, use setSimpleSqlQuery(String) or
setSimpleSqlQuery(String, String, Object[]) method.
To use more complex query, use setSqlQuery(String) method.
The constrcuted SQL query format is following
(LQ =
SELECT (fromSql) [WHERE (customWhereSql) AND (LQ filter conditions)]
[ORDER BY (customOrderbySql), (LQ order conditions)]
fromSql - FROM clause String.customWhereSql - custom WHERE clause String.customWhereArgs - custom WHERE clause arguments.customOrderbySql - custom ORDER BY clause String.customOrderbyArgs - custom ORDER BY clause arguments.public abstract void setSqlQuery(String sqlQuery)
ListQuery filter and order conditions are not added
automatically. To add them, use getDatabaseFilter* and
getDatabaseOrder* methods.
For simpler cases, use
one of the setSimpleSqlQuery methods instead.
sqlQuery - the SQL query that will be used to retrieve the item range
from the list and count the items.public abstract void setCountSqlQuery(String countSqlQuery)
By default, total items count and items range queries are constructed automatically based on the original query. This method should only be used, if it can considerably boost the perfomacne of count query.
countSqlQuery - the SQL query used to count the items in the database.public abstract void addNullParam(int valueType)
NULL PreparedStatement parameter for
later setting.
This method should not be used with one of the
setSimpleSqlQuery methods.
valueType - the type of the NULL value.public abstract void addStatementParam(Object param)
PreparedStatement parameter for later setting.
This method should not be used with one of the
setSimpleSqlQuery methods.
param - a PreparedStatement parameter.public abstract void addStatementParams(List params)
PreparedStatement parameters for later setting.
This method should not be used with one of the
setSimpleSqlQuery methods.
params - PreparedStatement parameters.protected abstract SqlStatement getCountSqlStatement()
protected abstract SqlStatement getRangeSqlStatement()
public void setDataSource(DataSource ds)
DataSource.
public Object execute(ConnectionCallback action)
DataSource is used to provide JDBC connection for
the action. The connection is always closed after the action.
This method is used by all other execute methods in
ListSqlHelper. To override getting the connection, you
have to use one of the ConnectionCallback returning methods
and use your own implementation to execute it.
action - callback object that specifies the action.
public ListItemsData execute(ResultReader reader)
ResultReader is used to convert the
ResultSet into a List.
The stored DataSource is used to provide JDBC connection for
the action. The connection will be closed automatically.
reader - ResultSet reader.
ListItemsData containing the item range and total
count.public ListItemsData execute(Class itemClass)
ListSqlHelper's BeanResultReader is used
to convert the ResultSet into a List.
The stored DataSource is used to provide JDBC connection for
the action. The connection will be closed automatically.
itemClass - Bean class.
ListItemsData containing the item range and total
count.public Long executeCountSql()
DataSource is used to provide JDBC connection for
the action. The connection will be closed automatically.
public List executeItemRangeSql(ResultReader reader)
ResultReader is used to convert the
ResultSet into a List.
The stored DataSource is used to provide JDBC connection for
the action. The connection will be closed automatically.
reader - ResultSet reader.
List containing the item range.public List executeItemRangeSql(Class itemClass)
ListSqlHelper's BeanResultReader is used
to convert the ResultSet into a List.
The stored DataSource is used to provide JDBC connection for
the action. The connection will be closed automatically.
itemClass - Bean class.
List containing the item range.public ConnectionCallback getListItemsDataCallback(ResultReader reader)
execute methods is recommended.
public ConnectionCallback getCountSqlCallback()
execute methods is recommended.
public ConnectionCallback getItemRangeSqlCallback(ResultReader reader)
execute methods is recommended.
public ResultReader createBeanResultReader(Class itemClass)
ResultSet reader.
In most cases, you should not use this method directly, instead
using one of the execute methods is recommended.
protected VariableResolver createExpressionBuilderResolver()
protected static RuntimeException createQueryFailedException(String QueryString,
List queryParams,
SQLException nestedException)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||