|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
This interface describes the DaoManager interface. It provides access to all DAOs it manages and also allows transactions to be committed and ended (possibly rolled back).
DAO instances returned from the DAO Manager are proxied such that transactions can be automatically started, committed and ended (or rolled back). This is a similar semantic to the JDBC autocommit, but much more powerful. Alternatively, tranasctions can be controlled programmatically, allowing you to demarcate wider scope transactions as needed. Either way, transactions will only be started for those contexts that require them. No unneccessary transactions will be started. When commitTransaction() and endTransaction() are called, all transactions which have been started in each configured context will be committed and ended respectively. endTransaction() will automatically rollback any transactions that have not been committed. Here's a couple of examples:// ************************************************************** // AUTO COMMIT TRANASACTION SEMANTIC // ************************************************************** DaoManager daoManager = DaoManagerBuilder.buildDaoManager(reader); PersonDao personDao = daoManager.getDao(PersonDao.class); // A transaction will be automatically started committed and ended // by calling any method on the DAO. The following insert and update // are TWO separate transactions. personDao.insertPerson (person); // Starts transaction person.setLastName("Begin"); personDao.updatePerson (person); // Starts a new transaction // ************************************************************** // PROGRAMMATIC DEMARCATION OF TRANSACTION SCOPE // ************************************************************** DaoManager daoManager = DaoManagerBuilder.buildDaoManager(reader); PersonDao personDao = daoManager.getDao(PersonDao.class); try { // Calling startTransaction() tells the DAO Manager that you // are going to be managing the transactions manually. daoManager.startTransaction(); personDao.insertPerson (person); person.setLastName("Begin"); personDao.updatePerson (person); // Commit all active transactions in all contexts daoManager.commitTransaction(); } finally { // End all active transactions in all contexts and rollback if necessary. daoManager.endTransaction(); }Important: In order to achieve global transaction behaviour (i.e. two phase commit), you'll need to configure all of your contexts using JTA, JNDI and XA compliant DataSources.
Method Summary | |
void |
commitTransaction()
Commits all transactions currently started for all DAO contexts managed by this DaoManager. |
void |
endTransaction()
Ends all transactions currently started for all DAO contexts managed by this DaoManager. |
Dao |
getDao(java.lang.Class type)
Gets a Dao instance for the requested interface type. |
Dao |
getDao(java.lang.Class iface,
java.lang.String contextId)
Gets a Dao instance for the requested interface type registered under the context with the specified id. |
DaoTransaction |
getTransaction(Dao dao)
Gets the transaction that the provided Dao is currently working under. |
void |
startTransaction()
Starts a transaction scope managed by this DaoManager. |
Method Detail |
public Dao getDao(java.lang.Class type)
type
- The interface or generic type for which an implementation
should be returned.
public Dao getDao(java.lang.Class iface, java.lang.String contextId)
iface
- The interface or generic type for which an implementation
should be returned.contextId
- The ID of the context under which to find the DAO
implementation (use for multiple interface defs).
public DaoTransaction getTransaction(Dao dao)
dao
- The Dao to find a transaction for.
public void startTransaction()
public void commitTransaction()
public void endTransaction()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |