Archive for the ‘Computers’ Category

Spring pagination support for Hiberate

May 18, 2006
 by 

As I have said before I love Spring and Hibernate; however, there is no Spring support for Hibernate’s pagination API. Why am I am not sure. Maybe they are supporting it now but heres what I did. First I made and abstract object I called ‘Page’. I also have a Solr subclass of this object but I will cover that later.


public abstract class Page {

    public List results;
    private int pageNumber;
    private int resultsPerPage;
    private int totalCount;
    private String queryString;
    private Integer totalPages = null;

    /*
        Getters and setters
    */

}


public class PageHibernate extends Page implements HibernateCallback {

    public PageHibernate() { }

    public PageHibernate(String queryString, int page, int resultsPerPage) {
        this.setPageNumber(page);
        this.setResultsPerPage(resultsPerPage);
        this.setQueryString(queryString);
    }


    public final Object doInHibernate(Session session)
            throws HibernateException {

        Query query = session.createQuery(this.getQueryString());
        query.setFirstResult((getPageNumber() – 1) * getResultsPerPage());
        query.setMaxResults(getResultsPerPage());

        return this.results = query.list();
    }
}


Since Spring abstracts your Hibernate interaction with HibernateDaoSupport you dont have to write straight criteria calls to Hibernate if you dont want to. Spring does create simple implementation to allow to write straight HQL and many other functions but not pagination. Rather than tackle this problem at this angle I decided to make the abstract class ‘Page’ that you see above for all my data stores. Anyway, here’s how easy it is to then hit the database with this object properly constructed and have it returned ready for use.


public Page getPageOfThings(int page, int resultsPerPage, String orderBy) {

    PageHibernate newPage = new PageHibernate(
            ”FROM Thing”, page, resultsPerPage);

    getHibernateTemplate().executeFind(newPage);

    List count = getHibernateTemplate().find(“SELECT count(*) FROM Thing”);

    newPage.setTotalCount(Integer.parseInt(count.get(0).toString()));

    return newPage;

}

Spring and Hibernate

March 12, 2006
 by 

Spring and Hibernate make Java web application development so much easier I barely remember what I did without them. Despite the steep learning curve, Hibernate especially so, they work so well together thanks to Spring. Spring is probably the most “open” open source framework out there for Java. It can and will play nice with tons of other frameworks like Tiles, SiteMesh, Velocity, JSF, as well as backend technologies like iBatis, Hibernate, ACEGI, and countless others.

I have begun to like them so much at the office that I am using it a home in all of my side projects. This blog will hopefully shed some light on some of these technologies to hopefully give back. Blogs like this are especially important because although these frameworks aren’t relatively new, there can be some holes in the documentation. Two books that helped me through my trouble were Matt Raible’s book “Spring Live!” and “Hibernate in Action”

Multimedia Flash video art project

August 2, 2005
 by 

something-beautiful.gif
I created this way back in Junior year of college for a class in which I was doing somewhat mediocre due to my lack in the introductory level discussions. Yea, yea. Anywho, I’ve been tuning and tweaking it on a off over time, but here it is. Please dont sue me for the use of copyrighted works. It was for school.

(click image to view)

Brand identity for Grape wine bar

July 21, 2005
 by 

A friend of my was attempting to open a wine bar which unfortunately never got opened. In the short time we worked together we went through several iterations but never came to a conclusion. He had a hard time time deciding whether he wanted something modern, traditional or somewhere in between. So, what I try and do with my clients is attempt to jog their thought process. This happens often.

grape.gif

grape5.gif



grape3.gif

My newest and last Flash movie for my site

March 25, 2005
 by 

micro2.gifThis is the final Flash thing that I made for my site. I am not sure why I carried on so long. I guess its because Flash was, at the time, the “flashiest” way to get your message across. I gotta say, it got me some business but its pretty out of date. Nevertheless, is some of my better work and it took many long hours to produce.
(click image to view)

eSec Lending Flash promotion

December 6, 2004
 by 

esec.gifWhen I was a Sophomore in college my guidance counselor contacted me for a job. Turned out to be a pretty cool gig and I learned a lot, not just about Flash, but consulting with a larger firm. This was definitely one of my better experiences and they were very sure on what they wanted which is very rare in the consulting business. It took me a total of about 100 hours which is pretty good considering its size. I’d love to do another one but I just dont have the time.

My first Flash site

November 23, 2004
 by 

micro1.gifThis is one of my first Flash works and I am still very proud of it. Its always hard to create something usable while your learning it for the first time. Flash is very powerful, yet convoluted language involving multiple events at different points in time. Now that I have moved more in the way of engineering I am going to start to learn Flex.

(Click the image to view)

Copyright © 2005-2011 John Clarke Mills

Wordpress theme is open source and available on github.