cancel
Showing results for 
Search instead for 
Did you mean: 

RetrieveLimitedRecordsCommand fetching only first 1000 records

pradeep_kumar5
Active Participant
0 Kudos

Hi,

For retrieving all the records from RetrieveLimitedRecordsCommand there are 2 ways to achieve it.

cmd.setPageSize(pageSize); // pageSize is integer number which is pased from Request

else if you want to get  all the records from repository , use the following approach;

cmd.setPageSize(Integer.MAX_VALUE);

hard coding pageSize is not right approach;

I am using the below code in my application

RetrieveLimitedRecordsCommand retrieveLimitedRecordsCommand = null;

ResultDefinition resultDefination = new ResultDefinition(tableId);

retrieveLimitedRecordsCommand = new RetrieveLimitedRecordsCommand(repositoryBean.getUserSessionContext());

retrieveLimitedRecordsCommand.setSearch(search);

retrieveLimitedRecordsCommand.setResultDefinition(resultDefination);

retrieveLimitedRecordsCommand.execute();

// Added below lines to get more than 1000 records

int totalRecordBasedOnSearch = retrieveLimitedRecordsCommand.getSearchTableMatchCount();

retrieveLimitedRecordsCommand.setPageSize(totalRecordBasedOnSearch);

retrieveLimitedRecordsCommand.execute();

By the above approach i am executing the command twice. (one is to get the count of records and another for retrieving records) Is there any efficient way to set PageSize other than this?

Regards

Pradeep

Accepted Solutions (1)

Accepted Solutions (1)

pradeep_kumar5
Active Participant
0 Kudos

Hi Martin,

Thanks for your reply. I agree with you, with this approach we are hitting mdm query maxItemCount(as in loop you have menioned above) times, as i have huge number of records in mdm table it takes time to load the screen and display those records in UI. It leads to performance issue. Client wants to display data without any delay, so i suggested the above approach as i mentioned earlier. Any way we have to compromise in these type of scenarios either we need huge memory to handle these situations or client has to wait untill all the data is loaded on the screen. It's all depends on client's choice.

Still looking for any other better approach.

Regards,

Pradeep

martin_schffler
Participant
0 Kudos

Hi Pradeep,

if you want to display the records in a UI then you can just use the paging provided by the MDM API directly.

Just use the page size you are actually displaying to the user and then when the user goes to the next page of results call the command again with the appropriate pageIndex to retrieve the next batch of items.

Regards,

Martin

pradeep_kumar5
Active Participant
0 Kudos

Hi Martin,

I want to display the records in a resultset component as soon as screen loads. Paging is a good option if i dispaly those records in UI and user wants to navigate from one page to another.

Regards,

Pradeep

Answers (1)

Answers (1)

martin_schffler
Participant
0 Kudos

Hi Pradeep,

be very carefull wiht reading all records at once as this can easily lead to OutOfMemoryErrors.

But if you really want to read all records just do it like this:

cmd.setPageSize(-1);

It makes no sense to first read how many items you have and then request exactly that number. There is no benefit over the hard coded value -1.

What you actually should do is some proper paging like this:

int pageIdx = 0;

itemCommand.setPageSize(PAGE_SIZE);

itemCommand.setPageIndex(0);

itemCommand.execute();

Record[] itemRecords = itemCommand.getRecords().getRecords();

int itemCount = itemRecords.length;

int maxItemCount = itemCommand.getSearchTableMatchCount();

while (itemCount < maxItemCount)

{

    // get the next batch of items

    itemCommand.setPageIndex(++pageIdx);

    itemCommand.execute();

    // and copy them to our array of items to delete

    Record[] tmpItems = itemCommand.getRecords().getRecords();

    int tmpItemCount = tmpItems.length;

     // do something with the records...

     // ...   

    itemCount = itemCount + tmpItemCount;

}

Regards,

Martin