Wednesday, February 29, 2012

Spring JDBC

Took a very short break from JPA and tried working with Spring JDBCTemplate for a small project.
It's a mock version of a complex super optimized service using a lot of custom native sql.
I appreciated the simplicity of JDBCTemplate, and specifically the NamedParameter version.
I found the RowCallbackHandler useful for my case where each row didn't necessarily mean one object, and I was able to reuse the handler across different queries.

One problem I had was attempting to avoid creating new tables, and thus using what I had for columns. One problem was the indexes missing for the searchable columns in where clause.

But another more interesting one was needing to map two numeric columns into a unique numeric key. And the key is limited to a long value. In the end, I was able to combine the two numbers using 32 bit shifting to create the long value, treating them both as ints (AA+BB=AABB). With the issue that it would not work if they were beyond the max int value. Fine for now.
And this ended up working great, being able to encode the column values into a single unique key and translate them back into the separate column values for querying.

Tuesday, February 21, 2012

Admitting defeat and victory

tl;dr: bad data for testing can waste a lot of time.

I spent the last week or so trying to solve an issue.
The original goal was to reimplement an integration with a black-box system.
And it wasn't working.
Not only was it failing, but each testing request attempt crashed the system, preventing further testing without someone to restart it.
And of course there was no useful response or error info with the failure.

So I investigated and found an issue with the protocol and fixed it. No change.
As a baseline and comparison, I brought the old code into the new project. Same outcome. Failure without a cause, system down.
At this point it is getting too late into the development cycle and time to prepare the backup plan. This involved the new code calling the old project (not ideal since goal was to replace/remove it).

This is a difficult process: to admit defeat.
To admit that the world does not work as you expect it to, especially as a developer. To abandon your grand idea and accept your least ideal path. To hope one day to be able to come back and fix it given the time.
And in the end, the results were the same! Still failing.

Now this pointed to the request data being bad.
I had suspicions since it was one of the few differences (sending a remove command for something that didn't exist).
My guess was partially correct, but the root cause was bad test data. The ID being used was not valid in this dev environment. Normally this fails with a useful error message for other commands, but for remove it crashes the system.

So after a painful slow stretch of testing (having only 1 chance to test before killing it and waiting for restart), it wasn't even an issue with my code.
After using a valid ID, all implementations worked as expected.

Yes, this issue with bad test data had come up recently here.

Monday, February 20, 2012

Fringe-tastic

Fringe is really in high gear it seems.
And I'm always trying to get caught up with the week-delay on Hulu.
So much happening lately on the show and its all good.
So that even an episode like the recent s04e12 welcome to westfield that could have been just a fun mystery/monster-of-the-week was still driving the larger story.

What I really liked was how it reminded me of other stories I've enjoyed (twilight zone, scifi/horror/zombie films, supernatural, etc)
Being trapped in an apparently deserted small town
People are going insane, "infected", looking like zombie/mutant, raid the sheriff station for guns
Effects occurring in cycle (i thought of silent hill)
Surroundings disappearing, approaching closer (reminded me of langoliers)
Even the beginning of the episode had an X-files feeling with cars suddenly dying on a backroad with radio interference and lights above similar to a UFO

So I enjoyed the classic scifi themes while also building the main story of Fringe this season (david robery jones, the timelines/universes, different versions of olivia and walter)