Big Al\’s Blog

Software Engineering, Enterprise Computing and The Digital Divide

Blog moved to http://www.webparation.org

Posted by Big Al on September 29, 2006

Hi all,

I’ve decided to host my blog off the free WordPress hosting service. My blog will continue at: http://www.webparation.org

Posted in Useless Drivel | Comments Off on Blog moved to http://www.webparation.org

I’ve got to get me one of those

Posted by Big Al on September 27, 2006

The Sony ReaderWhile reading the news today I noticed this entry on a PC World blog: http://blogs.pcworld.com/staffblog/archives/002849.html

The entry reports the shipping of the E-Book device that I’ve been waiting so dearly for the last few years. Supposedly, the device will be out by next month (hopefully to nice marketing people at Sony won’t forget the European market).

To get full information on the device click on to Sony Reader’s web-site: http://www.learningcenter.sony.us/assets/itpd/reader/

Posted in Useless Drivel | Comments Off on I’ve got to get me one of those

Wrong number(s)

Posted by Big Al on September 24, 2006

I’m currently on a consulting job in Russia (Republic of Karelia to be exact) and something peculiar has just happened. Within the last few hours I’ve had several calls from people dialling the wrong number; One call on my Danish number and two on my newly set-up Russian number. Three things came to mind;

  1. The Russian secret service is for some reason trying to get me
  2. A satellite fell down and calls are being wrongly routed
  3. Freak coincidence – people are just too drunk to dial the right number

Without doubt it is just a freak coincidence, but I was sound asleep when I received both calls which annoy me as it had taken me quite some time to fall asleep (and now here I am writing a blog entry).

Anyway, let me try to fall back to sleep.

Posted in Useless Drivel | 4 Comments »

Hugh Masekela Concert in Kampala, Uganda!

Posted by Big Al on September 2, 2006

This evening I went for a Hugh Masekela concert and I can only say that I was completely blown away. I love South African Jazz and enjoy Hugh Masekela’s music above all other. I was even lucky enough to get an after party ticket which gave me the opportunity to greet Mr. Masekela.

Hugh Masekela Live In Concert

One day I hope that I’ll be as skilled doing what I do, as Mr. Masekela is at doing what he does.

You can read more information about Hugh Masekele on Wikipedia

Posted in Events | Comments Off on Hugh Masekela Concert in Kampala, Uganda!

Comment-driven development

Posted by Big Al on August 19, 2006

I’m currently in Tanzania where I am giving training to a group of software developers of one of our business partners.

Yesterday I was giving training on various documentation techniques that could be applied in the various phases (requirements, design, building, testing, and implementation) of a software project. While talking about documentation techniques during the building (i.e. coding) phase I mentioned “inline comments” as one of the obvious techniques. I talked about how sometimes when solving a problem using an unfamilar programming language it could be beneficial first to write the comments in step-by-step form. e.g. the problem of “Creating a variable number of random positioned and coloured lines in an image (in PHP)” could be written out in comments like this:

<?php
    // 1. Create the image where the lines will appear
    // 2. Find out how many lines to create
    // 3. For each line
    //    - Determine a random position
    //    - Determine a random colour
    //    - Insert the line into the image
    // 4. Output image
?>

From that we can then do the code one comment at a time:

<?php
    // 1. Create the image where the lines will appear
    $width = 100;
    $height = 100;
    $image = imagecreate($width, $height);
    imagefill ($image, 0, 0, imagecolorallocate($image, 255, 255, 255));

    // 2. Find out how many lines to create
    $lineCount = (int)$_GET["line_count"];

    // 3. For each line
    for ($i = 0; $i <= $lineCount; $i++) {
        // Determine a random position
        $randomPosX1 = rand(0, $width);
        $randomPosX2 = rand(0, $width);
        $randomPosY1 = rand(0, $width);
        $randomPosY2 = rand(0, $width);

        // Determine a random colour
        $randomColour = imagecolorallocate($image, rand(0, 255), rand(0, 255), rand(0, 255));

        // Insert the line into the image
        imageline($image, $randomPosX1, $randomPosY1, $randomPosX2, $randomPosY2, $randomColour);
    }

    // 4. Output image
    header("Content-type: image/png");
    imagepng($image);
    imagedestroy($image);
?>

Anyway, this code is not revolutionary or anything. The funny thing was that I coined the term comment-driven development for this approach. I think that is a bit funny considering all the x-driven development techniques that exists out there.

More on my trip to Tanzania later.

Posted in Software Engineering | Comments Off on Comment-driven development

Moved the JavaScript Validation Library to Google Code Repository

Posted by Big Al on August 8, 2006

Since WordPress don’t actually allow file storing on the free blog hosting I decided to set-up a project on the Google Code Repository: http://code.google.com/p/simple-jsvalidator/

You can get the code through the Subversion WebDAV front-end: http://simple-jsvalidator.googlecode.com/svn/tags/1.0.0/  or if you want to commit changes to the code you can e-mail me and I’ll add you as a project member (allowing you to commit your changes).

Posted in Software Engineering, Web Programming | Comments Off on Moved the JavaScript Validation Library to Google Code Repository

Portal Server Feature Matrix Added

Posted by Big Al on August 6, 2006

I’ve added a page (https://lykke.wordpress.com/portal-servers/) where I wll try to maintain a feature matrix of the various portal servers. Please be patient while I add the information, feel free to add your comments on the page if I have missed out on something.

Posted in Portal Development, Software Engineering | Comments Off on Portal Server Feature Matrix Added

Upgraded to Liferay 4.1.0

Posted by Big Al on August 6, 2006

Liferay 4.1.0 was finally released on Thursday (3. August) and I happily downloaded both the Professional (Tomcat Bundle) and Enterprise (JBoss/Tomcat Bundle) edition. I have A LOT of comments on this, but for now I’ll give you my very first impression.

Now, I don’t prefer to use Microsoft Windows but since this is the only supported desktop operating system in the organisation I work for I’ve decided to keep XP on my workstation (my servers are all Ubuntu Linux). One of Window’s ugly faces is the filename length limit including parent directory names (of, I think 256 characters). This will certainly give you problems when installing the Enterprise version. The Enterprise version contains a lot of generated classes containing nested classes and thereby end up being pretty long. So, the conclusion of the Enterprise installation is that it was not possible, even when I tried to unzip it directly from the C: drive. Liferay packagers, if you are listening, JAR up your classes, don’t leave them in the classes/ directory. Anyways, the Enterprise version installed without any problems on my Ubuntu boxes, and the Professional version installed without any problems on my XP box (btw, can you call a laptop a box??).

The previously problems that I was complaining about regarding Jackrabbit have now been solved so that is jolly good.

Now to a problem that wasted too much of my time. Well, it was probably my own fault rather than Liferay. The Liferay portalt is built on the concept of being a company, therefore if you want to set-up your own portal you should change the context parameter called company_id to your own domain name. By default the company_id is set to liferay.com which is good for testing. As I installed the new version of Liferay I forgot about this and left it as liferay.com. When the installation was over I wanted to test out some of my many portlets to see if they would still be working. The last time I deployed my portlets I had set a different company_id, big-al.com (as I virtually host more than one portal on the same machine). This is where the problem comes, when you deploy a portlet with a company_id that doesn’t exist on the server it doesn’t give you a nice error in the log saying “company_id” does not exist, nope, it gives you “NullPointerException” in the HotDeploymentListener. How on earth am I suppose to debug my application with an error like that??!? Anyways, as I said, that was my fault for not paying attention when I deployed my portlets, but Liferay, if you are listening, improve on the error messages in the log. The error is described here, only I saw it too late to save me any time: http://support.liferay.com/browse/LEP-894
That’s all for now, however, while anticipating the release of Liferay 4.1.0 I have been experimenting with a whole bunch of other JSR168 complaint portal servers; Apache Pluto (well, Pluto is a container only, but good for testing), Apache Jetspeed 2, uPortal, and eXo platform. I hope to get some time to write a concise review before long.

Posted in Portal Development, Software Engineering | Comments Off on Upgraded to Liferay 4.1.0

Self-referencing classes in Hibernate

Posted by Big Al on August 4, 2006

I’m relatively new to Hibernate and love the functionality it provides, not to say the amount of time it saves me from writing entity classes, jdbc code, and SQL tables. However, I found it strange that the Hibernate manually did not any examples of setting up self-referencing classes that you would normally have in a parent/child structure. The example they have for parent/child structures are with classes of two different types, what I am talking about here is a class that has children of the same type as it self. For example if you have a hierachy of categories:

Class on the left is how it would look in the analysis model, the class on the right is how it would look when implemented

As an E/R diagram this would be realised as:

One category can have many sub categories. One sub category can have only one parent category

 

This structure could be formulated as the following Hibernate mapping:

 

 

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping package="mypackage">

<class name="Category" table="CATEGORY">

<id name="id" type="int">
            <meta attribute="use-in-equals">true</meta>
            <column name="CATEGORY_ID" />
            <generator class="native" />
        </id>

<property name="categoryName" type="string">
            <meta attribute="use-in-tostring">true</meta>
            <column name="CATEGORY_NAME" length="150" not-null="true" unique="false" index="CATEGORY_NAME" />
        </property>

<bag name="subCategories" lazy="false" cascade="all-delete-orphan" inverse="true">
            <key column="PARENT_CATEGORY_ID" />
            <one-to-many class="Category" />
        </bag>

<many-to-one name="parentCategory" class="Category">
            <column name="PARENT_CATEGORY_ID" />
        </many-to-one>
    </class>

</hibernate-mapping>

If you run the above mapping through the hbm2java task in Ant (or Eclipse with JBOSS-IDE installed) you should get a class as described on the class diagram above. If you also run the mapping through hbm2ddl (to MySQL) you should get the SQL script below

CREATE TABLE `category` (
    `CATEGORY_ID` int(11) NOT NULL auto_increment,
    `CATEGORY_NAME` varchar(150) NOT NULL,
    `PARENT_CATEGORY_ID` int(11) default NULL,
    PRIMARY KEY  (`CATEGORY_ID`),
    KEY `CATEGORY_NAME` (`CATEGORY_NAME`),
    KEY `FK31A8ACFEAF2C96DF` (`PARENT_CATEGORY_ID`),
    CONSTRAINT `FK31A8ACFEAF2C96DF` FOREIGN KEY (`PARENT_CATEGORY_ID`) REFERENCES `category` (`CATEGORY_ID`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1

There are other ways of mapping the one-to-many relationship, but I’m leading to this solution as I need the relationship to be inverse so that I can get a parent from a child, and from a parent to all its children.

Comments on this approach are welcome

Posted in Software Engineering | 7 Comments »

Unit Testing with Hibernate

Posted by Big Al on August 3, 2006

I’m bit thinking about the idea of creating a website dedicated to testing patterns. I love the whole test-driven approach to building software but when you start working with new APIs and technologies it usually takes a lot of time to get your head around how to write unit/integration/acceptance tests for code using those new APIs/Technologies. Some books are dedicated to given tips on how to unit test under different kinds of technologies (I can highly recommend JUnit Recipies and JUnit In Action), but it would be nice to have a dedicated website where people contribute and add their experience. If you know such as site already, please let me know.

Anyway, I just wanted to give my testing pattern for testing applications/code that use Hibernate. Hibernate is a fantastic Object-Relational Mapping API that will save you hours if you currently write all your JDBC yourself. Anyways, this is not an introductory tutorial on Hibernate (Check out http://www.hibernate.org).

When I use Hibernate I usually create a Manager object for each type of Class that I wish to store in the database

Class Diagram

So, if I want to test if using the add() method on the PersonManager works my Junit test would look like this:

import java.util.List;
import junit.framework.TestCase;

public class AddPersonTest extends TestCase {

private PersonManager pm = new PersonManager();

public void testAddPerson() {
        Person person = new Person("Allan Lykke", "Christensen", "VP DICTM");
        this.pm.save(person);
        List persons = this.pm.getList();
        assertTrue(persons.size() >= 1);
        assertTrue(persons.contains(person));
    }

}

My pattern is therefore

  1. Insert a given object into the database.
  2. Get a complete list of all objects in the database.
  3. Check that the list contains at least 1 object (the one I’ve just inserted).
  4. Check that the object that I inserted also exists in the complete list extracted.

Remember that in order to do step 4 you need to implement the equals() method of your object. hbm2java can do this for you if you automatically generate your Java sources using the XML file describing the object.

I’d love to hear other about other testing patterns.

Posted in Software Engineering, Software Testing | Comments Off on Unit Testing with Hibernate