Tuesday, July 21, 2009

See my pretty hammer...

It happened again.

I learned about a feature in OpenJPA that allows you to specify the fetch behavior exactly as you need it - fetch groups.

And, they are awesome.  My opinion doesn't carry much weight - but if it did, then fetch groups would be part of the JPA spec.

But like every tool - they should only be used when it is appropriate.

One reason that they should be used only as really needed is that in Apache Geronimo, casting a regular EntityManager to an OpenJPAEntityManager causes a new transaction to be started.

In itself that isn't necessarily so bad, but it does begin to clutter things if you use them excessively.  And, that is exactly what I did.

I took my shiny new hammer and started whacking everything.

Including my thumb.


Tuesday, July 14, 2009

I wonder if this box is too small...

I am starting to think that I will need to take another look at the database that I am using.

Up until now, I have been using MySQL because it is free and many (many, many,...) web sites use it for their database back end.

But I seem to be testing its limits - at least on the hardware I'm running it on.

I have been steadily growing a Java app (JEE5) using Apache OpenJPA to connect to the database.

When I first started, the EJB3 and JPA were still in development.  EJB2 was too complicated for the benefit that I thought that I would get so I 'faked it' and created my own psuedo EJB app using: JDBC, servlets, servlets pretending to be EJBs, and POJOs.

The database performance was fairly bad because I have -severely- interlinked data model.  So getting the data to display anything typically involves at least 8 tables linked heavily and repeatidly.

Here is a try at describing something similar to my structure.  If you want a headache, try drawing out the relationship diagram.

  • Master entity (1 -> M) Component
  • Master entity (1 -> 1) Category
  • Master entity (1 -> 1) Sub-Category
  • Master entity (1 -> 1) Sub-Sub-Category
  • Master entity (1 -> 1) Creator (User)
  • Master entity (1 -> 1) Owner (User)

  • Category (1 -> M) Sub-Category

  • Sub-Category (1 -> M) Sub-Sub-Category

  • User (1 -> 1) Department

  • Component (1 -> 1) Component Class
  • Component (1 -> M) Component Attribute

  • Component Class (1 -> M) Class Attribute

  • Class Attribute (1 -> M) Attribute Value (list of possible)

  • Component Attribute (1 -> 1) Attribute
  • Component Attribute (1 -> 1) Value

  • Attribute (1 -> M) Attribute Value (list of possible)

JPA rescued me.  Just changing my data access to use JPA increased the performance of my app about ten-fold.  And, it simplified my code - I was in love.

Later EJB3 session beans took the place of my fake EJBs (servlets).  And I was in love again.

But now, I have millions of rows in over a hundred tables.  Linked together in ways that I could probably not even write JDBC to access anymore.  And the data is stored in MySQL.

Don't get me wrong - I really do like MySQL.  It has been good to me.

But my database with data and indexes is approaching three gig.  As in three billion bytes - and MySQL is starting to have some trouble.

So I think I might need to stray.

Breaking up is hard to do though.

Thursday, July 9, 2009

Wouldn't you know...

Well, I'm trying to move forward with using/learning Groovy.

But, I need to use it with JPA and EJB3 session beans.

In case you were wondering...  There aren't any good ('realistic') examples of how to do this.  At least not that I was able to find on the web.

It may be, that there are books that demonstrate how to use them - I don't know yet.

So, instead of being able to jump in and run -

Baby steps.

Wednesday, July 8, 2009

'Scuse me while I whip this out...

I think that the biggest problem with learning about a new programming language or tool is:

While you are holding your new 'hammer',
everything looks like a nail.

And you need to learn what the real cases are that the new tool is actually is the right one for the job.

Otherwise, you end up writing lots of bad code trying to shoehorn an inappropriate method into a place it does not belong.

For me, there is a second problem that I sometimes have trouble overcoming.  And that is when I already have a solution (possibly a very ugly one) that should have used this new method that I just learned.  In this case, it is scary to break something that works just to do it the 'right' way.

There have been some resounding successes for me recently.

Trading JDBC data access for JPA - Amazing improvement in code understandability and speed.

Trading 'thick' servlets that included large chunks of functionality that really belonged in EJBs for EJBs - Tremendous increase in code resuse and automatic transaction support inherited from the EJB container.

Not every experiment panned out though.  I used a message driven bean to perform a cleanup process asynchronously that really needed to stay synchronous (I still haven't cleaned all of the mess up from that).

So, now - as I try to learn Scala and Groovy (I can't seem to limit myself to one language at a time) it is hard to find when and how to apply them.

Oh well.

If it was easy...

Everyone would do it.

Tuesday, July 7, 2009


That is something that I have a combination of far too much and far too little of.

When I am working on something - I can do so completely ignoring just about everything else (fatigue, hunger, distracting noises, etc).

But, there are way too many things that I want/need to learn.  Particularly with computer technology (and languages).

And, since any one would take at least a few months to figure out whether I really want to learn it (and the fact that there are only twenty-four hours in a day) - how could I pick just one at a time?

I should though.  And I know that I should.

Because instead of already having a decent start on Drupal - I have managed to taste:
  • Drupal
  • Ruby (very small taste)
  • Scala
  • Groovy
  • etc
But I cannot do anything useful in any of them.

So - I have to pick one.

And focus on it.

Everything else will have to just go on my todo list.

Where did I put that thing?

And which one comes first?

Scala and Groovy would probably be most useful for work...