Mittwoch, 25. November 2009

App Egnine for Java Perfomance - Best practices

Some best practices... If you have other recommendations - drop me a line :)

General
0. Repeat after me: It is stupid to use Google App Engine - Because it is an early preview (check out http://appengine.google.com)
But:
- It's a cool philosophy - relieving us from maintaining servers and such
- The community and the guys at google are really helpful and work hard to improve - nice!

1. Read the blog of GAE:
http://gae-java-persistence.blogspot.com/

2. Follow the mailing list of GAE:
http://groups.google.com/group/google-appengine

Datastore specific
1. Use Key only queries whenever possible
http://gae-java-persistence.blogspot.com/2009/10/keys-only-queries.html

2. Use batch gets to fetch stuff from the datastore
http://gae-java-persistence.blogspot.com/2009/10/executing-batch-gets.html

3. Reuse Persistence Managers
Creating Persistence Managers takes time (at lest a bit). Avoid that by simply reusing an open persistence Manager

Donnerstag, 29. Oktober 2009

web.xml servlet mappings and GUICE to the rescue

If you are working on bigger servlet web projects you are quickly annoyed by two facts:
1) web.xml gets bigger bigger and bigger filled with thousands of url mappings and lots of boilerplate code
2) the URL mappings cannot be configured via RegExp. For instance you cannot do prefix matching on URLs. Not nice.

But Guice (a project at Google) comes to the rescue. It tackles the problem in a very clean way -  you end up with a java file where you can write regexp code mapping to servlets -- and the web.xml is almost empty. Easy, straight forward and cool to maintain.

The following steps are required:

1) Add the three GUICE jars to your WEB-IF/lib dir (btw: AAAAH @Google: switch to Maven!)
2) Add the @Singleton Annotation to your all your servlets
3) Add the GuiceListener and filter to your web.xml and generate the classes.
4) Rewrite your previously formulated urls and servlets in web.xml intoMyServletModule
5) Remove all mappings from web.xml

Note: You can only write one mapping definition per .serve(SERVLET). This might mean you have to rewrite your mappings a bit, but it certainly clears up the code...

works:
serve("/journals","/journals/*").with(JournalBrowserServlet.class);

wrong:
serve("/journals","/journals/*").with(JournalBrowserServlet.class);
serve("/journals","/journals/*").with(JournalBrowserServlet.class);


Done :) Thanks to the GUICE Team for the excellent work :)

More information (including source for the listeners and stuff) can be found on
- http://code.google.com/p/google-guice/wiki/ServletModule
and
- http://code.google.com/p/google-guice/wiki/GoogleAppEngine (A bit Google App Engine specific)

Samstag, 24. Oktober 2009

Karmic Koala 32 bit and GWT: libstdc++.so.5: cannot open shared object file: No such file or directory

After an update to Ubuntu 9.10 (32 bit) the GWT hosted mode (1.7.x) does not work any more because there was a switch to libstdc 6.

Solution:
Download the jaunty libstdc and install it:

1. Download
http://archive.ubuntu.com/ubuntu/pool/universe/g/gcc-3.3/libstdc++5_3.3.6-17ubuntu1_i386.de


2. Extract libstdc 5:

dpkg-deb --fsys tarfile libstdc++5_3.3.6-17ubuntu1_i386.deb  | tar -O --extract './usr/lib/libstdc++.so.5.0.7' > libstdc++.so.5  


3. Move libstdc to libary folder:
sudo mv libstdc++.so.5 /usr/lib


4. notify ubuntu:
sudo ldconfig 

works

Mittwoch, 21. Oktober 2009

Design mistakes you should omit

Found at: http://blog.webdistortion.com/2009/10/01/9-usability-mistakes-even-the-big-boys-make/

Freitag, 16. Oktober 2009

JPA vs JDO on the Google App Engine for Java

Much fuzz is going on when it comes to "my favorite object relational mapper".

Recently I started a project using the Google App Engine (for Java of course ;) ). The underlying datastore supports JPA and JDO as standard - and many people ask: "Which one is better - the heck".

The answer is not really simple...

Quick summary:
JPA
- a bit more lightweight in terms of the amount of annotations needed
- more SQL like query syntax
- some features missing (objects not detachable by JPA arg)

JDO
- a bit more stuff to write into your classes (each field has to be annotated eg)
- the syntax is more Java like (&& operator instead of AND and.. == instead of =)
- in the moment really mature in terms of features needed
- better support by Google team (this may change, but there is at least more documentation and so on...
- and NO! JDO is not dead or so. There were simply some political tendencies that forced to put JDO under the Apache umbrella and make a new RDBMS mapping system.

And the most important facts behind the real political stuff of JPA vs. JDO is imho best described by the datanucleus team:
http://www.datanucleus.org/products/accessplatform_1_1/jdo_jpa_faq.htm


 Hope that helps..

Donnerstag, 2. Juli 2009

Netbeans RCP and MAC OS X results in java.lang.NoClassDefFoundError: javax/swing/GroupLayout$Group

Just recently I got feedback from a user that got a huge

java.lang.NoClassDefFoundError: javax/swing/GroupLayout$Group
error when firing up a Netbeans RCP application under MAC OS X.

After investigating into it the problem it seemed that the problem was Java 5. When using Java 6 it threw the error under the Mac. Well. If you know the policy of Apple regarding Java it is quite unhandy to advice the users to sign up for a developer account, download java 6, search for scripts, reset the Java JDK and so on.

Luckily there is a simpler solution:
If you are in Netbeans you can switch the Forms between using Java 6 style of deploy a library along with your application. check yout the Inspector and then "Layout Generation Style".

Freitag, 26. Juni 2009

Generating an update center for Netbeans RCP

The customer nowadays expects to get the latest and best version of the software automatically. If you code your applications using the Netbeans Platform 6.5 (or rich client platform) this is really easy.
  1. Add the dependency "Auto Update Services" to your module
  2. Click on "new..." and then on new update site. Fill out everything and your are done...
  3. In your main module (The mothership of all modules) click on "create nbms". This creates everything that is needed to perform an update. Then copy these files to the place you specified in 2). And you are done :)
Do not forget to increase the version of your modules. Otherwise your application will not find an update :)