Jul 18 2008

Managing databases for ORM based applications

adam

Powerful ORM frameworks like hibernate and Ibatis and more recently JPA based ORM frameworks like Toplink, Hibernate and openJPA have taken a great deal of drudgery and error prone code out of the average enterprise application codebase. Many IDEs now provide powerful tool support for writing and maintaining code based on these frameworks. One effect of all this has been to move attention away from the database and into code, particularly in instances where developers are using automatic ddl generation from their ORM framework.

In such a situation, developers often don’t think about the effect that changes to their java code are having on the underlying database. Before there has been an initial release this may not necessitate migration of production data, but it can lead to large amounts of time wasted when changes in code necessitate schema changes, particularly if these changes clash with schemas other developers have established in their development environment. After an initial production release it can lead to serious problems if developers alter domain objects which are mapped using ORM frameworks. Simple XML or Annotation changes can wipe out or make redundant whole segments of the production database when released into the wild, or completely alter the semantics of existing data.

There is no doubt that a new discipline is required for developers when writing code using ORM frameworks. Paritcularly where there are multiple developers and potentially multiple production releases (pretty well every agile project I have ever known). This discipline should focus on the database schema that ORM frameworks are generating. Such schemas need to be versioned in the same way as the codebase is versioned. Luckily a tool called Liquibase exist for exactly this problem.

Liquibase provides for the creation and maintanence of database schemas and their data. I have not yet used it to make changes on production databases but we have been using it in development and it has had a very positive effect on productivity as developers no longer have to spend time working out why their tests are no longer working only to eventually discover that it is due to data changes conflicting with their existing schema.

Liquibase manages schemas and data through change sets and the database itself. It stores the change set ids in the database along with a checksum for the change set so that it can determine if the change set has been altered, invalidating it against that database.

With Liquibase in place the database can be generated and/or updated without the use of the ORM frameworks auto generation of DDL, in fact it is essential that this be turned of. For Spring applications a data migrator bean can be configured to automatically generate or update the database on startup of the application context and check that the schema is valid for application data mappings. If this is not desirable Liquibase has Ant targets and Maven goals that can be executed.


Mar 18 2008

weblogic descriptor

adam

Just so I don’t have to google this again, here is how to fix the weblogic.xml descriptor when you get this message:

library is on the classpath of this project, but is not in the weblogic.xml file

Adding a library reference to the deployment descriptor

1. Select and expand the project in question in the Project Explorer view.
2. Locate the node labeled WebLogic Deployment Descriptor and expand it.
3. Find the node labeled J2EE Libraries.
4. Right-click on the J2EE Libraries node and select Add.
5. Click Browse and choose the library that should be referenced.
6. Adjust the reference information as necessary.
7. Click on the Ok button.


Mar 17 2008

Testing Flex

adam

Flex applications are reasonably easy to write, and they certainly build themselves a lot faster than standard web applications which need a rich user interface. Testing them is a bit of a problem though. I looked as ASUnit initially, but the whole framework was so Windows-centric that I gave up in disgust. I could tell after a very short time that even if I got it working on my Mac there would be no way to run it in an automated build loop.

After that I started playing with FlexUnit. This framework is much more generic and quite simple to use. The most confusing thing about it is that there seems to be a FlexUnit project on Sourceforge as well as Google code and they don’t appear to have anything to do with each other. I couldn’t make head ‘nor tail of the Sourceforge one but the version on Google code, which appears to have some Adobe support behind it was simple to install and use and this article gives quite detailed instructions about how to use it.

Testing in Flex is still not always that easy, even when you have a reasonably easy to use framework like FlexUnit. You still have to write code which can be unit tested. This is the real value of rigorously testing your code. You have to write your code in such a way as it can be tested. When you do this your code becomes more loosely coupled and more highly decomposed. This leads to not only more testable code, but to more re-usable code…”Vive le testing”

Once you have tests you need a constant integration loop to run your tests and keep you honest. Initially we didn’t think this would be possible, turns out we were wrong. Antennae is an open source project on Google code which addresses exactly this problem. A detailed explanation of how to install and use it can be found in the Flex Cookbook. There is a fair bit of mucking around involved, but with a bit of determination you can reasonably easily get your Flex codebase to build and execute it’s FlexUnit tests in a constant integration loop.


Mar 15 2008

Migration Complete!

adam

Ok, my weblog has found a new home. It started life at Voodoo Programming, a domain I let lapse when I began consulting too regularly to do any work there. It then lived a private life on my laptop for a while, it didn’t see a lot of action during that time. Now it has a new home at oneadam. Hopefully I will be a bit more diligent about blogging things again, now that I have my vanity domain, I have been extremely slack of late. I look forward to broadening my blogging horizons, perhaps not just limiting myself to tech tricks and notes to self.


Mar 8 2008

Multiline Labels

adam

Doh, blew quite a bit of time on this thinking that there must be some way to make a Label multiline… there isn’t! Have to use a Text control. Note to self: Google first, think and experiment later.


Feb 16 2008

Flex BlazeDS Spring an Integration Story

adam

At the Melbourne Spring User Group (MSUG) meeting in Feb I presented on integrating an Adobe Flex Rich Internet Application with a J2EE services tier using Spring as the integration glue and BlazeDS for lightweight binary data transfer using ActionScript message Format (AMF). I have made the slides from that presentation available here.

Many people seem to think that their has to be some hard decision made about whether to go with the sexy flash based user interface of a Flex application, or the robust, scalable dependability delivered by a Java based application. I say “Why not have the best of both worlds?”. The approach I outline is completely Open Source and free and it is trivially easy to configure BlazeDS to use the Spring bean factory to expose a standard Spring service facade to remoting calls by a Flex application.

Documentation for BlazeDS can be found here. An explanation of the Adobe example Spring factory can be found here. it contains the source code as well. You will need to copy it and paste it into your project source tree.

I hope this is useful to people.


Feb 10 2008

J2ME Logging

adam

As soon as an enterprise developer starts developing for mobile devices the paradigm changes. For me reliable logging is almost the first thing I missed in J2ME. Even System.out, were you to be so crass as to use it ;) , is unreliable on some devices.

I found a sourceforge project called MicroLog this looks very promising. It is log4j compatible and the download is only the source code so you simply add it to your project source tree. It is quite lightweight and considering the development time wasted when you cannot get reliable debug information it seems well worth it.


Jan 20 2008

Flex as a J2EE MVC Tier

adam

I began my web programming life using Perl and PHP and I don’t like the idea of becoming a language snob, however, I have to admit I have been somewhat of a Java purist over the past couple of years in particular and I saw no reason to make an exception for the presentation tier.

I was thinking the other day about that saying: ‘When your only tool is a hammer, everything looks like a nail‘. This came up when I was looking at working AJAX functionality into a Spring MVC web application. I had already worked JQuery into the UI for effects and to speed up querying the DOM. I had an custom tag library called SpringLayout, which I was using to integrate error messages and speed up validation responses. I had Yahoo! tabs going for client side tabs, and I started thinking about how difficult this application would be to maintain, particularly if that person wasn’t me.

What I was really after was a Rich Internet Application (RIA). Because Java is my hammer, the RIA looked like a nail. But I started wondering whether there might be an easier way to achieve the rich user experience without sacrificing the well tested and proven Java application… along came Flex 3. Flex uses a component based approach based on ActionScript. I’m not going to go into the details of the Flex application framework, except to say that writing RIAs is extremely simple and intuitive using Flex and flex builder.

One of the interesting side effects of moving to a non-Java presentation tier technology is that you quickly become aware of areas where you have allowed application logic to bleed into the presentation tier. Without some type of artificial barrier, such as having to translate objects into ActionScript, it is quite possible for POJO based applications to leak some of their business logic out into the MVC layer. Kept to a minimum this is not the end of the world, however I prefer to have a complete separation, particularly since we often have to expose business services to automated clients.

BlazeDS has been an interesting tool in coming to terms with Flex as the client for my java based applications. It is an open source offering from adobe, allowing Flex clients to make RPC calls or access JMS queues and topics and has recently been released as a Beta. It performs the translation to ActionScript Message Format (AMF) transparently, greatly easing the effort in developing a transport and translation service for your Flex client. It is essentially a cut down version of the Adobe LiveCycle Server.

I will be blogging in more detail on the technical issues I have come across in coding in Flex and using Flex Builder as well as plugging in BlazeDS.


Nov 11 2007

MyEclipse tomcat will not deploy

adam

This is really irritating. I can’t even count the number of times the MyEclipse hot deployment to Tomcat has gone pear shaped. Fixing this particular problem can really waste a lot of time.

Symptoms: Repeated message that MyEclipse cannot redeploy to Tomcat as the deployment is locked. Various recommendations follow that you stop tomcat and redeploy, ect and they all fail. When this really starts getting weird is when you undeploy remove the deployment in MyEclipse, restart Eclipse and Tomcat and still the same stuff happens.

Solution: You have to get really medieval on it.

  1. Remove the deployment.
  2. Stop tomcat
  3. Refresh the project
  4. Start Eclipse from the command line using the -clean flag i.e. $eclipse -clean or c:\eclipse.exe -clean (in windows)

Aug 27 2007

Eclipse plugins

adam

Below is a list of eclipse 3.2 plugins which I like and whos URLs I am constantly forgetting. hopefully I will never need to google these again :)

1. The Maven 2 plugin provides the ability to search the various Maven repos for dependecies. It also allows the prject to be built by the Maven builder, automatically manages your POM and will attach source if requested. This plugin was a little buggy initially but seems to be fine now. If you are building your project with Maven 2 I really recommend this.

Update site: http://m2eclipse.sonatype.org/update/

2.Emma plugin for eclipse. This provides full coverage analysis as a plugin for eclipse. It allows you to run your test suite under Emmas coverage analysis tool and provides immediate feedback as well as code highlighting to indicate sections of code which have not been visited by tests. This plugin is really useful for keeping you honest.

Update site: http://update.eclemma.org/

3. a) Subclipse is a subversion plugin from tigris. It is free and provides pretty much all the same features you are used to seeing for CVS, but for SVN. It also has some nice features for navigating into branches and branching with uncommited code, etc

The eclipse update site for this is: http://subclipse.tigris.org/update_1.4.x

b)Another Subversion plugin for elipse is Subversive. i changed to this plugin recently because it seems to resolve conflicts in a manner more like the old CVS conflict resolution tool. The icon set is not quite as nice as the Subclipse set, but it seems to perform slightly better for conflict resolution.

Update site: http://www.polarion.org/projects/subversive/download/1.1/update-site/

4. Veloedit is a Velocity template editor. Very basic, but better than nothing when you are writing velocity templates.

Update site: http://veloedit.sourceforge.net/updates/

5. XFire plugin. This is quite a useful plugin if you want IDE support for xFiring service endpoints.

Update site: http://dist.codehaus.org/xfire/update/

6. Spring IDE. If you are using Spring this is a must-have plugin. Provides bean file support for dependencies as well as making sure that class names are valid.

Update site: http://dist.springframework.org/release/IDE