mvn 3.0.3 + java 7 Datasource fail

11 11 2011

Okay just wanted to mention that if you’ve done a custom Datasource for java 6 and try to compile it with java 7 on maven using backwards compability you get this:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile (default-compile) on pr
oject wallboard-cisco-drivers: Compilation failure
[ERROR] \nino\develop\eclipseworkspace\projects\internalcomponents\Applications\wallboard\trunk\wallboard-cisco-dri
vers\src\main\java\com\netdesign\dao\cisco\general\[149,43] error: is not abstract and does not override abstract method getParentLogger() in
[ERROR] -> [Help 1]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1]
[ERROR] After correcting the problems, you can resume the build with the command
[ERROR] mvn -rf :wallboard-cisco-drivers

Please notice that i’ve specified this in my pom:


Only solution are to grab an old jdk 6 and compile it with that.. I was using jdk 1.7.0.

Feel free to correct me if im wrong somehow.

Guice and JDBC #2

4 11 2011

So a little while ago, I wrote about jdbc and guice.. I’ve been using mybatis since then.. And it just came to me yesterday “with mybatis you can do simple jdbc with guice”. Something similar to Spring JDBC templates.

So heres how (integer select), using annotation approach in something called a mapper class.

@Select(value = "select ${sql}")
public Integer updateCustomerEntrance(@Param("sql") String sql);

Thats it the only stuff you need to ensure are that your select will return an integer, and thats it. Mybatis will manage connection pool, connection etc for you.

It’s probably also possible for you to just return a object.. you’ll need at least 3 methods one for each type of sql, select update and delete.

However this approach are not at all utilizing mybatis’s power and are prone to SQL injection.. But it will do the job, and you can then go ahead an convert your legacy code slowly to use mybatis’s full potential.

Heres howto setup guice using it:

Guice Caching And Interceptors

14 05 2010

A little while ago I wanted to try out Guice 2’s Interceptors. And amazingly enough, I managed to create an integration towards ehcache in a couple of hours and had fun too.

The result is this

package org.slurry.cache4guice;

public interface Calculator {

        public int calculateSomethingWild(Integer number) throws InterruptedException ;

        public int calculateSomethingWild(Integer number,Integer number2) throws InterruptedException ;


package org.slurry.cache4guice;

import org.slurry.cache4guice.annotation.Cached;

public class CalculatorImpl implements Calculator {

        public int calculateSomethingWild(Integer number)
                        throws InterruptedException {

                return number;


        public int calculateSomethingWild(Integer number, Integer number2)
                        throws InterruptedException {

                return number + number2;


And bind it in your module

package org.slurry.cache4guice;


public class GuiceModule extends AbstractModule {

        protected void configure() {



So what’s backing those annotations in line 19 and 28 of the first source code box, whats doing all the magic?
1. An annotation, dada 🙂

package org.slurry.cache4guice.annotation;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Retention(RetentionPolicy.RUNTIME) @Target(ElementType.METHOD)
public @interface Cached {


2. An interceptor, more interesting, look at line 18 the most important thing in the interceptor implementation

package org.slurry.cache4guice.aop;

import net.sf.ehcache.Cache;
import net.sf.ehcache.CacheManager;
import net.sf.ehcache.Element;

import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;


public class CacheInterceptor implements MethodInterceptor {

        private CacheManager cacheManager;

        private CacheKeyGenerator cacheKeyGenerator;

        public Object invoke(MethodInvocation invocation) throws Throwable {

                return getResultFromCacheOrMethod(invocation);



3. Some Guice setup, in a module look at line 18,19 and 20. And actually line 19 are only needed if you need something injected into your interceptor

package org.slurry.cache4guice.module;

import net.sf.ehcache.CacheManager;

import org.slurry.cache4guice.annotation.Cached;
import org.slurry.cache4guice.aop.CacheInterceptor;
import org.slurry.cache4guice.aop.CacheKeyGenerator;
import org.slurry.cache4guice.cache.StringBasedKeyGenerator;


public class CacheModule extends AbstractModule {
        protected void configure() {

                CacheInterceptor cacheInterceptor = new CacheInterceptor();
                bindInterceptor(Matchers.any(), Matchers.annotatedWith(Cached.class),

        protected Class getCacheKeyGeneratorClass() {

                return StringBasedKeyGenerator.class;

So could it be easier? I mean theres only 3 steps. Now I haven’t shown all the code, only the relevant ones for guice. There’s a little more to it. And I should probably expand the functionality, so there’s a evict from cache annotation, that can evict certain caches. So did you need a cache for guice or did you want to play with interceptors, now you got both 🙂

All hosted here, with source code and tests,  if you have additions please contribute


14 05 2010

So sitting in the hotel, geecon 2010 are over. All in all a nice experience. A little small maybe. But content was great, thats the important thing. And if you look at the price, if probably the best conference for the price, 100 eur… Cant get much cheaper.

The website

And the slides/videos (some, I guess they’ll all come latter) :

Guice JDBC and Pools

12 03 2010

These last days I’ve been working on a Rest application  which provides a generic interface to a database. So the idea are to provide a “REST” driver that can look into any given database. Since I needed look into any given table I could’nt use my ordinary stack with guice / warp persist and JPA. But had to create my own jdbc template (like spring jdbc template).  Doing db stuff one needs a connection pool and since C3P0 are somewhat dead (haven’t had a release in ages), I decided to go with Apache DBCP.

Im having one problem though if I use PoolableDatasource I get the dreaded “ Address already in use: connect”. If I manage the pool via the ObjectPool myself, it works like a charm. Not what I’ve hoped for.

Im wondering if it would be better (simpler) if I i used (Bone CP). I guess some one should make something like the Spring jdbc template for guice.

I’ve done some more testing and found out following things:

  • C3P0 are simple to setup, you can always owervrite defaults by property files or xml files
  • C3P0 are slower than Apache DBCP
  • Apache DBCP, pooled connection does not work or I am using it wrong
  • Bone CP, cannot connect to a jdbc uri with embedde password, user / password needs to be setup explicitly (which gives problems when using in memory hsql, no password / user)

For now I think i will be sticking to C3P0 since i gives the most clean implentation, although a little slower than the rest (we are talking miliseconds, for 150 concurrent users).

EDIT I need to revisit Bone CP since it has been updated and are now available in central repo 🙂

Building Software Cheat Sheet

10 12 2009

Building Software with a smile

I’ve been wanting to write this article for a while now, I use all my articles as personal notes, plus giving back to the community are something that counts in my book aswell. The article are about how we manage and build our software at work and the stuff im using for my private pet projects. It’s an ever evolving process, that will probably never stop. There’s always process’s that can be simplified. It’s a short article that you can use for getting a stack together quick. Enough chatter, onto the fun stuff 🙂


We try to adhere under the ideas of people like Robert Martin (whom have summed up a lot of ideas of other people), go grab clean code you wont regret it. In short write code in a minimalistic readable way, remember to test it, care about your code and smile. Clean code really has summed it all up. Although there’s a lot of books on the topic’s of coding, testing etc. It’s my favorite. Oh and do not forget something like scrum.


I’m not going to rant about why but we use Java, there’s several reasons but I have no deeper feelings about this topic, I havent looked enough into Ruby, Scala etc. to be a judge. Mostly that there’s so many things available for Java, however the same are the case for Grails, Rails etc. I just like static languages a bit more. However the topics in are not in depth about Java.

Building System

We are using Apache Maven 2, which has some really nice features like it’s convenience over configuration. There’s very good integration towards build servers and a huge list of plug-ins that’ll to the job for you. Just rememberer do it the maven way, and let the system work for you, do not fight it 🙂 One side of Maven are testing, for that we are using a mixture of Junit4, Jmock and JBehave that ensures us maximum freedom and productivity.

Build Server

As for build server we are using Hudson, it’s simple and straight forward. It has great integration towards maven, I guess we could just as well have used Continuum but Hudson worked on first try Continuum did not. In Hudson we have three projects per Maven project, one for continuous integration and one for making a release and one for our metrics. The CI project are notified by our version system upon changes, then grabs the source and builds. The release project awaits when we are ready for a release, and then assigned build manager “clicks” build, awaits and downloads the finished release product, simple as that! The release process of course, checks out a fresh copy tags it in scm builds and releases/package the artifacts. I’ll write a bit about the metrics project below.


Now what goes hand in hand with a build server are a metrics analyser like Sonar which actually are a bunch of subprojects packaged nicely together and presented in style. It’s really easy to add to any Maven project just have the sonar running and run mvn sonar:sonar and voila fresh metrics. Just remember sonar will only keep one set of metrics per day AFAIK.

Before I discovered Sonar I used a lot of time configuring Maven metric plugins. However Sonar does it all and easy, plus have a lot of features/plugins, like timeline hotspots and quick wins. Very nice all in all.

Version System

For scm we use Subversion, no real arguments here it works for me and I haven’t tried out any other scm. Most annoying thing though are that we are having some trouble using branches (svn 1.5 using eclipse/tortoise etc) otherwise not much to say. I’ve peeking a bit towards git, but haven’t had the time to go further.

Ticket System & Wiki

For Tickets/Defects/issues & Wiki we use trac. Reasons are that it’s simple and materialistic. Although sometimes to minimal, theres always a plugin that will just expand trac the way you want. Only thing that are bothersome is working with multiple trac sites. I’ve been eager to try redmine out, it seems like trac but can a bit more. So heres what im missing in trac:

  • Ticket dependencies
  • Multiple site support easy


We use Eclipse, mainly because it’s the one I’ve been using longest and one of our vendors has made a specific product based on eclipse. I’ve tried both subclipse and subversive, and can’t figure out what are best. None of them seems to be working optimally with branches. Only way to get a good diff when merging a branch are in svn command line :/ One note though we are limited to Eclipse 3.2 and plugins that support that. So it might be better in newer versions.

I’ve been told a couple of times by different people that idea, are better and actually will make you more productive. And now with the free community version I might give it a try.


So following above, you should be set all the software mentioned in this article are free. Now go download and start making the world a better place. There’s a lot of projects out there waiting for you, either open source or for money. And just remember it’s better to try than not, some one once said it’s by our mistakes we learn 🙂

Stuff we use:

Stuff that i’d like to investigate:

Ohh and if you have any comment’s feel free to write.

Cleaning Code Practically Episode 1

8 10 2009

Last Øredev I were at a presentation done by Robert Martin, author of the book Clean Code. I were really impressed by what his message where. So we are trying to follow his word at work and today a topic came up. So a colleague had this code:

public String getRequestString() throws MQException {
String request = "";
request += Helper.leftRightFilled(true, String.valueOf(getSessionNumberAndIncreaseIt()), '0', 3);
request += Helper.leftRightFilled(true, getVersion(), '0', 3);
request += Helper.leftRightFilled(true, getTransaction(), 'X', 4);
request += Helper.leftRightFilled(true, getLanguage(), 'X', 2);
request += Helper.leftRightFilled(true, getCallersPhoneNumber(), '0',16);
request += Helper.leftRightFilled(false, dynamicSettingMQ.getCustomerNumber(), ' ', 16);
request += Helper.leftRightFilled(true, String.valueOf(dynamicSettingMQ.getNumberOfUnsucceededCalls()), '0', 3);
return request;

I intermediately though that could be more readable, so I just pushed a lot into functions, and did a little to the helper class:

public String getRequestString() throws MQException {
String request = "";
request += createSessionNumberString();
request += createVersionString();
request += createTransactionString();
request += createLanguageString();
request += createCallersPhoneNumberString();
request += createCustomerNumberString();
request += createNumberOfUnsucceededCallsString();
return request;
protected String createCallersPhoneNumberString() throws MQException {
return Helper.leftRightFilled(true, getCallersPhoneNumber(), '0', 16);
protected String createCustomerNumberString() throws MQException {
return Helper.leftRightFilled(false, dynamicSettingMQ.getCustomerNumber(), ' ', 16);
protected String createLanguageString() throws MQException {
return Helper.leftRightFilled(true, getLanguage(), 'X', 2);
protected String createNumberOfUnsucceededCallsString() throws MQException {
return Helper.leftRightFilled(true, dynamicSettingMQ.getNumberOfUnsucceededCalls(), '0', 3);
protected String createSessionNumberString() throws MQException {
return Helper.leftRightFilled(true, getSessionNumberAndIncreaseIt(),'0', 3);
protected String createTransactionString() throws MQException {
return Helper.leftRightFilled(true, getTransaction(), 'X', 4);
protected String createVersionString() throws MQException {
return Helper.leftRightFilled(true, getVersion(), '0', 3);

At first the colleague thought it was nice, but then remembered he really needed a overview of locations used in the string manipulation. So a thing between the two are needed:

public String getRequestString() throws MQException {
String request = "";
request += createSessionNumberString('0', 3);
request += createVersionString('0', 3);
request += createTransactionString('X', 4);
request += createLanguageString('X', 2);
request += createCallersPhoneNumberString('0', 16);
request += createCustomerNumberString(' ', 16);
request += createNumberOfUnsucceededCallsString('0', 3);
return request;
protected String createCallersPhoneNumberString(char fillWith, int length) throws MQException {
return Helper.leftRightFilled(true, getCallersPhoneNumber(), fillWith,length);
protected String createCustomerNumberString(char fillWith, int length) throws MQException {
return Helper.leftRightFilled(false, dynamicSettingMQ.getCustomerNumber(), fillWith,length);
protected String createLanguageString(char fillWith, int length) throws MQException {
return Helper.leftRightFilled(true, getLanguage(), fillWith,length);
protected String createNumberOfUnsucceededCallsString(char fillWith, int length) throws MQException {
return Helper.leftRightFilled(true, dynamicSettingMQ.getNumberOfUnsucceededCalls(), fillWith,length);
protected String createSessionNumberString(char fillWith, int length) throws MQException {
return Helper.leftRightFilled(true, getSessionNumberAndIncreaseIt(),fillWith,length);
protected String createTransactionString(char fillWith, int length) throws MQException {
return Helper.leftRightFilled(true, getTransaction(), fillWith,length);
protected String createVersionString(char fillWith, int length) throws MQException {
return Helper.leftRightFilled(true, getVersion(), fillWith, length);

Im not satisfied, but not sure it can be done more clean? And if you are wondering about why we are doing all this string manipulation, we are working with some legacy MQ. If we split up the code without parameters as above we lose the quick overview.. But could the code be simplified even more please come with your suggestion..