com.jpattern.orm.session
Interface Session

All Known Subinterfaces:
SessionSqlPerformer
All Known Implementing Classes:
OrmSession

public interface Session

Author:
Francesco Cina 21/mag/2011

Method Summary
<T> int
delete(List<T> object)
          Delete the objects from the database
<T> int
delete(T object)
          Delete one object from the database
 DeleteQuery deleteQuery(Class<?> clazz)
          Delete the objects of a specific table
 DeleteQuery deleteQuery(Class<?> clazz, String alias)
          Delete the objects of a specific table
<T> T
doInTransaction(TransactionCallback<T> transactionCallback)
          Execute a block of code inside a Transaction or participate to an existing one
<T> T
doInTransaction(TransactionDefinition transactionDefinition, TransactionCallback<T> transactionCallback)
          Execute a block of code inside a Transaction or participate to an existing one
<T> boolean
exist(Class<T> clazz, Object idValue)
          Return whether a Bean with a specific id exists in the DB.
<T> boolean
exist(Class<T> clazz, Object[] idValues)
          Return whether a Bean with the specific ids exists in the DB.
<T> boolean
exist(T object)
          Return whether a Bean exist in the DB using the Object type and id(s).
<T> T
find(Class<T> clazz, Object idValue)
          Find a bean using is ID.
<T> T
find(Class<T> clazz, Object[] idValues)
          Find a bean using is IDs.
<T> FindQuery<T>
findQuery(Class<T> clazz)
          Create a new query
<T> FindQuery<T>
findQuery(Class<T> clazz, String alias)
          Create a new query
 CustomFindQuery findQuery(String selectClause, Class<?> clazz, String alias)
          Create a new query
<T> T
findUnique(Class<T> clazz, Object idValue)
          Find a bean using is ID.
<T> T
findUnique(Class<T> clazz, Object[] idValues)
          Find a bean using is IDs.
<T> List<T>
save(Collection<T> objects)
          Persist the new objects in the database
<T> T
save(T object)
          Persist the new object in the database
<T> List<T>
saveOrUpdate(Collection<T> objects)
          For each object in the list, update the object if it exists, otherwise save it
<T> T
saveOrUpdate(T object)
          Update the object if it exists, otherwise save it
 ScriptExecutor scriptExecutor()
          A script executor useful to execute multiple sql statement from files.
 SqlExecutor sqlExecutor()
          An executor to perform any kind of plain SQL statements.
 Transaction transaction()
          Begin a transaction or participate to an existing one using the default ITransactionDefinition
 Transaction transaction(TransactionDefinition transactionDefinition)
          Begin a or participate to an existing one depending on the specific transactionDefinition
<T> List<T>
update(Collection<T> objects)
          Update the values of the existing objects in the database
<T> T
update(T object)
          Update the values of an existing object in the database
 UpdateQuery updateQuery(Class<?> clazz)
          Update the objects of a specific TABLE
 UpdateQuery updateQuery(Class<?> clazz, String alias)
          Update the objects of a specific TABLE
 

Method Detail

transaction

Transaction transaction()
                        throws OrmException
Begin a transaction or participate to an existing one using the default ITransactionDefinition

Returns:
Throws:
OrmException

transaction

Transaction transaction(TransactionDefinition transactionDefinition)
                        throws OrmException
Begin a or participate to an existing one depending on the specific transactionDefinition

Returns:
Throws:
OrmException

doInTransaction

<T> T doInTransaction(TransactionCallback<T> transactionCallback)
Execute a block of code inside a Transaction or participate to an existing one

Parameters:
transactionCallback -
Returns:

doInTransaction

<T> T doInTransaction(TransactionDefinition transactionDefinition,
                      TransactionCallback<T> transactionCallback)
Execute a block of code inside a Transaction or participate to an existing one

Parameters:
transactionCallback -
Returns:

exist

<T> boolean exist(T object)
              throws OrmException
Return whether a Bean exist in the DB using the Object type and id(s).

Type Parameters:
T -
Parameters:
object -
Returns:
Throws:
OrmException

exist

<T> boolean exist(Class<T> clazz,
                  Object idValue)
              throws OrmException
Return whether a Bean with a specific id exists in the DB.

Type Parameters:
T -
Parameters:
clazz - The Class of the object to load
idValue - the value of the identifying column of the object
Returns:
Throws:
OrmException

exist

<T> boolean exist(Class<T> clazz,
                  Object[] idValues)
              throws OrmException
Return whether a Bean with the specific ids exists in the DB.

Type Parameters:
T -
Parameters:
clazz - The Class of the object to load
idValues - an ordered array with the values of the identifying columns of the object
Returns:
Throws:
OrmException

find

<T> T find(Class<T> clazz,
           Object idValue)
       throws OrmException
Find a bean using is ID.

Type Parameters:
T -
Parameters:
clazz - The Class of the object to load
idValue - the value of the identifying column of the object
Returns:
Throws:
OrmException

find

<T> T find(Class<T> clazz,
           Object[] idValues)
       throws OrmException
Find a bean using is IDs.

Type Parameters:
T -
Parameters:
clazz - The Class of the object to load
idValues - an ordered array with the values of the identifying columns of the object
Returns:
Throws:
OrmException

findUnique

<T> T findUnique(Class<T> clazz,
                 Object idValue)
             throws OrmException,
                    OrmNotUniqueResultException
Find a bean using is ID. An OrmNotUniqueResultException is thrown if nothing is found.

Type Parameters:
T -
Parameters:
clazz - The Class of the object to load
idValue - the value of the identifying column of the object
Returns:
Throws:
OrmException
OrmNotUniqueResultException

findUnique

<T> T findUnique(Class<T> clazz,
                 Object[] idValues)
             throws OrmException,
                    OrmNotUniqueResultException
Find a bean using is IDs. An OrmNotUniqueResultException is thrown if nothing is found.

Type Parameters:
T -
Parameters:
clazz - The Class of the object to load
idValues - an ordered array with the values of the identifying columns of the object
Returns:
Throws:
OrmException
OrmNotUniqueResultException

save

<T> T save(T object)
       throws OrmException
Persist the new object in the database

Type Parameters:
T -
Parameters:
object -
Returns:
the bean representing the saved object (with updated generated fields)
Throws:
OrmException

saveOrUpdate

<T> T saveOrUpdate(T object)
               throws OrmException
Update the object if it exists, otherwise save it

Type Parameters:
T -
Parameters:
object -
Returns:
the bean representing the saved or updated object (with updated generated fields))
Throws:
OrmException

update

<T> T update(T object)
         throws OrmException
Update the values of an existing object in the database

Type Parameters:
T -
Parameters:
object -
Returns:
the bean representing the saved object (with updated generated fields)
Throws:
OrmException

save

<T> List<T> save(Collection<T> objects)
             throws OrmException
Persist the new objects in the database

Type Parameters:
T -
Parameters:
objects - the objects to persist
Returns:
a new collection that contains the beans representing the saved objects
Throws:
OrmException

saveOrUpdate

<T> List<T> saveOrUpdate(Collection<T> objects)
                     throws OrmException
For each object in the list, update the object if it exists, otherwise save it

Type Parameters:
T -
Parameters:
objects - the objects to persist
Returns:
a new collection that contains the beans representing the saved or updated objects
Throws:
OrmException

update

<T> List<T> update(Collection<T> objects)
               throws OrmException
Update the values of the existing objects in the database

Type Parameters:
T -
Parameters:
objects - the objects to update
Returns:
a new collection that contains the beans representing the updated objects
Throws:
OrmException

updateQuery

UpdateQuery updateQuery(Class<?> clazz)
                        throws OrmException
Update the objects of a specific TABLE

Parameters:
clazz - the TABLE related Class
Throws:
OrmException

updateQuery

UpdateQuery updateQuery(Class<?> clazz,
                        String alias)
                        throws OrmException
Update the objects of a specific TABLE

Parameters:
clazz - the TABLE related Class
alias - The alias of the class in the query.
Throws:
OrmException

delete

<T> int delete(T object)
           throws OrmException
Delete one object from the database

Type Parameters:
T -
Parameters:
object -
Returns:
the number of deleted objects
Throws:
OrmException

delete

<T> int delete(List<T> object)
           throws OrmException
Delete the objects from the database

Type Parameters:
T -
Parameters:
objects - the objects to delete
Returns:
the number of deleted objects
Throws:
OrmException

deleteQuery

DeleteQuery deleteQuery(Class<?> clazz)
                        throws OrmException
Delete the objects of a specific table

Parameters:
clazz - the TABLE related Class
Throws:
OrmException

deleteQuery

DeleteQuery deleteQuery(Class<?> clazz,
                        String alias)
                        throws OrmException
Delete the objects of a specific table

Parameters:
clazz - the TABLE related Class
alias - The alias of the class in the query.
Throws:
OrmException

findQuery

<T> FindQuery<T> findQuery(Class<T> clazz)
                       throws OrmException
Create a new query

Type Parameters:
T -
Parameters:
clazz - The class of the object that will be retrieved by the query execution. The simple class name will be used as alias for the class
Returns:
Throws:
OrmException

findQuery

<T> FindQuery<T> findQuery(Class<T> clazz,
                           String alias)
                       throws OrmException
Create a new query

Type Parameters:
T -
Parameters:
clazz - The class of the object that will be retrieved by the query execution.
alias - The alias of the class in the query.
Returns:
Throws:
OrmException

findQuery

CustomFindQuery findQuery(String selectClause,
                          Class<?> clazz,
                          String alias)
                          throws OrmException
Create a new query

Parameters:
selectClause - the select clause of the query (do not use the "select" keyword)
clazz - The class of the object that will be retrieved by the query execution.
alias - The alias of the class in the query.
Returns:
Throws:
OrmException

sqlExecutor

SqlExecutor sqlExecutor()
An executor to perform any kind of plain SQL statements.

Returns:

scriptExecutor

ScriptExecutor scriptExecutor()
                              throws OrmException
A script executor useful to execute multiple sql statement from files.

Returns:
Throws:
OrmException


Copyright © 2013. All Rights Reserved.