You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ibatis.apache.org by "Clinton Begin (JIRA)" <ib...@incubator.apache.org> on 2006/07/27 07:15:14 UTC

[jira] Closed: (IBATIS-327) suggest: PaginatedDataList getCount() Implements

     [ http://issues.apache.org/jira/browse/IBATIS-327?page=all ]

Clinton Begin closed IBATIS-327.
--------------------------------

    Resolution: Won't Fix
      Assignee: Clinton Begin


This request has been made before, and we've turned it down.  It simply doesn't make any sense to do anything other than:  SELECT count(1) ... etc.



> 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: 李义冬
>         Assigned To: Clinton Begin
>
> <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