2

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.setDateRange(...)
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.

  • 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
  • 1
    It seems that Builder pattern could help me: stackoverflow.com/a/1953567 – 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. jparsec.codehaus.org might be what you need. – Alex Nov 29 '12 at 21:15
2

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.

  • 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
0

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

HashCode hc = hf.newHasher()
   .putLong(id)
   .putString(name)
   .putObject(person, personFunnel)
   .hash();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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