Sonntag, 31. Mai 2009

The future of the human race

This science fiction future theory differs from the golden future theories of movies like Star Trek. It predicts no nuclear war but is more frightening than Terminator or The Chronicles of Riddick. Its theory seems also more presumably than the other ones: via

Samstag, 30. Mai 2009

EasyMock as an easy to use alternative to jMock

EasyMock does exactly what its name promises: It provides an easy way to mock objects. I never really liked the way jMock needs to be used. mockery.checking takes an ExpectationBuilder named expectations as single parameter. But this parameter is a special initialized object of type Expectations - I always had to look into the docs and count the brackets. The auto completition feature of eclipse also works bad for this way of programming. Here is a sample test using jMock:

  public void testInterceptWithWrongSetSessionMethod( ) throws Throwable {
      final Method[] methods = getSortedMethods();
      final HibernateHelper hibernateHelper = mockery.mock(HibernateHelper.class);
      final IAnnotatedMethodLocator methodLocator = mockery.mock(IAnnotatedMethodLocator.class);
      final MockServiceBean serviceBean = mockery.mock(MockServiceBean.class);
      final Session transactional = mockery.mock(Session.class);
      final MethodInvocation invocation = mockery.mock(MethodInvocation.class);
      mockery.checking(new Expectations() {
              one(methodLocator).getAnnotatedMethod(invocation, HBSISetSession.class);
      HibernateBasedServiceInterceptor interceptor = new HibernateBasedServiceInterceptor(hibernateHelper, methodLocator);
      try {
          fail("exception expected");
      } catch (ServiceException e) {
And the next beautiful test method is using EasyMock:

  public void testInterceptWithWrongSetSessionMethodEasyMock( ) throws Throwable {
      Method[] methods = getSortedMethods();
      HibernateHelper hibernateHelper = EasyMock.createMock(HibernateHelper.class);
      IAnnotatedMethodLocator methodLocator = EasyMock.createMock(IAnnotatedMethodLocator.class);
      MockServiceBean serviceBean = EasyMock.createMock(MockServiceBean.class);
      Session transactional = EasyMock.createMock(Session.class);
      MethodInvocation invocation = EasyMock.createMock(MethodInvocation.class);
      EasyMock.expect(methodLocator.getAnnotatedMethod(invocation, HBSISetSession.class)).andReturn(methods[1]);
      EasyMock.replay(hibernateHelper, methodLocator, serviceBean, transactional, invocation);
      HibernateBasedServiceInterceptor interceptor = new HibernateBasedServiceInterceptor(hibernateHelper, methodLocator);
      try {
          fail("exception expected");
      } catch (ServiceException e) {
      EasyMock.verify(hibernateHelper, methodLocator, serviceBean, transactional, invocation);
Clean Java code using a nice and easy to use API.

Sniffing keystrokes from wireless keyboards

I'm currently @ ph-neutral in Berlin and listening to an interesting talk about wireless keyboards. It seems to be very easy to sniff the keystrokes since the encryption is done using xor. If anyone is interested in additional information about this topic he should look out for the keykeriki project home page.

Donnerstag, 28. Mai 2009

JPA and default values

Today I found out that it is not possible to define default values of fields which are mapped to a column of table in a database. The workaround is to do the work in the default constructor and a manual tweak of the generated database schema. IMHO this is one of the cases which prevents fully automatic schema generation and increases the development time and chance of bugs :-(

Mittwoch, 27. Mai 2009

Expose for Vista

Many software developers are fighting a war against the chaos of many open windows at the same time. A few weeks ago I found the holy hand grenade on a Kubuntu box built by the secret research institution of the developers fraction: a feature called expose. It arranges all open windows next to each other and zooms out so its easy to catch a glimpse of them. Since the Kubuntu box didn't run very stable I searched a solution for Vista. Found many commercial and noncommercial versions and decided to use the one called switcher. It's kewl, very configurable, free and stable. It can be downloaded from the product website I already shared it with my brothers in arms and got quiet a response so I thought it might be worth blogging about it...

Mittwoch, 20. Mai 2009

Germany - a country full of terrorists

*attention - sarcasm*
Today I saw it in the news on youtube: 82 million terrorists are living in Germany. Thank god the german state pays attention and is going to hunt down all the black hats:

Dienstag, 12. Mai 2009

jQuery Autocomplete Plugin

jQuery doesn't ship with an auto complete UI component. I found a very nice, and very very very very flexible jQuery Plugin doing this job named Autocomplete. It supports static and dynamic data and cause of its event model it's very flexible. For instance it's no problem to have a autocomplete text field for a ZIP code which automatically fills in an additional city field. It also has formatters which can be used to format the proposals - eg. the ZIP field fills in ZIP codes but provides ZIP - CITY as proposal.

sunshine live webradio without the annoying advertisments popup

Quick access to pure dance / trance / techno music without any overhead of pictures, advertisements and clicks is available at this url: Sunshine Live - Livestream

UTF-8 character encoding problems with ISO-8859-1 encoded Java property files

Java property files need to be ISO-8859-1 encoded. But when it comes to i18n of an application you'll have to overcome the limitations of this character set. In short: ISO-8859-1 does not support all required characters. Changing the encoding of property files to utf-8 is not (yet) supported by Java. To overcome this limitation the guys from built an editor named PropertiesEditor. It writes the property file with properly escaped UTF8 symbols.

Donnerstag, 7. Mai 2009

Hibernate Transactions and Connection Pooling

After 2 years of Java development using hibernate I noticed that my understanding of hibernate sessions and transactions was completely wrong. I thought:
  • I can interact with the database within and without a transaction.
  • Performance is better without a transaction.
  • Inserting a single entity without a transaction is good thing.
  • I don't need to step into the details of connection pooling until performance issues occurs.
  • If I call session.close() the session is closed and hibernate takes care of open transactions
I got it all wrong. After a bit of rtfm'ing and testing I noticed:
  • Interaction with a database always requires a transaction in hibernate. There is a feature called auto-commit which opens a transaction before executing a statement and closes it immediately after execution of the statement. This behavior is causing performance issues if a huge amount of queries is executed(Lazy Collections). So if I'm working with hibernate, I have to define the scope of the transaction(s).
  • Performance difference between commit and rollback within a transaction which not issued any write access is really hard to measure - there is no real difference.
  • Inserting a single entity without a transaction is impossible.
  • [ INFO] 21:17:01 org.hibernate.connection.DriverManagerConnectionProvider:64 - Using Hibernate built-in connection pool (not for production use!)
  • If I call session.close() using built in connection pooling the last transaction is untouched and reused by the next session obtained by sessionFactory.openSession(). Worst case scenario is one day of inserts and updates and the next day a transaction.rollBack() causes a heavy data loss. Using an alternative connection pooling (eg C3p0) is a must do, not a nice to have.
I created a simple test project named 'de.rhauswald.learning.hibernate.transactions' and committed it to this repository.

How to install Eclipse Subversive SVN Plugin

1. Adding the required update sites to the Eclipse Update/Add-On Manager Open Eclipse and navigate to Help->Software Updates...

Switch to the Available Software tab und use the Add Site... Button to the following URL's:

Note that these URL's may change over the time. Have a look at the Eclipse project site of Subversive to get fresh URL's.

2. Selecting and installing the required components The following components needs to be checked:
Subversive SVN Connectors
Subversive SVN Team Provider
SVNKit 1.3.0 Implementation

Click Install... and restart Eclipse after installation finished.

If you are new to the whole topic, you should rtfm the documentation of the plugin

  © Blogger template 'Morning Drink' by 2008

Back to TOP