本文介绍了使用Oracle JDBC驱动程序隐式缓存功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很确定其他人已经问过这个问题,但是我仍然找不到满意的答案. 因此,这是我的情况:我想使用Oracle的JDBC驱动程序隐式语句缓存(在此处记录: http://docs.oracle.com/cd/B28359_01/java.111/b31224/stmtcach.htm#i1072607 )

I am pretty sure that somebody else already asked this question, but I still couldn't find a satisfactory answer to it. So, here is my scenario: I want to use the Oracle's JDBC driver implicit statement caching (documented here: http://docs.oracle.com/cd/B28359_01/java.111/b31224/stmtcach.htm#i1072607)

我需要使用来自第三方JDBC池提供程序的连接(更具体地说,是Tomcat JDBC),我在那里别无选择.

I need to use the connections from a 3rd party JDBC pool provider (to be more specific, Tomcat JDBC) and I have no choice there.

问题在于启用隐式缓存的方法是一个两步过程(根据文档):

The problem is that the way to enable the implicit caching is a two-step process (accordingly to the documentation):

1.

2.

我可以忍受1(以某种方式可以将我的池配置为将OracleDataSource用作主要连接工厂,并可以在其中设置OracleDataSource.setImplicitCachingEnabled(true)).但是在第二步中,我已经需要存在连接才能调用setStatementCacheSize.

I can live with 1 (somehow I can configure my pool to use the OracleDataSource as a primary connection factory and on that I can set the OracleDataSource.setImplicitCachingEnabled(true)).But at the second step, I already need the connection to be present in order to call the setStatementCacheSize.

我的问题是,是否有可能在数据源级别为statementCacheSize指定默认值,以便可以从已经启用隐式缓存的OracleDataSource连接中获取数据.

My question is if there is any possibility to specify at the data source level a default value for the statementCacheSize so that I can get from the OracleDataSource connections that are already enabled for implicit caching.

PS:我在这里找到了一些相关的问题: Oracle jdbc驱动程序:隐式语句缓存还是setPoolable(true)?

PS: some related questions I found here:Oracle jdbc driver: implicit statement cache or setPoolable(true)?

更新(可能的解决方案):

最终我做到了:

  1. 使用oracle.jdbc.pool.OracleDataSource创建了本机连接池.
  2. 使用org.apache.tomcat.jdbc.pool.DataSource创建了一个使用本机端口的tomcat JDBC连接池(请参阅属性dataSource).
  3. 通过AOP启用poincut,以便在执行"execution(public java.sql.Connection oracle.jdbc.pool.OracleDataSource.getConnection())"之后,拾取对象并执行所需的设置.
  1. Created a native connection pool using oracle.jdbc.pool.OracleDataSource.
  2. Created a tomcat JDBC connection pool using org.apache.tomcat.jdbc.pool.DataSource that uses the native one (see the property dataSource).
  3. Enabled via AOP a poincut so that after the execution of 'execution(public java.sql.Connection oracle.jdbc.pool.OracleDataSource.getConnection())' I pickup the object and perform the setting I wanted.

该解决方案效果很好;我只是为自己必须写一些样板而感到不高兴(我期待一个直截了当的属性).

The solution works great; I am just unhappy that I had to write some boilerplate to do it (I was expecting a straight-forward property).

推荐答案

白皮书 Oracle JDBC内存管理表示

oracle.jdbc.implicitStatementCacheSize

该属性的值是 整数字符串,例如"100".它是语句的初始大小 缓存.将属性设置为正值可启用隐式 语句缓存. 默认值为"0".该属性可以设置为 通过-D 的系统属性,或通过getConnection的连接属性.

The value of the property is an integer string, e.g. "100". It is the initial size of the statement cache. Setting the property to a positive value enables the Implicit Statement Cache. The default is "0". The property can be set as a System property via -D or as a connection property via getConnection.

这篇关于使用Oracle JDBC驱动程序隐式缓存功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-18 12:37