Enterprise Beans Tutorial

Home| Forums | Join Google Group | Join Yahoo Group | Jobs
Get custom programming done at GetAFreelancer.com!
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


32 2. Obtain the DataSource associated with the logical name. · InitialContext ic = new InitialContext(); · DataSource ds = (DataSource) ic.lookup(dbName);
3. Get the Connection from the DataSource.
Connection con = ds.getConnection(); When To Connect When coding an enterprise bean, you must decide how long the bean will retain the connection.
Generally you have two choices: either hold the connection for the lifetime of the bean, or only during each
database call. Your choice determines the method (or methods) in which your bean connects to a database. Longterm Connections You can design an enterprise bean that holds a database connection for its entire lifetime.
Because the bean connects and disconnects just once, its code is slightly easier to write.
But there's a tradeoff-- other enterprise beans may not acquire the connection. Session and entity beans issue
the lifelong connections in different methods. Session Beans · The EJB container invokes the ejbCreate method at the beginning of a session bean's life cycle, and
invokes the ejbRemove method at the end. To retain a connection for the lifetime of a session bean, you
connect to the database in ejbCreate and disconnect in ejbRemove.
· If the session bean is stateful, you must also connect in ejbActivate and disconnect in ejbPassivate. A
stateful session bean requires these additional calls because the EJB container may passivate the bean
during its lifetime. During passivation, a stateful session bean is saved in secondary storage, but a
database connection may not be saved in this manner.
· Because a stateless session bean cannot be passivated, it does not require the additional calls in
ejbActivate and ejbPassivate.
Entity Beans · After instantiating an entity bean and moving it to the pooled stage, the EJB container invokes the
setEntityContext method. Conversely, the EJB container invokes the unsetEntityContext method when
the entity bean leaves the pooled stage and becomes eligible for garbage collection.
· To retain a database connection for its entire lifespan, an entity bean connects in the setEntityContext
method and disconnects in the unsetEntityContext method.
Short-term Connections · Briefly held connections allow many enterprise beans to share the same connection. · Because the EJB container manages a pool of database connections, enterprise beans can quickly
obtain and release the connections.
· For example, a business method might connect to a database, insert a row, and then disconnect. · In a session bean, a business method that connects to a database should be transactional. The transaction
will help maintain data integrity.
Container-Managed Connections · With container-managed persistence, the entity bean class does not contain the code that connects to a
database. Instead, this code is generated by the Application Deployment Tool. Using the tool, you
specify the JNDI name of the database in the JNDI Name field of the Deployment Settings dialog box.


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