This is a static archive of the original page - if you experience problems with these widgets contact me directly.

GenericServiceImplementation


[ Show snip ]

Change 1 at 2007-01-28 20:11:57 by Herbert Poul (Kahless):

__Page in Progress__ This page IS NOT finished.. you propably want to ignore it..
no idea if it will ever become useful .. but.. well .. it's just a collection of thoughts
so i don't forget how i implemented my generic gwt services ;)


This page describes how i built a generic service which automatically executes and returns 
named hibernate queries.

The idea is pretty much based on the IBM developerworks article: {link:Don't repeat the DAO!|http://www-128.ibm.com/developerworks/java/library/j-genericdao.html} just adopted for the use with GWT.

1 Technology

For this to work i used
- GWT (of course)
- Spring to manage my RemoteServiceServlet's
- Hibernate to access my data
- {link:CGLIB|http://cglib.sourceforge.net/} to create a dynamic proxy.

1 Goal

The goal is pretty simply... Write as few code as possible.. for many data access
operations this should be quite easy esspecially if you only need to fetch non-sensitive 
data where more or less no business logic is involved but only a simple hibernate query
like 'from Config' which would return all 'Config' objects in the database.

There are at least two java classes (actually... interfaces) which we need to create for 
GWT: one which extends RemoteService and is implemented by our servlet and one containing
all AsyncCallback methods - but this should be all we need.

1.1 BaseInformationService

{code}
public interface BaseInformationService extends RemoteService {
  /**
   * Returns a list of all configurations.
   * @gwt.typeArgs 
   */
  public List listConfig();
}
{code}

1.1 BaseInformationServiceAsync

{code}
public interface BaseInformationServiceAsync {
  public void listConfig(AsyncCallback callback);
}
{code}

1 Configuration

The only information which is actually needed for retrieving a simple list of 'Config'
objects is the hibernate query. This can be simply configured as named query within any
hibernate mapping file (or as annotation):

{code}
from Config
{code}

1 Implementation

Since i were not able to create a proxy solely through spring configuration i 
created a FactoryBean which uses CGILIB to create a dynamic proxy which extends
GWT's RemoteServiceServlet and implements any GWT service i want it to.



1 TODO finish this !