Menu

Home

Vijay

jSQL Library

jSQL is a java library provide developers to filter the java collections with syntax similar to SQL. It enhances you application performance by ignoring the database connection if you already having a database records in the java collection.

Features

  • Provides generic logic to filter the java collection.
  • Currently =,<,<=,>,>= operators are supported.
  • like operator and order by clause will be supported for ordered collection based on any property without implement comparator interface.
  • No configuration required

Get Started

  1. Download the library from here.
  2. Add Library into you project.
  3. jSql requires antlrv3 library, that is included in default download package
  4. Use the following code to create an instance of CollectionFilter class.

    ~~~~~~~~~~~~~~~~~~
    CollectionFilter<emp> objFilter = new CollectionFilter<emp>(list, "name=\"aa106\"");
    list = (List<emp>) objFilter.getFilteredCollection();</emp></emp></emp>

    //list: first parameter passed to CollectionFilter class constructor is collection to be filtered.
    //query: "name=\"aa106\"" is second parameter which is the filter that is going to be applied on collection.
    ~~~~~~~~~~~~~~~~~~~

  5. getFilteredCollection() is function in CollectionFilter class which returns the filtered collection.

Filter SQL Syntax

  • Filter follows similar to sql syntax without select,order by and supports where clause without where. So syntax goes like this :

    ~~~~~~~~~~~~~
    (propertyName operator operand) logical operator (propertyName operator operand)

    age>=20 and age<=35 and deptName="Finance"

    //This will return the collection contain object which are from Finance department and age is between 20 and 35.
    ~~~~~~~~~~~~~

  • Use " " double code to represent string comparison, so you have to use escape sequence( "name=\"Ajay\"") while passing to CollectionFilter class.

Future Enhancements

  • More operators like,IN,between will be supported.
  • Order By Clause will be supported to Collection can be sorted without implement comparator interface

Auth0 Logo