One of the biggest problem which is commonly faced in searches is pagination; On the first day of my new job, I was asked to looked the performance issues related in the search functionality of the application. When I looked at the application, application is slow when the users gets a search results of magnitude of 6000 records( each record had 10 fields to be displayed) and all the results were displayed in a single HTML page (Even if you had designed one search implementation, you would have guessed what the problem is).
There is no pagination concept implemented for this search/ problem, its a logical thing to say this search program is using whole lots of memory and slow. Assuming the search queries are already fine-tuned, Slowness can be mainly attributed to the HTML rendering by the browser. IE browser render the complete HTML and then displays it to the user so the slowness can be easily be found compared to Firefox 2, where the browser starts displaying the data as it receives (rather completely render it and displays it).
Given this background, Now we started seriously looking at pagination as the only option. In pagination, could think three approaches as a potential solutions
- Real time pagination on the server side.
- Criteria Caching based pagination on Server side.
- Pagination on the UI front.
Lets go in details of each one of them.
Real time pagination on the server side :
This is an approach where from the UI, always pass the search criteria plus the page start record and the end record (or size of the page). So your server implementation will have these two extra arguments along with your query and returns you only the required result set which needs to be passed to front end.
On the implementation front, you could handle this scenario at two levels
- Write a stored procedure which takes your criteria and start and end record (or Size) for the page as argument and using ‘cursors’ you can return only the required result set, for more details on oracle specific result set using cursor click here
- Say you are using ORM tools like hibernate, they make our life even easier you could try something like
Query q = s.createQuery( “your query….” );
q.setMaxResults(PAGE_SIZE);
q.setFirstResult(PAGE_SIZE * pageNumber);
List page = q.list();
- For more details on this hibernate approach click here
Lets looks at the pros and cons of this approach
- Its a real time pagination search, say your query is based on order by name, on the first page we show say 25 records, in the mean while say another user deletes few records (say 20 to 25th record gets deleted), now when the first user click the next button, the request goes as original criteria and retrieve the records from 26th to 50th record and we return 26 to 50 th records (because of the deletion, ideally we should have displayed from 20th to 45th records), essentially now we are not showing 5 records this is a disadvantage. For the same example, addition of records ‘could’ be an advantage for this approach.
Criteria Caching based pagination on Server side
This is an approach where all records matching to the search criteria will be fetched from the database to the the server and cached. Caching is based the search criteria and a timeout period.
From the UI point of view, request will contain the search criteria plus the start record and the size( r the end record) to be fetched.
Lets looks at the pros and cons of this approach
- This solution should fairly work for most of the search cases, unless you have a requirement for real time pagination.
- When Caching is considered, Caching algorithm plays an important role and this also has to take care of the timeout period and the memory allocated for the caching mechanism.
- Arriving on the timeout period is quite crucial as this directly impacts your performance of the search. Too low timeout (is very near to real time pagination case) will cause too many hits to your database and can cause slowness also has the drawbacks of real time pagination. Too long timeout period will have the drawback of having out-dated data on the server cache.
Pagination on the UI front
This is an approach where all the records corresponding the search criteria will be retrieved from the database and held in the controller of the UI Framework and using custom tag libraries the records could be displayed in the Jsp/ Servlet.
Here are some of the recommendations for writing your own custom pagination tab lib
- The bean will have attributes for collection of all the records, total number of pages, records per page and start record number for the current page.
- On the first display of the page, read all the corresponding records for this page and store the bean in HTTP Session.
- On the selection of the next page, previous page, etc.,; retrieve the bean from the HTTP Session and then calculate which data needs to be displayed.
Lets looks at the pros and cons of this approach
- This would be dream design approach for small volume search results (where memory is not a constraint).
- Most the cases, you do have a memory constraint, hence this may not be a feasible approach.
Written by Ravi Nallakukkala on March 30th, 2007 with 2 comments.
Read more articles on Design and Hibernate.
Nope.
Weblogic 8 (including all service packs) supports only jdk 1.4.x
For more information…
http://e-docs.bea.com/platform/suppconfigs/configs81/81_over/overview.html
Written by Ravi Nallakukkala on March 26th, 2007 with no comments.
Read more articles on Servers.
Dozer is a powerful, but simple Java Bean to Java Bean mapper that recursively copies data from one object to another.
Dozer supports simple property mapping, complex type mapping, bi-directional mapping, implicit-explicit mapping, as well as recursive mapping. This includes mapping collection attributes that also need mapping at the element level.
This is different from Bean utils, which copies the data recursively for the object which has the same property names. Bean-Utils has a restriction for working with complex data types.
Dozer tool can be found here
here’s some of the key advantages found on Dozer
- Can define the mapping / exlude mapping in a configuration mapping file.
- Support for Spring (tested Dozer 3.0/ 3.1 with Spring 2.0).
Recommanded Usage Scenario:
- Highly recommanded for the scenarios, where the usage of design patterns for Data Transfer Object (Dto) and Business Objects (Bo).
- For scenario of Data transfer from UI form elements to Data transfer objects (Dto).
Disadvantages for Dozer
- I used this tool under Java 5/ Spring 2.0. Dozer was instantiated using Spring. our architecture was like, all the business Objects (Bo) were placed in one project. Had a facade (facade has Dto) for a set of functionalitie. Now the problem was the definition of spring configuration for the dozer, as Dto and Bo were present in various projects, so this created a need for the definition spring configuration definition on a top level project than at leaf level.
Written by Ravi Nallakukkala on March 25th, 2007 with no comments.
Read more articles on Spring and Tools.
PHP Designer 2007 - Personal is a free IDE for PHP for both beginner- and professional developers. PHP Designer 2007 is designed to boost your productivity and enhance the process of editing, debugging, analyzing and publishing application- and Websites powered by PHP, HTML, MySQL, XML, CSS, JavaScript, VBScript, Java, C#, Perl, Python and Ruby.
Download PHP Designer 2007 - Personal Edition here
PHP Designer 2007 editor has a good class browser and debuger for PHP, to have the debugger enabled you need have php installed in your machine (tested with PHP Designer 2007 - Personal 5.0.2 and php5.2.1).
Not satisfied with this editor, never mind. Click here for some more list of PHP Editors.
Written by Ravi Nallakukkala on March 25th, 2007 with no comments.
Read more articles on Editors.
Need less to say this is a extreamly popular free java editor, http://www.eclipse.org/
WSAD/ RSA 6.x are based on Eclipse technology.
Please look here for any Eclipse plugins
Written by Ravi Nallakukkala on March 25th, 2007 with no comments.
Read more articles on Editors.
You can use “for each” java syntax for iterating through the arrays, probably you are already aware you can definitely use for each syntax for iterating over classes implementing iterator.
here’s an example for iterating a array using for each syntax
public class test{
public static void main(String[]arg){
String []arr = new String[]{”one”,”two”};
for(String each: arr) System.out.println(each);
}
}
Output:
one
two
Written by Ravi Nallakukkala on March 25th, 2007 with no comments.
Read more articles on Java/ J2EE.
Environment Maven 2.0/ Windows XP/ Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_09-b03)
I had a peculiar problem with Maven 2.0, my builds were working fine and one fine monday morning, I got a problem
Caused by: java.lang.RuntimeException: Not a valid URL: file:/C:/Documents and Settings/rnallakukkala/.m2
/repository/com/dpwn/newops/server/core/model/1.0-SNAPSHOT/model- 1.0-SNAPSHOT.jar
at org.jboss.util.file.ArchiveBrowser.getBrowser(Unknown Source)
at org.hibernate.ejb.Ejb3Configuration.scanForClasses(Ejb3Configuration.java:588)
… 75 more
Caused by: java.net.URISyntaxException : Illegal character in path at index 18: file:/C:/Documents and Settings/rnallakukkala/.m2/repository/com/dpwn/newops/server/core/model/1.0-SNAPSHOT/model-1.0-SNAPSHOT.jar
at java.net.URI$Parser.fail(URI.java:2816)
at java.net.URI$Parser.checkChars(URI.java:2989)
at java.net.URI$Parser.parseHierarchical(URI.java:3073)
at java.net.URI$Parser.parse(URI.java:3021)
at java.net.URI.<init>(URI.java:578)
when trying to look for a dependency jar (this dependency jar is available in my local repository)
Additional Information for this problem
- Found that this problem has been reported to maven here
- Root problem is that there is a space in the maven repository path location.
- Related bug has been raised in Java here, unfortunately closed as “will not be fixed”.
Solution
- Change the local repository location to a different path without spaces.
Configuring your Local Repository
- You can specify your user configuration in ${user.home}/.m2/settings.xml
- Location can be modified through the following configuration changes (to the above file)
<settings>
...
<localRepository>/path/to/local/repo/</localRepository>
...
</settings>
Written by Ravi Nallakukkala on March 25th, 2007 with no comments.
Read more articles on Build.
Advantages:
- Hibernate Beans are easier to implement since you don’t need any interface coding.
- Queries can be dynamic and perform faster (at least on WebLogic and JBoss)
- Hibernate offers a more object-oriented approach. You can map is-a relationships as subclasses.
- For data transfer you can use Hibernate Beans as DTOs if you want (and if it’s applicable). You can even fill ‘custom’ DTOs with query results just with one line of code using the select-new construct.
Disadvantages:
- Hibernate Beans are not automatically ‘locked’ for others while used during a transaction. This can lead to inconsistent data when more clients concurrently modify the same data.
-Object Pooling is an Issue
Written by Ravi Nallakukkala on March 25th, 2007 with no comments.
Read more articles on Hibernate and Java/ J2EE.