Overview 

 SQLind is NOT yet another persistence framework for java but a complementary API provinding tools to help doing what other frameworks such hibernate are not made for : perform complex queries and wire results to objects. SQLind doesn't create complex queries from objects but create objects from complex queries. Major benefits of the API are :

  • Externalization of SQL in a developper friendly xml file
  • On fly queries update for debug purpose
  • Advanced XML templated definition (conditionnal sections, included queries, ...)
  • High performance ruptured bean grap wiring using hot transformation class generation

  •  see : [ Getting started ... ]
     
    Release 

     Latest stable release :


     Required libraires :

     Optional libraires :

    common-beanutils
    ( required for input bean wiring in version older than 2.1.2-GA )

    javassist
    ( required for output bean wiring )

    SQLind4HQL
    ( extension for hibernate )

    SQLind4EJB
    ( extension for EJB3 )

     see : [ Maven ... ]

    Maven 

    All releases are available from SQLind maven repository here

    SQLind is available from maven central repository.

    include one of these sections in your pom.xml :

    SQLind
    SQLind4HQL SQLind4EJB

    Getting started 

    Here is a 3 steps short tutorial to create your fist query with SQLind :

    STEP 1 : Download SQLind library and add it to your classpath

       see : [ Maven ... ] [ Release ... ]


    STEP 2 : Create a XML query template file in your classpath
    If attribute policy is set to 'reload', the query definition will be reloaded from file each time getSQLQuery(..) is called. This is obviously bad for performances but can be very usefull to allow hot modification. Note that the performed query string is logged by log4j using an INFO level. The 'debug' policy have the same behavior except that console is used instead of log. The tag <var id="field"/> declares a parameter (same id can be used several times ).

       see : [ Advanced templating ... ]


    STEP 3 : Use SQLind API to invoke query
       see : [ Advanced wiring ... ]


    NOTE : if no wiring is needed, it is possible to create multi statement queries (PL/SQL)
    Advanced templating 

      Summary of available tags : var, section, include, inject.


  • <var id="fieldId"/> declares a parameter


  • <section id="name"/> defines optional sections in query


  • <include id="queryId" params="sectionName,injectionId=value,..."/> includes another query. (params attribute is optional)


  • <inject id="injectId"/> creates an injection (substitution) point in the query
    In case of query over several schemas, the db schema must be set to null in getSQLQuery(...) method to avoid auto prefexing. In this case, inject tag can be used to set a custom prefixing to each table.


  • Advanced wiring 

      Wiring policies

  • lru : use a java reflection cache (implementing Last Recent Used algorythm) to create beans from query.

        This policy can be used if no bean wiring is done, when rare and small queries are performed or if javassist API cannot be added to classpath.
     

  • fast : create a transformation class at runtime to map beans from query result.

        This policy have an overhead compilation time on the first call but give very fast performances.
     When used in a web container (Tomcat,Jboss...), some classpath issues can appears du to multiple classloader management.
     If some class cannot be found by javassist, they can be added using the -Dsqlindcp=<classpath> JVM argument.



  •   Wiring behaviours

  • Create an annoted bean grap to fit your query

    The SQLind(column="ColumnName or Alias") annotation placed on a setter method will map the matching field with the columnName column.
    Note that severals columns can be defined on a given field to fit different queries : SQLind(column={"colName1","colName2"})
    Column mapping is done trying to resolve simple column name (ex: 'table.ColName' or 'colName' ) or using an 'as' alias (ex: 'sum(colName) as total' )

    The SQLind(link=Clazz) annotation placed on a setter method will propagate the mapping to the given aggregated bean. If the linked field is a single type,
    the bean class will be entire part of the declaring bean level rupture definition (one to one relationship). If the field is a List of Bean,
    the mapping will be done as a n+1 rupture level (one to many relationship).
     



  • Perform query using a custom implemented behaviour
     
    Considering the folowing datas in the table 'myTable' :
    Here is the 'one bean per record' strategy

    This implementation is equivalent to getSingleBeanList() method


    Here is the 'one bean per rupture' strategy

    This implementation is equivalent to getBeanList() method


  • Hibernate / EJB3 

    SQLind4HQL and SQLind4EJB are extension libraries allowing to use SQLind with hibernate HQL and EJB QL.
    The following examples are for hibernate but both API are very close (just replace Session by EntityManager and HQL by EJB in naming).
    Obviosly, storing the query results in a persistent entity bean have a limited interest ,Criteria are better for that purpose until query use too many not direct relationshipped entities.

     see : [ Release ... ] [ Maven ... ]  [ Advanced wiring ... ] [ Advanced templating ... ]


    Term of use 

     SQLind is a free API distributed under the Open Software License version 3.0 and can be use in any, commercial or non commercial, larger work.


    Contact 

     You can ask any question related to SQLind using the folowing email : infosqlind.net
     We encourage you to open a topic on the official source forge project forum here