JoSQL tools 15649 6401


I just read an announcement of a new release of JoSQL, SQL for Java Objects. My first reaction was a bit reserved but after a quick glance at their website I am quite impressed already. JoSQL provides functionality to use SQL statements to query a collection of Java Objects (Strings, files, any java object). For example, retrieve all java files from a list of files:

    // Get a list of objects.
List myObjs = getMyObjects ();
    // Create a new Query.
Query q = new Query ();
    // Parse the SQL you are going to use.
q.parse ("SELECT * FROM WHERE name LIKE ''");
    // Execute the query.
QueryResults qr = q.execute (myObjs);
    // Cycle over the query results.
List res = qr.getResults ();
for (int i = 0; i < res.size (); i++)
  File f = (File) res.get (i);
    // Do something with the File.

This works on any class, not just File and String because JoSQL uses introspection to discover the the attributes of an object are automagically 'publish them as columns' for JoSQL queries.
For example:

 public class Person
    private String firstname;
    // more attributes
    // getters and setters
    // other code

Then you can use Select * from nl.amis.demo.josql.domain.Person where firstname = :studentname to query a List of Person objects (the 'select *' returns the whole Person object). This offers great and familiar search facilities that would otherwise require a lot of java coding. It also performs quite well, the query returns result within 200 ms for a list of 100000 Person objects; for a million Person objects it takes about 1.5 s (don't forget to increase the memorysize for the Java VM (-Xmx256m)).
This zip file contains a simple JDeveloper/Eclipse project to try it out (java5 and for Eclipse 3.1 or JDeveloper 10.1.3 EA1).

See the site for more information and more examples.