Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Here is a query language, more specifically, it's JQL, you can use it in Jira, to search for issues, it's something like SQL, but quite simpler.

My case is that, I need to construct such queries programmatically, in my application. Something like:

JQLMachine jqlMachine = new JQLMachine()
jqlMachine.setStatuses("Open", "In Progress")
jqlMachine.setReporter("foouser", "baruser")
jqlMachine.getQuery() --> String with corresponding JQL query is returned

You get my point I hope. I can imagine the code for this, but it's not nice, using my current knowledge how I'd do that.

That's why I'm asking. What you'd advice to use to create such thing. I believe some patterns for creating something like this already exist and there is already best practices, how to do that in good way.

share|improve this question
take a look at domain-specific languages, that's what jql is. – Alex Nov 28 '12 at 19:15
Yep, you are true. And I need to create a "generator" for such DSL, to use in my applications, so I don't have to construct every JQL query manually and create conditions when and where to use each query. – stibi Nov 28 '12 at 19:57
It seems that Builder pattern could help me: – stibi Nov 28 '12 at 22:05
what language are you using? – Alex Nov 29 '12 at 21:08
the reason i ask is because in Java, for example, there is something called java parser combinator. might be what you need. – Alex Nov 29 '12 at 21:15

You should look into the concept of Object-relational Mapping.

Unfortunately, I doubt an ORM solution has been developed for JQL. It is possible that you can extend an existing ORM package to support JQL.

share|improve this answer
That's true, there is a similarity with ORM for databases, but my case only touch the edges of ORM. I don't need to map any database entities to objects, neither communicate with databases or anything like this. My only one concern is to compose valid JQL String corresponding to given parameters. – stibi Nov 28 '12 at 19:59
@stibi So the "output" of your program will actually be the queries? Seems as though that can be a templating paradigm (for which you can use something like Apache Velocity). – smp7d Nov 29 '12 at 15:35

I would recommend Builder/Method chaining like Guava uses for it's HashCode and HashFunction classes. Hashing Explained

HashCode hc = hf.newHasher()
   .putObject(person, personFunnel)
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.