I need to set some specific Oracle JDBC connection properties in order to speed up batch INSERT
s (defaultBatchValue
) and mass SELECT
s
After digging around in the Tomcat code for a bit, I found that the dataSource.getPoolProperties().getDbProperties()
is the Properties
object that will actually get used to generate connections for the pool.
If you use the BeanPostProcessor
approach mentioned by @m-deinum, but instead use it to populate the dbProperties
like so, you should be able to add the properties in a way that makes them stick and get passed to the Oracle driver.
import java.util.Properties;
import org.apache.tomcat.jdbc.pool.DataSource;
import org.apache.tomcat.jdbc.pool.PoolConfiguration;
@Component
public class OracleConfigurer implements BeanPostProcessor {
@Override
public Object postProcessBeforeInitialization(Object bean, String name) throws BeansException {
if (bean instanceof DataSource) {
DataSource dataSource = (DataSource)bean;
PoolConfiguration configuration = dataSource.getPoolProperties();
Properties properties = configuration.getDbProperties();
if (null == properties) properties = new Properties();
properties.put("defaultRowPrefetch", 1000);
properties.put("defaultBatchValue", 1000);
configuration.setDbProperties(properties);
}
return bean;
}
@Override
public Object postProcessAfterInitialization(Object bean, String name) throws BeansException {
return bean;
}
}