Archive for November, 2003

Off to India

Monday, November 24th, 2003

I just found out that I will be going to India in January for 6 months.

I’ll be working for the ThoughtWorks India office on various of our projects out there. I have been wanting to so this for a while — and we’ve now made it happen.

Its going to be a challenge, both personally and professionally, but anyone who knows me will understand how much I am looking forward to soaking up the culture while I’m there.

Wireless!

Wednesday, November 19th, 2003

OK so I now have a wireless access point for my new ThoughtWorks laptop. Boring I know —I can now blog without cables. Very cool.

Incidentally, I love the fact that devices all have web pages for configuration, it makes installataion a breeze — open the manual and find out the IP address and bob’s your uncle.

Data object memes

Monday, November 17th, 2003

At the codehaus HausParty James Strachan, myself and a few others got to thinking about O/R mapping and Groovy.

We came up with the idea of extending the GPath syntax to allow us to specify strongly typed queries.

For example, assume that you have a collection of Person objects called people. In Groovy you can do the following to get all people with the surname ‘Bloggs’ who are over 21:

bloggsOfAge = people.findAll{it.lasName=='Bloggs' && it.age>21}
//iterate through the returned values
bloggsOfAge.each {
//do something
}

What we are trying to allow in Groovy is to specialise the collection class that will at runtime turn this into an SQL query:

SELECT * FROM Person WHERE Person.lastName='Bloggs' AND Person.age > 21

Its a fairly simple transformation, and what it gives you is very powerful — a query that is checked at compile time, not runtime.

Of course we could also turn this into some kind of xslt/xpath:

<xsl:for-each match="//Person[@lastName=='Bloggs && @age>21']">
<xsl:apply-templates select="."/>
</xsl:for-each>

But it gets cooler. In Groovy and similar languages you can build these objects dynamically. Groovy GPath works on HashMaps for example as well as real objects. And I don’t think its clear that using real objects (aka O/R mapping) is the best way to do this kind of db stuff. Maybe this kind of dynamic object construction is better?

Note that the key difference with current query syntaxes like JDO/EJBQL is taht they are just strings and therefore not checked by the compiler. There is a lot more difference between:

doQuery("it.lasName=='Bloggs' && it.age>21");

and

findAll {it.lasName=='Bloggs' && it.age>21}

than a mere absence of quotes.

James tells me that he’s been talking to people at the Apache Conference about the idea. I think if the idea flies we whould be able to write trivial adapters for other persistence technologies like Prevayler and OJB

Here’s a bit more of the zeitgeist:
Ted Neward
James Strachan
Smalltalkers with the same idea
The GPath wiki page
James Strachan’s post explaining GDO