You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user-java@ibatis.apache.org by Guido García Bernardo <gg...@tid.es> on 2005/03/18 12:12:31 UTC

PaginatedList & 'google like' results

Hi,

I am using ibatis PaginatedList functionality for paging through search results, 
and I would like to add the ability for a user to go to the last page of the results 
(something like Google results) instead of having to page through big result sets as
it is done in JPetStore4:

  <logic:notEqual name="orderBean" property="orderList.firstPage" value="true" >
    <a href="switchOrderPage.shtml?pageDirection=previous">PREV</a>
  </logic:notEqual>
  <logic:notEqual name="orderBean" property="orderList.lastPage" value="true" >
    <a href="switchOrderPage.shtml?pageDirection=next">NEXT</a>
  </logic:notEqual>

Is this possible or should I do two queries (my actual "select fields from..." 
and a new "select count(*) from...") to achieve it?

Thank you very much,
Guido.

-- 
Guido García Bernardo - ggarciab@itdeusto.com
Tfn. +34 983 54 89 08
ITDEUSTO - Valladolid


Re: PaginatedList & 'google like' results

Posted by Brandon Goodin <br...@gmail.com>.
Brice, can we put those website links you referenced onto the ibatis
wiki under the "Powered By IBatis" section?

http://wiki.apache.org/ibatis/Powered_20By_20IBatis

Brandon


On Fri, 18 Mar 2005 08:24:32 -0600, Brice Ruth <bd...@gmail.com> wrote:
> The product catalogs on www.powersentry.com, www.newpoint.com,
> www.zincklysbro.dk, and www.wilkinsonswordgarden.com all use
> PaginatedList to provide the Page [1] 2 3 4 ... functionality.
> 
> I have a simple Action that looks like this:
> 
>        public ActionForward gotoPage(
>                ActionMapping mapping,
>                ActionForm form,
>                HttpServletRequest request,
>                HttpServletResponse response)
>        {
>                DynaActionForm myForm = (DynaActionForm) form;
>                // Get PRODUCT_INFO_KEY object from session
>                PaginatedList products = (PaginatedList)
> request.getSession().getAttribute(Constants.PRODUCT_LIST_KEY);
> 
>                if (products != null) {
>                        try {
>                                String page = (String) myForm.get("page");
>                                if (page.equalsIgnoreCase("next")) {
>                                        products.nextPage();
>                                } else if (page.equalsIgnoreCase("previous")) {
>                                        products.previousPage();
>                                } else {
>                                        int pageNum = new Integer(page).intValue();
> 
>                                        products.gotoPage(pageNum);
>                                }
> 
>                                request.setAttribute(Constants.PRODUCT_LIST_CURRENT_PAGE,new
> Integer(products.getPageIndex()));
> 
>                                return mapping.findForward("success.showCategory");
> 
>                        } catch (NumberFormatException e) {
>                                return mapping.findForward("browse");
>                        } catch (RuntimeException e) {
>                                return mapping.findForward("browse");
>                        }
>                } else {
>                        return mapping.findForward("browse");
>                }
>        }
> 
> To make this work, when I do the initial query to populate the
> PaginatedList, I do as you indicated - one query for the objects, one
> query for the count. To hide this double-step, you could put that in
> your DAO, if you're using one (I am not).
> 
> Brice
> 
> 
> On Fri, 18 Mar 2005 12:12:31 +0100, Guido García Bernardo <gg...@tid.es> wrote:
> > Hi,
> >
> > I am using ibatis PaginatedList functionality for paging through search results,
> > and I would like to add the ability for a user to go to the last page of the results
> > (something like Google results) instead of having to page through big result sets as
> > it is done in JPetStore4:
> >
> >   <logic:notEqual name="orderBean" property="orderList.firstPage" value="true" >
> >     <a href="switchOrderPage.shtml?pageDirection=previous">PREV</a>
> >   </logic:notEqual>
> >   <logic:notEqual name="orderBean" property="orderList.lastPage" value="true" >
> >     <a href="switchOrderPage.shtml?pageDirection=next">NEXT</a>
> >   </logic:notEqual>
> >
> > Is this possible or should I do two queries (my actual "select fields from..."
> > and a new "select count(*) from...") to achieve it?
> >
> > Thank you very much,
> > Guido.
> >
> > --
> > Guido García Bernardo - ggarciab@itdeusto.com
> > Tfn. +34 983 54 89 08
> > ITDEUSTO - Valladolid
> >
> >
>

Re: RES: PaginatedList & 'google like' results

Posted by Brice Ruth <bd...@gmail.com>.
Absolutely true ... of course, as I mentioned, I could put this in a
DAO and get around that problem. I just opted not to use a DAO this
time, mostly for expediency's sake (as usual).

Brice


On Fri, 18 Mar 2005 11:32:58 -0300, Leonardo Holanda
<le...@atlantico.com.br> wrote:
> That's nice. The problem in my case is that the Architects in my company
> does not allow us to put database layer especific code into the web
> layer code. But, if it's not a problem, thats nice. But remember, if one
> day you decide to chance iBatis for another framework, you will have to
> touch the web code (the action in your example).
> 
> -----Mensagem original-----
> De: Brice Ruth [mailto:bdruth@gmail.com]
> Enviada em: sexta-feira, 18 de março de 2005 11:25
> Para: ibatis-user-java@incubator.apache.org
> Assunto: Re: PaginatedList & 'google like' results
> 
> The product catalogs on www.powersentry.com, www.newpoint.com,
> www.zincklysbro.dk, and www.wilkinsonswordgarden.com all use
> PaginatedList to provide the Page [1] 2 3 4 ... functionality.
> 
> I have a simple Action that looks like this:
> 
>         public ActionForward gotoPage(
>                 ActionMapping mapping,
>                 ActionForm form,
>                 HttpServletRequest request,
>                 HttpServletResponse response)
>         {
>                 DynaActionForm myForm = (DynaActionForm) form;
>                 // Get PRODUCT_INFO_KEY object from session
>                 PaginatedList products = (PaginatedList)
> request.getSession().getAttribute(Constants.PRODUCT_LIST_KEY);
> 
>                 if (products != null) {
>                         try {
>                                 String page = (String)
> myForm.get("page");
>                                 if (page.equalsIgnoreCase("next")) {
>                                         products.nextPage();
>                                 } else if
> (page.equalsIgnoreCase("previous")) {
>                                         products.previousPage();
>                                 } else {
>                                         int pageNum = new
> Integer(page).intValue();
> 
>                                         products.gotoPage(pageNum);
>                                 }
> 
> request.setAttribute(Constants.PRODUCT_LIST_CURRENT_PAGE,new
> Integer(products.getPageIndex()));
> 
>                                 return
> mapping.findForward("success.showCategory");
> 
>                         } catch (NumberFormatException e) {
>                                 return mapping.findForward("browse");
>                         } catch (RuntimeException e) {
>                                 return mapping.findForward("browse");
>                         }
>                 } else {
>                         return mapping.findForward("browse");
>                 }
>         }
> 
> To make this work, when I do the initial query to populate the
> PaginatedList, I do as you indicated - one query for the objects, one
> query for the count. To hide this double-step, you could put that in
> your DAO, if you're using one (I am not).
> 
> Brice
> 
> On Fri, 18 Mar 2005 12:12:31 +0100, Guido García Bernardo
> <gg...@tid.es> wrote:
> > Hi,
> >
> > I am using ibatis PaginatedList functionality for paging through
> > search results, and I would like to add the ability for a user to go
> > to the last page of the results (something like Google results)
> > instead of having to page through big result sets as it is done in
> > JPetStore4:
> >
> >   <logic:notEqual name="orderBean" property="orderList.firstPage"
> value="true" >
> >     <a href="switchOrderPage.shtml?pageDirection=previous">PREV</a>
> >   </logic:notEqual>
> >   <logic:notEqual name="orderBean" property="orderList.lastPage"
> value="true" >
> >     <a href="switchOrderPage.shtml?pageDirection=next">NEXT</a>
> >   </logic:notEqual>
> >
> > Is this possible or should I do two queries (my actual "select fields
> > from..." and a new "select count(*) from...") to achieve it?
> >
> > Thank you very much,
> > Guido.
> >
> > --
> > Guido García Bernardo - ggarciab@itdeusto.com
> > Tfn. +34 983 54 89 08
> > ITDEUSTO - Valladolid
> >
> >
> 
>

RES: PaginatedList & 'google like' results

Posted by Leonardo Holanda <le...@atlantico.com.br>.
That's nice. The problem in my case is that the Architects in my company
does not allow us to put database layer especific code into the web
layer code. But, if it's not a problem, thats nice. But remember, if one
day you decide to chance iBatis for another framework, you will have to
touch the web code (the action in your example).

-----Mensagem original-----
De: Brice Ruth [mailto:bdruth@gmail.com] 
Enviada em: sexta-feira, 18 de março de 2005 11:25
Para: ibatis-user-java@incubator.apache.org
Assunto: Re: PaginatedList & 'google like' results


The product catalogs on www.powersentry.com, www.newpoint.com,
www.zincklysbro.dk, and www.wilkinsonswordgarden.com all use
PaginatedList to provide the Page [1] 2 3 4 ... functionality.

I have a simple Action that looks like this:

	public ActionForward gotoPage(
		ActionMapping mapping,
		ActionForm form,
		HttpServletRequest request,
		HttpServletResponse response) 
	{
		DynaActionForm myForm = (DynaActionForm) form;
		// Get PRODUCT_INFO_KEY object from session
		PaginatedList products = (PaginatedList)
request.getSession().getAttribute(Constants.PRODUCT_LIST_KEY);
		
		if (products != null) {
			try {
				String page = (String)
myForm.get("page");
				if (page.equalsIgnoreCase("next")) {
					products.nextPage();
				} else if
(page.equalsIgnoreCase("previous")) {
					products.previousPage();
				} else {
					int pageNum = new
Integer(page).intValue();
				
					products.gotoPage(pageNum);
				}
				
	
request.setAttribute(Constants.PRODUCT_LIST_CURRENT_PAGE,new
Integer(products.getPageIndex()));
				
				return
mapping.findForward("success.showCategory");
				
			} catch (NumberFormatException e) {
				return mapping.findForward("browse");
			} catch (RuntimeException e) {
				return mapping.findForward("browse");
			}
		} else {
			return mapping.findForward("browse");
		}
	}

To make this work, when I do the initial query to populate the
PaginatedList, I do as you indicated - one query for the objects, one
query for the count. To hide this double-step, you could put that in
your DAO, if you're using one (I am not).

Brice


On Fri, 18 Mar 2005 12:12:31 +0100, Guido García Bernardo
<gg...@tid.es> wrote:
> Hi,
> 
> I am using ibatis PaginatedList functionality for paging through 
> search results, and I would like to add the ability for a user to go 
> to the last page of the results (something like Google results) 
> instead of having to page through big result sets as it is done in 
> JPetStore4:
> 
>   <logic:notEqual name="orderBean" property="orderList.firstPage"
value="true" >
>     <a href="switchOrderPage.shtml?pageDirection=previous">PREV</a>
>   </logic:notEqual>
>   <logic:notEqual name="orderBean" property="orderList.lastPage"
value="true" >
>     <a href="switchOrderPage.shtml?pageDirection=next">NEXT</a>
>   </logic:notEqual>
> 
> Is this possible or should I do two queries (my actual "select fields 
> from..." and a new "select count(*) from...") to achieve it?
> 
> Thank you very much,
> Guido.
> 
> --
> Guido García Bernardo - ggarciab@itdeusto.com
> Tfn. +34 983 54 89 08
> ITDEUSTO - Valladolid
> 
>


Re: PaginatedList & 'google like' results

Posted by Brice Ruth <bd...@gmail.com>.
The product catalogs on www.powersentry.com, www.newpoint.com,
www.zincklysbro.dk, and www.wilkinsonswordgarden.com all use
PaginatedList to provide the Page [1] 2 3 4 ... functionality.

I have a simple Action that looks like this:

	public ActionForward gotoPage(
		ActionMapping mapping,
		ActionForm form,
		HttpServletRequest request,
		HttpServletResponse response) 
	{
		DynaActionForm myForm = (DynaActionForm) form;
		// Get PRODUCT_INFO_KEY object from session
		PaginatedList products = (PaginatedList)
request.getSession().getAttribute(Constants.PRODUCT_LIST_KEY);
		
		if (products != null) {
			try {
				String page = (String) myForm.get("page");
				if (page.equalsIgnoreCase("next")) {
					products.nextPage();
				} else if (page.equalsIgnoreCase("previous")) {
					products.previousPage();
				} else {
					int pageNum = new Integer(page).intValue();
				
					products.gotoPage(pageNum);
				}
				
				request.setAttribute(Constants.PRODUCT_LIST_CURRENT_PAGE,new
Integer(products.getPageIndex()));
				
				return mapping.findForward("success.showCategory");
				
			} catch (NumberFormatException e) {
				return mapping.findForward("browse");
			} catch (RuntimeException e) {
				return mapping.findForward("browse");
			}
		} else {
			return mapping.findForward("browse");
		}
	}

To make this work, when I do the initial query to populate the
PaginatedList, I do as you indicated - one query for the objects, one
query for the count. To hide this double-step, you could put that in
your DAO, if you're using one (I am not).

Brice


On Fri, 18 Mar 2005 12:12:31 +0100, Guido García Bernardo <gg...@tid.es> wrote:
> Hi,
> 
> I am using ibatis PaginatedList functionality for paging through search results,
> and I would like to add the ability for a user to go to the last page of the results
> (something like Google results) instead of having to page through big result sets as
> it is done in JPetStore4:
> 
>   <logic:notEqual name="orderBean" property="orderList.firstPage" value="true" >
>     <a href="switchOrderPage.shtml?pageDirection=previous">PREV</a>
>   </logic:notEqual>
>   <logic:notEqual name="orderBean" property="orderList.lastPage" value="true" >
>     <a href="switchOrderPage.shtml?pageDirection=next">NEXT</a>
>   </logic:notEqual>
> 
> Is this possible or should I do two queries (my actual "select fields from..."
> and a new "select count(*) from...") to achieve it?
> 
> Thank you very much,
> Guido.
> 
> --
> Guido García Bernardo - ggarciab@itdeusto.com
> Tfn. +34 983 54 89 08
> ITDEUSTO - Valladolid
> 
>

Re: R: PaginatedList & 'google like' results

Posted by Vamsee Kanakala <va...@gmail.com>.
Zoran Avtarovski wrote:

> DisplayTag (http://displaytag.sourceforge.net/) in combination with 
> iBatis is fantastic. 

I've been thinking about this too. Can you point to some code as to how 
you did this?

TIA,
Vamsee.

Re: R: R: PaginatedList & 'google like' results

Posted by Zoran Avtarovski <zo...@conads.com>.
We have two implementations we use. One fro small to medium sized lists 
where we basically use iBatis and displaytag as standard, using caching 
in iBatis to store the list. The second method, for large lists we 
customise displaytag and use two queries, one to get whole list size and 
one to get relevant display items.

All the grunt work is done in our business layer, which we customised 
specifically for iBatis/displaytag. This is probably a no-no in 
programming practice, but it fits well for what we need.

Z.

Fabrizio Gianneschi wrote:

>I like displaytag, too, but I was not able to use it in this case ('Google
>like' list), because it doesn't have a way to force by hand the number of
>results returned by the count query.
>
>If I remember well, page numbers were autocalculated by the tag itself,
>using the list passed as a parameter.
>So we switched to another less featured but simpler tag (Pager Taglib) and
>used displaytag only for small lists.
>
>It would be great if you have a working solution that we didn't found...
>
>Is this thread starting to be a little off-topic? :)
>
>Fabrizio
>
>-----Messaggio originale-----
>Da: Zoran Avtarovski [mailto:zoran@conads.com]
>Inviato: lunedì 21 marzo 2005 11.23
>A: ibatis-user-java@incubator.apache.org
>Oggetto: Re: R: PaginatedList & 'google like' results
>
>
>DisplayTag (http://displaytag.sourceforge.net/) in combination with
>iBatis is fantastic. You don't have to store the list in the session and
>if you design your app well the ibatis cache reduces your db hits to a
>minimum, improving performance. Plus it has host of added extras such as
>dynamic sorting, exporting different formats, grouping and a load more.
>
>I had no problems implementing it and the forums on sourceforge have
>been great.
>
>Z.
>
>
>Guido García Bernardo wrote:
>
>  
>
>>Thank you very much.
>>I don't like the Brice Ruth idea of using the session to store the
>>PaginatedList object.
>>
>>Finally I've done it this way, using a ListWrapper instead of using a
>>com.ibatis.common.util.PaginatedList.
>>
>>My ListWrapper implements java.util.List and contains:
>>- isFirstPage/isLastPage/isMiddlePage, getPageIndex, getPageSize
>>methods, so my JSP is 'compatible' with the previous aproach using
>>PaginatedList.
>>- getRowCount, getPageCount, so now I can do a 'google like' paginated
>>list.
>>
>>Regards.
>>
>>Fabrizio Gianneschi wrote:
>>
>>    
>>
>>>I'm used to execute two queries (count + select) for each stament in
>>>this
>>>kind of situations.
>>>The code is hidden in the DAOs, so the business/web layers are not
>>>aware of
>>>the strategy.
>>>
>>>The following is the generic method I use:
>>>
>>>private List executePagedQuery(Object params, int offset,
>>>                int limit, boolean countResults, String query, String
>>>countQuery) {
>>>
>>>       List l = super.getList(query, params, offset, limit);
>>>       if (countResults) {
>>>           Integer size = (Integer) super.getObject(countQuery, params);
>>>           ListWrapper wrapper = new ListWrapper(l, size);
>>>           return wrapper;
>>>       } else {
>>>           return l;
>>>       }
>>>   }
>>>
>>>"ListWrapper" is a simple java.util.List wrapper that espose a
>>>constructor,
>>>used to inject the maximum number of results, which PaginatedList
>>>doesn't
>>>expose.
>>>
>>>I think you should put the two queries in the same transaction, also.
>>>
>>>Regards,
>>>Fabrizio
>>>
>>>-----Messaggio originale-----
>>>Da: ggb275@tid.es [mailto:ggb275@tid.es]
>>>Inviato: venerdì 18 marzo 2005 12.13
>>>A: ibatis-user-java@incubator.apache.org
>>>Oggetto: PaginatedList & 'google like' results
>>>
>>>
>>>Hi,
>>>
>>>I am using ibatis PaginatedList functionality for paging through search
>>>results,
>>>and I would like to add the ability for a user to go to the last page
>>>of the
>>>results
>>>(something like Google results) instead of having to page through big
>>>result
>>>sets as
>>>it is done in JPetStore4:
>>>
>>> <logic:notEqual name="orderBean" property="orderList.firstPage"
>>>value="true" >
>>>   <a href="switchOrderPage.shtml?pageDirection=previous">PREV</a>
>>> </logic:notEqual>
>>> <logic:notEqual name="orderBean" property="orderList.lastPage"
>>>value="true" >
>>>   <a href="switchOrderPage.shtml?pageDirection=next">NEXT</a>
>>> </logic:notEqual>
>>>
>>>Is this possible or should I do two queries (my actual "select fields
>>>from..."
>>>and a new "select count(*) from...") to achieve it?
>>>
>>>Thank you very much,
>>>Guido.
>>>
>>>      
>>>
>>- Guido García Bernardo - ggarciab@itdeusto.com
>>ITDEUSTO - Valladolid
>>
>>    
>>
>
>  
>

Re: flushOnExecute and batch execute

Posted by Brandon Goodin <br...@gmail.com>.
It should be flushing anytime insertRole is executed. Go ahead and
file a bug in JIRA.

Brandon


On Tue, 22 Mar 2005 02:22:15 -0800, Amad Fida <am...@gmail.com> wrote:
> I have my sql map defined as follows...
> 
>   <cacheModel id="roleCache" type="LRU" readOnly="false" serialize="true">
>     <flushInterval hours="24"/>
>     <flushOnExecute statement="insertRole"/>
>     <flushOnExecute statement="updateRole"/>
>     <flushOnExecute statement="deleteRole"/>
>     <flushOnExecute statement="deleteAllRoles"/>
>     <property name="size" value="200"/>
>   </cacheModel>
> 
>   <insert id="insertRole">
>     INSERT INTO ROLES
>     (roleKey, roleName, roleDescription, roleComments, createUser,
> updateUser, createDate, updateDate)
>     VALUES
>     (#roleKey#, #roleName#, #roleDescription#, #roleComments#,
> #createUser#, #updateUser#, #createDate#, #updateDate#)
>   </insert>
> 
> there are other statements as well but this will explain my problem.
> When I execute "insertRole" with a SqlMapExecutor.executeBatch(), my
> cache doesn't get flush. Is not suppose to do that or am I missing
> something.
> 
> Thanks
> 
> Amad
> 
>

flushOnExecute and batch execute

Posted by Amad Fida <am...@gmail.com>.
I have my sql map defined as follows...

  <cacheModel id="roleCache" type="LRU" readOnly="false" serialize="true">
    <flushInterval hours="24"/>
    <flushOnExecute statement="insertRole"/>
    <flushOnExecute statement="updateRole"/>
    <flushOnExecute statement="deleteRole"/>
    <flushOnExecute statement="deleteAllRoles"/>
    <property name="size" value="200"/>
  </cacheModel>

  <insert id="insertRole">
    INSERT INTO ROLES
    (roleKey, roleName, roleDescription, roleComments, createUser, 
updateUser, createDate, updateDate)
    VALUES
    (#roleKey#, #roleName#, #roleDescription#, #roleComments#, 
#createUser#, #updateUser#, #createDate#, #updateDate#)
  </insert>

there are other statements as well but this will explain my problem. 
When I execute "insertRole" with a SqlMapExecutor.executeBatch(), my 
cache doesn't get flush. Is not suppose to do that or am I missing 
something.

Thanks

Amad


R: R: PaginatedList & 'google like' results

Posted by Fabrizio Gianneschi <fa...@gruppoatlantis.com>.
I like displaytag, too, but I was not able to use it in this case ('Google
like' list), because it doesn't have a way to force by hand the number of
results returned by the count query.

If I remember well, page numbers were autocalculated by the tag itself,
using the list passed as a parameter.
So we switched to another less featured but simpler tag (Pager Taglib) and
used displaytag only for small lists.

It would be great if you have a working solution that we didn't found...

Is this thread starting to be a little off-topic? :)

Fabrizio

-----Messaggio originale-----
Da: Zoran Avtarovski [mailto:zoran@conads.com]
Inviato: lunedì 21 marzo 2005 11.23
A: ibatis-user-java@incubator.apache.org
Oggetto: Re: R: PaginatedList & 'google like' results


DisplayTag (http://displaytag.sourceforge.net/) in combination with
iBatis is fantastic. You don't have to store the list in the session and
if you design your app well the ibatis cache reduces your db hits to a
minimum, improving performance. Plus it has host of added extras such as
dynamic sorting, exporting different formats, grouping and a load more.

I had no problems implementing it and the forums on sourceforge have
been great.

Z.


Guido García Bernardo wrote:

> Thank you very much.
> I don't like the Brice Ruth idea of using the session to store the
> PaginatedList object.
>
> Finally I've done it this way, using a ListWrapper instead of using a
> com.ibatis.common.util.PaginatedList.
>
> My ListWrapper implements java.util.List and contains:
> - isFirstPage/isLastPage/isMiddlePage, getPageIndex, getPageSize
> methods, so my JSP is 'compatible' with the previous aproach using
> PaginatedList.
> - getRowCount, getPageCount, so now I can do a 'google like' paginated
> list.
>
> Regards.
>
> Fabrizio Gianneschi wrote:
>
>> I'm used to execute two queries (count + select) for each stament in
>> this
>> kind of situations.
>> The code is hidden in the DAOs, so the business/web layers are not
>> aware of
>> the strategy.
>>
>> The following is the generic method I use:
>>
>> private List executePagedQuery(Object params, int offset,
>>                 int limit, boolean countResults, String query, String
>> countQuery) {
>>
>>        List l = super.getList(query, params, offset, limit);
>>        if (countResults) {
>>            Integer size = (Integer) super.getObject(countQuery, params);
>>            ListWrapper wrapper = new ListWrapper(l, size);
>>            return wrapper;
>>        } else {
>>            return l;
>>        }
>>    }
>>
>> "ListWrapper" is a simple java.util.List wrapper that espose a
>> constructor,
>> used to inject the maximum number of results, which PaginatedList
>> doesn't
>> expose.
>>
>> I think you should put the two queries in the same transaction, also.
>>
>> Regards,
>> Fabrizio
>>
>> -----Messaggio originale-----
>> Da: ggb275@tid.es [mailto:ggb275@tid.es]
>> Inviato: venerdì 18 marzo 2005 12.13
>> A: ibatis-user-java@incubator.apache.org
>> Oggetto: PaginatedList & 'google like' results
>>
>>
>> Hi,
>>
>> I am using ibatis PaginatedList functionality for paging through search
>> results,
>> and I would like to add the ability for a user to go to the last page
>> of the
>> results
>> (something like Google results) instead of having to page through big
>> result
>> sets as
>> it is done in JPetStore4:
>>
>>  <logic:notEqual name="orderBean" property="orderList.firstPage"
>> value="true" >
>>    <a href="switchOrderPage.shtml?pageDirection=previous">PREV</a>
>>  </logic:notEqual>
>>  <logic:notEqual name="orderBean" property="orderList.lastPage"
>> value="true" >
>>    <a href="switchOrderPage.shtml?pageDirection=next">NEXT</a>
>>  </logic:notEqual>
>>
>> Is this possible or should I do two queries (my actual "select fields
>> from..."
>> and a new "select count(*) from...") to achieve it?
>>
>> Thank you very much,
>> Guido.
>>
> - Guido García Bernardo - ggarciab@itdeusto.com
> ITDEUSTO - Valladolid
>


Re: R: PaginatedList & 'google like' results

Posted by Zoran Avtarovski <zo...@conads.com>.
DisplayTag (http://displaytag.sourceforge.net/) in combination with 
iBatis is fantastic. You don't have to store the list in the session and 
if you design your app well the ibatis cache reduces your db hits to a 
minimum, improving performance. Plus it has host of added extras such as 
dynamic sorting, exporting different formats, grouping and a load more.

I had no problems implementing it and the forums on sourceforge have 
been great.

Z.


Guido García Bernardo wrote:

> Thank you very much.
> I don't like the Brice Ruth idea of using the session to store the 
> PaginatedList object.
>
> Finally I've done it this way, using a ListWrapper instead of using a 
> com.ibatis.common.util.PaginatedList.
>
> My ListWrapper implements java.util.List and contains:
> - isFirstPage/isLastPage/isMiddlePage, getPageIndex, getPageSize 
> methods, so my JSP is 'compatible' with the previous aproach using 
> PaginatedList.
> - getRowCount, getPageCount, so now I can do a 'google like' paginated 
> list.
>
> Regards.
>
> Fabrizio Gianneschi wrote:
>
>> I'm used to execute two queries (count + select) for each stament in 
>> this
>> kind of situations.
>> The code is hidden in the DAOs, so the business/web layers are not 
>> aware of
>> the strategy.
>>
>> The following is the generic method I use:
>>
>> private List executePagedQuery(Object params, int offset,
>>                 int limit, boolean countResults, String query, String
>> countQuery) {
>>
>>        List l = super.getList(query, params, offset, limit);
>>        if (countResults) {
>>            Integer size = (Integer) super.getObject(countQuery, params);
>>            ListWrapper wrapper = new ListWrapper(l, size);
>>            return wrapper;
>>        } else {
>>            return l;
>>        }
>>    }
>>
>> "ListWrapper" is a simple java.util.List wrapper that espose a 
>> constructor,
>> used to inject the maximum number of results, which PaginatedList 
>> doesn't
>> expose.
>>
>> I think you should put the two queries in the same transaction, also.
>>
>> Regards,
>> Fabrizio
>>
>> -----Messaggio originale-----
>> Da: ggb275@tid.es [mailto:ggb275@tid.es]
>> Inviato: venerdì 18 marzo 2005 12.13
>> A: ibatis-user-java@incubator.apache.org
>> Oggetto: PaginatedList & 'google like' results
>>
>>
>> Hi,
>>
>> I am using ibatis PaginatedList functionality for paging through search
>> results,
>> and I would like to add the ability for a user to go to the last page 
>> of the
>> results
>> (something like Google results) instead of having to page through big 
>> result
>> sets as
>> it is done in JPetStore4:
>>
>>  <logic:notEqual name="orderBean" property="orderList.firstPage"
>> value="true" >
>>    <a href="switchOrderPage.shtml?pageDirection=previous">PREV</a>
>>  </logic:notEqual>
>>  <logic:notEqual name="orderBean" property="orderList.lastPage"
>> value="true" >
>>    <a href="switchOrderPage.shtml?pageDirection=next">NEXT</a>
>>  </logic:notEqual>
>>
>> Is this possible or should I do two queries (my actual "select fields
>> from..."
>> and a new "select count(*) from...") to achieve it?
>>
>> Thank you very much,
>> Guido.
>>
> - Guido García Bernardo - ggarciab@itdeusto.com
> ITDEUSTO - Valladolid
>

Re: R: PaginatedList & 'google like' results

Posted by Guido García Bernardo <gg...@tid.es>.
Thank you very much.
I don't like the Brice Ruth idea of using the session to store the 
PaginatedList object.

Finally I've done it this way, using a ListWrapper instead of using a 
com.ibatis.common.util.PaginatedList.

My ListWrapper implements java.util.List and contains:
- isFirstPage/isLastPage/isMiddlePage, getPageIndex, getPageSize 
methods, so my JSP is 'compatible' with the previous aproach using 
PaginatedList.
- getRowCount, getPageCount, so now I can do a 'google like' paginated list.

Regards.

Fabrizio Gianneschi wrote:

>I'm used to execute two queries (count + select) for each stament in this
>kind of situations.
>The code is hidden in the DAOs, so the business/web layers are not aware of
>the strategy.
>
>The following is the generic method I use:
>
>private List executePagedQuery(Object params, int offset,
>                 int limit, boolean countResults, String query, String
>countQuery) {
>
>        List l = super.getList(query, params, offset, limit);
>        if (countResults) {
>            Integer size = (Integer) super.getObject(countQuery, params);
>            ListWrapper wrapper = new ListWrapper(l, size);
>            return wrapper;
>        } else {
>            return l;
>        }
>    }
>
>"ListWrapper" is a simple java.util.List wrapper that espose a constructor,
>used to inject the maximum number of results, which PaginatedList doesn't
>expose.
>
>I think you should put the two queries in the same transaction, also.
>
>Regards,
>Fabrizio
>
>-----Messaggio originale-----
>Da: ggb275@tid.es [mailto:ggb275@tid.es]
>Inviato: venerdì 18 marzo 2005 12.13
>A: ibatis-user-java@incubator.apache.org
>Oggetto: PaginatedList & 'google like' results
>
>
>Hi,
>
>I am using ibatis PaginatedList functionality for paging through search
>results,
>and I would like to add the ability for a user to go to the last page of the
>results
>(something like Google results) instead of having to page through big result
>sets as
>it is done in JPetStore4:
>
>  <logic:notEqual name="orderBean" property="orderList.firstPage"
>value="true" >
>    <a href="switchOrderPage.shtml?pageDirection=previous">PREV</a>
>  </logic:notEqual>
>  <logic:notEqual name="orderBean" property="orderList.lastPage"
>value="true" >
>    <a href="switchOrderPage.shtml?pageDirection=next">NEXT</a>
>  </logic:notEqual>
>
>Is this possible or should I do two queries (my actual "select fields
>from..."
>and a new "select count(*) from...") to achieve it?
>
>Thank you very much,
>Guido.
>
- 
Guido García Bernardo - ggarciab@itdeusto.com
ITDEUSTO - Valladolid


R: PaginatedList & 'google like' results

Posted by Fabrizio Gianneschi <fa...@gruppoatlantis.com>.
I'm used to execute two queries (count + select) for each stament in this
kind of situations.
The code is hidden in the DAOs, so the business/web layers are not aware of
the strategy.

The following is the generic method I use:

private List executePagedQuery(Object params, int offset,
                 int limit, boolean countResults, String query, String
countQuery) {

        List l = super.getList(query, params, offset, limit);
        if (countResults) {
            Integer size = (Integer) super.getObject(countQuery, params);
            ListWrapper wrapper = new ListWrapper(l, size);
            return wrapper;
        } else {
            return l;
        }
    }

"ListWrapper" is a simple java.util.List wrapper that espose a constructor,
used to inject the maximum number of results, which PaginatedList doesn't
expose.

I think you should put the two queries in the same transaction, also.

Regards,
Fabrizio

-----Messaggio originale-----
Da: ggb275@tid.es [mailto:ggb275@tid.es]
Inviato: venerdì 18 marzo 2005 12.13
A: ibatis-user-java@incubator.apache.org
Oggetto: PaginatedList & 'google like' results


Hi,

I am using ibatis PaginatedList functionality for paging through search
results,
and I would like to add the ability for a user to go to the last page of the
results
(something like Google results) instead of having to page through big result
sets as
it is done in JPetStore4:

  <logic:notEqual name="orderBean" property="orderList.firstPage"
value="true" >
    <a href="switchOrderPage.shtml?pageDirection=previous">PREV</a>
  </logic:notEqual>
  <logic:notEqual name="orderBean" property="orderList.lastPage"
value="true" >
    <a href="switchOrderPage.shtml?pageDirection=next">NEXT</a>
  </logic:notEqual>

Is this possible or should I do two queries (my actual "select fields
from..."
and a new "select count(*) from...") to achieve it?

Thank you very much,
Guido.

--
Guido García Bernardo - ggarciab@itdeusto.com
Tfn. +34 983 54 89 08
ITDEUSTO - Valladolid



RES: PaginatedList & 'google like' results

Posted by Leonardo Holanda <le...@atlantico.com.br>.
Hi Guido, I had bad time with paginated in web application. I think it's
more appropriate to Swing/AWT apps. I'm simply using
queryForList(statement, paramObj, (pageNumber * pageSize), pageSize).

Leo.


-----Mensagem original-----
De: ggb275@tid.es [mailto:ggb275@tid.es] 
Enviada em: sexta-feira, 18 de março de 2005 08:13
Para: ibatis-user-java@incubator.apache.org
Assunto: PaginatedList & 'google like' results


Hi,

I am using ibatis PaginatedList functionality for paging through search
results, 
and I would like to add the ability for a user to go to the last page of
the results 
(something like Google results) instead of having to page through big
result sets as it is done in JPetStore4:

  <logic:notEqual name="orderBean" property="orderList.firstPage"
value="true" >
    <a href="switchOrderPage.shtml?pageDirection=previous">PREV</a>
  </logic:notEqual>
  <logic:notEqual name="orderBean" property="orderList.lastPage"
value="true" >
    <a href="switchOrderPage.shtml?pageDirection=next">NEXT</a>
  </logic:notEqual>

Is this possible or should I do two queries (my actual "select fields
from..." 
and a new "select count(*) from...") to achieve it?

Thank you very much,
Guido.

-- 
Guido García Bernardo - ggarciab@itdeusto.com
Tfn. +34 983 54 89 08
ITDEUSTO - Valladolid