Ravi Kiran V wrote:I have written a Template for getting Oracle Connection for my Application
What do you mean a template ... like a template pattern?
If so, this is not a template pattern (see: Template) ... would have to say more of a singleton.
Anyhow, regarding the code.
Perhaps your getConnection() method should return only a connection, without any init or lookup stuff in it?
Meaning you could create a:
- lazy loading singleton (created on demand ... first use)
- or put the init in a static initializer (created when class is loaded ... if not too early)
- or make a inner wrapper for the initialization and again use a singleton
Beside this, you'll have to catch following two execptions: SQLException & NamingException.
edit: or since this is a static method, you should perhaps re-thrown some custom exception with appropriate msg.
First of all thanks for all the knowledge Transfer .
I purposefully did not add any Exception handling to make it look simpler .
The basic idea of posting this question is that , Mine is a web based Application , where more than 100 users can access the Application simultaneously , so i created a Connection Pool with a Capacity of 100 .
Now my requirement is that i want to allow a single user Obtain only One Connection(Even though he opens a new window of my application) so please tell me how to achieve this . (I think that i cannot make a blunder with going for static methods for Obtaining Connections as this is a web application).
and also i think that there is a difference between Template and a Template Method pattern(Correct me if i am wrong).
In theory, you could use the caller's IP address and code so that you restrict the number of connections. But this is a bad idea.
* Users could come from a common router, in which case all clients will have the router's IP
* You cannot restrict a user from using more than one connection. How do you handle cases where the connection went sour and how do you track these changes ?
* Writing your own connection pool can be a big design challenge. For example, your static method cannot restrict the number of Connections to 100. A singleton per server instance will be able to. However even the singleton has to keep track of Connections and when they need to be released. If a Connection is closed the pool has to be refreshed with a new Connection. Handling all these transitions requires a lot of testing, which the app server providers have already implemented and done for you.
Long story short, use the connection pool provided by the app server