It would still be useful to be able to perform SQL like queries on Java Objects however, JoSQL is designed to "fill the gap". JoSQL uses SQL to perform operations on objects that are useful to Java programmers and as such diverges from "normal" RDBMS SQL in some areas, you have been warned!
For example, given a set of
java.io.File
objects to try and return just a subset of File objects that match certain criteria and sort them generally requires at least 2 "chunks" of code, usually a tailor-made Comparator
and a method(s) to "filter" the File objects for the criteria.JoSQL provides both of those functions (and more!) in a single operation with NO custom-code required from the application developer, thus:
SELECT * FROM java.io.File WHERE (name LIKE "%.html" OR name LIKE "%.txt" OR name LIKE "%.xml" ) AND lastModified BETWEEN toDate('01-1-2004') AND toDate('31-1-2004') AND length >= 10000 ORDER BY lastModified DESC, name, length DESC
Query q = new Query (); q.parse (sqlStatement); // Find list of "java.io.File" objects List myFiles = getMyFiles (); List results = q.execute (myFiles);
java.io.File
objects that matched the criteria AND they would be ordered according to the "ORDER BY" clause.And that was all performed in 3 simple lines of Java!
JoSQL is also designed to get around SQLs aggregate function issues. JoSQL does not have any notion of "aggregate functions", a function is just a function. But it would be very useful to have "aggregate functionality" mixed with standard SQL. This is perfectly possible with JoSQL, i.e.:
/* * Find all Files that have a length that is greater than or equal * to the average length of ALL files in the set AND * the length of the name of the File is greater than or equal * to the average length of ALL files in the set. */ SELECT * FROM java.io.File WHERE length >= avg (:_allobjs, length) AND length (name) >= avg (:_allobjs, length (name))
Of course, the above would be VERY inefficient for moderately large datasets. However JoSQL has methods to prevent this (and of course it would be nice to have those values available for use AFTER the query has completed).