Constantino Cronemberger
Constantino Cronemberger

Reputation: 2261

Why Oracle's PoolDataSource ignores connectionProperties values?

In my contex.xml file for Tomcat I have this datasource declaration:

<Resource name="jdbc/my_ds" auth="Container" factory="oracle.ucp.jdbc.PoolDataSourceImpl" 
          type="oracle.ucp.jdbc.PoolDataSource" description="UCP Pool in Tomcat" 
          connectionFactoryClassName="oracle.jdbc.pool.OracleDataSource" minPoolSize="1" maxPoolSize="10" 
          initialPoolSize="2" inactiveConnectionTimeout="20" setMaxIdleTime="1800" 
          user="my_user" password="my_password" 
          url="jdbc:oracle:thin:@mydb.com:1234:DATABASEID" connectionPoolName="MY_UCPPool" 
          connectionProperties="defaultBatchValue=7000,defaultRowPrefetch=7000" validateConnectionOnBorrow="true"/>

But in my DAO code when I check the fetch size it is not returning 7000 as expected:

if (s.getFetchSize() < 100) {
   log.warn("fetch size is too small: " + s.getFetchSize());
}

Upvotes: 4

Views: 1288

Answers (1)

Constantino Cronemberger
Constantino Cronemberger

Reputation: 2261

After decompiling the class PoolDataSourceImpl, I have found this piece of code:

propStrs = cfPropsStr.substring(1, cfPropsStr.length() - 1).split(", ");

when it is parsing the content of the connectionProperties.

This means that:

  1. The separator is ", " and not ","
  2. First and last characters are discarded

So you just need to change the declaration from:

connectionProperties="defaultBatchValue=7000,defaultRowPrefetch=7000"

to:

connectionProperties=" defaultBatchValue=7000, defaultRowPrefetch=7000 "

or even:

connectionProperties="_defaultBatchValue=7000, defaultRowPrefetch=7000_"

Notice that there is no need to use spaces at the beginning or at the end, it can be any character.

With the initial configuration the result would be the key "efaultBatchValue" and the value "7000,defaultRowPrefetch=700".

Upvotes: 5

Related Questions