views:

117

answers:

3

Our application exposes queries by way of web services, and what we've found is that our clients often want custom queries, either by way of further limiting the results returned by specifying additional criteria, or by asking for things that we don't already expose.

Now, we can take the approach of creating new methods for each of these new methods, but that's somewhat inconvenient; deployment of our application at a client site usually requires weeks of staged integration testing. We've proposed a named query mechanism, where the application administrator would define queries by name that are parameterized, and a corresponding web service that simply invokes these parameters. However, I can't help but think that someone has solved this problem before, so I'd like some input from the SO community on possible designs.

Thanks!

Updates

The specification pattern is a good one, but our application deals with enough data that we want to push as much of the querying work down into an RDBMS, which can do a better job of optimizing the query plan than we would ever want to. Moreover, we support three RDBMS backends, so we're stuck using a greatest-common-denominator approach: we use as much capability as the least functional database can provide.

+1  A: 
  • Take a look at Hibernates Criteria API and use it or build some similar functionality for Your users.
  • If it's worth the effort, provide a tree-like interface for grouping criterias. ("all criteria of a group must match" / "one criteria must match" / "negate")

Advantages:

  • Easy to build.
  • User parameters are possible.
  • Powerful queries are possible.
  • You can apply restrictions like SELECT ... FROM table WHERE someRestriction AND (user-provided criteria)
Black
+2  A: 

I would also recommend to consider the "Specification Pattern" in this type of applications as a design decision for your backend. Check the following posts about "Specification Pattern":

http://www.mattberther.com/2005/03/25/the-specification-pattern-a-primer/

http://devlicio.us/blogs/jeff_perrin/archive/2006/12/13/the-specification-pattern.aspx

mnour
A: 

Since we really don't know which how your users use your interface it seems a little premature to give a technical advice on something that feels a lot closer to "Inmates are running the Asylum" problem. There are some very good advice and common ways to solve this i technical aspects but do they work for your users? Maybe the really don't give a crap about your problem but rather have a fine working one button solution? (Or more like google?)

Jonke
It's a valid -- and accurate -- observation; they like the pushbutton approach.I'd still like to have some ideas, though. We may not use them, in part for the reasons you cite, but it might help guide us to a better solution in the end.
Chris R