suggest: PaginatedDataList getCount() Implements
------------------------------------------------
Key: IBATIS-327
URL: http://issues.apache.org/jira/browse/IBATIS-327
Project: iBatis for Java
Issue Type: Wish
Components: SQL Maps
Environment: SqlMapExecutor.queryForPaginatedList(String id, Object
paramObject, int pageSize)
to PaginatedList, But i cann't obtain the total of query
Reporter: 李义冬
<select id="getUser resultMap="user-result-List">
select * from user where sex = #sex#
</select>
I know, "select count(*) from (select * from user where sex = ?) so, add method
getCount() to PaginatedList.java
public int getCount() {
if (count == -1) {
SqlMapClientImpl sqlMapClient = (SqlMapClientImpl) sqlMapExecutor;
GeneralStatement statement = (GeneralStatement)
sqlMapClient.getMappedStatement(statementName);
RequestScope requestScope = new RequestScope(); // i cann't
obtains RequestScope from requestPool.
statement.initRequest(requestScope);
Sql sql = new PaginateSql(statement.getSql());
String selSql = sql.getSql(requestScope, parameterObject);
ParameterMap parameterMap = sql.getParameterMap(requestScope,
parameterObject);
Object[] obj = parameterMap.getParameterObjectValues(requestScope,
parameterObject);
Connection con = null;
PreparedStatement ps = null;
ResultSet result = null;
try {
con = sqlMapClient.getDataSource().getConnection();
ps = con.prepareStatement(selSql);
parameterMap.setParameters(requestScope, ps, obj);
result = ps.executeQuery();
while (result.next()) {
count = result.getInt(1);
}
} catch (SQLException e) {
e.printStackTrace(); //To change body of catch statement use
File | Settings | File Templates.
} finally {
try {
result.close();
} catch (SQLException e) {
// ignore
}
try {
ps.close();
} catch (SQLException e) {
// ignore
}
try {
con.close();
} catch (SQLException e) {
// ignore
}
}
}
return count;
}
I am very superficial to the framework understanding, this code is shoddy, but
it can obtains count. I thought you understand my meaning, anticipates your
reply
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira