Hi Everybody ,
I my project I have written a BMP which deals with two tables in Oracle.
I am opening the connection to the database in the setEntityContext() method using it in all the database routines and then closing it in the unSetEntityContext() method.Its working fine.
But my PM says that its not effiecint to open the connection in setEntityContext() method, keeping it live and then closing it at the end in unSetEntityContext()
I have got large no. of database routine methods, will it affect performance or working of my BMP if I open & close the conn in every method .........How is it done normally .....what is the design convention for BMP for this
what the EJB specs says about this
If anybody has an idea please let me know
Thanks in Advance
Rupesh
-
Database connection convention in BMP (9 messages)
- Posted by: Rupesh Sangoi
- Posted on: January 23 2002 03:13 EST
Threaded Messages (9)
- Database connection convention in BMP by Kevin Leong on January 23 2002 13:08 EST
- Database connection convention in BMP by T J on January 23 2002 18:11 EST
- Database connection convention in BMP by Toby Hede on January 23 2002 18:46 EST
- Database connection convention in BMP by T J on January 24 2002 15:22 EST
-
Database connection convention in BMP by Sree Gorty on January 31 2002 04:01 EST
- Database connection convention in BMP by T J on February 01 2002 12:42 EST
-
Database connection convention in BMP by Sree Gorty on January 31 2002 04:01 EST
- Database connection convention in BMP by T J on January 24 2002 15:22 EST
- Database connection convention in BMP by Pranab Ghosh on January 23 2002 19:09 EST
- Database connection convention in BMP by sridhar G on January 24 2002 06:03 EST
- Database connection convention in BMP by sanjay lalwani on January 24 2002 06:12 EST
-
Database connection convention in BMP[ Go to top ]
- Posted by: Kevin Leong
- Posted on: January 23 2002 13:08 EST
- in response to Rupesh Sangoi
Try creating a class to manage a pool of connection with methods to get and free connection from/back to the pool.
Thus, you are not actually opening and closing the DB connections (which are expensive).
Kevin Leong
www.zhanra.com -
Database connection convention in BMP[ Go to top ]
- Posted by: T J
- Posted on: January 23 2002 18:11 EST
- in response to Kevin Leong
If he's using bmp, the app server has that built-in. -
Database connection convention in BMP[ Go to top ]
- Posted by: Toby Hede
- Posted on: January 23 2002 18:46 EST
- in response to Rupesh Sangoi
Your App Server should provide a DataSource, accessible through the standard JNDI interface. This should provide you with the pooling you need.
I generally palm my DataAccess (DA) to another class, instantiated by the BMP Entity as required (this lets you then create factory method patterns to determine particular database implementions at runtime, if required).
Acquire the datasource in the constructor of the DA class or the setEntityContext method of your BMP:
InitialContext initCtx = new InitialContext();
DataSource dataSource = (DataSource) initCtx.lookup("jdbc/default");
Then, as you need the connection, get it from the DataSource (as in this occurs in the any method that reuires a connection):
Connection con = dataSource.getConnection();
Then close the connection when you finished with it, my understanding is that this returns it to the pool, rather than actually closing it.
-
Database connection convention in BMP[ Go to top ]
- Posted by: T J
- Posted on: January 24 2002 15:22 EST
- in response to Toby Hede
"Then close the connection when you finished with it, my understanding is that this returns it to the pool, rather than actually closing it. "
That's correct. -
Database connection convention in BMP[ Go to top ]
- Posted by: Sree Gorty
- Posted on: January 31 2002 04:01 EST
- in response to T J
I concur with Sridha G...regarding not creating connection in setEntityContext and instead creating and removing it in the same method call. Because removal of actual entity bean is upon the discretion of the container. if the container does not remove the bean for a while and the max connection pool creation has been reached and then new request for database connection has to wait until the entity bean holding the connections are removed or destroyed.
SG -
Database connection convention in BMP[ Go to top ]
- Posted by: T J
- Posted on: February 01 2002 00:42 EST
- in response to Sree Gorty
If you crate a conn in the entitycontext, that con is in use for lord knows how long. You should reserve a conn, use it, then return it asap. THat's what pooling is all about. -
Database connection convention in BMP[ Go to top ]
- Posted by: Pranab Ghosh
- Posted on: January 23 2002 19:09 EST
- in response to Rupesh Sangoi
Your AppServer manages database connections in a pool anyway. When you are getting a connection and releasing it, all you are doing is getting the connection from the pool and returning it to the pool. So it's not an expensive operation.
Pranab -
Database connection convention in BMP[ Go to top ]
- Posted by: sridhar G
- Posted on: January 24 2002 06:03 EST
- in response to Pranab Ghosh
Hi,
For every connection we need to close the connection,other wise your connection pool will loose all the connection.So its not advisable to create connection in setentitycontext and close unsetentitycontext as it is called only after bean is removed .so better to close conn for every method call. -
Database connection convention in BMP[ Go to top ]
- Posted by: sanjay lalwani
- Posted on: January 24 2002 06:12 EST
- in response to Rupesh Sangoi
hey Rupesh Where are you?
Remember me?