Saturday, April 23, 2011

Monday, September 13, 2010

Hibernate Named Native SQL Queries mapping to POJO in xml

Spent sometime looking for a way to create named in the orm.xml. I would have ranted about why every single example I had related to annotations, but that's already been covered sufficiently here or even why they all related to returning entity results when all you need sometimes is a simple POJO. This had me yearning back to the good old days of iBatis.

That goes into the orm.xml.

FYI, I was using hibernate 3.2.x, with the orm_1_0.xsd. ResultTransformers to do the quick POJO thing are only available when using Hibernate raw i.e. not using JPA. A good example is available here.

Sunday, September 12, 2010

IceScrum2 on AWS Micro instances

It's been a while since my last post. I've been under the pump at work and job hunting as well. The announcement from AWS this week about Micro-Instances were too much of a temptation for me. A $54 yearly reservation cost works out to $9.61 reservation cost per month and $5.11 usage at $0.007/hr at 730.5 hours on average in a month. A member of the AWS user group compared it to about 4 Big macs a month at US$ 3.73. Being vegetarian I'd prefer to compare it to about 4 cups of coffee per month.

So, what to do with this new found power? I'm moving some of my development environment online. At the moment that includes:
  • A JBoss 4.2.2 staging server
  • IceScrum 2
  • Hudson integration server
I've previously covered how to get started with AWS for J2EE servers. However, there are some pitfalls using Micro Instances. First, you can only boot from EBS. This may or may not be a good thing. On the plus, your data will always be persisted regardless of shutting down the server. The main negative is the additional cost of the EBS. I'll put it at another cup of coffee a month. Second, I'm migrating my existing IceScrum instance so I need to create an instance of Amazon RDS and export my MySql data to the RDS.

IceScrum2 requires 512MB to work properly (Seriously? 512MB for a simple web-app). The micro instance comes with 613MB each. Which doesn't leave much to throw around. Still, it works well. Next, I'll be putting up Hudson.

Saturday, September 4, 2010

ASP.NET ReportViewer control Dynamic reports with Object Data Source

I've been recently playing around with the built-in reporting control that ships with Visual Studio 2005+. At the time of writing, I'm working with Visual Studio 2008, with Microsoft.Reporting version 9.0. There aren't that many tutorials I found on the web for creating dynamic reports using Object Data Sources. For the uninitiated, an object data source is simply a strongly typed collection of objects with pre-defined properties. Visual Studio should pick up any classes with a method returning a strongly typed list of the objects.

Once you've got that bit sorted, now how to load the data source dynamically...

That's it. All sorted. Clear the data source from the report every time you want to regenerate the report.

Thursday, July 8, 2010

Arduino Button Bouncing - Why doesn't my LED remain on?

This is an update to my last posting on Getting Started with Arduino. After a couple of days of frustration, I purchased an Arduino Prototyping Shield (I don't think I'm yet ready to pick up the soldering iron and build it from a kit) as the Freetronics Starter Kit I purchased only comes with a mini breadboard and lots of the tutorials come with a prototyping shield and needed to see something consistent. Anyway, I was looking at this button tutorial on the Arduino website.

The circuit is similar to the one in my last post, and the sketch from the arduino website is reproduced below:

When tested out, the LED only turns on when the button is pressed. Turns out, due to the spring mechanism in the button, a rapid sequence of on off signals are sent when the button is pressed (Remember Arduino is a continous loop!). Hence a delay of about 10-50 milliseconds delay correctly detects a transition, as seen below:

Wednesday, June 30, 2010

Getting started with Arduino on Freetronics TwentyTen

Barely a week ago, I was happily unboxing my Freetronics Arduino starter kit (available here in Australia) and the Getting started with Arduino book by Massimo Banzi one of the 5 developers of the Arduino environment. The introductory chapters of the book are well written and you get a good sense for the passion of Massimo for electronics and prototyping. The obligatory what is electricity and the water pump analogy out of the way, it gets stuck in the first sketch - making an LED blink. This is relatively easy to achieve and a nice quick and easy success for the beginner.

The next challenge was to use a push-button switch to add some interactivity to the mix. This is where the lack of an endorsed starter kit makes following the book a challenge. There isn't enough of an introduction to the electronics components required (other than explaining where they can be purchased). The diagram uses a full-size bread board which is different to the tiny breadboard that comes in the Freetronics starter kit. Still, its not impossible to figure out. My circuit is shown below:

The LED is partially obscured but the other connections can be easily figured out. A slightly more challenging tutorial is available here.

Friday, June 25, 2010


SQLServer (both express and full versions) provide a useful command line tool (sqlcmd) which you can use to run batch tasks. See the full list of options here. Here's a quick way to get usable CSV output from this tool.

The main things to watch out for are specifying the correct delimiter.
  • -s: For Comma-Seperated-Values (CSV), the value of -s ","works a joy.
  • -W: The -W option removes the trailing whitespace.
  • -h: Setting this to -1 removes the headers of the fields (if your query is returning a result set).
  • -i: This is the input file (the file with the sql to be executed). For interactive scripts and to make your batch file resuable, set this to %1 to use the first command line argument
  • -o: This specifies the output file
  • -S: The server.
  • -U: The user
  • -P: Password
The complete version of the reusable script with comments and usage:

I'm still working on how to remove the number of rows affected line after the result set.

UPDATE: Setting NoCount On (Set NotCount On) in the SQL file disables this behaviour.