Or to use Gavin’s example of:
(And this is assuming that we even need the classes to define what the placeholders are, that we’re not using something like the SQL library in Spring, etc.)
I really feel like I’m missing something here. Gavin and Dave are smart guys and from what I’ve seen very practical as well. But why would you use the query by criteria type of code at all? It’s more difficult to read, for one, and has more code (~~ more errors). The query as string is also much easier to integrate with an existing library of queries, even with a phrasebook of queries created by the database folks who are for some reason treated like peasants by many programmers.
I do recognize that you can use such a framework to isolate you from changes in basic SQL – translating the PostgreSQL pattern matching to other systems can be a PITA, for example. But is it really worth the added obfuscation?
So many programmers treat SQL and database folks like some booger man and I still don’t understand why. Is it because SQL is easy to learn and understand? (I can teach my wife SQL basics in 15 minutes. Java basics?) Because it’s been around for 20 years and is tainted with some legacy virus? (Darn that historical knowledge?) Because lots of interesting SQL isn’t really portable from vendor to vendor? (You probably switch databases fewer times than you switch programming languages, and that doesn’t stop you from using Java or Perl, does it?)
I know that database people sometimes can be a PITA. Working without many modern programming language constructs for a long time can do that to you. But many of those database people have seen application frameworks arrive with a huff and fall by the wayside after the CTOs and managers who championed them left to spread their overengineering ways elsewhere.