>
> SessionBeanA - method1
> ******************************
> 1. Get a database connection
> 2. Insert a few rows
> 3. Close connection
>
> SessionBeanB - method2
> ******************************
> 1. Get a database connection
> 2. Insert a few rows
> 3. Close connection
>
> SessionBeanC - method-3
> ******************************
> call sessionBeanA.method1()
> call sessionBeanB.method2()
>
> question
> ***********
> If all three beans are marked as TX_REQUIRED, How does the EJB server
> commits or rollback? For a regular JDBC connection( I think) , a close()
> method will not allow any more rollbacks or commits.  How does EJB Server
> know to give the SessionBeanB-method2() the same connection that was given
> to sessionBeanA?

java.sql.Connection is simply an interface.  Vendors implement this
interface to allow you to connect to a database.  The EJB container does the
same thing, and encapsulates the JDBC drivers calls.  For instance,

1) When you get a connection via a DataSource this is purely logical.  It is
the job of the container to make sure all beans in the same tx use the same
physical Connection implementation (assumption:  we are using a shared
connection psuedo coordinator).

2) The call to close() is also logical.  If a tx is pending the container
will ignore this call.  If the tx is complete it will affect the tx, and
retun the connection to the cache.  The connection never actually closes.


>
> Does EJB Server need the use of a special JDBC driver to accomplish this?
> What if we want to use our own JDBC driver?

No, it will provide its own inplementation of java.sql.Connection which
wraps any JDBC driver.

>
> Some of the books have advocated the following method to obtain the
> connection:
>
> Datasource ds = (Datasource)jndiContext.lookup("java:comp/env/jdbc/myDB");
> java.sql.Connection con = ds.getConnection();

The DataSource an the Connection are just interfaces.  The underlying
implementations of these interfaces work with the containers tx manager to
do this.  Ahhh, the power of indirection :)

Dave Wolf
Internet Applications Division
Sybase

>
> I don'e see how the Datasource could have been aware of the ongoing
> transaction. What could I be missing?
>
> Thanks for your help
> Satya.
>
> ==================================================================
> =========
> To unsubscribe, send email to [EMAIL PROTECTED] and include
> in the body
> of the message "signoff EJB-INTEREST".  For general help, send email to
> [EMAIL PROTECTED] and include in the body of the message "help".
>
>

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff EJB-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to