Gnome fonts follow up

It’s only been 1 day since I setup my gnome to use a smaller font, but it already feels much nicer. Really amazing what a small little change can do. I’m one of those persons who wants as much as possible on his screen. Maybe that’s something typically for coders? Many people I know want clear and big fonts, I want small and more.

For all you coders out there who use gnome and haven’t set there font smallers, really try it out. Maybe you’ll have the same reaction as me.

One thing I noticed was the fact that eclipse has it’s own font settings and I had to change these manually, no biggy but it’s a shame it’s not (yet) integrated.

gnome fonts

In my spare time I always use gnome, but during the day I have to use microsoft. (Client Company policy) One thing that was always bizarre was the fact that in my day job my computer is running at 1200×1024 and my laptop is running 1440×900. But I always had the feeling my windows maching could display more on a smaller screen. So I started looking around in my ubuntu menu’s and I found a configuration under System -> Preferences -> fonts (It was in dutch so I’m not sure if this is the actual translation but should be something like this)

I included a before and after screenshot, just like at the amount of information that is displayed on my screen now. I’m back a happy hacker ๐Ÿ™‚

before the update
before

after the update
after

the font menu
font menu

I updated the font size and set it to 8 instead of 10, Appearantly if you change the dpi settings you can do something similar but I don’t know the exact difference between the 2 (I now what they mean but don’t know exactly what impact they have on the system.)

Generics sweetness

As I wrote earlier, last week I did a presentation on Hibernate as a good speaker I investigate my subject. During my investigation I came a cross the project that is being done for the Hibernate in Action second edition. In this book they used some generics for creating the CRUD DAO objects and it really opened my eyes. For me generics was a nice to have gadget for typecasting my collections, I had no idea this could be done with it. So read and be amazed!!

You have an interface like this:

public interface GenericDAO<T , ID extends Serializable>{
    T findById(ID id, boolean lock);
    List<T> findAll();
    List<T> findByExample(T exampleInstance, String... excludeProperty);
    T makePersistent(T entity);
    void makeTransient(T entity);
    void flush();
}


you have an basic implementation of this interface:

public abstract class GenericHibernateDAO<t , ID extends Serializable> implements GenericDAO<t , ID> {
    private Class<T> persistentClass;
    private Session session;
    public GenericHibernateDAO() {
        this.persistentClass = (Class<T>) ((ParameterizedType) getClass()
                                .getGenericSuperclass()).getActualTypeArguments()[0];
     }
    @SuppressWarnings("unchecked")
    public void setSession(Session s) {
        this.session = s;
    }
    protected Session getSession() {
        if (session == null)
            throw new IllegalStateException("Session has not been set on DAO before usage");
        return session;
    }
    public Class<T> getPersistentClass() {
        return persistentClass;
    }
    @SuppressWarnings("unchecked")
    public T findById(ID id, boolean lock) {
        T entity;
        if (lock)
            entity = (T) getSession().load(getPersistentClass(), id, LockMode.UPGRADE);
        else
            entity = (T) getSession().load(getPersistentClass(), id);

        return entity;
    }
    @SuppressWarnings("unchecked")
    public List<T> findAll() {
        return findByCriteria();
    }
    @SuppressWarnings("unchecked")
    public List<T> findByExample(T exampleInstance, String[] excludeProperty) {
        Criteria crit = getSession().createCriteria(getPersistentClass());
        Example example =  Example.create(exampleInstance);
        for (String exclude : excludeProperty) {
            example.excludeProperty(exclude);
        }
        crit.add(example);
        return crit.list();
    }
    @SuppressWarnings("unchecked")
    public T makePersistent(T entity) {
        getSession().saveOrUpdate(entity);
        return entity;
    }
    public void makeTransient(T entity) {
        getSession().delete(entity);
    }
    public void flush() {
        getSession().flush();
    }
    /**
     * Use this inside subclasses as a convenience method.
     */
    @SuppressWarnings("unchecked")
    protected List<T> findByCriteria(Criterion... criterion) {
        Criteria crit = getSession().createCriteria(getPersistentClass());
        for (Criterion c : criterion) {
            crit.add(c);
        }
        return crit.list();
   }

}

And you have a descendent of this base class

public class BillingDetailsDAOHibernate
        extends     GenericHibernateDAO<Billingdetails , Long>
        implements  BillingDetailsDAO {

    @SuppressWarnings("unchecked")
    public List<Billingdetails> findConcrete(Class concreteClass) {
        return getSession().createCriteria(concreteClass).list();
    }
}

In short the descendent tells his parent Substitute all you T with BillingDetails and your Id with Long and abracadabra you have a simple CRUD dao for your billingDetails. Now how’s that for some fancy programming.

At the moment I’m rewritting my DAO objects to return generic collections, maybe in the next refactoring cycle I’ll use this design pattern.

My bet is that with the rise of generics, we’ll see more and more design patterns that are based on generics as this is very powerfull. The example above will surely be used in more projects to come!!

No reaction about my JUG, guess nobody is interested in learning Java. ๐Ÿ™

ps sorry if wordpress f*cked up the layout, but still check it out

Jboss messaging

I had to give jboss messaging a go to. Hmm doesn’t look that difficult either. Now a simple MessageDrivenBean and I’m in business.

The Sender:

import java.util.Properties;

import javax.jms.Queue;
import javax.jms.QueueConnection;
import javax.jms.QueueConnectionFactory;
import javax.jms.QueueSender;
import javax.jms.QueueSession;
import javax.jms.Session;
import javax.jms.TextMessage;
import javax.naming.Context;
import javax.naming.InitialContext;

public class JbossJmsTest
{

   public static void main(String[] args) throws Exception
   {
      log.info("Creating jndi context - alternatively use a jndi.properties");
      Properties properties = new Properties();
      properties.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
      properties.put(Context.URL_PKG_PREFIXES, "org.jnp.interfaces");
      properties.put(Context.PROVIDER_URL, "localhost");
      InitialContext ctx = new InitialContext(properties);

      log.info("Looking up queue");
      Queue queue = (Queue) ctx.lookup("queue/testQueue");

      log.info("Looking up connection factory");
      QueueConnectionFactory qcf = (QueueConnectionFactory) ctx.lookup("UIL2ConnectionFactory");

      log.info("Creating connection");
      QueueConnection qc = qcf.createQueueConnection();
      try
      {
         log.info("Creating session");
         QueueSession qs = qc.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
         
         log.info("Creating sender");
         QueueSender sender = qs.createSender(queue);

         log.info("Creating message");
         TextMessage message = qs.createTextMessage("hello");

         log.info("Sending message");
         sender.send(message);
      }
      finally
      {
         qc.close();
      }
   }

   public static class log
   {
      public static void info(String message)
      {
         System.out.println(message);
      }
      public static void error(String message, Throwable t)
      {
         System.err.println(message);
         t.printStackTrace();
      }
   }
}

The receiver

import java.util.Properties;

import javax.jms.Message;
import javax.jms.Queue;
import javax.jms.QueueConnection;
import javax.jms.QueueConnectionFactory;
import javax.jms.QueueReceiver;
import javax.jms.QueueSender;
import javax.jms.QueueSession;
import javax.jms.Session;
import javax.jms.TextMessage;
import javax.naming.Context;
import javax.naming.InitialContext;

public class JbossJmsReceiver {
	public static void main(String[] args) throws Exception
	   {
	      log.info("Creating jndi context - alternatively use a jndi.properties");
	      Properties properties = new Properties();
	      properties.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
	      properties.put(Context.URL_PKG_PREFIXES, "org.jnp.interfaces");
	      properties.put(Context.PROVIDER_URL, "localhost");
	      InitialContext ctx = new InitialContext(properties);

	      log.info("Looking up queue");
	      Queue queue = (Queue) ctx.lookup("queue/testQueue");

	      log.info("Looking up connection factory");
	      QueueConnectionFactory qcf = (QueueConnectionFactory) ctx.lookup("UIL2ConnectionFactory");

	      log.info("Creating connection");
	      QueueConnection qc = qcf.createQueueConnection();
	      try
	      {
	         log.info("Creating session");
	         QueueSession qs = qc.createQueueSession(false, Session.DUPS_OK_ACKNOWLEDGE);

	         log.info("Creating receiver");
	         QueueReceiver receiver = qs.createReceiver(queue);

	         log.info("Try to receive message, it will not work");
	         while(true){
		    	 Message received = receiver.receiveNoWait();
		    	 /*if (received != null)
		    		 throw new RuntimeException("Should not get a message if the connection is not started!");*/
		
		    	 //log.info("You have to start the connection before receiving messages");
		    	 qc.start();
		
		    	 //log.info("This receive will work");
		    	 received = receiver.receiveNoWait();
		    	 if(received!=null){
		    		 log.info("Got message: " + received);
		    	 }
	         }
	      }
	      finally
	      {
	         qc.close();
	      }
	   }

	   public static class log
	   {
	      public static void info(String message)
	      {
	         System.out.println(message);
	      }
	      public static void error(String message, Throwable t)
	      {
	         System.err.println(message);
	         t.printStackTrace();
	      }
	   }
}

this is almost the identic code of the jboss site only problem is finding it. It seems jboss has changed the jms server. I’m using jboss-4.0.3SP1 and somewhere they have changed JbossMQ to JBossMessaging or something. I still have to get the details but first things first getting some code working ๐Ÿ™‚

First Jabber POC

On my current project I see some real future into messaging. I had some intensive discussions with my manager as he is more pro SOAP webservices then into messaging. But when you have push and pull mechanisms SOAP really isn’t the answer, what would you do? setup 2 SOAP services and let them communicate?? Well what if the specs change and a third party joins in? recode everything and if bla = true connect to X, else connect to Y? Really not!!!
What you can do is place a Queue where you publish everything on. You can use Jboss 4, it has one build in or if you want to go further you could use the Jabber protocol (same as google talk if I’m not mistaken). I have a jabber running on my server and did a very small test in java. I used the smack library, a small native java library. And I wrote this stupid little expample

public static void main(String[] args){
		try {
			XMPPConnection.DEBUG_ENABLED = true;
			SSLXMPPConnection.DEBUG_ENABLED = true;
			XMPPConnection con = new XMPPConnection("pczone.be",5222);
			con.login("xxx", "xxx");
			con.createChat("me").sendMessage("hello");
			PacketFilter filter = new PacketTypeFilter(Message.class);
			PacketCollector myCollector = con.createPacketCollector(filter);
			
			PacketListener myListener = new PacketListener(){
				public void processPacket(Packet pac){
					System.out.println(pac.toString());
				}
			};
			con.addPacketListener(myListener,filter);
		} catch (Exception e) {
			e.printStackTrace();
		}
}

What this stupid little example did was simply logon to my server, send me a message and listen for incoming messages. I ran this in debugmode with a breakpoint on the System.out.println line, when I replied to my message my breakpoint worked. I could inspect the message and see somewhere in the body my content wrapped in a jabber xml.

Off course it’s no rocket science, but it’s always nice when you see something spectaculair. ๐Ÿ™‚

I’ll certainly use this in future projects. How exactly, hmm not yet sure ๐Ÿ™‚

Java Workshop

Yesterday evening we did an internal workshop. I explained Hibernate a bit Jacob (a collegeau) also shared his experiences on the Hibernate topic as we implemented Hibernate in a totally different way. Afterwards Jacob gave a session on Spring Webflow. I have to say it’s been a while since I went to programmers workshop. Our l2u meetings are not actually coding, more setting up and explaing new stuff. But hey I’m a coder, not an administrator but as most geeks I know my way around administration as well but it’s not my core business ๐Ÿ™‚

I spend quite some time preparing the workshop, I even listened to a session of gavin himself recorded on a mp3 player. (I’ll put it up later.) I made a small example and then I did a pojo with 2 relationships to other tables. While preparing this workhop it gave me the opportunity to take a closer look at the things we don’t use in our project. .e.g. we always use HQL to retrieve our objects. Never do we use the Criteria classes way, it comes down to the same thing but it’s more Object oriented then an EJBQL like query ๐Ÿ™‚

Although Jacob his session was rather short (due to our enthousiasm) it was really interesting. I had read the spring book, but I can’t remember much from the web flow framework besides it being a continution framework. I have to say it was a lot to take at once but it’s really really nice.
As most of you might know one of the common problems in J2EE web application is that if a user starts at page A, go’s to page B, go’s to page C and then hits the back button 2 times, changes something in form A and submits it. We actually have a merge of page C with page A. This is a problem and this is where a continuation framework comes to the rescue.
It holds some kind of version of the submited paged and if you your back button a couple of times and then submit the serverside object’s state will correspond as if you had never gone any further in your workflow. You actually went back in your workflow.
He also explained that you can define flows. Let’s say you have a OrderFlow,SearchProductFlow and SearchCustomerFlow. You can start your OrderFlow and when you come to the state where the product should get added you leavy your OrderFlow and start a subflow, the SearchProductFlow. Once this flow has finished (and the user has his selected products) we return those products into the OrderFlow and we go on from the point we left it. You then go a couple of steps further and come to the point you have to select a Customer, then you start another subflow, SearchCustomerFlow,… you get the point.

I’m not quite sure, but I believe Ruby on Rails also has this feature. I bet there are more projects out there that do this, but in Java this was rather hard to do. until now offcourse

On another note I was talking to a friend of mine, I told him I was going to give a talk on Hibernate. He told me would have loved to join, but it was an internal workshop. I talked to my boss about this and kinda proposed to make a more open thing. Something like a jug. I know we have Bejug but I haven’t seen much events off them and on their site isn’t much info about them, therefor I would like to ask if any of the readers of this entry who are interested in joining such a jug would send me an email (fix dot pczone dot be). who knows if we can get a small community together we could actually do a session at least once a month. Probably in the future 1 topic per session will be done as 2 topics were really to much ๐Ÿ™‚

So Axel or Tom who’s next ๐Ÿ˜‰

evolution

Today someone told me, you always come back to money and cars, talk more about hacking would ya. Well actually I know that I talk about this a lot but there is a good reason for this. I’m 26 years old and counting, my girlfriend and I have been together for over 2 years now, next year is here last year at college. After she finishes she’ll move in with me and we’ll start saving for our own litlle house with a garden. That was the only requirement she had.
So I started counting, I have been working for over 4 years full time and during my collega I did summer jobs and after school I helped in small software firms. Building php3 applications (those were the days ๐Ÿ™‚ ). As I’m not the big spender I do have some savings my girlfriend however (as every student) has little savings.

We agreed that in the future we would have 2 kids, and that I would get my own little office in our house. That makes a 4 bedroom house, nobody likes commuting to work but I will have to do it, that’s no problem at all but how long my commute will take is the question. Will I buy a house where they still are cheap and commute for nearly 3 hours every day or spend some more money and commute only 1 hour a day, hmm though question. But now comes the point I wanted to make, if at the moment you want to buy a small house with 4 bedrooms and a small garden, well that’s gonna cost you easily 200.000 รขโ€šยฌ. Well I for one don’t have that money, so I started looking at loans. Well let’s say you leand 180.000 รขโ€šยฌ (you don’t want to blow all your savings!!) well that comes down to over 1200 รขโ€šยฌ a month for 20 years. Kinda makes me sad. Well blaming me about talking to much about money is the same as blaming me about thinking about my future!!! So first things first, I’ll be putting my self on the (hopefully) right track to the future my girlfriend and I want, once I’m on that track I promise I’ll be my old self again and I’ll be talking about coding day and night. And that’s a promise I’m not going to brake, So don’t worry I’m not going to become a suite. Maybe from the outside I’ll be wearing one, but hey it’s easier to influences from the inside and you musn’t judge people on how they look, right?! Yes right!!!

Istanbul

As I like everybody like screencasts, I fiddled with Istanbul. Seems it has some problems recording my desktop. My guess is, it’s because of my ati pci-express videocard that wasn’t supported when I configured my X. Congrats to the team of Istanbul, I like your product. It makes screencasting really simple, and It even records in Theorra. What could a guy want more ๐Ÿ™‚ (hmmm, maybe sound?). In combination with java applet of the fluendo guys that really makes a kick ass combo for doing demo’s and tutorials. As the people over here are also giving demo’s and tutorials I’ll show them the nice features of the opensource applications and who knows maybe they’ll even buy support.

I really need to follow up on my videocard support, maybe by now it is supported and I can run Xgl without my X crashing after 5 minutes ๐Ÿ™‚

Eclipse Callisto

As some of you might know, there is a new version of eclipse out. Well together with that version came some other eclipse projects. One of them was BIRT (Business Intelligence And Reporting Tools) well I think it’s really amazing. If you don’t believe me checkout this screencast and tell me I’m wrong!! Actually funny as at the moment we are doing a Crystal Reports integration and I had mentioned Jasper Reports here (an java opensource reporting tool), guess they have a strong competitor on the market. Let’s hope they push eachother to the limits and the community will only benefit from it!! To bad we still are working here with Crystal Reports, believe me I’m trying to convert everybody to opensource.

UPDATE
my bad, callisto is the name of all the projects combined ๐Ÿ™‚
END UPDATE

Totally unrelated, I’ve been very very busy the last couple of weeks. I’m trying to get my needed capital to start my own sweet BVBA or better EVBA. On saturday I hope to get the approval for renting a nice 2 bedroom appartment in Leuven. If everything goes well, I’ll be having a lot more spare time in a few months and I can finally can help some projects I like but don’t satisfy my needs at the moment. I maybe sound stupid but I always get the feeling I’m not doing enough for the oss, I’m spreading it everywhere I come, I submit bugreports, now and then a small patch nothing fancy yet. I even set myself a goal “for every company I’ll work for, I have to at least introduce 1 opensource project”. But I hope to have achieved much more in a year from now, probably one of the first projects I’m going to take a look at is Diva. If you don’t know Diva go check it out!!

Eat your own dogfood

Well yesterday I told someone, I mostly use the eat your own dogfood rule. Well for most parts I really do that, but today I had to use our webinterface for sending mails. Well we are using roundcube and because I mostly use rich client appz, evolution and thunderbird I haven’t used roundcube that much. Well as I already mentioned today I had to and boy do I hate it now. At first it seems really nice and smooth, you have drag and drop, everything is ajax (buzzword alert!!) nice nice nice. I wrote a mail +60 lines, I hit the send button and I got the alert your session has timed out!!!! Okay hit the back button nothing, again back, still nothing. After hitting that back button like a maniak I realized I had to rewrite my email and believe me that sucks!!! I pulled up my scite editor wrote it in there and copy pasted it into roundcube.

So task for this evening, setup squirrel and imp mail. Maybe even try the new jboss callobaration stuff as the vidcast seemed nice. To bad you have to have the new flash 9 beta installed.

So all suggestions for other good webmail clients are welcome!!