2008 03 30

The latest version 2.5 of Wordpress was released yesterday and I’ve just upgraded Noulakaz.net.

I use a number of plugins and I had a small issue with one of them, Alex King’s Popularity Contest, which kept generating fatal errors when activated. Fortunately, I came across a simple one-line fix. This is where open source software really shines compared to its proprietary cousins…

Dear readers, please spend a few minutes testing the weblog and don’t hesitate to contact me if you notice any issue. Thanks.

Popularity: 2% [?]

  • Share/Bookmark

written by avinash

2008 03 26

Despite my interest in all things Ruby especially Ruby on Rails, I’ve decided to have a look at some powerful enterprise Java technologies. As you know, last semester, I taught Software Architecture at Masters level and I’ve become fond of using Java once more (which I used for the lab sessions).

Of course, the fact that Java is now opensource and so are most of the most interesting Java libraries and frameworks has also influenced me.

Anyway, today I’ve spent some time with Hibernate which is a framework to map plain old Java objects (POJOs) to relational databases. Basically, it allows a programmer to write a database application using normal object-oriented development methodologies and without writing a single line of SQL.

The first step is to write a POJO. It does not have to be a Javabean (Hibernate is perfectly happy if attributes don’t have getters and setters). For instance, this will do:

public class District {
    private Integer id;
    private String name;

    public District() {
    }
}

Then write a mapping file which is basically an XML which describes how each attribute will be stored in a relational database. In many cases, this is trivial:

<hibernate-mapping>
    <class name="datasource.District" table="DISTRICTS">
        <id name="id" column="DISTRICT_ID" access="field">
            <generator class="native" />
        </id> 
        <property name="name" column="NAME" access="field" />
    </class>
</hibernate-mapping>

In case you have a many-to-one or a many-to-many association, have a look at chapter 7 of the Hibernate documentation. It’s explicit enough.

Configuring Hibernate to connect to your database is easy (I use MySQL 5.0 with the latest Connection/J JDBC driver). Just follow the official tutorial. The important part is:

<!-- Drop and re-create the database schema on startup -->
<property name="hbm2ddl.auto">create</property>

Finally, write a small toy application in Java to force Hibernate to create the database schema:

package hibernate;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

public class CreateDatabaseSchema {
    public static void main(String[] args) {
        Session session = null;
        
        try {
            SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
            session = sessionFactory.openSession();
            session.flush();
            session.close();
        }
        
        catch (Exception e) {
            System.out.println(e.getMessage());
        }
    }
}

Tomorrow, I’ll use the Spring framework to decouple Hibernate from my application. I’ll surely indulge in some dependency injection. Yummy!

(Muhammad Ali picture courtesy of this website)

Popularity: 2% [?]

  • Share/Bookmark

written by avinash

2008 03 16

We were at Péreybère on Sunday as delightfully narrated by Gavin on his blog. There, after some swimming and kayaking, we indulged ourselves (twice!) in some “glaçon rapé” (pictured above). It’s basically, in case you are not from Mauritius, ice served with different kinds of syrup.

I may be wrong but I think “glaçon rapé” is typically Mauritian. I don’t remember seeing something similar in other countries.

Another example might be “mine-bouillie carri gros-pois” (boiled noodles with beans curry). Granted, many have never tasted it. But I can tell that this bizarre combination tastes very nice. Just ask Kavi, Begum and Christina who are converts now!

Yet another example is the “dholl puri” which is one of the staple food of many of us at lunchtime. It’s a kind of pancake with a mixture of different curries and chili. I didn’t see anything similar when I visited India.

Can you think of other examples of food only found in Mauritius?

(“Glaçon rapé” photo by G@V!N)

Popularity: 4% [?]

  • Share/Bookmark

written by avinash