OAF_开发系列29_实现OAF中批次处理迭代器RowSet/RowSetIterator(案例)

20150814 Created By BaoXinjian

一、摘要


在Oracle官方指南和例子中,一般遍历记录,都是通过RowSetIterator的方式进行,RowSetIterator的用法,通过为VO创建一个迭代器来 循环每一个行

但在实际应用也可以通过Row和Rowset的方式进行遍历记录

具体情况具体分析

 

1. 选中记录和记录集合的三种方式

(1). 通过Row选中第一条记录:vo.getFirstFilteredRow("SelectFlag", new String("Y"));

(2). 通过RowSet选中所有被选中的记录:vo.getFiterredRow("SelectFlag", new String("Y"));

(3). 通过RowSetIterator选中所有记录:vo.createRowSetIterator("selectIter");

 

二、实施分析


Step1. 创建CO中的方法

(1). vo.getFirstFilteredRow("SelectFlag", new String("Y"));

(2). vo.getFiterredRow("SelectFlag", new String("Y"));

(3). vo.createRowSetIterator("selectIter");

Step2. 在CO具体控制代码,分析三种选中方案

public void processFormRequest(OAPageContext pageContext, 
                               OAWebBean webBean) {
    super.processFormRequest(pageContext, webBean);

    try {
        EmpManageAMImpl am = (EmpManageAMImpl)pageContext.getApplicationModule(webBean);
        EmployeesItaraterVOImpl vo = am.getEmployeesItaraterVO();

        //方案1. 通过ROW获取第一个选中栏位    
        if ("select".equals(pageContext.getParameter(EVENT_PARAM))) {
            EmployeesItaraterVORowImpl row = (EmployeesItaraterVORowImpl) vo.getFirstFilteredRow("SelectFlag", new String("Y")); //获取记录集合
            System.out.println("RowFirstEmployeeId=" + row.getEmployeeId());
        }

        //方案2. 通过ROWSET获取所有选中栏位    
        if ("select".equals(pageContext.getParameter(EVENT_PARAM))) {
            Row[] rowset = vo.getFilteredRows("SelectFlag", new String("Y")); //获取记录集合
            for (int i = 0; i < rowset.length; i++) {
                EmployeesItaraterVORowImpl row = (EmployeesItaraterVORowImpl)rowset[i]; //取得当前记录
                System.out.println("RowsetEmployeeId=" + row.getEmployeeId());
            }
        }

        //方案3. 通过RowSetIterator所有选中栏位
        if ("select".equals(pageContext.getParameter(EVENT_PARAM))) {
            int rowcount = vo.getFetchedRowCount(); //取当前提取的记录集的记录数
            RowSetIterator selectIter = vo.createRowSetIterator("selectIter"); //建立记录集的指示器
            if (rowcount > 0) {
                selectIter.setRangeStart(0); //设置循环起点,相当于移动指针到第一条记录
                selectIter.setRangeSize(rowcount); //设置循环次数
                for (int i = 0; i < rowcount; i++) {
                    EmployeesItaraterVORowImpl row = (EmployeesItaraterVORowImpl)selectIter.getRowAtRangeIndex(i); //取得当前记录
                    System.out.println("ItaraterEmployeeId=" + row.getEmployeeId());
                }
            }
selectIter.closeRowSetIterator(); } } catch (Exception ex) { ex.printStackTrace(); } }

 

三、测试运行


Step1. 选中一条记录测试三种选中方式

Step2.  显示记录如下

Step3. 选中全部记录测试显示选中方式

Step4. 显示记录如下

 

Thanks and Regards

posted on 2015-07-25 14:10  东方瀚海  阅读(837)  评论(0编辑  收藏  举报