I have a fairly simple requirement for a query API which I need to implement.
So, I need to query a datastructure and from the the client’s perspective, it’s like:
Select * where idValue=baseball and child.age<10 and child.city=Sydney
(and it should support any other future arguments added to the database)
Now, how can I realize this form of query in a java argument – which is clean, elegant and obvious to the user (for example use enum=idValue,age,city) etc.
My thoughts: Map<QUERY, VALUE> can work? But how do I specify age<10 or age>=20?
My client interface:
List<Child> getChildern(x);
Where x = the above mentioned select query.
References: How to Design a Good API and Why it Matters
Usecase: I have a backend database (application embedded) to which I want to provide access to for developers. My app populates the data but that data should be query-able by the api users. Now the dataabase is berkley db where I have a custom way of storing data objects.
Well, your question is just a touch too general, an actual answer would take a lot more space than would be appropriate in a SO answer. However I recommend you take a peek at Spring-Ldap’s Fileter API which more or less does what you need. It might contain more that you want to implement here, but just focus on the basic idea and go from there, because, what ever you might say about the Spring stuff, it certanly has good clean simple APIs:
http://static.springsource.org/spring-ldap/docs/1.2.0/api/spring-ldap/org/springframework/ldap/filter/package-summary.html
http://static.springsource.org/spring-ldap/docs/1.3.x/reference/html/basic.html#basic-filters