RSS Feed
15
Oct.
2003

Minor changes in the backend

Last night I tweaked the RSS generator servlet a little bit. The pubDate field is now formatted correctly and the lastBuilDate contains the right date. This was broken before. While working on my administration interface I realized that I must redesign a part of the API in my Enterprise JavaBean that deals with the creation and updating of weblog entry objects. Currently I create a WeblogEntryTO (transfer object) as follows:

WeblogEntryTO newEntry = weblogService.createWeblogEntry(headline, body);
newEntry.setVisible(true);
weblogService.updateWeblogEntry(newEntry);
The create method currently performs the following steps:
  • It creates a new instance of WeblogEntryTOImpl
  • It assigns an ID
  • It stores the entry in the database via Hibernate
As you can see the createWeblogEntry method acts like a Factory thus creating concret implementations of the interface WeblogEntryTO. This design has some major drawbacks:
  • Adding new attributes to WeblogEntryTO may force a change to the createWeblogEntry signature
  • Implementing a preview function is somewhat tricky
You may ask why the client doesn't simply create an instance of WeblogEntryTOImpl directly? Because WeblogEntryTOImpl provides several methods which should be visible to Hibernate only. The interface WeblogEntryTO therefore doesn't export all methods of WeblogEntryTOImpl. I think I will change the API in the following way:
WeblogEntryTO newEntry = weblogService.prepareNewEntry();
newEntry.setHeadline("..");
newEntry.setBody("..");
newEntry.setVisible(true);
weblogService.storeEntry(newEntry);
The important thing is that the prepareNewEntry method would not store the entry in the database and it would not assign a real ID but an UNASSIGNED_ID. Since the interface provides no method for chaning the ID the client cannot disorganize the system. When the client invokes storeEntry(...) the storeEntry method will look at the ID and either add a new entry via calling hibernateSession.save() or updating the entry via hibernateSession.update().
This way it would be easier to implement a preview (and discard if needed) function.