Ramin Javanbakht wrote:

> Hi:
>
> In the EJB solution, if one has a bean (either session or entity) that
> requires access to the database, one must use DataSource object. I know of
> several ways to do this:
>
> 1. Declare the DataSource object as a non-static member of the bean. This is
> a bad solution, because, if you have 1000 beans in your EJB containers, you
> end up with 1000 data sources instances.
>
> 2. Declare the DataSource object as STATIC member of the bean. Now you have
> only one instance of the DataSource object, but you have to worry about
> controlling the concurrent access to it. That by itself can be a bottleneck.
> Looking at the ConnectionManager.java source, it seems that the
> getConnection() method is declared as a "synchronized".
>
> 3. Have a separate class that is following the "singleton" design pattern,
> and provides two static methods (getConnection, and closeConnection) that
> can be called to get and release a "Connection" object from and to the
> database connection pool. This solution has a problem, because a developer
> must remember to do the get/close combo in it's bean. No container
> involvement!
>
> In summary, it seems to be that EJB provides database connection pooling at
> the object level. However, Microsoft solution, Microsoft Transaction Server
> (MTS) does it at the container level. That is, they have implemented
> solution 3.
>
> Anyway, I would like to know your thoughts. WHAT IS THE MOST EFFICIENT AND
> EASIEST WAY TO USE DATABASE CONNECTION IN EJB BEANS?
>

Since the beginning, I decided that if I was taking the overhead of EJB
specification, I did want it to have TRANSPARENT persistency. And that means
Container Managed Persistance. So, the only SQL code that I have in my whole
system are the WHERE clauses of the findXXX methods.

I would say that I would have chosen a different solution if I wanted to do SQL
(or JDBC programming).

In principle all that is required to migrate my application to a different App
Server is to edit the properties files (I'm using 1.6.1 ).

In fact, my system runs under Linux, using PostgreSQL, (for development), and
under Win NT, using MS SQL Server, for deployment, WITH THE SAME SOURCE CODE.
(Except that the test scripts for populating the database use NOW for Postgres
and GETDATE() for SQL Server.)

That is my experience. Your mileage will vary.

>
> Thanks and Regards
> Ramin Javanbakht
>
> ----
> This list is cross-posted to two mail lists.  To unsubscribe,
> follow the instructions below for the list you subscribed to.
> For objectweb.org: send email to [EMAIL PROTECTED] and
> include in the body of the message "unsubscribe ejb-container-group".
> For enhydra.org: send email to [EMAIL PROTECTED] and include
> in the body of the message "unsubscribe ejb-container-group".

----
This list is cross-posted to two mail lists.  To unsubscribe,
follow the instructions below for the list you subscribed to.
For objectweb.org: send email to [EMAIL PROTECTED] and
include in the body of the message "unsubscribe ejb-container-group".
For enhydra.org: send email to [EMAIL PROTECTED] and include
in the body of the message "unsubscribe ejb-container-group".

Reply via email to