I made a change in the blogger configuration to ease the later work when blogging. It is possible that older entries are not correctly formatted.

Thursday, 13 December 2007

First Start to Hibernate

In the series of new technologies which I should get my hands on and about which I wish to get an overview Hibernate is an important candidate.

First of all Hibernate is an Object/Relation Mapping framework, this means that it is used to create maps between object oriented structures and relational databases. The main goal is to keep the object in a running system as persistent as possible with the data present in the database in order to ensure consistency in the data. Another important point is also the efficiency of querying and the optimized use of resources.

In Hibernate this is managed through the use of a mapping defined using XML configuration files. The mappings are stored in a file looking like that:

<?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>
[...]
</hibernate-mapping>

A mapping as the following shape:

<class name="myaddressbook.model.Person" table="PERSONS">
....
</class>
where the name is the java name of the class, whereas PERSONS is th name of the relational table of this class.

the fields of a class Person of the sort:

package myaddressbook.model.Person;

class Person {

Long id;
String name;
Date birthday;

// plus the corresponding getters/setters
}
would look like:

<id name="id" column="PERSON_ID">
           <generator class="native"/>
       </id>
       <property name="birthday" type="timestamp" column="BIRTHDAY"/>
       <property name="name"/>


finally the complete file should be under: person.hbm.xml at the place where the file is found.

For the configuration of Hibernate, it is important to set the information about the database. For this, there are different possibilities:

  • a properties file
  • an XML configuration files
  • or using Java to set the information

Wednesday, 12 December 2007

Spring framework

The following explanation comes mainly from an article from: the ServerSide

Since Spring is a framework which is gathering speed and value in the software industry, I also had to take a look at this framework.

The spring framework is based on the use of a method close to the design pattern: dependency injection (a flavor of another pattern called inversion of control). The basic idea is that there is a light-weight container which helps the programmer managing the life cycle of the objects ( from creation to destruction). It is similar to the idea of bean container, but also work with POJOs (Plain Old Data Objects). This has two advantages:

  • it is a lightweight container which can be used on top of application servers like Web Sphere, JBoss,...
  • the configuration of the object can be done easily through configuration files (some can be in XML, but simple property files are also possible)
Supplementary to the Inversion of control features, the spring framework provides a number of supplementary help tools. For example: using the JDBCTemplate class on a data source, it is easy to query and store the results of the query in a list.

JDBC, Hibernate and Transactions

There is many possibilities to use JDBC with DAO object with the spring framework. It allows the possibility to use configuration to use JTA transaction or direct call using direct JDBC calls or calls to Hibernate.

Aspect Orientation

Using the Spring AOP features you can specify:

  • Interception: some code can be called before or after method calls for any interface or class.
  • Introduction: it is possible to use advices to modify the class or implementation of classes and objects ( the called code when getting to a point cut, i.e when a crosscutting feature must be implemented
  • Static and dynamic pointcuts: the static pointcuts define what happens when a join point is reached; it is possible to consider parameters of method for the pointcut definition. Through separation from pointcuts and interceptors, the interceptors can be reused in different applications.
Moreover, Spring integrates with AspectJ, so it is possible to use aspectJ code with Spring.

Again using the AOP from spring, it is possible to implement transaction management with Rollback with or without JTA.

MVC

Spring contains a powerful and highly configurable MVC framework which integrates well with struts, JSP, velocity...

EJB

Spring framework can be useful for implementing EJBs as well as on the client side of the EJBs

Testing

Testing is very important for enterprise applications, Spring allows many aspects of testings in particular unit testing through the use of the inversion of control design pattern.

This is very succint especially toward the end but I will complete it later.

AspectJ: Aspect Oriented Programming

Since Aspect orientation is gaining importance, as well as being very useful, I sum up here a few things about aspect orientation. This short explanation uses mainly the tutorial from: http://www.tomjanofsky.com/aspectj_tutorial.html
Aspect oriented programming is used when some action should be performed at specific moment of the program, but do not influence the way of running of the program. The typical examples is logging, caching, history, timing, authentication...
There is a number of new concept to learn: crosscutting concern, join point, point cuts, advice.
  • a join point is a point of the execution of the program
  • a point cut is a way of selecting join points in the program
  • an advice is the code to be executed when reaching the point cut
there are many ways of defining the point cut, e.g. during method call, or initialisation, or calls for setting or getting the value of a field, class execution or object initialisation An example: pointcut foo() : call (* * BankAccount.* (*)) defines a point cut foo applying advice when any method with one parameter is called on an object of class BankAccount. The syntax for deining an aspect is:
public aspect TraceAspect {
pointcut trace () : call (* * (..)) && ! within(TraceAspect);
before() : trace() {
System.out.println("ADV:"+thisJoinPoint.getSignature());
}
}
Note the keyword aspect, as well as before() ... the advice is:
System.out.println("ADV:"+thisJoinPoint.getSignature());
and is called before a method when not within( TraceAspect) Since there are already many aspect oriented programming with the spring framework, it might be prefarable to use that.

Tuesday, 11 December 2007

C# and Mono

First tries with Mono, C# and all the .NET thing. I am also interested in getting an overview of C# and .NET through the use of Mono on my Fedora box. First good to know there are a number of possible languages which should also work with Mono: C#, Java, VB.Net, Boo ( similar to Python), Javascript, PHP, and some others ... (see The Mono Language page ). First tries with using the Gtk# interface (see tutorial).

Scala Programming Language

Yet another programming language I want to take a look at: Scala.

It seems to be fully compatible with Java too as well as having many features similar to Groovy (see my post on groovy).

One of the thing though that seems really interesting is the concurrent programming features as shown at this place. I still need to try that though. I also want to know in which way it differs from Message Passing Interfaces (actually I think it is kind of like MPI).

It does not seem to be as developped as Groovy. So I think I'll stick with learning Groovy.

A personal note on Ruby and Ruby on Rails

I bought the Ruby on Rails Hors Serie 33 from Linux Magazine.

Not bad! I learned a lot from the different tutorial. I spent a few evening trying a few things out.

I found there were a few interesting things in Rails. I am not really in love with ruby though. This might only be because I felt a little annoyed of a few idiosyncracies of the language, I might get used to them though (in particular this global, not global variable thing).

There was nothing really problematic when you know enough of python, perl, java and the like.

What I really like though was: Rails. I tried it and you really get a few simple things done in very little time. That's really cool. I tried the address book example from the Hors Serie and I also implemented a little blog management system just for the heck of it.

I liked the ActiveRecord, and Action Pack and also the scaffolding stuff as well as the possibility to test it quickly with a small server.

Learning Groovy or Groovy Learning

Well I decided to learn Groovy.

It seems to have the most interesting properties, something like python or perl for java, except without the things I dislike from perl and python (about the former, it's not readible, about the latter I dislike the formatting constraint).

I haven't tested the compilation issue or the speed but this should not be a big problem. We'll see.

I made myself a summary from the groovy syntax and features from the tutorial.

I really like: (see: the differences from Java )

  • closures
  • the simple list and map syntax... What a pain it is in Java.
  • groovy markup as a nice way to work with XML, HTML, ANT...
  • easy use of regular expressions !!!!!! YEAH!
  • less problems with quotation marks and multi line strings
  • Gstring ( something to use variables for strings )
  • lots of supplementary useful methods (see the groovy jdk )
  • easy iteration ( though 1.5 did make things a lot easier)
  • easy setter/getter mechanism for beans
  • using closure for listeners

I'll have to try GRAILS, because I tried Rails And I found it not bad really.

It would also be interesting to see whether Groovy can be combined with JSF which I really liked.

But I think I am just starting feeling groovy.

Tuesday, 4 December 2007

Reinstalling Fedora 8

After having Ubuntu on my disk for something like a week. I wanted to try reinstalling Fedora 8 from scratch, in order to notice the differences better. After having created a new fedora live CD, I installed fedora.
  1. back up from the data I had from the debian.
  2. Partitioning
    1. create a boot partition
    2. create LVM partition
  3. create some useful partitions in the LVM partition
    1. root partition
    2. home partition
  4. let anaconda install every thing
  5. reboot
  6. complete the necessary information after first boot

Monday, 3 December 2007

Philipps firmware update using Wine

Yesterday I managed to use update the firmware from my Philips DVD drive (PHILIPS DVD+RW DVD8601) in order to burn a few CDs. For this I used Wine on ubuntu. The update worked after a few little configurations (I had not yet used Wine).
  1. first install wine on debian
  2. find the correct update from the DELL? (was it DELL) page
  3. log as root
  4. look for the missing dll library for wine ( after I had gotten a missing library error), found it on the internet. The library was mfc42.dll
  5. then put the library in c:\windows\system using wine
  6. used $ wine .exe , it popped up a small window asking where some software should be decompressed
  7. chose a subdirectory from temp to decompress the software
  8. then executed the .exe file which was there
  9. it took a few minutes but finished cleanly
  10. reboot
  11. test the software