Friday, April 18, 2008

Save the Sharks!

I just watched Sharkwater. In my opinion this is the best documentary I have seen in a while. It shows some amazing underwater footage. Seeing the hammerhead sharks congregate near Cocos Island is truly impressive. Nevertheless, the movie delivers an important message: Sharks are not the dangerous animals as you might see on the mass media. More people are killed by vending machines every year than by sharks. 
In fact, sharks are an important keystone species without which many marine ecosystems may collapse. For example research indicates that the ongoing removal of sharks contributes to the decline of coral reefs. I am a certified diver and would like to continue enjoying the mystique and beauty of the world's coral reefs.

SHARKWATER

Sharks are are literally in danger of being wiped off the map by overfishing (shark finning) and habitat destruction – Every year 50-100 million sharks are killed. The documentary also explains and shows the effects of longline fishing, a really nasty practice.
Thus, even if you don't love sharks, they are critical for the marine environment and need to be protected. We cannot afford loosing them. Please spread the word! 

Wednesday, April 16, 2008

Using Annotations in Spring 2.5 to the Extreme

For the past couple of years I have been using Spring in almost all of my projects. It has been mostly a great experience. However, there was always a lot of XML involved in order to wire all those beans together. This held true also for Hibernate as well as other frameworks. Did I mention Acegi Security?...

Well, then the community decided that annotations were an awesome way of cutting down on all this configuration clutter. Paired with the concept of sensible defaults brought over from the Rails community, live started to get easier. Guice introduced annotations-based dependency injection (DI), which has also been adopted by Spring. Thus, if you use JPA or Hibernate Annotations combined with all the whiz-bang offered by Spring you can virtually eliminate all your XML glue-code.

Well, with Spring 2.5 you can take DI to the extreme by also eliminating all your dependency-setters. For example, in your service methods you can annotate your private data access object variable declarations with annotations (e.g. @Autowired) that will inject the necessary dependencies for you. No need to declare public setters.

While this sounded kind of exciting and works well, I started scratching my head when dealing with unit-testing. How do I mock my service class' dao objects when there are neither public setters nor respective constructors?

For this issue Spring comes to the rescue with the following helper class, which provides helper methods for setting non-public variables or setters:

org.springframework.test.util.ReflectionTestUtils

Here is an example using EasyMock for creating a partial mock object:

...
final User Dao userDao = EasyMock.createStrictMock(UserDao.class);
EasyMock.expect(userDao.save(user)).andReturn(user);
ReflectionTestUtils.setField(userService, "userDao", userDao, UserDao.class);
EasyMock.replay(userDao);
...

And in my Service class I declare:

...
/** User Dao. */
private @Autowired UserDao userDao;
...

For more information regarding the new features in Spring 2.5 check out this article at InfoQ as well as this blog entry.

This very streamlined way of doing dependency injection without setters is very interesting, but to me it poses the following question:

Is this usage of annotations pushing the envelope a little too far?

It certainly binds you code more to the underlying framework (Spring) but on the other hand it feels kind of nice and works well. In my understanding this might be a really productive way of implementing smaller projects but it might be problematic for bigger ones...

Saturday, April 12, 2008

AJUG's Server found a new Home

I moved the server of the Atlanta Java User Group from the Midtown Atlanta to its new location in Suwanee, Ga. For many years the server was hosted by a data center facility in Midtown but last weekend we got the surprising news that due to policy changes we had to move out. Therefore, Burr Sutter, our president, sent out a message to our community asking for help. Thanks to many, many responses from AJUG's members, we had a few options by the middle of the week. At the end we chose 4t Networks who offered use sponsored hosting. 

By the way, the data-center in Suwanee, Ga. The data-center is really quite impressive - you can find more information here

Wednesday, April 9, 2008

Social Networking and the Atlanta Java User Group

The Atlanta Java User Group has certainly a very healthy membership basis. We have 1400 subscribers to our announcement mailing list as well as 600 subscribers to the general membership mailing list. 11 days ago I created a group on LinkedIn for the Atlanta Java User Group in order to increase the visibility of the group. Previously, I had already become a member of the Java Posse LinkedIn Group and wanted to provide the same exposure to the Atlanta Java User Group. It has been quite exciting to see the rapid adoption rate. Within 48 hours we had 100 sign-ups and yesterday we hit 155 subscribers. It seems that social networking is becoming an essential tool to IT professionals these days. 

Sunday, March 16, 2008

Changing Company without Changing the Job

Starting this week I am working for Engauge instead of Spunlogic. Well, it is still the same job but Spunlogic joins Engauge and thus becomes part of it. This is certainly something you don't experience every day plus we got a nice welcome package :-)

AJUG March Meeting - JPA with Spring 2.5

Today I finished preparing for the Atlanta Java User Group's March meeting next Tuesday (Updating the website/preparing the mailing list announcement) .

The topic is: Enterprise JPA with Spring 2.5. You can find more details here. Pratik Patel will give the presentation and I am really looking forward to it. Thanks Pratik!

Tuesday, March 11, 2008

Highlighting Source Code in HTML

I came a project on Google Code that is particularly interesting for us software devs when writing our blog entries that often encompass code snippets. Therefore, take a look at SyntaxHighlighter. SyntaxHighlighter formats your source code by using JavaScript, only, and supports many different language including Java, Ruby and Python.

Monday, March 10, 2008

Toilets for America

Although the current political situation here in the US is crappy, to say it bluntly, this blog entry is not about politics but rather about how you can save a lot of water when using the right toilet.

Growing up in Germany, I am accustomed to having toilets with instant flush-stop which are very effective. As far as I believe and read on various internet sites the situation is quite similar across other European countries, Japan, Israel, Australia etc.

In the US the situation is improving but unfortunately still lacking. My wife and I live in a twenty year-old town-home in Atlanta, Ga, that had the original toilets still in place. This means the toilets were using approximately 3.5 gallons (13.2 liters) of water per flush. Not good.

Since last year residents of Georgia have been enduring a total outdoor watering ban, and I finally decided it is time to start doing something. And thus I spent some time investigating the options I have in order to save more water by replacing my toilets.

Currently, federal law mandates toilets that are using 1.6 gallons (6.1 liters) of water per flush. This is much better than my old toilets, but we can do better. There is a federal label for water-saving products called EPA WaterSense. Products with this label are required to use no more than 1.3gallons per flush. Cool, but can I do even better?

The best - To reduce water consumption even further, you can choose dual-flush toilets that reduce water consumption by an additional 25%. Those toilets have basically 2 buttons. One for the 'big stuff' and one for 'liquids' using only 0.8gallons (3 liters) of water per flush.

Once I decided to go for the best available option, provided the price be acceptable, the tough part started. Which manufacture/model do I choose as well as where to buy?

First of all, the 2 big home improvement stores, Lowe's and Home Depot, were quite a bust. Their selection of EPA Watersense certified toilets is quite limited. Taking it to the next step and asking for dual flush toilets is like asking for the moon. This is very disappointing for a metropolitan area of 4.5 million in a severe drought.

Anyway, in my opinion, the best product I was able to come up with is a company called Caroma and they provide a list of their local suppliers on their website. Luckily they have suppliers that are local to Atlanta.

The model I chose is the Sydney 305 Elongated and thus I purchased 3 toilets from ecoTransitions Inc. They were extremely helpful and home-delivered.

Installation was quite straightforward, considering the fact that this has been my first installation ever. Finally, I must say they work great!!

Wednesday, February 20, 2008

BeanComparator

Sometimes you just have the requirement to sort java collections...In that case the BeanComparator from Jakarta Commons is quite handy:

ArrayList sortFields = new ArrayList();
sortFields.add(new BeanComparator("lastName"));
sortFields.add(new BeanComparator("firstName"));
ComparatorChain multiSort = new ComparatorChain(sortFields);
java.util.Collections.sort(rows,multiSort);

Friday, February 15, 2008

Email Aliases on a Linux Box

It is actually dead-simple:

vi /etc/aliases

Add your aliases like:

contact: somebody@somewhere.com

(Multiple email addresses are separated using a comma)

Afterwards run the command newaliases so that the made changes take effect.

Thus, if your server's domain is foobar.com, then any email sent to contact@foobar.com goes to somebody@somewhere.com

That's it.