on 02-20-2013 9:36 AM
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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
93 | |
10 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.