: Techiey Dreamz :

Sunday, February 12, 2006

Pagination in Hibernate !


Pagination in Hibernate and EJB3

by gavin@hibernate.org | Link

Pagination, I want to display "next" and "previous" buttons to the user, but disable them if there are no more, or no previous query results. But I don't want to retrieve all the query results in each request, or execute a separate query to count them. So, here's the correct approach:

public class Page {      private List results;   private int pageSize;   private int page;      public Page(Query query, int page, int pageSize) {              this.page = page;       this.pageSize = pageSize;       results = query.setFirstResult(page * pageSize)           .setMaxResults(pageSize+1)           .list();      }      public boolean isNextPage() {       return results.size() > pageSize;   }      public boolean isPreviousPage() {       return page > 0;   }      public List getList() {       return isNextPage() ?           results.subList(0, pageSize-1) :           results;   }}        

You can return this object to your JSP, and use it in Struts, WebWork or JSTL tags. Getting a page in your persistence logic is as simple as:

public Page getPosts(int page) {    return new Page(         session.createQuery("from Posts p order by p.date desc")        page,        40    );}        

The Page class works in both Hibernate and EJB 3.0.

Related links :

Check-out the discussion about ScrollableResults over paging here.

Thursday, November 03, 2005

Firefox tip

If you minimize Firefox, it will (automagically) reclaim memory that it?s no longer using.

Apparently this is a workaround for the Firefox bug where it doesn?t reclaim memory for tabs that you?ve closed (a long time FireFox / Mozilla bug I?ve blogged about in the past). Now when Noel told me this, I immediately tried it and saw my memory usage go from 153 megs* to 52 megs. Awesome. Thanks Noel. (Oh and this works in Thunderbird also so I strongly recommend minimizing your Firefox and Thunderbird windows every few hours).

[-via-]

Tuesday, October 25, 2005

AJAX RSH and AMASS

Ajaxian

Brad Neuberg has posted full instructions for working with both the Really Simple History framework as well as AMASS, the AJAX MAssive Storage System.

The Really Simple History framework

The Really Simple History (RSH) framework makes it easy for AJAX applications to incorporate bookmarking and back and button support. By default, AJAX systems are not bookmarkable, nor can they recover from the user pressing the browser's back and forward buttons. The RSH library makes it possible to handle both cases.

Download the Really Simple History framework


AMASS

The AJAX MAssive Storage System (AMASS) uses a hidden flash applet to allow JavaScript AJAX applications to store an arbitrary amount of sophisticated information on the client side. This information is permanent and persistent; if a user closes their browser or navigates away from the web site, the information is still present and can be retrieved later by the web page. Information stored by web pages is private and locked to a single domain, so other web sites can not access this information.

AMASS makes it possible to store an arbitrary amount of sophisticated data, way pass the 4K limit of cookies or the 64K limit of Internet Explorer's proprietary client-side storage system. An AMASS-enabled web site can store up to 100K without user permission. After 100K, users are prompted on whether the web site can store the requested amount of information. Users can approve or deny the storage request. The AMASS system informs the client-side application on whether the storage request was allowed or denied.

View the README files for both, where you can download the frameworks; they are both open source under a BSD license, so feel free to use them in your own consulting.

Example of using the storage handler

function statusHandler(status) {if (status == Storage.SUCCESS) {  var results = storage.get(keyName);  alert("Results from statusHandler="+results);}else if (status == Storage.PENDING) {  alert("Results pending approval of storage space from user");}else if (status == Storage.FAILED) {  alert("Storage request denied");}};
Download the AJAX MAssive Storage System

Sunday, October 23, 2005

Free SIP soft phone

Avaya?s venerable PC soft phone is now available free of charge, in order to get you acquainted with Avaya and introduce the look and feel of their phones. It?s a cool alternative to X-Lite, though it disapointingly only runs on Windows. Check it out at Avaya?s site.

Escalator powered by Duracell

 

This is a really clever idea, placing a faux battery cover at the foot of an escalator to make it look as if the contraption is being operated by a pair of giant Duracell batteries. What size would you call those, anyway? Size ZZ? Anyway, it's very eye-catching and me like it. The only problem, however, is that if the escalator breaks down it kind of sends a bad, al beit subliminal, message about the battery, doesn't it?

 

Tuesday, October 11, 2005

ROWNUM and ROWID

What is ROWNUM and ROWID ??

First of all, both are covered in the SQL Reference, "Basic Elements of Oracle SQL", Chapter 2:
http://download-west.oracle.com/docs/cd/B10501_01/server.920/a96540.pdf

They are also both referred to as pseudo-columns. That is, they are not "real" columns that will show up when you DESC a table. They don't actually exist anywhere in the database. But they're available for you to use.

In fact, ROWNUM only exists for a row once it is retrieved from a query. It represents the sequential order in which Oracle has retrieved the row. Therefore it will always exist, be at least 1, and be unique (among the rows returned by the query). Obviously it will change from query-to-query.

What about ROWID?

ROWID actually represents the physical location of the record/row in the database. That being the case, it is (according to Oracle documentation) the fastest way to retrieve a particular row. Faster than an index, even.

[source : http://thinkoracle.blogspot.com/2005/10/rownum-and-rowid.html]

: techieydreamz :

First techiey dreamz

This is my first techiey dreamz ;) .. Jus' to be catchy added 'y" @ the end in 'techiey' .. Let me start my dream here ..! Wait n Watch !!

: techieydreamz :