2
votes

I've been asked to write some code which can create multiple jboss datasource connection pools programatically upon startup.

I've done this using a shell script which generates -ds.xml files at startup, which jboss then reads, but I've been told it must be done programmatically in Java.

Of course I can create the datasources myself, that's easy enough, but we need to use a jboss connection pool with a configurable max and min pool size, bound in JNDI. I'd rather not write my own connection pool implementation...

And just to make the problem that much harder, we're using jboss 5.0.1 and no we can't upgrade it for this task.

Is this even possible?

-edit-

So I can do this:

   OracleDataSource ds = new OracleDataSource();
   ds.setURL(url);
   ds.setUser(user); 
   ds.setPassword(pass); 
   Context ctx = JndiLookups.getInitialContext();
   ctx.bind(dsName, ds);

But I don't think this gives me connection pooling, does it? I need to be able to specify a connection pool size, blocking timeout, etc

2
As to the connection pool, can't you use delegation/composition? - fge
Not clear what you mean by that... - mdarwin
I mean to create a "wrapper class" over your data source implementation which would just delegate its methods to the underlying data source. Sort of how you would "extend" a Collection instead of inheriting it. - fge
I don't want to implement a datasource at all - I want to use an existing implementation of datasource which supports connection pooling. - mdarwin
Well, you said that you "need to be able to specify a connection pool size" etc... Ohwell - fge

2 Answers

0
votes

My conclusion is that it's not worth trying - the simplest way is to use shell scripts to dynamically generate the -ds.xml files on startup.

-1
votes
Class.forName( dbDriver );
Connection con = DriverManager.getConnection( dbUrl );

Connection is a connection.