| java.lang.Object org.araneaframework.backend.list.helper.BaseListSqlHelper
All known Subclasses: org.araneaframework.backend.list.helper.ListSqlHelper,
BaseListSqlHelper | abstract public class BaseListSqlHelper (Code) | | 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.
author: Jevgeni Kabanov (ekabanov at araneaframework dot org) author: Rein Raudjärv since: 1.1 |
Inner Class :public class BeanResultReader implements ResultReader | |
Method Summary | |
abstract public void | addNullParam(int valueType) Adds a NULL PreparedStatement parameter for
later setting. | abstract public void | addStatementParam(Object param) Adds a PreparedStatement parameter for later setting. | abstract public void | addStatementParams(List params) Adds PreparedStatement parameters for later setting. | public 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. | public Object | execute(ConnectionCallback action) Execute a JDBC data access operation, implemented as callback action
working on a JDBC Connection.
The stored DataSource is used to provide JDBC connection for
the action. | public 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 .
The stored DataSource is used to provide JDBC connection for
the action. | public 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 .
The stored DataSource is used to provide JDBC connection for
the action. | public Long | executeCountSql() Executes a SQL query that should retrieve the total count of items in the
list.
The stored DataSource is used to provide JDBC connection for
the action. | public List | executeItemRangeSql(ResultReader reader) Executes a SQL query that should retrieve a range of items from the
list.
Provided ResultReader is used to convert the
ResultSet into a List .
The stored DataSource is used to provide JDBC connection for
the action. | public List | executeItemRangeSql(Class itemClass) Executes a SQL query that should retrieve a range of items from the
list.
ListSqlHelper 's BeanResultReader is used
to convert the ResultSet into a List .
The stored DataSource is used to provide JDBC connection for
the action. | public ConnectionCallback | getCountSqlCallback() Returns the total count query callback. | abstract protected SqlStatement | getCountSqlStatement() Returns the total count SQL query String and parameters. | public String | getDatabaseFields() Returns the database fields list seperated by commas, which can be used
in "SELECT" clause. | public String | getDatabaseFilter() Returns the filter database condition, which can be used in "WHERE"
clause. | public List | getDatabaseFilterParams() Returns the List of parameters that should be set in the
PreparedStatement that
belong to the filter database conditions. | public 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.
Parameters: prefix - Prefix added before the expression. Parameters: suffix - Suffix added after the expression. | public String | getDatabaseOrder() Returns the order database representation, which can be used in "ORDER BY" clause. | public List | getDatabaseOrderParams() Returns the List of parameters that should be set in the
PreparedStatement that belong to the order database representation. | public 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.
Parameters: prefix - Prefix added before the expression. Parameters: suffix - Suffix added after the expression. | public 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. | public ConnectionCallback | getItemRangeSqlCallback(ResultReader reader) Returns the item range query callback. | public ConnectionCallback | getListItemsDataCallback(ResultReader reader) Returns the total count and item ragne queries callback. | public NamingStrategy | getNamingStrategy() | protected SqlExpression | getOrderSqlExpression() Returns the order SqlExpression , which can be used in
"ORDER BY" clause. | abstract protected SqlStatement | getRangeSqlStatement() Returns the itme range SQL query String and parameters. | public ResultSetColumnReader | getResultSetColumnReader() | public ValueConverter | getValueConverter() | protected void | init() | abstract public void | setCountSqlQuery(String countSqlQuery) Sets the SQL query used to count the items in the database. | public void | setDataSource(DataSource ds) Stores the DataSource . | public void | setFields(Fields fields) | public void | setFilterExpression(Expression filterExpr) Sets the filter expression saving it for later automatic SQL query
creation. | public void | setItemRangeCount(Long itemRangeCount) Sets the count of items in the range. | public void | setItemRangeStart(Long itemRangeStart) Sets the (0-based) starting index of the item range. | public void | setListQuery(ListQuery query) Sets the starting index and count of items in the range and
filtering and ordering expressions. | public void | setNamingStrategy(NamingStrategy namingStrategy) | public void | setOrderExpression(ComparatorExpression orderExpr) Sets the order expression saving it for later automatic SQL query
creation. | public void | setResultSetColumnReader(ResultSetColumnReader resultSetColumnReader) | public 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.
ListQuery filter and order conditions are used
automatically.
To use additional custom filter (and order) conditions,
use
BaseListSqlHelper.setSimpleSqlQuery(String,String,Object[]) or
BaseListSqlHelper.setSimpleSqlQuery(String,String,Object[],String,Object[]) method. | public 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.
ListQuery filter and order conditions are used automatically
and they must not be added to this metohd's arguments. | public 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.
ListQuery filter and order conditions are used automatically
and they must not be added to this metohd's arguments. | abstract public void | setSqlQuery(String sqlQuery) Sets the SQL query that will be used to retrieve the item range from the
list and count the items. | public void | setValueConverter(ValueConverter valueConverter) |
DEFAULT_RANGE_START | final protected static Long DEFAULT_RANGE_START(Code) | | |
BaseListSqlHelper | public BaseListSqlHelper()(Code) | | Creates ListSqlHelper without initializing any fields.
|
BaseListSqlHelper | public BaseListSqlHelper(DataSource dataSource)(Code) | | Creates ListSqlHelper and provides it with the
DataSource .
|
BaseListSqlHelper | public BaseListSqlHelper(ListQuery query)(Code) | | Creates ListSqlHelper initializing the appropriate fields.
|
BaseListSqlHelper | public BaseListSqlHelper(DataSource dataSource, ListQuery query)(Code) | | Creates ListSqlHelper initializing the appropriate fields
and providing it with the DataSource .
|
addNullParam | abstract public void addNullParam(int valueType)(Code) | | Adds a NULL PreparedStatement parameter for
later setting.
This method should not be used with one of the
setSimpleSqlQuery methods.
Parameters: valueType - the type of the NULL value. |
addStatementParam | abstract public void addStatementParam(Object param)(Code) | | Adds a PreparedStatement parameter for later setting.
This method should not be used with one of the
setSimpleSqlQuery methods.
Parameters: param - a PreparedStatement parameter. |
addStatementParams | abstract public void addStatementParams(List params)(Code) | | Adds PreparedStatement parameters for later setting.
This method should not be used with one of the
setSimpleSqlQuery methods.
Parameters: params - PreparedStatement parameters. |
createBeanResultReader | public ResultReader createBeanResultReader(Class itemClass)(Code) | | Returns Bean ResultSet reader.
In most cases, you should not use this method directly, instead
using one of the execute methods is recommended.
|
createExpressionBuilderResolver | protected VariableResolver createExpressionBuilderResolver()(Code) | | Creates the VariableResolver for SqlExpressionBuilder that converts
Variable names to their Database Field names according to the naming strategy.
the VariableResolver for SqlExpressionBuilder that convertsVariable names to their Database Field names according to the naming strategy. |
createQueryFailedException | protected static RuntimeException createQueryFailedException(String QueryString, List queryParams, SQLException nestedException)(Code) | | Returns query failed Exception that contains query String and params.
|
execute | public Object execute(ConnectionCallback action)(Code) | | Execute a JDBC data access operation, implemented as callback action
working on a JDBC Connection.
The stored 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.
Parameters: action - callback object that specifies the action. a result object returned by the action, or null. |
execute | public ListItemsData execute(ResultReader reader)(Code) | | 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 .
The stored DataSource is used to provide JDBC connection for
the action. The connection will be closed automatically.
Parameters: reader - ResultSet reader. ListItemsData containing the item range and totalcount. |
execute | public ListItemsData execute(Class itemClass)(Code) | | 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 .
The stored DataSource is used to provide JDBC connection for
the action. The connection will be closed automatically.
Parameters: itemClass - Bean class. ListItemsData containing the item range and totalcount. |
executeCountSql | public Long executeCountSql()(Code) | | Executes a SQL query that should retrieve the total count of items in the
list.
The stored DataSource is used to provide JDBC connection for
the action. The connection will be closed automatically.
the total count of items in the list. |
executeItemRangeSql | public List executeItemRangeSql(ResultReader reader)(Code) | | Executes a SQL query that should retrieve a range of items from the
list.
Provided 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.
Parameters: reader - ResultSet reader. List containing the item range. |
executeItemRangeSql | public List executeItemRangeSql(Class itemClass)(Code) | | Executes a SQL query that should retrieve a range of items from the
list.
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.
Parameters: itemClass - Bean class. List containing the item range. |
getCountSqlCallback | public ConnectionCallback getCountSqlCallback()(Code) | | Returns the total count query callback.
In most cases, you should not use this method directly, instead
using one of the execute methods is recommended.
|
getCountSqlStatement | abstract protected SqlStatement getCountSqlStatement()(Code) | | Returns the total count SQL query String and parameters.
|
getDatabaseFields | public String getDatabaseFields()(Code) | | Returns the database fields list seperated by commas, which can be used
in "SELECT" clause.
the database fields list seperated by commas, which can be usedin "SELECT" clause. |
getFieldsSqlExpression | protected SqlExpression getFieldsSqlExpression()(Code) | | Returns the fields SqlExpression , which can be used in
"SELECT" clause.
the fields SqlExpression , which can be used in"SELECT" clause. |
getFilterSqlExpression | protected SqlExpression getFilterSqlExpression()(Code) | | Returns the filter SqlExpression , which can be used in
"WHERE" clause.
the filter SqlExpression , which can be used in"WHERE" clause. |
getItemRangeSqlCallback | public ConnectionCallback getItemRangeSqlCallback(ResultReader reader)(Code) | | Returns the item range query callback.
In most cases, you should not use this method directly, instead
using one of the execute methods is recommended.
|
getListItemsDataCallback | public ConnectionCallback getListItemsDataCallback(ResultReader reader)(Code) | | Returns the total count and item ragne queries callback.
In most cases, you should not use this method directly, instead
using one of the execute methods is recommended.
|
getOrderSqlExpression | protected SqlExpression getOrderSqlExpression()(Code) | | Returns the order SqlExpression , which can be used in
"ORDER BY" clause.
the order SqlExpression , which can be used in"ORDER BY" clause. |
getRangeSqlStatement | abstract protected SqlStatement getRangeSqlStatement()(Code) | | Returns the itme range SQL query String and parameters.
|
init | protected void init()(Code) | | |
setCountSqlQuery | abstract public void setCountSqlQuery(String countSqlQuery)(Code) | | Sets the SQL query used to count the items in the database. SQL query
must start with SELECT.
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.
Parameters: countSqlQuery - the SQL query used to count the items in the database. |
setDataSource | public void setDataSource(DataSource ds)(Code) | | Stores the DataSource .
|
setItemRangeCount | public void setItemRangeCount(Long itemRangeCount)(Code) | | Sets the count of items in the range.
|
setItemRangeStart | public void setItemRangeStart(Long itemRangeStart)(Code) | | Sets the (0-based) starting index of the item range.
|
setListQuery | public void setListQuery(ListQuery query)(Code) | | Sets the starting index and count of items in the range and
filtering and ordering expressions.
|
setSimpleSqlQuery | public void setSimpleSqlQuery(String fromSql, String customWhereSql, Object[] customWhereArgs)(Code) | | Sets the SQL query (with arguments) that will be used to retrieve the
item range from the list and count the items.
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
BaseListSqlHelper.setSimpleSqlQuery(String) method.
To use also custom order by conditions, use
BaseListSqlHelper.setSimpleSqlQuery(String,String,Object[],String,Object[]) method.
To use more complex query, use
BaseListSqlHelper.setSqlQuery(String) method.
The constrcuted SQL query format is following
(LQ = ListQuery):
SELECT (fromSql) [WHERE (customWhereSql) AND (LQ filter conditions)]
[ORDER BY (customOrderbySql), (LQ order conditions)]
Query arguments are automatically added in the appropriate order.
Parameters: fromSql - FROM clause String. Parameters: customWhereSql - custom WHERE clause String. Parameters: customWhereArgs - custom WHERE clause arguments. |
setSimpleSqlQuery | public void setSimpleSqlQuery(String fromSql, String customWhereSql, Object[] customWhereArgs, String customOrderbySql, Object[] customOrderbyArgs)(Code) | | Sets the SQL query (with arguments) that will be used to retrieve the
item range from the list and count the items.
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
BaseListSqlHelper.setSimpleSqlQuery(String) or
BaseListSqlHelper.setSimpleSqlQuery(String,String,Object[]) method.
To use more complex query, use
BaseListSqlHelper.setSqlQuery(String) method.
The constrcuted SQL query format is following
(LQ = ListQuery):
SELECT (fromSql) [WHERE (customWhereSql) AND (LQ filter conditions)]
[ORDER BY (customOrderbySql), (LQ order conditions)]
Query arguments are automatically added in the appropriate order.
Parameters: fromSql - FROM clause String. Parameters: customWhereSql - custom WHERE clause String. Parameters: customWhereArgs - custom WHERE clause arguments. Parameters: customOrderbySql - custom ORDER BY clause String. Parameters: customOrderbyArgs - custom ORDER BY clause arguments. |
setSqlQuery | abstract public void setSqlQuery(String sqlQuery)(Code) | | Sets the SQL query that will be used to retrieve the item range from the
list and count the items. SQL query must start with SELECT.
All query arguments must be added additionally.
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.
Parameters: sqlQuery - the SQL query that will be used to retrieve the item rangefrom the list and count the items. |
|
|