0

In our application we are managing datasource through C3P0PooledDataSource and configuration is done in applicationContext.xml file.

    <bean id="parentDataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close" abstract="true">
    <property name="acquireIncrement" value="${jdbc.acquireIncrement}" />
    <property name="minPoolSize" value="${jdbc.minPoolSize}" />
    <property name="maxPoolSize" value="${jdbc.maxPoolSize}" />
    <property name="maxIdleTime" value="${jdbc.maxIdleTime}" />
    <property name="maxIdleTimeExcessConnections" value="${jdbc.maxIdleTimeExcessConnections}" />
</bean>
<bean id="ds1" parent="parentDataSource" singleton="true">
        <property name="driverClass" value="${ds1.jdbc.driver}" />
        <property name="jdbcUrl" value="${ds1.jdbc.url}"/>
        <property name="user" value="${ds1.jdbc.user}" />
        <property name="password" value="${ds1.jdbc.password}" />   
    </bean>
 <bean id="ds2" parent="parentDataSource" singleton="true">
    <property name="driverClass" value="${ds2.jdbc.driver}" />
    <property name="jdbcUrl" value="${ds2.jdbc.url}"/>
    <property name="user" value="${ds2.jdbc.user}" />
    <property name="password" value="${ds2.jdbc.password}" />   
</bean>

Now at the time of deployment there are 2 pools created and each of them has its own minPoolSize and accordingly those many connections are being created. Is there any way that we can defined the configuration of minPoolSize, maxPoolSize etc at one level and all data sources will be managed through that.

kapil gupta
  • 335
  • 3
  • 19

1 Answers1

0

Looks like you want to have single data source that maintains connections to two different databases/schemes/connection pools.

If so, I don't think that is possible. Reason being, let's assume that is possible, now how would an application using this data source knows that the connection is for a particular database/schema before firing a query.

  • This is correct!! But what I want is different data sources managed by 1 pool configuration. How about creating a poolwrapper and managing two child pools but I got stuck in getting it done through applicationContext.xml. If we can refer to same bean object from different bean declaration in xml then this can be achieved but I am not sure how can we do it. – kapil gupta Sep 09 '16 at 09:06
  • @kapilgupta Not sure I completely get the statement `If we can refer to same bean object from different bean declaration in xml`. I am interpreting it as you want reference a bean (from say beandef2.xml) declared in a another xml file (from say beandef1.xml). If so, can't we import the the `beandef1.xml` in the `beandef2.xml` file using ``. More on this at [http://stackoverflow.com/questions/7711750/how-to-reference-a-bean-of-another-xml-file-in-spring](http://stackoverflow.com/questions/7711750/how-to-reference-a-bean-of-another-xml-file-in-spring) – Madhusudana Reddy Sunnapu Sep 09 '16 at 09:45
  • No, I meant if this can be achieved by sharing the same reference, that was just a thought. I have to anyways get the child pool managed by one central pool or parent pool – kapil gupta Sep 12 '16 at 04:35