Friday, April 28, 2006

Bodington DB Layer and Empty Subclasses

The Bodington VLE has its own DB layer that allows Java objects to be stored and loaded from the database without having to touch JDBC and SQL. If you have an object that can already be persisted in the database layer and want to subclass it without adding any instance fields (so you don't need an extra table) you can store both the orginal class and the subclass in the same table. The reason this can work is that for every object stored in the database the DB layer keeps track (through the objects table) which Java type it should map to. The SQL to allow this subclassed object to be stored is something like: INSERT INTO classes (type, super_type, db_name, table_name, java_class) VALUES(109, 10, null, null, 'org.bodington.server.resources.NewSubclass') The type being the new ID for this type. And the super_type being the persisted class that you are subclassing. Using this we could have a new resource class for every type of resource and then we can use polymophism, rather than having switch statements and constants.

Thursday, April 27, 2006

GNER and Wifi

GNER Wifi service is designed to provide a Wifi service on trains. On Monday I was travelling back from a meeting on the 16:05 from Leeds to London Kings Cross (in the quiet coach) and I opened up my iBook, straight away it detected the network and I associated with it. However no matter what I did it refused to give me a DHCP lease. So all I can report is don't rely on Wifi being available as it may be broken.

Tuesday, April 11, 2006

Save Parliament! Stop the Legislative and Regulatory Reform Bill

I hope the Save Parliament campain gains a little more media attention again. If you're in the UK please spend 5 minutes reading the site.

Monday, April 10, 2006

GeoURL

Thanks to Joe for pointing me to GeoURL which basically says how you should put location metadata into your web pages. After a quick edit of my blog templates you'll now know that I live in High Wycombe, it would be nice if there were some support from blogger for this so that when you set you location in your profile it could exposes the geourl metadata as well, but hey.

Wednesday, April 05, 2006

Compiling for Older JVMs

I've been doing some development on WebLearn from home today and had to perform build to be deployed on our test server. Now normally I develop on the same software as we run on the production machines but I just happened to only have the Java 1.5 SDK installed on my home machine. Not really thinking I set the target to 1.4 so that the outputted class files were compatible with the 1.4 JVM that we use on our testing and production machines. This is done through our ant build file with something like: <javac srcdir="src" destdir="build" source="1.4" target="1.4"/> The cruital bit I thought was the target attibute. However after shipping the build to the sysadmin guys they come back saying they're getting a stack trace when deploying the application: java.lang.NoSuchMethodError: java.lang.StringBuffer.insert (ILjava/lang/CharSequence;) Ljava/lang/StringBuffer; org.bodington.servlet.BuildingServlet.init (Unknown Source) which shows that although the class files could be run by the 1.4 JVM they used API calls that only exist in the 1.5 JVM. Now at first this is comfusing because the code compiles fine with a 1.4 compiler and classes so what has changed as all the 1.4 API calls should exist in 1.5 (apart from the deprecated ones that were removed). The problem comes from some code similar to this: StringBuffer str1 = new StringBuffer("123456"); StringBuffer str2 = new StringBuffer(" "); str1.insert(2, str2); Under the 1.4 StringBuffer API there isn't the method insert(int offset, StringBuffer str) so the compiler uses the method insert(int offset, Object str). In the 1.5 API again there isn't a perfect match but there is a better one than the Object one, it is the method insert(int offset, CharSequence str) and as StringBuffer implements CharSequence this closer API call is used. We could have fixed the code by changing it to: str1.insert(2, (Object)str2); but this just fixes one call and there maybe others that we didn't find. The real solution to this is to compile against the 1.4 classes when you are using the 1.5 compiler. Todo this you can use something like the following: <javac srcdir="src" destdir="build" source="1.4" target="1.4" bootclasspath="/home/buckett/j2sdk1.4.2_11/jre/lib/rt.jar" extdirs=""/> But of course for this you need to have downloaded the 1.4 SDK so I might as well have used the 1.4 compiler. However it is very likely that the 1.5 compiler contains better optimisations so WebLearn should run faster. However in future I think I'll just use the 1.4 compiler as it isn't worth the hassel. Sun does have a document on this this topic but labels it Cross Compiling. Why both the Sun and the ant documentation don't mention that when using the target option you probably also want to use the bootclasspath option. It seems obvious looking back but it wasn't at the time.

Monday, April 03, 2006

Thunderbird Address Book and LDAP

Here at Oxford University we have an LDAP server that contains details of all the staff and students, although it isn't yet a production service it is available to computing services (OUCS) staff members. At first I tried configuring Thunderbird to access the LDAP server but found that searches took far too long so I just forgot about it and carried on using Thunderbird without LDAP support. Then one of my colleagues Paul Trafford was trying to switch from Eudora to Thunderbird and was complaining that Thunderbird was taking ages to perform searches so I had another look into it. The reason that the searches were taking ages is that it was performing queries on attributes that don't have good indexes and so these required full scans taking a long time. Unfortunately finding and changing the queries used by Thunderbird isn't an easy task. After a little Googling the first thing to come up was a page explaining how LDAP attributes map onto Address Book properties and although this was useful it didn't explain how to change the search that was begin run. A few people have blogged this and someone else's experience with Thunderbird and LDAP was helpful although it didn't go all the way to solving my problems. After a little more Googling I found another page that have details of hidden preferences for LDAP searches. Now using this and the search that Paul had used in Eudora I was able to recreate a useful and fast LDAP search. Here are the lines for pref.js in your Thunderbird profile directory. You should only edit this file when Thunderbird is not running as it gets saved when Thunderbird closes. user_pref("ldap_2.autoComplete.directoryServer", "ldap_2.servers.Oxford"); user_pref("ldap_2.servers.Oxford.description", "Oxford"); user_pref("ldap_2.servers.Oxford.filename", "abook-1.mab"); // Oxford uses an objectClass of oucsOrganizationPerson to show a person. user_pref("ldap_2.servers.Oxford.uri", "ldap://ldap.ox.ac.uk:389/ou=people,dc=ox,dc=ac,dc=uk??sub?(objectClass=oucsOrganizationalPerson)"); // Our LDAP stores some other useful data that should be mapped to attributes so we can search on it. user_pref("ldap_2.servers.default.attrmap.Custom1", "universityBarcode"); user_pref("ldap_2.servers.default.attrmap.Custom2", "oucsUsername"); user_pref("ldap_2.servers.default.attrmap.Custom3", "uniqueIdentifier"); user_pref("ldap_2.servers.default.attrmap.Department", "oucsDivision"); // Although we have a displayname field it isn't indexed so search and diplay common name. user_pref("ldap_2.servers.default.attrmap.DisplayName", "cn"); user_pref("ldap_2.servers.default.attrmap.PreferMailFormat", "preferredMail"); // Search on Oxford stuff user_pref("mail.addr_book.quicksearchquery.format", "?(or(Custom1,=,@V)(Custom2,=,@V)(Custom3,=,@V)(DisplayName,c,@V))"); Adding this to your config means that you can search on the common name, barcode, uniqueID and username and it is fast. It doesn't mean that you will be able to use the LDAP server when composing mails though as it seems that some of these preferences aren't used by that code and so the search still looks at the default attributes and as a result very slow here. This has only been tested with Thunderbird 1.5

Sunday, April 02, 2006

New Eclipse Milestone (3.2M6)

A couple of days ago Eclipse 3.2M6 was released with some more nice features. It's getting to the point that I might switch to the new version (currently using the stable build, 3.1.2) for my main version as long as it is reasonably stable. I'll probably have a go next week and see how it goes.