NLJug J-Fall 2010

By Rob, November 18, 2009 11:07 pm

Wednesday the 11th of november I visited JFall for the second time. This is the yearly event of the Dutch Java usergroup next to the JSpring in april. I attended on several sessions targetting especially new Java developments. For example the big improvements in JDK 7 where I was interested in.

  • Keynote – Enterprise 2.0: New Technologies, Innovations and Communities (Reginald Hutcherson)
  • Speed up your applications with Java SE 7 (Jeroen Borgers)
  • Scaling Out with Hadoop and NoSql (Age Mooij)
  • Keynote – Adobe Systems (Christophe Coenraets)
  • The Quest for Parallelism: How To ‘upgrade’ Your Application (Jan-Hendrik Kuperus)
  • JDK 7, What’s in it and what’s not (Simon Ritter)
  • Google Wave: what is it, and how does it work? (Jos Dirksen)

(I translated some of the subjects to English)

Three of them had a lot in common, the speeding up, the parallelism and the jdk7 where the most interesting ones. The other sessions where more informative and for fun.

The subjects I was really excited about, are the new concurrency features in Java. Being this more and more important with the current multicore cpus and the cloud computing hype we can’t ignore it! And it’s not only faster, it’s also very cool and not even hard to give it a try as a normal programmer. I even think that this new stuff makes our live easier then the old fashioned threading stuff in Java 5 and earlier (a lot of new stuff in Java 7 is already available through Java 6 in the updates but often not enabled by default).

Some cool and nice features are:

  • Fork join framework (next step in parallelism, helps you execute task based procedures)
  • Escape analysis (improvement in allocating memory for objects based on the scope of the object)
  • Project jigsaw (module management)
  • Compressed 64 bit pointers (store 64 bit pointers in 32 bit)
  • Garbage first collector (new algorithm for garbage collecting)

That’s it for now, I didn’t have the time to start playing around with the new Beta of jdk7. Hope to get started soon!

Share and Enjoy:
  • Print
  • Digg
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • DZone
  • RSS
  • Twitter

Duchenne Heroes 2010

By Rob, November 12, 2009 11:27 pm

This time no technical kind of thing, the last months I’ve been working on an update of a website which I voluntary manage for my athletics club (www.av56.nl). I rewrote my simple own MVC framework to the well know CodeIgniter framework. And except that, I’ve been biking quite a lot too. Especially since I bought a road bike (Giant TCR Advanced 2) next to my mountainbike (Cube Reaction).

That biking crazyness has now been changed into a new adventure called Duchenne Heroes. In short some facts:

  • 7 days of mountainbiking
  • 100 km each day
  • 10.000 altimeters
  • 4 countries
  • 4 people per team

And that all with just one main goal, collecting money for the Duchenne foundation. A good description can be read on wikipedia about what Duchenne is. The idea came up after a few beers (always the guilty one :) ) with some friends and since last saturday, our team of four people is a fact! We started creating a website this week but there’s  a lot of work left: clubjegoes.nl

So, keep an eye on our website if you’re interested or even better, donate money to our team. We need 10.000 euro in total. We’re now busy thinking about how to create special sponsor packages. And not unimportant, start training since this is one of the toughest tours in the Benelux.

My next will soon be published, it’s about the Dutch NLJUG day called JFall which I attended last wednesday. It’s a conference of the Dutch Java user group. I’ll briefly describe the subjects I followed and try to dig into them later. Especially the new Java 7 improvements have my attention, awesome new stuff designed for multi core processors and cloud computing!

Share and Enjoy:
  • Print
  • Digg
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • DZone
  • RSS
  • Twitter

Using a custom Oracle collection type with iBatis

By Rob, September 17, 2009 8:28 pm

Some months ago I came across a problem with the more complex custom Oracle types in combination with iBatis. I thought that it would be nice to share it with you. In my case I had to link a list of objects in Java to an array of structs in SQL (Oracle).

The biggest part of the trick is inside a custom type handler, which is actually a helper class with two important methods, the setParameter and the getResult. setParameter if for mapping parameters before firing the query and the getResult is for processing the result (if you use a custom type as an OUT parameter). For the example I used a Quantity class which has two properties, id and quantity. My Oracle types are a struct (Quantity) and a table of that struct (QuantityList)

The code will show you the rest, because once you know how to deal with this, other cases are quite easy.

package nl.tigrou.test;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

import java.util.List;
import oracle.jdbc.driver.OracleTypes;
import oracle.sql.ARRAY;
import oracle.sql.ArrayDescriptor;
import oracle.sql.STRUCT;
import oracle.sql.StructDescriptor;

import org.springframework.jdbc.support.nativejdbc.C3P0NativeJdbcExtractor;
import org.springframework.jdbc.support.nativejdbc.CommonsDbcpNativeJdbcExtractor;

import com.ibatis.sqlmap.client.extensions.ParameterSetter;
import com.ibatis.sqlmap.client.extensions.ResultGetter;
import com.ibatis.sqlmap.client.extensions.TypeHandlerCallback;
import com.ibatis.sqlmap.engine.type.JdbcTypeRegistry;
import com.mchange.v2.c3p0.impl.NewProxyConnection;

public class QuantityListTypeHandler implements TypeHandlerCallback
{

  private static final String QUANTITY = "QUANTITY";
  private static final String QUANTITYLIST = "QUANTITYLIST";

  static
  {
    JdbcTypeRegistry.setType(QUANTITY, OracleTypes.STRUCT);
    JdbcTypeRegistry.setType(QUANTITYLIST, OracleTypes.ARRAY);
  };  

  public void setParameter(ParameterSetter setter, Object parameter) throws SQLException
  {
    try
    {
      List<Quantity> quantities = (List<Quantity>) parameter;

      Connection conn = setter. getPreparedStatement(). getConnection();
      if(conn instanceof NewProxyConnection)
      conn = new C3P0NativeJdbcExtractorImpl().getNativeConnection(conn);

      StructDescriptor quantityStruct = StructDescriptor.createDescriptor(QUANTITY, conn);
      ArrayDescriptor quantityList = ArrayDescriptor.createDescriptor(QUANTITYLIST, conn);

      STRUCT[] elements = new STRUCT[quantities == null ? 0 : quantities.size()];

      for (int count = 0; count < elements.length; count++)
      {
        Quantity quantity = quantities.get(count);

        elements[count] = new STRUCT(quantityStruct, conn, new Object[] { quantity.getId(), quantity.getQuantity() });
      }

      ARRAY array = new ARRAY(quantityList, conn, elements);

      setter.setArray(array);
    } catch (SQLException sqle)
    {
      throw sqle;
    }
  }

  private class C3P0NativeJdbcExtractorImpl extends C3P0NativeJdbcExtractor
  {
    public Connection getNativeConnection(Connection con) throws SQLException
    {
      return doGetNativeConnection(con);
    }
  }

  public Object getResult(ResultGetter getter) throws SQLException
  {
    ARRAY array = (oracle.sql.ARRAY) getter.getArray();
    ResultSet rs = array.getResultSet();
    List<Quantity> quantities = new ArrayList<Quantity>();
    while (rs != null &amp;amp;amp;&amp;amp;amp; rs.next())
    {
     STRUCT struct = (STRUCT) rs.getObject(2);
     Object[] attribs = struct.getAttributes();
     Quantity quantity = new Quantity();
     quantity.setId(((java.math.BigDecimal) attribs[0]).longValue());
     quantity.setQuantity(((java.math.BigDecimal) attribs[1]).intValue());
     quantities.add(quantity);
    }
    return quantities;
  }

  public Object valueOf(String value)
  {
    if (value == null)
      return new ArrayList<Quantity>();
    return value;
  }
}

And the corresponding query in one of your xml mapping files. The magic is all inside the inline parameter.

SELECT * FROM sometable x
LEFT JOIN TABLE (
  CAST
  (
    #quantities,handler=quantityListTypeHandler,jdbcType=STRUCT,javaType=Quantity# AS QuantityList
  )
) s ON (s.identifier = x.id)

BTW, if you haven’t noticed it yet, iBatis 3 is about to release. Check out the release candidates because they did an awesome job!

Share and Enjoy:
  • Print
  • Digg
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • DZone
  • RSS
  • Twitter

First Garmin Edge 705 experiences

By Rob, July 11, 2009 7:53 pm

Some weeks ago I bought the Garmin Edge 705. It’s THE gps device for biking. It’s waterproof, has a heart rate and cadence monitor. You can compare it with a TomTom but with a lot more features specialized for biking. More info here: Garmin.

Example picture:

garmin-edge-705_.450x450The only thing I didnt like, where the maps which you need to actually use the gps. For example, a map for the Netherlands costs you around 130 Euro. But there’s also a free alternative which is even better but you’ll have to do some research and reading. One of the sites which helped me a lot is openmtbmaps.org, this is based on the openstreetmaps which are free maps maintained by you and me (I really like that, just like Open Source Software). Openmtbmaps is more dedicated to mountainbiking, meaning other rendering of the map and extra info like difficulty.

Enough about the gps system and maps, now the results! Two weeks ago I went for a holiday to the Black Forest in the southern part of Germany. I uploaded maps to my edge 705 and included some tracks from gpsies.com (amazing site too). Once there, I also bought an old fashioned paper based map including some routes at the local store.

I have biked several tracks but a nice (and heavy) one I would like to use as an example. It was a track over 60 kilometers and more then a thousand meters of climbing. I’m still experiencing with all the software and converting of thousand standards in maps world (gpx, kml, kmz, tcx etc), so there are some strange details in the charts below. Like the straight lines in google maps and the max speed of 20 km/h in the last chart. Yes, I’m sure that I biked harder :) . With a max of 55 km/h.

So the experiencing is still not over and my Edge 705 has a lot of unused features. Time to go biking again!

Elevation Profile
Speed Profile

Share and Enjoy:
  • Print
  • Digg
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • DZone
  • RSS
  • Twitter

AOP Advices and Aspect combinations

By Rob, June 14, 2009 8:37 pm

It’s about a month ago that I was completely stucked with a Spring AOP configuration. While working on a better transaction management (see older post), I kept struggling in a circle of either a non functioning transaction system or broken AOP aspects. It really drove me nuts so I decided to avoid that pain for somebody else. No examples and code this time, just a simple pointer to the Spring documentation (which clearly took too much time to find :) ).

Let’s start with the note in the documentation:

Advising aspects

In Spring AOP, it is not possible to have aspects themselves be the target of advice from other aspects. The @Aspect annotation on a class marks it as an aspect, and hence excludes it from auto-proxying.

(Source – Spring reference docs)

After searching a bit more information, since the text above not really explains why they’re excluded, I found the following 2 “rules”:

  • Classes with annotations @AspectJ and classes that implement or extend any other AOP component are excluded from the autoproxy. This is because they aren’t target classes, and they perform tasks in Spring AOP infrastructure.
  • Proxy is not applied to beans that implement the interfaces BeanPostProcessor or BeanFactoryPostProcessor. The class AnnotationAwareAspectJAutoProxyCreator implements the interface BeanPostProcessor, which allows the class to modify the life cycle of beans on which a proxy must be created and applied.

The first point here explains why Aspects are not proxied. The second point names another condition.

So, conclusion:

Never use Aspects (@Apects) and proxy based transaction management on the same bean!

It’s simple to avoid by creating a separate Aspect which advices other beans. Something like this:

@Aspect
public class TestAspect
{

  @Before("execution(* someThing) ")
  public void doSomethingElse()
  {

  }
}

That’s it! At the moment I’m working on the website of my local athletics club, with CodeIgniter I’m finally enjoying PHP programming again.

Share and Enjoy:
  • Print
  • Digg
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • DZone
  • RSS
  • Twitter

Panorama Theme by Themocracy