客户端排序+休眠寻呼? [英] Client Side sorting + Hibernate Paging?

查看:111
本文介绍了客户端排序+休眠寻呼?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用GWT的UI和Hibernate / Spring的buisness-layer.Following GWT小部件用于显示记录。( http://collectionofdemos.appspot.com/demo/com.google.gwt.gen2.demo.scrolltable.PagingScrollTableDemo/PagingScrollTableDemo.html < /a>)。我假设排序是在客户端完成的。



我没有检索整个结果集,因为它的巨大。
我使用

  principals = getHibernateTemplate()。findByCriteria(criteria,$ b $ fromIndex,numOfRecords); 

检索数据。在Hibernate层中排序没有标准。



这种方法没有给出正确的行为,因为它只对客户端中的当前数据集进行排序。



这个问题的最佳解决方案是什么?



注意:我可以使用UI框架获取主排序列和其他排序列。
可能我可以使用hibernate层中的primary-sort-column对结果进行排序吗?

解决方案

您需要在服务器上排序。



然后您可以: 将完整的结果集发送给客户端并在客户端处理分页。问题是结果集可能很大,无法从数据库中检索并发送到客户端。

  • 处理服务器端的分页。客户端和服务器一次只从数据库请求一个页面。接下来的问题是,每次你向db请求一个特定的页面时,你都会一次又一次地排序相同的数据来提取页面1,页面2等等。这可能是一个大数据库的问题。


  • 在两者之间有一个权衡

    >


    • 设置一个限制,比如说300个项目
    • 服务器根据order by

    • 服务器保存缓存中的结果集(最多301项)

    • 客户端逐页请求服务器

    • 服务器使用缓存处理分页

    • 如果有301个项目,客户端将显示命中列表包含300多个项目,它已被截断 。




  • 注1:通常,客户不在乎他是否可以没有去到最后一页。您可以改进解决方案,先计算总行数(此时不需要订购),以便您可以显示对用户更好的消息,例如, 结果包含2023个元素,只能查看前300个。注意2:如果您在不使用任何顺序标准的情况下一页接一页地请求数据,大多数db(至少Oracle)不保证任何排序。因此,如果向数据库发出两个请求,则可能在第1页和第2页中有相同的项目。如果多个项目具有相同的值(例如相同日期),则会发生同样的问题。数据库不保证具有相同值的元素之间的任何顺序。如果是这种情况,那么我会建议使用PK作为最后的命令标准(例如 ORDER BY date,PK ),以便在一致的方式。注意3:我讲的是客户端和服务器,但是您可以根据自己的具体情况调整想法。




    I use GWT for UI and Hibernate/Spring for buisness-layer.Following GWT widget is used to display the records.(http://collectionofdemos.appspot.com/demo/com.google.gwt.gen2.demo.scrolltable.PagingScrollTableDemo/PagingScrollTableDemo.html).I assume the sorting is done in client side.

    I do not retrieve the entire result set since its huge. I use

    principals = getHibernateTemplate().findByCriteria(criteria,
                        fromIndex, numOfRecords);
    

    to retrive data.Theres no criteria for sorting in Hibernate layer.

    This approach does not give the correct behaviour since it only Sorts the current dataset in the client.

    What is the best solution for this problem?

    NOTE : I can get the primary-Sort-column and other sort Columns using the UI framework. May be I can sort the result using primary-sort-column in the hibernate layer?

    解决方案

    You need to sort on the server.

    Then you can either:

    • send the complete resultset to the client and handle pagination on the client side. The problem is that the resultset may be big to retrieve from db and sent to the client.

    • handle the pagination on the server side. The client and the server request only one page at a time from the db. The problem then is that you will order the same data again and again to extract page 1, page 2, etc. each time you ask the db for a specific page. This can be a problem with large database.

    • have a trade-off between both (for large database):

      • Set a limit, say 300 items
      • The server asks the db for the first 301 items according to the order by
      • The server keept the resultset (up to 301 items) in a cache
      • The client request the server page by page
      • The server handles the pagination using the cache
      • If there are 301 items, the client displays "The hit list contains more than 300 items. It has been truncated".

    Note 1: Usually, the client doesn't care if he can't go to the last page. You can improve the solution to count for the total number of rows first (no need of order by then) so that you can display message that is better to the user, e.g. "Result contained 2023 elements, only first 300 can be viewed".

    Note 2: if you request the data page by page in the database without using any order criterion, most db (at least Oracle) don't guarantee any ordering. So you may have the same item in page 1 and 2 if you make two requests to the database. The same problem happens if multiple items have the same value that is use to order by (e.g. same date). The db doesn't guarantee any ordering between element with the same value. If this is the case, I would then suggest to use the PK as the last order criterion to order by (e.g. ORDER BY date, PK) so that the paging is done in a consistent way.

    Note 3: I speak about client and server, but you can adapt the idea to your particular situation.

    这篇关于客户端排序+休眠寻呼?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆