com.jpattern.orm.session
Class OrmSession

java.lang.Object
  extended by com.jpattern.orm.session.OrmSession
All Implemented Interfaces:
Session, SessionSqlPerformer

public class OrmSession
extends Object
implements SessionSqlPerformer

Author:
Francesco Cina 27/giu/2011

Constructor Summary
OrmSession(IOrmClassToolMap ormClassToolMap, SessionStrategy sessionStrategy, TypeFactory typeFactory, Validator validator)
           
 
Method Summary
<T> int
delete(List<T> objects)
          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 value)
          Return whether a Bean with a specific id exists in the DB.
<T> boolean
exist(Class<T> clazz, Object[] values)
          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 value)
          Find a bean using is ID.
<T> T
find(Class<T> clazz, Object[] values)
          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 value)
          Find a bean using is ID.
<T> T
findUnique(Class<T> clazz, Object[] values)
          Find a bean using is IDs.
 IOrmClassToolMap getOrmClassToolMap()
           
<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.
 SqlPerformer sqlPerformer()
          Return an executor to perform plain sql queries.
 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
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

OrmSession

public OrmSession(IOrmClassToolMap ormClassToolMap,
                  SessionStrategy sessionStrategy,
                  TypeFactory typeFactory,
                  Validator validator)
Method Detail

findQuery

public final <T> FindQuery<T> findQuery(Class<T> clazz)
                             throws OrmException
Description copied from interface: Session
Create a new query

Specified by:
findQuery in interface Session
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

public final <T> FindQuery<T> findQuery(Class<T> clazz,
                                        String alias)
                             throws OrmException
Description copied from interface: Session
Create a new query

Specified by:
findQuery in interface Session
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

public final CustomFindQuery findQuery(String selectClause,
                                       Class<?> clazz,
                                       String alias)
                                throws OrmException
Description copied from interface: Session
Create a new query

Specified by:
findQuery in interface Session
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

getOrmClassToolMap

public final IOrmClassToolMap getOrmClassToolMap()

exist

public <T> boolean exist(T object)
              throws OrmException
Description copied from interface: Session
Return whether a Bean exist in the DB using the Object type and id(s).

Specified by:
exist in interface Session
Returns:
Throws:
OrmException

exist

public <T> boolean exist(Class<T> clazz,
                         Object value)
              throws OrmException
Description copied from interface: Session
Return whether a Bean with a specific id exists in the DB.

Specified by:
exist in interface Session
Parameters:
clazz - The Class of the object to load
value - the value of the identifying column of the object
Returns:
Throws:
OrmException

exist

public <T> boolean exist(Class<T> clazz,
                         Object[] values)
              throws OrmException
Description copied from interface: Session
Return whether a Bean with the specific ids exists in the DB.

Specified by:
exist in interface Session
Parameters:
clazz - The Class of the object to load
values - an ordered array with the values of the identifying columns of the object
Returns:
Throws:
OrmException

find

public final <T> T find(Class<T> clazz,
                        Object value)
             throws OrmException
Description copied from interface: Session
Find a bean using is ID.

Specified by:
find in interface Session
Parameters:
clazz - The Class of the object to load
value - the value of the identifying column of the object
Returns:
Throws:
OrmException

find

public final <T> T find(Class<T> clazz,
                        Object[] values)
             throws OrmException
Description copied from interface: Session
Find a bean using is IDs.

Specified by:
find in interface Session
Parameters:
clazz - The Class of the object to load
values - an ordered array with the values of the identifying columns of the object
Returns:
Throws:
OrmException

findUnique

public final <T> T findUnique(Class<T> clazz,
                              Object value)
                   throws OrmException,
                          OrmNotUniqueResultException
Description copied from interface: Session
Find a bean using is ID. An OrmNotUniqueResultException is thrown if nothing is found.

Specified by:
findUnique in interface Session
Parameters:
clazz - The Class of the object to load
value - the value of the identifying column of the object
Returns:
Throws:
OrmException
OrmNotUniqueResultException

findUnique

public final <T> T findUnique(Class<T> clazz,
                              Object[] values)
                   throws OrmException,
                          OrmNotUniqueResultException
Description copied from interface: Session
Find a bean using is IDs. An OrmNotUniqueResultException is thrown if nothing is found.

Specified by:
findUnique in interface Session
Parameters:
clazz - The Class of the object to load
values - an ordered array with the values of the identifying columns of the object
Returns:
Throws:
OrmException
OrmNotUniqueResultException

save

public final <T> T save(T object)
             throws OrmException
Description copied from interface: Session
Persist the new object in the database

Specified by:
save in interface Session
Returns:
the bean representing the saved object (with updated generated fields)
Throws:
OrmException

update

public final <T> T update(T object)
               throws OrmException
Description copied from interface: Session
Update the values of an existing object in the database

Specified by:
update in interface Session
Returns:
the bean representing the saved object (with updated generated fields)
Throws:
OrmException

updateQuery

public final UpdateQuery updateQuery(Class<?> clazz)
                              throws OrmException
Description copied from interface: Session
Update the objects of a specific TABLE

Specified by:
updateQuery in interface Session
Parameters:
clazz - the TABLE related Class
Throws:
OrmException

updateQuery

public final UpdateQuery updateQuery(Class<?> clazz,
                                     String alias)
                              throws OrmException
Description copied from interface: Session
Update the objects of a specific TABLE

Specified by:
updateQuery in interface Session
Parameters:
clazz - the TABLE related Class
alias - The alias of the class in the query.
Throws:
OrmException

delete

public final <T> int delete(T object)
                 throws OrmException
Description copied from interface: Session
Delete one object from the database

Specified by:
delete in interface Session
Returns:
the number of deleted objects
Throws:
OrmException

delete

public final <T> int delete(List<T> objects)
                 throws OrmException
Description copied from interface: Session
Delete the objects from the database

Specified by:
delete in interface Session
Returns:
the number of deleted objects
Throws:
OrmException

deleteQuery

public final DeleteQuery deleteQuery(Class<?> clazz)
                              throws OrmException
Description copied from interface: Session
Delete the objects of a specific table

Specified by:
deleteQuery in interface Session
Parameters:
clazz - the TABLE related Class
Throws:
OrmException

deleteQuery

public final DeleteQuery deleteQuery(Class<?> clazz,
                                     String alias)
                              throws OrmException
Description copied from interface: Session
Delete the objects of a specific table

Specified by:
deleteQuery in interface Session
Parameters:
clazz - the TABLE related Class
alias - The alias of the class in the query.
Throws:
OrmException

scriptExecutor

public final ScriptExecutor scriptExecutor()
                                    throws OrmException
Description copied from interface: Session
A script executor useful to execute multiple sql statement from files.

Specified by:
scriptExecutor in interface Session
Returns:
Throws:
OrmException

sqlExecutor

public final SqlExecutor sqlExecutor()
Description copied from interface: Session
An executor to perform any kind of plain SQL statements.

Specified by:
sqlExecutor in interface Session
Returns:

transaction

public final Transaction transaction()
                              throws OrmException
Description copied from interface: Session
Begin a transaction or participate to an existing one using the default ITransactionDefinition

Specified by:
transaction in interface Session
Returns:
Throws:
OrmException

transaction

public Transaction transaction(TransactionDefinition transactionDefinition)
                        throws OrmException
Description copied from interface: Session
Begin a or participate to an existing one depending on the specific transactionDefinition

Specified by:
transaction in interface Session
Returns:
Throws:
OrmException

doInTransaction

public <T> T doInTransaction(TransactionCallback<T> transactionCallback)
                  throws OrmException
Description copied from interface: Session
Execute a block of code inside a Transaction or participate to an existing one

Specified by:
doInTransaction in interface Session
Returns:
Throws:
OrmException

doInTransaction

public <T> T doInTransaction(TransactionDefinition transactionDefinition,
                             TransactionCallback<T> transactionCallback)
                  throws OrmException
Description copied from interface: Session
Execute a block of code inside a Transaction or participate to an existing one

Specified by:
doInTransaction in interface Session
Returns:
Throws:
OrmException

sqlPerformer

public SqlPerformer sqlPerformer()
                          throws OrmException
Description copied from interface: SessionSqlPerformer
Return an executor to perform plain sql queries.

Specified by:
sqlPerformer in interface SessionSqlPerformer
Returns:
Throws:
OrmException

saveOrUpdate

public <T> T saveOrUpdate(T object)
               throws OrmException
Description copied from interface: Session
Update the object if it exists, otherwise save it

Specified by:
saveOrUpdate in interface Session
Returns:
the bean representing the saved or updated object (with updated generated fields))
Throws:
OrmException

save

public <T> List<T> save(Collection<T> objects)
             throws OrmException
Description copied from interface: Session
Persist the new objects in the database

Specified by:
save in interface Session
Parameters:
objects - the objects to persist
Returns:
a new collection that contains the beans representing the saved objects
Throws:
OrmException

saveOrUpdate

public <T> List<T> saveOrUpdate(Collection<T> objects)
                     throws OrmException
Description copied from interface: Session
For each object in the list, update the object if it exists, otherwise save it

Specified by:
saveOrUpdate in interface Session
Parameters:
objects - the objects to persist
Returns:
a new collection that contains the beans representing the saved or updated objects
Throws:
OrmException

update

public <T> List<T> update(Collection<T> objects)
               throws OrmException
Description copied from interface: Session
Update the values of the existing objects in the database

Specified by:
update in interface Session
Parameters:
objects - the objects to update
Returns:
a new collection that contains the beans representing the updated objects
Throws:
OrmException


Copyright © 2013. All Rights Reserved.