0

For the statistics part of an application there are several queries that often change and are also rather long. Both IMHO arguments to remove the queries from the source code and put them somewhere where they can be easily edited in an eye friendly format and also copy / pasted from and to a QL editor. This disqualifies named-queries from JPA.

The environment is a Seam application, but this question might be interesting for J2EE in general.

From my view there are three solutions: For relative static queries I can use a Seam managed query home, but it handling of parametrized queries is getting ugly when your parameters are not in any scope and just passed as method parameters.

My current solution is to put all queries into a Seam messages file and access them through the messages array.

A third way would be to create your own Seam component that reads the queries from somewhere and provides them.

How do you managed such a scenario? Did I miss some obvious solution?

Elmar Weber
  • 2,683
  • 28
  • 28

2 Answers2

1

Today appeared similar but not Seam specyfic question in SO, maybe there you'll find some ideas.

Community
  • 1
  • 1
cetnar
  • 9,357
  • 2
  • 38
  • 45
  • I ended up using the same solution as proposed in the referenced question, with a little modification: formulate sql query each in a single file, merge files to properties file with maven task, use file through seam component. – Elmar Weber May 31 '11 at 16:51
0

You can put queries in components.xml

IAdapter
  • 62,595
  • 73
  • 179
  • 242
  • Thanks for response, that was the first approach I described, as mentioned, IMHO it has the drawbacks of unscoped parametrization (or lack thereof). – Elmar Weber Oct 04 '09 at 19:10
  • You could also use groovy and its multiline strings(you can make groovy seam components). In this case every solution has its drawbacks. – IAdapter Oct 04 '09 at 19:33
  • I have been putting my queries in components.xml. I separate my components up by project so if I use a query only in a particular project at a certain layer, I declare it there. There is a JIRA issue filed to externalize them outside of XML, possibly in the entity class, service class, or other specific location that it is used. It would be very similar to @NamedQuery(name = "", query = "") ... type syntax. –  Dec 31 '09 at 18:21