0

我们有一个 SQLJ 文件,我们在其中指定了一个迭代器来从表中获取多条记录。目前,我们正在尝试通过一次从总共 300 条记录中提取 50 条记录来将 300 条记录从中间表上传到实际表。

我们面临的问题是,每次获取都会创建 50 个迭代器,其中 1 个游标是 DICTIONARY LOOKUP CURSOR CACHED,49 个是 OPEN-RECURSIVE。在遍历迭代器之后,我们在 finally 块中有一个 close 调用,但这会关闭一个 one 游标,剩下 48 个 OPEN-RECURSIVE 游标和 1 个 DICTIONARY LOOKUP CURSOR CACHED。我想知道是否有任何特定的方法可以关闭所有这些。我曾尝试在网络上查看,但在这种情况下并没有真正遇到太多。

    #sql public static iterator UploadDetailsList(BigDecimal ID, String FUNCTION_ID,String TABLE_NAME)
#sql public static iterator UploadDetailsListAnother(BigDecimal ID, String FUNCTION_ID,String TABLE_NAME)
public List<UploadDto> getRecords(UploadDto newDto,int fromRowNo){
    //fromRowNo is sent as 0
    int maxResults=50;
    int toRowNum= fromRowNo + maxResults;
    UploadDetailsList uploadDetailsList=null;
    UploadDetailsListAnother uploadDetailsListAnother=null;
    try{
        #sql  uploadDetailsList = {SELECT ID,FUNCTION_ID,TABLE_NAME FROM UPLOAD_TABLE WHERE  STATUS= 'U' AND ROWNUM BETWEEN :fromRowNo AND :toRowNum};
        while(uploadDetailsList.next()){
            //populate details to Dto object
           try{
                #sql  uploadDetailsListAnother = {SELECT ID,FUNCTION_ID,TABLE_NAME FROM UPLOAD_TABLE WHERE  STATUS= 'U' AND ROWNUM BETWEEN :fromRowNo AND :toRowNum};
                while(uploadDetailsListAnother.next()){
                    //populate details to Dto object
                }
           }
            catch(Exception e){
                //print error
            }
        }
    }
    catch(Exception e){
        //print error
    }
    finally{
        try{
            dbg("Inside finally in List<UploadDto> getRecords(UploadDto newDto,int fromRowNo)");
            if(uploadDetailsList != null){
                dbg("Closing uploadDetailsList");
                uploadDetailsList.close();
            }
             if(uploadDetailsListAnother != null){
                dbg("Closing uploadDetailsListAnother");
                uploadDetailsListAnother.close();
            }
        }
        catch(Exception e){
            //print error
        }
    }
}

有人可以让我知道我哪里出错了,或者我可能遗漏了什么吗?

4

1 回答 1

0

发现我犯的最愚蠢的错误。第一个 while 循环内的第二个迭代器应该在那个迭代器的 try catch 之后已经关闭,并且有一个 finally 块。这对我有用。把问题留在这里,以防其他人犯同样的错误。这是代码

#sql public static iterator UploadDetailsList(BigDecimal ID, String FUNCTION_ID,String TABLE_NAME)
#sql public static iterator UploadDetailsListAnother(BigDecimal ID, String FUNCTION_ID,String TABLE_NAME)
public List<UploadDto> getRecords(UploadDto newDto,int fromRowNo){
    //fromRowNo is sent as 0
    int maxResults=50;
    int toRowNum= fromRowNo + maxResults;
    UploadDetailsList uploadDetailsList=null;
    UploadDetailsListAnother uploadDetailsListAnother=null;
    try{
        #sql  uploadDetailsList = {SELECT ID,FUNCTION_ID,TABLE_NAME FROM UPLOAD_TABLE WHERE  STATUS= 'U' AND ROWNUM BETWEEN :fromRowNo AND :toRowNum};
        while(uploadDetailsList.next()){
            //populate details to Dto object
           try{
                #sql  uploadDetailsListAnother = {SELECT ID,FUNCTION_ID,TABLE_NAME FROM UPLOAD_TABLE WHERE  STATUS= 'U' AND ROWNUM BETWEEN :fromRowNo AND :toRowNum};
                while(uploadDetailsListAnother.next()){
                    //populate details to Dto object
                }
           }
            catch(Exception e){
                //print error
            }
            //moved the finally here with closing of the inner iterator
            finally{
                try{
                    if(uploadDetailsListAnother != null){
                        dbg("Closing uploadDetailsListAnother");
                        uploadDetailsListAnother.close();
                    }
                }
                catch(Exception e){
                    //print error
                }
            }
        }
    }
    catch(Exception e){
        //print error
    }
    finally{
        try{
            dbg("Inside finally in List<UploadDto> getRecords(UploadDto newDto,int fromRowNo)");
            if(uploadDetailsList != null){
                dbg("Closing uploadDetailsList");
                uploadDetailsList.close();
            }

        }
        catch(Exception e){
            //print error
        }
    }
}
于 2017-04-28T06:53:12.613 回答