Dave,
Thanks for a very informative reply. I have been doing some reading. And
your answers are confirming most of the material. In addition to these
interfaces ( Connection etc ) being logical, the other key seem to be the
JTS. This became evident, when I asked my self the following question:
If beanA and beanB (one not knowing about the other ) both ask for a
connection how does the data source object clever enough to return the same
physical connection? It seems JTS uses the "Thread" object that is common
for both the beans( If they had been called on the same thread ) to realize
that there is a current transaction that is going on and will return the
same connection to the second bean.
You are also correct when you said that the EJB servers (via JTS ) are
encapsulating the third party JDBC drivers to provide this functionality.
Which means one would not be able to use this facility if they use the third
party JDBC drivers directly.
Thanks again for your time
Satya.
-----Original Message-----
From: Dave Wolf [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, September 20, 2000 10:40 PM
To: [EMAIL PROTECTED]
Subject: Re: EJBs & JDBC, commit(), rollback()
>
> 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".
===========================================================================
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".