Is there a design pattern for implementing a non-SQL parametric search feature in Java?

I'm not entirely sure what is the best approach for designing what I would call a "parametric" search or rule engine. I have a Java object that has multiple fields. I will be running a java object against multiple requests to make sure it meets certain criteria.

Bugzilla's bug search feature is an example. In the user interface, you choose things like status, permission, severity. Then hit go and it returns errors that match those criteria. I am assuming this is implemented by generating an SQL query from the fields selected in the UI.

In my case, the object that contains the values ​​is not in the database , so this is not an obvious answer. My object is also quite complex and requires adding multiple tables ... and it seemed like a hack to create database tables to then use the query engine on the database. Also, in my application, the user basically creates these mappings and they need to be stored in the database. So in this case, you end up saving the raw sql query string to the database, which sounds like serious security, no, no to me. (But, I'm not the database guy, so maybe that's how it's done.)

At this point, I'm really looking for some guidance. I hope there is some type of design for what I am trying to accomplish. I've tried searching for various things like "parametric search pattern pattern" and "engine rules" and I haven't found anything that works. Is this what LINQ will decide? I looked at it briefly and it seemed like it would be overkill too.

Thanks in advance.

Edit 1:
Here are some additional details that I hope the comments will clarify so far. I want the user to create some rules that are similar if the foo.getTemperature () object is> = 30 and foo.getTypeOfMsg () == Alert. Then restore the Warning settings object. If foo.getTypeOfMsg () == "Test", then get the "Test" object. The rules are user driven and therefore there are endless possibilities. The foo object is retrieved by the web service and I don't need to store it in the database.

+2


source to share


2 answers


If you are not using a database to store your object, everything else is the same except for the "generate SQL query" part. You should look at the Specification Template . BOM objects basically have one method, IsSatisfiedBy, which takes an object to see if it meets the BOM. Adding some parameter to a BOM based on user input seems like a pretty straightforward exercise and sounds like it would work in your case.

Not sure if I understand the "mappings" part, but since you are not generating a raw SQL query, just make sure your spec objects are serializable and store it however you want.



LINQ can do this just like normal OL C # or Java.

+2


source


Are you trying to make a data-driven solution that can be arbitrarily changed by the user or someone else, or you are looking for something internal.

A user driven solution has endless possibilities that are not known at build time, but it requires some kind of user interface. You have to link the solution to the UI (for example, show the table and allow them to be clicked to sort by a given row / rows and maybe let them enter "filter criteria" for each row), so I'm not sure what the use for your search will provide ..



An internally managed solution has a fixed number of capabilities that are known at build time. You can easily code each one - perhaps not as easy as doing it the way you describe it, but not overly complicated as there are a limited number of solutions you have to implement.

0


source







All Articles