I am designing a web application that retrieves records from a database according to user search criteria. After retrieving results, another stage exists in the flow in which the results are "decorated" with additional data.
For example, we may have a Persons database table with columns such as: name, age, height, weight. The program can filter that table by a certain logical computation formula, e.g. keep all Person records where the person's weight is less than her "ideal weight", defined as:
IDEAL_WEIGHT = (height/100) * age
So, we will show all records where IDEAL_WEIGHT < weight, this can be accomplished with SQL, stored procedures, etc - bottom line is that we filter with SQL. Concerning the "results decoration" stage, it can be, for example, calculating the WEIGHT_PER_INCH for each result, defined as
WEIGHT_PER_INCH = height / weight
These "decoration" computations may be a lot more complex than the above, and are actually broader than mathematical formulas - they may involve data residing on remote hosts, or rely on other computations units. So - it seems SQL and probably PL/SQL are not suited for the job, rather Java is - bottom line is that we "decorate" with Java.
Now, what we mentioned above is filtering by IDEAL_WEIGHT and decorating with WEIGHT_PER_INCH, but what happens if we want to be able to have it the other way around? (i.e. filter by WEIGHT_PER_INCH and decorate with IDEAL_WEIGHT).
You may say that all these computation units should be of one type - either stored SQL procedures, or Java classes. But if they're SQL procedures they are not expressive enough, and if they are Java classes, they cannot be used to search a database quickly.
My question is:
Is there a clean, widely-used, fast way to invoke Java from SQL, e.g.
Select * from Persons p where IDEAL_WEIGHT(p) < p.weight
where IDEAL_WEIGHT() is a Java method, not an SQL procedure.
or: Is there some other way around all this?
Thanks a bunch for your thoughts.