I'm trying to create a function which return a list of an Object with Page ( from spring data ).
The problem is that the returned values "totalElements" & "total pages" are incorrect
There is 10 elements, but totalElements = 110, and totalPages = 2 when the 10 elements enter easily in a page of 100 elements
PS : I am forced to use the object MongoTemplate in which there is no find function which takes a Pageable. So i'm forced to create it manually.
The code i'm using :
PageableExecutionUtils.getPage(orders,pageable,() -> orders.size());
the orders is a List of my results ( which are correct ), the page is defined like following :
Pageable pageable = new PageRequest(pageIndex,numberOfTransactionsPerPage);
Thank you for everything
Looks like you have 110 elements, and you have page size 100, so 2nd page is the last page with 10 elements because other 100 elements was on 1st page.
Related
I'm using the
Page<T> findAll(#Nullable Specification<T> spec, Pageable pageable);
interface in the JpaSpecificationExecutor and I am getting this weird behavior.
The endpoint looks as :
/endpoint?size={size}&page={pageNumber}
we're having 2234 rows, and with size=20, we're having 112 pages.
i.e (111*20) + (1*14) = 2234
i.e 111 pages with 20 rows and 1 page with 14 rows
I'm using
Page<myDto> myDtoPage= repository.findAll(specification, pageable);
myDtoPage.total is correct i.e(2234) only when page=111 i.e last page(page starting with 0 so 111 is the last page)
i.e /endpoint?size=20&page=111
For any other value of pageNumber for eg /endpoint?size=20&page=110 the total is not correct and has bigger value i.e(25251).
Also, when greater value for the pageNumber is provided than the existing pageNumber,
i.e /endpoint?size=20&page=112, I'm getting no data which seems fine.
Also, for /endpoint?size=20&page=111, I'm getting 14 data which is also fine.
The only weird behavior is the myDtoPage.total value which is correct only when page=111 and some bigger value for any other pageNumber value.
I am trying to write an MDX query which selects top 100 rows by dimension or measure value.
Fragment on a query
NonEmpty([Domain].[Domain].[Domain].Members , { [Measures].[Total - Domains] } )
I can use topcount and get top 100 rows by "order_count" measure successfully:
topcount(NonEmpty([Domain].[Domain].[Domain].Members , { [Measures].[Total - Domains] } ), 100, [Measures].[order_count])
However, when i try to do that on the dimension value, it does not seem to work properly it seems like it is not doing sorting operation):
topcount(NonEmpty([Domain].[Domain].[Domain].Members , { [Measures].[Total - Domains] } ), 100, [Domain].[Domain].[Value])
I have read that topcount expects numeric expression to sort and my domain value is a string, so I have tried using head() and order(), but I still get incorrect results.
UPDATE: Is seems that i needed to use [Domain].[Domain].properties('Value') instead of [Domain].[Domain].[Value]
SOLVED
I have one query in service class
PageRequest page = new PageRequest(pageNo,batchSize , new Sort(new Order(Direction.ASC, "Id")));
Page pPage = this.pRepository.findByStatusAndParentPId( Status.PENDING, -1, page);
where batchSize=500
In repository we have following code:
#Query("select p from Part p where p.succeedOn IS NOT NULL and p.Status=? and p.parentId=?")
Page<Payment> findByStatusAndParentId( String status, Integer parentId, Pageable p);
Now flow is like this, i want to fetch 500 rows everytime whose status is pending and then i need to process it and need to change the status to success. So using Pageable is giving me wrong result because , suppose it fetch first 500 rows whose status is pending , it processed it and changed the status to success, now it will again make sql query and will fetch row from 501 to 1000 , but actually row 1 to 500 also have status pending as older processed rows status changed to success, so they will not be covered in sql query.
Now to solve this i want to do pagenation with from last row of last fetched Id , say last time it fetched from 100 to 600, then i want to give 601 as argument and want to fetch all rows onward..... hopefully i am able to explain my answer. Limit in query do not work in JPA.
Thanks
I think you can just keep fetching page 1. Assuming each batch is processed in its own transaction, then by the time you process the second batch, page 1 should give you the next 500 un-processed rows
In my app, I am using JQGrid to render the data in Grid.
In this case, my Grid is set to loadonce:true and It also provides filter toolbar facility.
My problem is, I am getting wrong count of total number of pages,total number of records and rowNum of the grid when i have used filter toolbar.
For example : My grid is having total 14 records and rowNum = 5. So there are total 3 pages as displayed in below image.
Now the code below works fine for me in normal case (case in which I have not used filters toolbar).
var records = $('#list10').getGridParam('records');
var rowNum = $('#list10').getGridParam('rowNum');
var pageCount = Math.ceil( parseInt(records) / parseInt(rowNum));
But When I used filters the above written code is not giving me updated result. Consider the image below for example ..
Here for this case the above mentioned code gives me same result as .. total pages =3 , total number of rows =14 and rowNum = 5.
Can anyone suggest me that How can I retrieve the updated value of page,total,records,rowNum when I have used filter toolbar ??
I have a small application that displays a list of shortURLs to a user. I'm using ASP.NET MVC3, Entity Framework, and an Oracle backend. I'm also using the PagedList library by Troy Goode (https://github.com/TroyGoode/PagedList)
I want the user to see the very last entry first, similar to how blog comments are ordered. To do this I added an "orderby descending" clause to the LINQ statement:
var links = from l in db.LINKS
orderby l.ID descending
select l;
In debug the "links" object is ordered as expected (in descending order, by the primary key "ID").
Now I want to pass this list of links to the view using the .toPagedList() method:
int pageSize = 3;
int pageNumber = (page ?? 1); // "page" comes from the request, if null set to 1
return View(links.ToPagedList(pageNumber, pageSize));
This works great if I only have 3 records (refer to "pageSize" above). However, when I add a 4th record I get unexpected behavior. Because I have the pageSize set to 3, adding a fourth record means there will be 2 pages. I would expect the ordering to be as follows:
Page 1:
ID: 4
ID: 3
ID: 2
Page 2:
ID: 1
That is not the case, what actually happens is this:
Page 1:
ID: 3
ID: 2
ID: 1
Page 2:
ID: 4
So my question, what the heck am I doing wrong here? Why is PagedList not following the order defined by the "orderby l.ID descending" expression in the LINQ statement? It is baffling to me because in the debugger it is clear that the "links" object is ordered properly before the .toPagedLIst() is used on it.
Any help is greatly appreciated!
You could try:
return View(links.ToPagedList(pageNumber, pageSize, m => m.ID, true));
It's off the top of my head, so I'm sorry if it doesn't work perfectly...
-- Wow, just noticed the date on this one... I need to stop trawling the unanswered pages without sorting by date!