JoSQL

Aino Andriessen
0 0
Read Time:1 Minute, 32 Second

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 java.io.File objects.
List myObjs = getMyObjects ();
    // Create a new Query.
Query q = new Query ();
    // Parse the SQL you are going to use.
q.parse ("SELECT * FROM java.io.File WHERE name LIKE '%.java'");
    // 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.

About Post Author

Aino Andriessen

Aino Andriessen is principal consultant and expertise lead 'Continuous Delivery'. His focus is on Oracle Fusion Middleware ADF and SOA development, Continuous Delivery, architecture, improving the software development proces and quality management. He is a frequent presenter at Oracle Open World, ODTUG Kaleidoscope, UKOUG Technology Conference and OUGN Vårseminar. He writes articles and publishes at the AMIS technology blog (http://technology.amis.nl/blog/).
Happy
Happy
0 %
Sad
Sad
0 %
Excited
Excited
0 %
Sleepy
Sleepy
0 %
Angry
Angry
0 %
Surprise
Surprise
0 %
Next Post

Data Profiling with Oracle Warehouse Builder 10gR2 (article in Dutch)

The 10gR2 or Paris release of Oracle Warehouse Builder is attracting a lot of attention. During Oracle Open World 2005 of course, and in a number of Blogs by among others Mark Rittman and Nicholas Goodman. At AMIS, we have participated in the Beta Test program since December 2004 and […]
%d bloggers like this: