Thursday, May 31, 2007

On the Street Where I Live

On the Street Where I Live

You must forgive the title and post full of cheese. I'm a sap when it comes to jazzy show tunes. Anyhow, more than a decade ago I was introduced to this song by my best friend, and I know I've found a particularly happy moment in my life when "On the Street Where You Live" starts playing in my mind.

This evening I went on a walk and really it was a beautiful Salt Lake evening. As I turned onto my block, the song started playing in my mind, and I knew what I would post to my blog tonight. I'm particularly grateful for moments where things are just right, even if they are fleeting. I'll take what I can get.

Sunday, May 27, 2007

Ouch! My Back

I went to see Pirates of the Caribbean: At World's End last night, and found it to be quite enjoyable. Yes, the show is a little on the long side, but I really liked it. Seriously, what's not to like about the pirates movies? The only downside to the whole experience was that while sitting in my camp chair at the drive-in, I did something to my back, and now it doesn't want to let me move very much. I've found that with a good dose of Advil, I can manage to sit in a high backed chair. Things seem to be okay so long as I don't do much with my arms or twist. I hope that this is just a really bad knot, or that I pulled a muscle somehow (though I have no idea how I would have done that). I'm looking forward to having a day off from work tomorrow. It's been a while since I last took a day from work in which I didn't have some other time-consuming task on the calendar in its place. If I can get out of this chair, or my bed, I might even get to go take some pictures.

Tuesday, May 22, 2007

To be a JS Ninja

Today I had three wishes.

  1. I wish that I was a JavaScript ninja, with a deep, abiding understanding of how the DOM was implemented in all of todays major browsers, particularly IE7 and why it never works the way you think that it should.

  2. I wish that when I get stuck like I got stuck today that Google was able to return more meaningful results.

  3. I wish that I had more web designer friends that are JavaScript ninjas, that do understand the DOM, particularly as it relates to IE7.

So there you have it. My three wishes for the day. Here's the back story, and a petition for someone's superior skill and knowledge.

The application that I am building at work would be greatly benefited by a framework that would accommodate light boxes. Yes, there are lots of implementations out there, but none of them were quite what I was looking for, so I set out to modify one to suit my purposes. Everything was up and running happy and fine in good 'ol Firefox. I jumped over to IE to make sure things were equally as happy, and found that seemingly simple things really weren't as simple as I had hoped.

The function would look like this:

function doStuff()
var node = $('myUpdateDiv1');
node.className = 'class1, class2' //class 2 overrides some attributes of class1
node.innerHTML = '... nice HTML chunk with a style tag
and other stuff that comes from
an AJAX call ...';

node = $('myUpdateDiv1');
var box = new lightbox(node);

And in Firefox if the innerHTML has a <style> tag that defines class2, then the div will assume the class2 style. However, IE really really hates it. So I ended up with code like this to solve the problem.

function doStuff()
var node = $('myUpdateDiv1');
node.replace(... HTML with embedded style right on the tags
coming from an AJAX call ...
node = $('myUpdateDiv1');
var box = new lightbox(node);

IE seems to require that if the style is going to work, that the styles be embedded on the tags in style attributes, and that the entire div be replaced, as innerHTML would replace the markup, but the styles wouldn't appear to take. I am sure that these issues have something to do with my non-ninja design, DOM and JavaScript skills. If you have a better answer that would allow the AJAX call to return an HTML chunk that could take a chunk like this, and render it in IE, I would be VERY happy. It would really simplify some aspects of this process that I am working on. It's critical that the web page be agnostic to the styling of the light box, as it would be much preferable for the implementer of the remote AJAX call to set his/her own styles for the box.

Here is a very simple toy page that I have been playing with. It's working in both IE and FF, but I would really like to get away from the node.replace(), and style on each HTML element if at all possible.

Can anyone tell me what I'm not understanding?

Wednesday, May 16, 2007


Really this is quite the rambling, I'm not exactly sure what it means, but it is a brain dump of some ORM related stuff that I've been thinking about for the past couple of days.

After having used Hibernate on a school project to help with object relational mapping (ORM) and now returning to an environment where I am writing all of my database code by hand, I understand why ORM is such an appealing solution. It isn't without its own headaches, but it does speed up development, because the developer isn't required to spend as much time on the data layer.

In the past month at work, I've spent most of my time writing service layers for a project that needs to support distributed API access by several applications across our line of business. To me it seems that when I am working on debugging code, more likely than not, the bugs appear in the data layer rather than in the business logic, or presentation layer. When I am debugging my data layer, or when I need to write yet another query to get at some aspect of the data, I am constantly faced with the question: why not use an ORM tool?

At my place of work the answer has been that ORM tools don't work well against legacy databases, and that they tend to add more overhead to processes that need to run really fast. Both arguments may have some validity. I have not yet tried to map objects against our legacy schema, and I do understand that if you one doesn't clearly understand the working of their ORM tool that some queries could end up being quite bloated. It is quite obvious that if all you need is a single field, and your ORM tool brings back 20, that's 19 fields that you didn't really need, but that argument sounds a lot like the argument that we should code every application in assembly because it would be very fast.

It was interesting to read a follow-up to this article in this month's Linux Journal. The Object Relational Mapping Quagmire, as the authors put it really needs some deep thought and attention. I think that they really hit the nail on the head. Yes ORM is nice because developers can deal with their happy objects, but relational databases and ORM don't have a perfect 1:1 correspondence because our objects hold information differently than our database tables do, and perfectly normalized data tables in BCNF will can cause a lot of pain for most ORM tools. It looks like there are some tools out there that aim to store data as objects rather than rows and columns, but that doesn't do much to solve the legacy database issue.

If a company currently does very well with the tools it has, and the legacy database it has supported for years, is it justifiable to start over? If it isn't broken, should it be fixed? I completely understand the decisions made by new companies to start out with the bleeding edge tools, but what about the legacy companies who have been making fine money with their tools for years? It's not an easy question, and I don't know that there are any exact answers. I don't believe that a company wants to be technologically stuck, but some upgrades seem almost prohibitive to the ever important bottom line. I'm a proponent for change, and it's always exciting to use the new tools, but re-structuring an entire database does seem counter-intuitive, even if I do have to write my DB code by hand.

Sunday, May 13, 2007

Hibernate and MySQL Connection Timeouts

Several weeks ago, while trying to finish up a portion of my senior project, my team was having some issues with our persistence layer. The issue had to do with the connection time out in MySQL, and the default C3P0 setup that Hibernate uses. As it took MUCH more research than I think it should have to solve the issue, I thought I would write a blog entry about it. Besides, I haven't set out to give anything back in quite a while. Note that while none of this information is new in any way, I have not been able to find it all gathered together in one place.

After my Spring/Hibernate/MySQL soltuion has been running but inactive for more than 8 hours, I get a broken pipe exception.

Root Cause:
MySQL automatically times out, and closes unused connections after 8 hours, and out of the box, Hibernate does not set up C3P0 to appropriately test/refresh its connection pool when connections go stale.

It seemed that as we searched the forums for an answer it wasn't immediately obvious what the right answer would be. We noticed that the C3P0 properties had different names, depending on how your project was configured. The hibernate documentation has some suggestions, but it turns out that the names of the properties are not stated correctly. It is also important to note that if properties are not set in the hibernate configuration they will be overridden by hibernate defaults. Here's a snippet from my hibernate.cfg.xml:

<!-- driver/connection info removed --!>
<!-- C3P0 Stuff -->
<property name=“hibernate.c3p0.acquire_increment”>3</property>
<property name=“hibernate.c3p0.idle_test_period”>14400</property>
<property name=“hibernate.c3p0.timeout”>25200</property>
<property name=“hibernate.c3p0.max_size”>15</property>
<property name=“hibernate.c3p0.min_size”>3</property>
<property name=“hibernate.c3p0.max_statements”>0</property>
<property name=“hibernate.c3p0.preferredTestQuery”>select 1;</property>

The important properties to note above are idle_test_period, and timeout. You want to make sure that C3P0 is configured to test for closed connections and time out unused connections at some rate beneath the threshold set on your MySQL server. With these properties in place you should be good to go.

Waiting 8 hours to conduct a test like this would be lame, so let's just change the connection timeout for the MySQL server, re-start the MySQL server, and our application to try it out. You can change the timeout time for MySQL by editing your /ect/my.cnf file (linux) or your my.ini file(windows). You would want to add the following line to the file:


Note that the value after the property is in seconds. Once you're done with your testing, you can remove the property and it will default back to 8 hours.


Configuring C3PO

C3P0 Hibernate Configuration

my_sql options()

Set the MySQL Connection Timeout

Saturday, May 12, 2007

The Void

I keep waiting for things to get less busy, but they never will. So far as the personal details of my life, I graduated from the University last week! The graduation commencement and convocation activities were really great. I appreciated the advice that was given and the thoughts that were shared. The whole experience was rather emotional. It's been almost seven years since the beginning of this journey. At first I thought I wanted to be a doctor, but then I found a real passion for computing. Changing my major may have added three years to my time at the University, but it was a good move for me personally.

So now that I have that piece of paper that says I jumped through collegiate hoops, I feel something of a void in my life. Yes, I should be quite happy that I won't be spending hours and hours on homework, but I really did come to enjoy the process of programming for personal education. I've decided that I must be involved with projects that force me to keep learning. It looks like I'll be playing with Ruby in the coming weeks, so though I am a Java developer by day, I'll play with Ruby by night, and hey, I might just get the hang of that Linux thing while I'm at it. I'll work on filling the void with extra sleep, programming projects, and it couldn't hurt to start dating. I'm starting to feel old.

Anyway, here's to change!