Here goes a SQL-Java coding style question...
How do others here deal with creating complex custom queries in Java cleanly?
I am speaking of the seemingly simple task of preparing a string which is the SQL statement to be executed.
I am aware of HQL, and also of stored procedures, but honestly I don't really love these solutions. Perhaps I can be convinced differently. Stored procedures are annoying to deploy/maintain, and parsing performance is not such a huge issue in my case -- flexibility takes precedence. HQL seems like a big leap, and has some limitations for my complex queries.
TO be clear, I am talking of super-ugly looking code like this:
return
"(" + topTwenty + ")" +
"UNION " +
"(" + twentyBeforeMe + ")" +
"UNION " +
"(" + meDummyQuery + ")" +
"UNION " +
"(" + twentyAfterMe + ")";
Where the variables topTwenty are for example also subqueries created similarly.
I never thought I'd say this, but it was cleaner in PHP which had the multi-line string and $variable embedding in the strings.
Do people ever use a trivial templating library? How do you neatly keep the strings in the program? Or do you put them in a separate file (also seems annoying to me somehow).