org.sequalite.session
Class Session

java.lang.Object
  extended by org.sequalite.session.Session

public class Session
extends java.lang.Object

Session is the facade to SeQuaLite.

Author:
Abhijit Pani

Method Summary
 java.util.List clone(java.util.List list)
          Clones a list of objects.
 java.lang.Object clone(java.lang.Object base)
          Clones an Object
 java.lang.Object[] clone(java.lang.Object[] array)
          Clones an ObjectArray
 void close()
          closes the session, takes care of closing the database connection if created by sequalite
 void commit()
          commit the session
 SeQuaLitePageModel createPageModel(java.lang.Class voClass, java.lang.String sqlName, java.lang.Object[] values, int recordsPerPage)
          Creates a pagination model using a predefined query.
 SeQuaLitePageModel createPageModel(java.lang.Class voClass, java.lang.String criteria, java.lang.Object[] values, java.lang.String sortBy, int recordsPerPage)
          Creates a pagination model.
 int delete(java.lang.Class voClass, java.lang.String criteria, java.lang.Object[] values)
          deletes rows from database depending on the criteria
 void delete(java.util.List objectList)
          deletes a set of objects from database and deletes children if on-delete-cascade is true
 void delete(java.lang.Object object)
          deletes an object from database and deletes children if on-delete-cascade=true
 void delete(java.lang.Object[] objectArray)
          deletes a set of objects from database and deletes children
 java.util.List executeCall(java.lang.Class voClass, java.lang.String namedProcedure, java.lang.Object[] inParams, java.util.List<java.lang.String> outParams)
           Executes a database stored procedure and a) populates the OUT parameters into outParams b) if the stored procedure returns resultsets, this method will return them Assumption, the parameters Order is IN first and then the OUT, the exception being for functions where they have a return value.
 java.util.List executeCall(java.lang.String procSQL, java.lang.Object[] inParams, java.util.List<java.lang.String> outParams)
           Executes a database stored procedure and a) populates the OUT parameters into outParams b) if the stored procedure returns resultsets, this method will return them Assumption, the Paramaters Order is IN first and then the OUT, the exception being for functions where they have a return value.
 java.util.List executeQuery(java.lang.Class voClass, java.lang.String sqlName, java.lang.Object[] values)
          Returns a List of voClass Objects executing the sql identified by sqlName
 java.util.List executeQuery(java.lang.String query, java.lang.Object[] values, SeQuaLiteResultMapper mapper)
          Returns a List of objects executing the query.
 int executeUpdate(java.lang.Class voClass, java.lang.String sqlName, java.lang.Object[] values)
          Executes a named DML defined in the O-R Map
 int executeUpdate(java.lang.String query, java.lang.Object[] values)
          Executes a native DML
 java.util.List find(java.lang.Class voClass, java.lang.String criteria, java.lang.Object[] values)
          Returns a List of voClass Objects matching the criteria
 java.util.List find(java.lang.Class voClass, java.lang.String criteria, java.lang.Object[] values, java.lang.String sortBy)
          Returns a List of voClass Objects matching the criteria in the sortBy order
 java.util.List<SeQuaLiteModel> findAsProxy(java.lang.Class voClass, java.lang.String criteria, java.lang.Object[] values, java.lang.String sortBy)
          Returns a List of voClass ProxyObjects matching the criteria in the sortBy order
 java.util.List getChildren(SeQuaLiteModel base, java.lang.String childName)
          Gets the Children associated with the childName
 java.util.List paginate(SeQuaLitePageModel pageModel, int page)
          Retrieves a page using pagination
 void realize(java.util.List objectList)
          Realizes a list of objects.
 void realize(java.lang.Object base)
          Realizes an object.
 void realize(java.lang.Object[] objectArray)
          Realizes an array of objects.
 void rollback()
          rollback the session
 void save(java.util.List objectList)
          inserts a set of objects to database and saves children if on-save-cascade is true.
 void save(java.lang.Object base)
          saves an object to database and saves children if on-save-cascade is true.
 void save(java.lang.Object[] objectArray)
          saves a set of objects to database and saves the children if on-save-cascade is true
 int update(java.lang.Class voClass, java.lang.String setter, java.lang.Object[] sValues, java.lang.String criteria, java.lang.Object[] cValues)
          update database
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

clone

public java.util.List clone(java.util.List list)
                     throws SeQuaLiteException
Clones a list of objects.

Parameters:
list -
Throws:
SeQuaLiteException

clone

public java.lang.Object clone(java.lang.Object base)
                       throws SeQuaLiteException
Clones an Object

Parameters:
base -
Throws:
SeQuaLiteException

clone

public java.lang.Object[] clone(java.lang.Object[] array)
                         throws SeQuaLiteException
Clones an ObjectArray

Parameters:
array -
Throws:
SeQuaLiteException

close

public void close()
           throws SeQuaLiteException
closes the session, takes care of closing the database connection if created by sequalite

Throws:
SeQuaLiteException

commit

public void commit()
            throws SeQuaLiteException
commit the session

Throws:
SeQuaLiteException

createPageModel

public SeQuaLitePageModel createPageModel(java.lang.Class voClass,
                                          java.lang.String sqlName,
                                          java.lang.Object[] values,
                                          int recordsPerPage)
                                   throws SeQuaLiteException,
                                          SeQuaLiteFinderException
Creates a pagination model using a predefined query. Let's say we need to display all the invoices with amount > 5000 and amount <= 10000 sorted by date.
 
 SeQuaLitePageModel pageModel = session.createPageModel(Invoice.class,
                "findBySql", new Object[] { 5000, 10000 }, 100);
 
 int pageCount = pageModel.getPageCount();
 List list = pageModel.getPage(1);
 for (Object o : list) {
        Invoice invoice = (Invoice) o;
        System.out.println("Invoice Number: " + invoice.getId() + ", Date: "
                        + invoice.getInvoiceDate() + ", Amount: " + invoice.getAmount());
 }
 
 
Where "findBySql" needs to be defined under Invoice class mapping in the O-R mapping file as below.
 
 <sql name="findBySql" type="find">
 SELECT * FROM INVOICE WHERE AMOUNT BETWEEN ? AND ? ORDER BY INVOICE_DATE DESC
 </sql> 
 
 

Parameters:
voClass -
sqlName -
values -
recordsPerPage -
Returns:
Throws:
SeQuaLiteException
SeQuaLiteFinderException

createPageModel

public SeQuaLitePageModel createPageModel(java.lang.Class voClass,
                                          java.lang.String criteria,
                                          java.lang.Object[] values,
                                          java.lang.String sortBy,
                                          int recordsPerPage)
                                   throws SeQuaLiteException,
                                          SeQuaLiteFinderException
Creates a pagination model. Let's say we need to display all the invoices with amount > 5000 and amount <= 10000 sorted by date.
 
 SeQuaLitePageModel pageModel = session.createPageModel(Invoice.class,
                "amount > ? && amount <= ?", new Object[] { 5000, 10000 },
                "invoiceDate DESC", 100);
 
 int pageCount = pageModel.getPageCount();
 List list = pageModel.getPage(1);
 for (Object o : list) {
        Invoice invoice = (Invoice) o;
        System.out.println("Invoice Number: " + invoice.getId() + ", Date: "
                        + invoice.getInvoiceDate() + ", Amount: " + invoice.getAmount());
 }
 
 

Parameters:
voClass -
criteria -
values -
sortBy -
recordsPerPage -
Returns:
Throws:
SeQuaLiteException
SeQuaLiteFinderException

delete

public int delete(java.lang.Class voClass,
                  java.lang.String criteria,
                  java.lang.Object[] values)
           throws SeQuaLiteException
deletes rows from database depending on the criteria

Parameters:
voClass -
criteria -
values -
Returns:
Throws:
SeQuaLiteException

delete

public void delete(java.util.List objectList)
            throws SeQuaLiteException
deletes a set of objects from database and deletes children if on-delete-cascade is true

Parameters:
objectList -
Throws:
SeQuaLiteException

delete

public void delete(java.lang.Object object)
            throws SeQuaLiteException
deletes an object from database and deletes children if on-delete-cascade=true

Parameters:
object -
Throws:
SeQuaLiteException

delete

public void delete(java.lang.Object[] objectArray)
            throws SeQuaLiteException
deletes a set of objects from database and deletes children

Parameters:
objectArray -
Throws:
SeQuaLiteException

executeCall

public java.util.List executeCall(java.lang.Class voClass,
                                  java.lang.String namedProcedure,
                                  java.lang.Object[] inParams,
                                  java.util.List<java.lang.String> outParams)
                           throws SeQuaLiteException
 Executes a database stored procedure and
  a) populates the OUT parameters into outParams
  b) if the stored procedure returns resultsets, this method will return them
 
 Assumption, the parameters Order is IN first and then the OUT,
 the exception being for functions where they have a return value.
 So the first parameter will be a OUT parameter there.
 

Parameters:
voClass -
namedProcedure -
inParams -
outParams -
Returns:
Throws:
SeQuaLiteException

executeCall

public java.util.List executeCall(java.lang.String procSQL,
                                  java.lang.Object[] inParams,
                                  java.util.List<java.lang.String> outParams)
                           throws SeQuaLiteException
 Executes a database stored procedure and
  a) populates the OUT parameters into outParams
  b) if the stored procedure returns resultsets, this method will return them
 
 Assumption, the Paramaters Order is IN first and then the OUT,
 the exception being for functions where they have a return value.
 So the first parameter will be a OUT parameter.
 

Parameters:
procSQL -
inParams -
outParams -
Returns:
Throws:
SeQuaLiteException

executeQuery

public java.util.List executeQuery(java.lang.String query,
                                   java.lang.Object[] values,
                                   SeQuaLiteResultMapper mapper)
                            throws SeQuaLiteException,
                                   SeQuaLiteFinderException
Returns a List of objects executing the query. SeQuaLiteResultMapper needs to be implemented to use this method.
 
        List list = session.executeQuery("SELECT ID,NAME FROM CUSTOMER WHERE ID=?", new OBJECT[]{1},
                new SeQuaLiteResultMapper(){
                        public Object createAndPopulate(ResultSet rs){
                                Customer customer = new Customer();
                                customer.setId(rs.get("ID"));
                                customer.setName(rs.get("NAME"));
                                return customer;
                        }
                });
 
 

Parameters:
query -
values -
mapper -
Returns:
Throws:
SeQuaLiteException
SeQuaLiteFinderException

executeQuery

public java.util.List executeQuery(java.lang.Class voClass,
                                   java.lang.String sqlName,
                                   java.lang.Object[] values)
                            throws SeQuaLiteException,
                                   SeQuaLiteFinderException
Returns a List of voClass Objects executing the sql identified by sqlName

Parameters:
voClass -
sqlName -
values -
Returns:
Throws:
SeQuaLiteException
SeQuaLiteFinderException

executeUpdate

public int executeUpdate(java.lang.Class voClass,
                         java.lang.String sqlName,
                         java.lang.Object[] values)
                  throws SeQuaLiteException
Executes a named DML defined in the O-R Map

Parameters:
voClass -
sqlName -
values -
Returns:
Throws:
SeQuaLiteException

executeUpdate

public int executeUpdate(java.lang.String query,
                         java.lang.Object[] values)
                  throws SeQuaLiteException
Executes a native DML

Parameters:
query -
values -
Returns:
Throws:
SeQuaLiteException

find

public java.util.List find(java.lang.Class voClass,
                           java.lang.String criteria,
                           java.lang.Object[] values)
                    throws SeQuaLiteException,
                           SeQuaLiteFinderException
Returns a List of voClass Objects matching the criteria

Parameters:
voClass -
criteria -
values -
Returns:
Throws:
SeQuaLiteException
SeQuaLiteFinderException

find

public java.util.List find(java.lang.Class voClass,
                           java.lang.String criteria,
                           java.lang.Object[] values,
                           java.lang.String sortBy)
                    throws SeQuaLiteException,
                           SeQuaLiteFinderException
Returns a List of voClass Objects matching the criteria in the sortBy order

Parameters:
voClass -
criteria -
values -
sortBy -
Returns:
Throws:
SeQuaLiteException
SeQuaLiteFinderException

findAsProxy

public java.util.List<SeQuaLiteModel> findAsProxy(java.lang.Class voClass,
                                                  java.lang.String criteria,
                                                  java.lang.Object[] values,
                                                  java.lang.String sortBy)
                                           throws SeQuaLiteException,
                                                  SeQuaLiteFinderException
Returns a List of voClass ProxyObjects matching the criteria in the sortBy order

Parameters:
voClass -
criteria -
values -
sortBy -
Returns:
Throws:
SeQuaLiteException
SeQuaLiteFinderException

getChildren

public java.util.List getChildren(SeQuaLiteModel base,
                                  java.lang.String childName)
                           throws SeQuaLiteException,
                                  SeQuaLiteFinderException
Gets the Children associated with the childName

Parameters:
base -
childName -
Returns:
Throws:
SeQuaLiteException
SeQuaLiteFinderException

paginate

public java.util.List paginate(SeQuaLitePageModel pageModel,
                               int page)
                        throws SeQuaLiteFinderException,
                               SeQuaLiteException
Retrieves a page using pagination

Parameters:
pageModel -
page -
Returns:
Throws:
SeQuaLiteException
SeQuaLiteFinderException
SeQuaLiteException

realize

public void realize(java.util.List objectList)
             throws SeQuaLiteException,
                    SeQuaLiteFinderException
Realizes a list of objects. This can be used in place of finder methods to realize a list of proxyObjects.

Parameters:
objectList -
Throws:
SeQuaLiteException
SeQuaLiteFinderException

realize

public void realize(java.lang.Object base)
             throws SeQuaLiteException,
                    SeQuaLiteFinderException
Realizes an object. This can be used in place of finder methods to retrieve single objects using primary keys. For example,
 
 Customer customer = new Customer();
 customer.setId(10);
 session.realize(customer);
 System.out.println("Customer Name: " + customer.getName());
 
 

Parameters:
base -
Throws:
SeQuaLiteException
SeQuaLiteFinderException

realize

public void realize(java.lang.Object[] objectArray)
             throws SeQuaLiteException,
                    SeQuaLiteFinderException
Realizes an array of objects. This can be used in place of finder methods to realize an array of proxyObjects.

Parameters:
objectArray -
Throws:
SeQuaLiteException
SeQuaLiteFinderException

rollback

public void rollback()
              throws SeQuaLiteException
rollback the session

Throws:
SeQuaLiteException

save

public void save(java.lang.Object base)
          throws SeQuaLiteException
saves an object to database and saves children if on-save-cascade is true.

Parameters:
base -
Throws:
SeQuaLiteException

save

public void save(java.lang.Object[] objectArray)
          throws SeQuaLiteException
saves a set of objects to database and saves the children if on-save-cascade is true

Parameters:
objectArray -
Throws:
SeQuaLiteException

save

public void save(java.util.List objectList)
          throws SeQuaLiteException
inserts a set of objects to database and saves children if on-save-cascade is true.

Parameters:
objectList -
Throws:
SeQuaLiteException

update

public int update(java.lang.Class voClass,
                  java.lang.String setter,
                  java.lang.Object[] sValues,
                  java.lang.String criteria,
                  java.lang.Object[] cValues)
           throws SeQuaLiteException
update database

Parameters:
voClass -
setter -
sValues -
criteria -
cValues -
Returns:
Throws:
SeQuaLiteException