JoSQL, SQL for collections of Java Objects, available

Home

News: JoSQL, SQL for collections of Java Objects, available

  1. JoSQL (SQL for Java Objects) provides the ability for a developer to apply a SQL statement to a collection of Java Objects. JoSQL provides the ability to search, order and group any Java objects and should be applied when you want to perform SQL-like queries on a collection of Java Objects.
       
    Given the announcement and press given elsewhere to Microsoft's LINQ technology, JoSQL seems to be an extension for Java that provides the same sort of ability of querying collections, albeit as an extension that's accessed via normal Java idioms rather than as a form of SQL embedded directly into the program text.

    To compare, here's a LINQ example from TSS.net:
    using System;
    using System.Query;
    using System.Collections.Generic;

    class App
    {
      static void Main() {
      String[] names = {"Burke", "Connor", "Frank", "Everett", "Albert", "George", "Harris", "David" };
      IEnumerable<string> expr = from s in names
                where s.Length == 5
                orderby s
                select s.ToUpper();
      foreach (string item in expr)
        {
          Console.WriteLine(item);
        }
      }
    }
    Using JoSQL, the example is slightly longer, because of the need for the use of a Collection rather than an array, and because Java SE 5 was used. It also looks a little less elegant at first because the "SQL" isn't embedded into the program text directly:
    package com.theserverside.josql;

    import java.util.*;
    import org.josql.*;

    public class App {
      @SuppressWarnings("unchecked")
      public static void main(String[] args) throws QueryParseException, QueryExecutionException {
        List<String> names=new ArrayList<String>();
        String[] n={"Burke", "Connor", "Frank", "Everett", "Albert", "George", "Harris", "David" };
        Collections.addAll(names, n);
        Query q=new Query();
        q.parse("select * from java.lang.String where length=5");
        List<String> results=(List<String>)q.execute(names).getResults();
        for(String name:results) {
          System.out.println(name);
        }
      }
    }
    One other consideration is that the examples aren't quite the same: the query from LINQ returns an upper-case version of the name, whereas JoSQL is unable to apply such a method to the selection (yet).

    While at version 1.0, the release notes specify that the version numbers increment by 0.1 every release; the "1.0" isn't significant.
  2. i've been waiting for this, great!
  3. The examples on their website seem even cooler.

        SELECT *
        FROM java.io.File
        WHERE name $LIKE "%.html"
        AND lastModified BETWEEN toDate('01-12-2004')
                            AND toDate('31-12-2004')
  4. However, their examples rely solely on collections of files, and I wanted to show the equivalence to LINQ, specifically, in the example.
  5. Several months ago I've evaluated this project and in my view it's not as useful as it seems to be for the following reasons:
    1) Redundant dependency on SQL. In many cases java based strategies(filters) are more efficient and easier to maintain than sql scripts.
    2) As far as I undertood josql takes a collection of objects (e.g. 1000000 files) and iterates over each element - this is inefficient, because real SQL engines(RDBMS) DO NOT iterate over all the table to find several rows satisfying WHERE criteria.

    Regards,
    Theodore Kupolov
  6. immense value for sorting[ Go to top ]

    Lists unfortunately don't have lots of indexing, since they aren't a database datastruct. Perhaps there is the notion of a TreeList kinda like a TreeMap that has sort order guaranteed.

    But without indexing or hashing schemes built into the List object, it has to do a full scan.

    The generalized resorting this thing can do is worth enough on the web tier, so when you have tables of data that can be resorted by user-selected column, you don't have to do custom resort logic or do another round trip to the web service/database/ejb server/hibernate query. Just resort your current collection's data on the web server. Likewise for filtering/searches/search result paring. This can still be a tremendous tool.
  7. immense value for sorting[ Go to top ]

    Lists unfortunately don't have lots of indexing, since they aren't a database datastruct. Perhaps there is the notion of a TreeList kinda like a TreeMap that has sort order guaranteed. But without indexing or hashing schemes built into the List object, it has to do a full scan.

    The generalized resorting this thing can do is worth enough on the web tier, so when you have tables of data that can be resorted by user-selected column, you don't have to do custom resort logic or do another round trip to the web service/database/ejb server/hibernate query. Just resort your current collection's data on the web server. Likewise for filtering/searches/search result paring. This can still be a tremendous tool.

    Doing simple sorting is one thing, but when you start to do queries like "select * from product, category where category.id='blah', product.category=category.primaryid, etc" how the tool generates the execution plan matters quite a bit. A simplistic implementation may end up iterating over the entire dataset hundreds or even thousands of times. For scalability, it's generally more efficient and more scalable if the dataset is indexed/sorted. Compiling the query so the conditions are in optimal order can make a huge difference.

    can someone share their experience about the tool. does it provide an easy way for developers to provide indexers that plugin? this is the first time I've heard of the tool.

    peter
  8. I currently use Apache Jakarta jXPath to query object graphs (Collection of Bean, Map, DOM, etc.) and it's a great tool (used by Apache Cocoon).
    JoSQL seems to fulfill equivalent needs, using the SQL query language in place of XPath.
    My guess is both may prove useful in different situation.
  9. Excellent!!

    I found a need for such a tool a couple of years back. Looked at some of the partially completed projects on sourceforge/freshmeat, but they just weren't 'there'. Heck, I even started to write my own....but you know how that goes.

    Nice looking website/manual also...

    *wring hands* Can't wait to start using it....
  10. It seems to be a natural fit, answering to the more than frequent question "how do I query my objects with prevayler?". Ok, there's jxpath, but sql is definitely easier for the average programmer.
  11. JoSQL simply great!![ Go to top ]

    A couple of months ago, I wrote an app that needs to read log files and generate reports from the log content. The most difficult part of that app is to write algorithm to simulate "GROUP BY" functions, if I not found JoSQL probably I need to write complex code(Binary Tree algo).
  12. I try:

      ...
      List l = SAService.getInstance().getSA(h); //get List of Beans
      Query q = new Query();
      q.parse("select marka from nkmk.ibatis.domain.SaAnalizRaw ");
      QueryResults qr = q.execute (l);
      ...

    And get error:

    java.lang.NoClassDefFoundError: com/gentlyweb/utils/Getter at org.josql.expressions.Accessor.init(Accessor.java:59) at org.josql.expressions.SelectItemExpression....

    And nkmk.ibatis.domain.SaAnalizRaw is POJO with field marka and methods getMarka(), setMarka().

    Thereis my mistake?