tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Daniel Mikusa <dmik...@vmware.com>
Subject Re: tomcat-jdbc: correct way to create a new separated org.apache.tomcat.jdbc.pool.DataSource from another one
Date Wed, 08 Aug 2012 12:19:24 GMT
----- Original Message -----
> Hello.
> 
> I have an use case in which I would want to copy an
> `org.apache.tomcat.jdbc.pool.DataSource`, to have two disjoint
> connection
> pools, with some pool properties changed.
> 
> My first thought was to do something like this:
> 
> PoolProperties props = new
> PoolProperties(baseDataSource.getPoolProperties());
> // set custom props ...
> DataSource newDataSource = new DataSource(props);
> 
> 
> The problem is that the PoolProperties class doesn't have such
> constructor.
> Another option could be to share the PoolProperties object, but, for
> what
> I've looked into the code, it doesn't seem safe.
> 
> The PoolProperties class implements the Cloneable interface, so I
> guess
> it's ok to use its clone method. The problem I have with this option
> is
> that DataSource#getPoolProperties() returns a PoolConfiguration which
> doesn't implements Cloneable. In my case I think it would be safe to
> cast
> the PoolConfiguration to PoolProperties, but it doesn't seem safe for
> the
> general case.
> 
> What would be the correct way to create a new separated DataSource
> from
> another one having some properties changed?
> 
> I'm using tomcat-jdbc 7.0.29 as a standalone library.
> 
> Thank you.
> 
> Regards,
> Germán
> 

Have you looked at the method "parsePoolProperties" on the DataSourceFactory class?

  public static PoolConfiguration parsePoolProperties(Properties properties)

You could load your configuration into a Properties object, create you first pool configuration
with "parsePoolProperties", alter the Properties object and then call "parsePoolProperties"
on the modified Properties object to create your second pool configuration.

Dan



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Mime
View raw message