Google App Engine

Posted April 29th, 2009 in Developers by Marcin Pilarczyk

The answer to the question from my last post is: Swedish. Although Linus Torvalds was born in Finland he belongs to Swedish minority.

A few days ago I was asked to prepare a very small application that does only one thing – adds items of some type to a list and allows anonymous visitors to filter the list with certain criteria. My first estimation for the task was around 6-8h so just a bit longer evening ;)

There are various technologies I could choose but as I’d recently heard that Google decided to release a brand new hosting environment for java applications. Thus, I’ve decided to select this possibility and incidentally pick up something new. Yet, there was only Python supported by Google. Finally we’ve got Java support as well!!! :) After reading a documentation I’ve realized that Google released a really powerful tool. It allows to create real multi tier applications within integrated environment where you can create your view layer in java – no mixing technologies, common libraries, one IDE, perfect mix in my honest opinion.

There is of course a documentation published so I’m not going to multiply it. The issue I would like to write about is influence of GWT usage on application architecture.

GWT is a very specific library. Although it allows to develop a web interface in a pure Java it also limits number of usable classes. Additionally all used types must be serializable.

Any more sophisticated application uses some kind of persistence, I have decided to use JDO. An simple persistent class definition may look like that:

@PersistenceCapable(identityType = IdentityType.APPLICATION, table = "Reservation")
public class ReservationEntity {
 
    private static final long serialVersionUID = 1L;
 
    @PrimaryKey
    @Persistent(valueStrategy =
          IdGeneratorStrategy.IDENTITY)
    private Long id;
 
    @Persistent
    private UserEntity user;
}

As you can see it’s only an annotated POJO class. However, persistence manager does some “magic” with the class. It has additional proxy fields that keep the entity object connected to a real DB entity. This are so called “attached objects”. I hope you can see the problem. We have objects connected to DB that are transferred through layers and finally transformed by GWT into Javascript objects. No chance… :) A big flaw in GWT architecture. Such object transfer throws an exception. Yet, there are two approaches suggested:

  • transfer objects… yeah, those old TO objects that were abandoned when EJB 3.0 appeared
  • extension of persistence manger and usage of reflection to cut off from proxies

Both solutions have disadvantages. The former causes redundancies in the code and the latter is slow and not maintainable. Anyway, we need to choose something as there is no possibility to transfer pure persistent objects into a view layer. A sample TO class relevant to our ReservationEntity may look like that:

public class ReservationTO implements Serializable {
    private static final long serialVersionUID = 1L;
 
    private UserTO user;
}

Note, that UserEntity class was transformed into its transferable equivalent.

To sum up. Google Apps has introduced a new powerful tool with limitations that you need to be aware of. The next limitation concerns indexes in queries to a repository in Google Apps… Maybe tomorrow ;)

Tags: , ,

No comments so far...

Leave a Reply