[Opensource] searchAndRetrieveList() method of MultiDBObject.java

larry hamel expresso at codeguild.com
Wed Dec 17 21:18:21 PST 2003


hi Liuhey,

Thanks for the feedback. I introduced realRecordCount to give some feedback about all the records that were being *skipped*.  but I was just guessing what would be useful.  On second thought, I suppose it will be best to log to the real count of the retrieved records (e.g., from 200 to 250), so I've changed the feedback as you suggested, renamed and refactored for clarity:

            int returnRecordCount = 0;
            int loopCount = 0;
            while (myConnection.next()) {
                loopCount++;

                //If there's limitation syntax on, then the first record will be the
                //maximum record.
                if (loopCount <= offsetRecord && offsetRecord > 0 &&
                        myConnection.getLimitationPosition() == DBConnection.LIMITATION_DISABLED) {
                    continue;
                }

                returnRecordCount++;

                // maxRecords = 0 by default, so I guess this means 0 doesn't count as max number... should default to -1 ??  LAH 12/03
                if ((returnRecordCount > maxRecords) && (maxRecords > 0)) {
                    break;
                }


                if (log.isDebugEnabled()) {
                    log.debug("Returning row " + loopCount);
                }

                MultiDBObject myObj = getThisMultiDBObj();
                ...

larry

At 05:55 PM 12/17/2003, liuhey wrote:
>No. Firstly I don't know what the realRecordCount mean. If  it means the count of the records which I want to search, then the code should be like below.
>Because I add the comments in your code. Maybe it looks  ugly. I think you can correct this. :-)
>
>
>            int recordCount = 0;
>            int realRecordCount= 0;
>  while (myConnection.next()) {
>>                 recordCount++;
>>                 realRecordCount++;
>> 
>>              //   if (log.isDebugEnabled()) {
>>              //      log.debug("Retrieved row " + realRecordCount);
>>             //   }
>                // I think you should not log  now.It is too early. Maybe this is the record we will ignore.
>> 
>>                 //If there's limitation syntax on, then the first record will be the
>>                 //maximum record.
>>                 if (recordCount < offsetRecord && offsetRecord > 0 &&
>>                         myConnection.getLimitationPosition() == DBConnection.LIMITATION_DISABLED) {
>>                     continue;
>>                 } else if (recordCount == offsetRecord && offsetRecord > 0 &&
>>                         myConnection.getLimitationPosition() == DBConnection.LIMITATION_DISABLED) {
>
>>                  //   recordCount = 0; //Reset count for counting for max records.
>                    //Now you should reset the count of the realRecordCount. If you reset the recordCount and we have set the offset then it will dead loop.
>                        realRecordCount =0;
>
>>                     continue; //Skip this record... next one, we will start loading.
>>                 }
>> 
>>             //    if ((recordCount > maxRecords) && (maxRecords > 0)) {
>               //Now You should use the realRecordCount 
>                     if ((realRecordCount > maxRecords) && (maxRecords > 0)) {
>>                     break;
>>                 }
>              //If you want to log .Now it is the time.
>               if (log.isDebugEnabled()) {
>                  log.debug("Retrieved row " + realRecordCount);
>                }
>> 
>>                 MultiDBObject myObj = getThisMultiDBObj();
>
>
>
>----- Original Message ----- 
>From: "larry hamel" <expresso at codeguild.com>
>To: <opensource at jcorporate.com>
>Sent: Wednesday, December 17, 2003 5:56 AM
>Subject: Re: [Opensource] searchAndRetrieveList() method of MultiDBObject.java
>
>
>> hi Liuhey,
>> 
>> ok, checked in the following code at 1526 on MultiDBObject.
>> 
>> does this echo what you've tested?
>> 
>> larry
>> ----------------------------
>> 
>>             while (myConnection.next()) {
>>                 recordCount++;
>>                 realRecordCount++;
>> 
>>                 if (log.isDebugEnabled()) {
>>                     log.debug("Retrieved row " + realRecordCount);
>>                 }
>> 
>>                 //If there's limitation syntax on, then the first record will be the
>>                 //maximum record.
>>                 if (recordCount < offsetRecord && offsetRecord > 0 &&
>>                         myConnection.getLimitationPosition() == DBConnection.LIMITATION_DISABLED) {
>>                     continue;
>>                 } else if (recordCount == offsetRecord && offsetRecord > 0 &&
>>                         myConnection.getLimitationPosition() == DBConnection.LIMITATION_DISABLED) {
>>                     recordCount = 0; //Reset count for counting for max records.
>>                     continue; //Skip this record... next one, we will start loading.
>>                 }
>> 
>>                 if ((recordCount > maxRecords) && (maxRecords > 0)) {
>>                     break;
>>                 }
>> 
>>                 MultiDBObject myObj = getThisMultiDBObj();
>> ...
>> 
>> At 09:06 PM 12/15/2003, liuhey wrote:
>> >Yes,I've made this change and it works well.
>> >
>> >----- Original Message ----- 
>> >From: "larry hamel" <expresso at codeguild.com>
>> >To: <opensource at jcorporate.com>
>> >Sent: Tuesday, December 16, 2003 2:19 AM
>> >Subject: Re: [Opensource] searchAndRetrieveList() method of MultiDBObject.java
>> >
>> >
>> >> hi Liuhey,
>> >> 
>> >> I'll be happy to check this in, but I would be more confident if you said "I've made this change and it works well."
>> >> 
>> >> Have you tried it?  (Perhaps you already have--you have been 100% correct in the past!)
>> >> 
>> >> BTW, I added a utility method to MultiDBObject recently, and also fixed a bug with it when using SecuredDBObjects as targets.  See CVS for those changes.
>> >> 
>> >> larry
>> >> 
>> >> At 09:04 PM 12/14/2003, you wrote:
>> >> >There is a bug in the searchAndRetrieveList() method of MultiDBObject.java.
>> >> >After executing the query, it ignores the offset property when it populates the MultiDBOBject objects from myConnection. 
>> >> >I think it should do this like the searchAndRetrieveList() method of DBObject.
>> >> >
>> >> >//MultiDBObject
>> >> > public synchronized List searchAndRetrieveList() throws DBException {
>> >> >            ..............
>> >> >            myConnection.execute(myStatement.toString());
>> >> >
>> >> >            int recordCount = 0;
>> >> >
>> >> >            while (myConnection.next()) {
>> >> >                MultiDBObject myObj = getThisMultiDBObj();
>> >> >                recordCount++;
>> >> >
>> >> >                if ((recordCount > maxRecords) && (maxRecords > 0)) {
>> >> >                    break;
>> >> >                }
>> >> >
>> >> >                int i = 1;
>> >> >
>> >> >                if (log.isDebugEnabled()) {
>> >> >                    log.debug("Retrieved row " + recordCount);
>> >> >                }
>> >> >
>> >> >                String oneFieldValue = null;
>> >> >    ......}}
>> >> >
>> >> >//DBObject
>> >> > public synchronized List searchAndRetrieveList() throws DBException {
>> >> >            ..............
>> >> >            myConnection = this.createAndExecuteSearch(retrievedFieldList);
>> >> >
>> >> >            int recordCount = 0;
>> >> >            int retrieveCount = 0;
>> >> >
>> >> >            while (myConnection.next()) {
>> >> >                recordCount++;
>> >> >                retrieveCount++;
>> >> >
>> >> >                //If there's limitation syntax on, then the first record will be the
>> >> >                //maximum record.
>> >> >                if (retrieveCount < offsetRecord && offsetRecord > 0 &&
>> >> >                        myConnection.getLimitationPosition() == DBConnection.LIMITATION_DISABLED) {
>> >> >                    continue;
>> >> >                } else if (retrieveCount == offsetRecord && offsetRecord > 0 &&
>> >> >                        myConnection.getLimitationPosition() == DBConnection.LIMITATION_DISABLED) {
>> >> >                    recordCount = 0; //Reset count for counting for max records.
>> >> >                    continue; //Skip this record... next one, we will start loading.
>> >> >                }
>> >> >                if ((recordCount > maxRecords) && (maxRecords > 0)) {
>> >> >                    this.setAttribute("More Records", "Y");
>> >> >                    break;
>> >> >                }
>> >> >    ......}}
>> >> >_______________________________________________
>> >> >Opensource mailing list
>> >> >Opensource at jcorporate.com
>> >> >http://mail.jcorporate.com/mailman/listinfo/opensource
>> >> >Archives: http://mail.jcorporate.com/pipermail/opensource/
>> >> 
>> >> _______________________________________________
>> >> Opensource mailing list
>> >> Opensource at jcorporate.com
>> >> http://mail.jcorporate.com/mailman/listinfo/opensource
>> >> Archives: http://mail.jcorporate.com/pipermail/opensource/
>> >> 
>> >_______________________________________________
>> >Opensource mailing list
>> >Opensource at jcorporate.com
>> >http://mail.jcorporate.com/mailman/listinfo/opensource
>> >Archives: http://mail.jcorporate.com/pipermail/opensource/
>> 
>> _______________________________________________
>> Opensource mailing list
>> Opensource at jcorporate.com
>> http://mail.jcorporate.com/mailman/listinfo/opensource
>> Archives: http://mail.jcorporate.com/pipermail/opensource/
>> 
>_______________________________________________
>Opensource mailing list
>Opensource at jcorporate.com
>http://mail.jcorporate.com/mailman/listinfo/opensource
>Archives: http://mail.jcorporate.com/pipermail/opensource/




More information about the Opensource mailing list