persistence@glassfish.java.net

Re: Fix for setFirstResult/setMaxResults issue

From: Michael Bouschen <Michael.Bouschen_at_Sun.COM>
Date: Thu, 16 Mar 2006 17:05:55 +0100

Hi Gordon, hi Tom,

> Hey Michael,
> My only concern with this change is that this TopLink API (setMaxRows, setFirstResult)
> are defined to be straight pass-through to JDBC. No arithmetic should be performed on these
> values once they are set on the query. Perhaps the arithmetic could be limited to the APIs
> on EJBQueryImpl. This would be more complicated here as there is no guarantee on the order
> in which the APIs would be called. Another alternative would be to add new APIs to ReadQuery
> that would be defined to 'float' MaxRows.

I have implemented the behavior in EJBQueryImpl. The class stores the
values as set by the user and passes the calculated values to the
DatabaseQuery (if available). The attached jar includes the change, plus
a new test in JUnitEJBQLComplexTestSuite.

Thanks!

Regards Michael

>
> --Gordon
>
> -----Original Message-----
> From: Michael Bouschen [mailto:Michael.Bouschen_at_Sun.COM]
> Sent: Wednesday, March 15, 2006 11:33 AM
> To: Tom Ware; Gordon Yorke
> Cc: persistence_at_glassfish.dev.java.net
> Subject: Fix for setFirstResult/setMaxResults issue
>
>
> Hi Tom, Hi Gordon,
>
> I looked at the glassfish issue 344 about setFirstResult and setMaxResults:
> https://glassfish.dev.java.net/issues/show_bug.cgi?id=344
>
> I followed the proposal Peter added to the glassfish issue and changed
> the code in class DatabaseCall method prepareStatement from
> if (getMaxRows() > 0) {
> statement.setMaxRows(getMaxRows());
> }
> to
> if (getMaxRows() > 0) {
> statement.setMaxRows(getFirstResult() + getMaxRows());
> }
>
> This fixes the issue.
>
> I would like to check in the fix, if there are no objections.
>
> Regards Michael
>