Earn Money
Trading Forex Online
Paramount Airways
Free Data Recovery
Cargo
Job Portal
HSBC Investment
Management
Cheap Web Hosting
Make Trip
Cheap Air Travel
Leisure Hotel
Free Air Travel
Mutual Fund Informations
Cheapest Cellular Plan
Free Sexy Indians
Call Center Software
Hot Indian
|
Programming Help |
Homework Help |
Counseling
Astrology Advice |
Tarot Advice |
Parenting
Dating Advice |
Love Advice |
Divorce Advice
Legal Advice |
Debt Advice |
Career Advice
Enterprise Beans Tutorial
21
Synchronizing a Session Bean's Instance Variables
The SessionSynchonization interface, which is optional, allows you to synchronize the instance variables
with their corresponding values in the database.
The container invokes the SessionSynchonization methods-- afterBegin, beforeCompletion, and
afterCompletion
-- at each of the main stages of a transaction.
The afterBegin method informs the instance that a new transaction has begun. The container invokes
afterBegin immediately before it invokes the business method. The afterBegin method is a good place to load the instance variables from the database.
The container invokes the beforeCompletion method after the business method has finished, but just before
the transaction commits. The beforeCompletion method is the last opportunity for the session bean to roll back the transaction (by calling setRollbackOnly). If it hasn't already updated the database with the values of the instance variables, the session bean may do so in the beforeCompletion method.
The afterCompletion method indicates that the transaction has completed. It has a single boolean parameter,
whose value is true if the transaction was committed and false if it was rolled back. If a rollback occurred, the session bean can refresh its instance variables from the database in the afterCompletion method
Methods Not Allowed in Container-Managed Transactions
You should not invoke any method that might interfere with the transaction boundaries set by the container. The list of prohibited methods follows:
commit, setAutoCommit, and rollback methods of java.sql.Connection getUserTransaction method of javax.ejb.EJBContext any method of javax.transaction.UserTransaction
You may, however, use these methods to set boundaries in bean-managed transactions.
Bean-Managed Transactions
·
In a bean-managed transaction, the session bean code invokes methods that mark the boundaries of the transaction.
·
An entity bean may not have bean-managed transactions; it must use container-managed transactions instead.
·
Although beans with container-managed transactions require less coding, they have one limitation: When a method is executing, it can be associated with either a single transaction or no transaction at all. If this limitation will make coding your session bean difficult, you should consider using bean-managed transactions.
The following pseudo-code illustrates the kind of fine-grained control you can obtain with bean-managed transactions. By checking various conditions, the pseudo-code decides whether to start and stop different transactions within the business method.
begin transaction ... update table-a ... if (condition-x) commit transaction else if (condition-y) update table-b commit transaction else rollback transaction begin transaction update table-c
|
|
|
Earn Money
Trading Forex Online
Paramount Airways
Free Data Recovery
Cargo
Job Portal
HSBC Investment
Management
Cheap Web Hosting
Make Trip
Cheap Air Travel
Leisure Hotel
Free Air Travel
Mutual Fund Informations
Cheapest Cellular Plan
Free Sexy Indians
Call Center Software
Hot Indian
|