2

I work on a project where the design is to have a database per customer. I have managed to read in Tomcat documentation and establish a connection pool. Since the databases are created automatically by the application when a customer registers, I needed a way to make a dynamic pool. the following post on stack overflow gave the hint of what is required:

Using dynamic Datasource with Tomcat

and I found on the web a page showing how to do this:

Writing and using a Tomcat ObjectFactory

I still have few questions:

1- who takes care of managing the connections in the pool ? in the datasource declaration in context.xml, we define some parameters that control various aspects like max idle time and max number of connections, etc. does tomcat handle this or do I have to take care of it in the implementation that i make when coding a class that implements the ObjectFactory interface ?

2- As I understand, when connections are closed, they return to the pool. suppose that I make a dynamic pool that has maximum 20 connections. and then 30 customers log in. so the pool returns 20 connections for the first 20 customers. when those connections are closed, they return to the pool and the next 10 customers will ask for connections to different databases than the ones already found in the pool. and the question is: will the pool automatically drop 10 connections and add new ones with the correct databases ? in if this is the case, does this really have an advantage over opening a connection upon request without a pool ? (asked with the thought of a site that will be heavily loaded. the amount of connection drop if i guessed correctly might be very high that it wouldn't justify what the pool is there to do: minimize creating connections from scratch)

3- I also wanted to ask if it is ok to implement it myself (considering I am new to this) or if i should find a library that does this (in case its not a task for the beginner in this area).

4- are there any alternatives for connection pools for managing connections to multiple databases that are added dynamically in an efficient way? (in case datasource will not help) what are the approaches used in similar situations?

Thank you in advance for your effort.

Community
  • 1
  • 1

1 Answers1

0

In declaring a datasource you can specify a datsource class, such as the Oracle datasource. It uses the parameters specified to manage the datasource for you. It is best to let the datasource manage itself. I have tried to write one and it is not simple.

I think the datasource will not be adequate for you, I could be wrong. A datasource requires a database url, username and password that will be fixed for the lifetime of the datasource.

Having different databases for different users will break this.

Look at the reference you gave above, the answer mentions using a resource which is different from a datasource.

Kara
  • 6,115
  • 16
  • 50
  • 57
Brett Walker
  • 3,566
  • 1
  • 18
  • 36
  • Thanks for your answer. I also thought it is not possible until I found the links above which show it is possible. I then asked the above questions just to make sure its worth the effort. otherwise I could find too late that even though it is possible, it is actually not practical. anyway based on what you have mentioned, i will edit and add a fourth question. thank you :) –  Aug 20 '11 at 09:36
  • The only place i found something is a dynamic connection pool and dynamic datasources in oracle WebLogic. on this link you can search for dynamic pool and dynamic datasource : http://download.oracle.com/docs/cd/E13222_01/wls/docs81/jdbc/programming.html this makes your answer correct as its not possible to have dynamic datasource with Tomcat as it seems. and even if it was possible, it is very hard as you have suggested. I will then open another question of what approaches to take and I will accept your answer. Thank you for your help :) –  Aug 25 '11 at 18:11