加入收藏 | 设为首页 | 会员中心 | 我要投稿 东莞站长网 (https://www.0769zz.com/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长百科 > 正文

使用Oracle JDBC驱动程序隐式缓存功能

发布时间:2021-01-23 13:57:26 所属栏目:站长百科 来源:网络整理
导读:我很确定其他人已经问过这个问题,但我仍然找不到满意的答案. ??所以,这是我的场景:我想使用Oracle的JDBC驱动程序隐式语句缓存(此处记录: http://docs.oracle.com/cd/B28359_01/java.111/b31224/stmtcach.htm#i1072607) 我需要使用来自第三方JDBC池提供程序

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

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

问题是启用隐式缓存的方法是两步过程(相应于文档):

1.

Call setImplicitCachingEnabled(true) on the connection
or
Call OracleDataSource.getConnection with the ImplicitCachingEnabled
property set to true. You set ImplicitCachingEnabled by calling
OracleDataSource.setImplicitCachingEnabled(true)

2.

In addition to calling one of these methods,you also need to call
OracleConnection.setStatementCacheSize on the physical connection. The
argument you supply is the maximum number of statements in the cache.
An argument of 0 specifies no caching.

我可以忍受1(不知怎的,我可以配置我的池使用OracleDataSource作为主连接工厂,并且我可以设置OracleDataSource.setImplicitCachingEnabled(true)).
但是在第二步,我已经需要连接才能调用setStatementCacheSize.

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

PS:我在这里找到的一些相关问题:
Oracle jdbc driver: implicit statement cache or setPoolable(true)?

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

最终我这样做了:

>使用oracle.jdbc.pool.OracleDataSource创建本机连接池.
>使用使用本机的org.apache.tomcat.jdbc.pool.DataSource创建了一个tomcat JDBC连接池(请参阅属性dataSource).
>通过AOP启用poincut,以便执行’execution(public java.sql.Connection oracle.jdbc.pool.OracleDataSource.getConnection())’后,我拾取对象并执行我想要的设置.

解决方案效果很好;我只是不高兴我不得不写一些样板来做它(我期待一个直接的属性).

解决方法

白皮书 Oracle JDBC Memory Management说

The 11.2 drivers also add a new property to enable the Implicit Statement Cache.

oracle.jdbc.implicitStatementCacheSize

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.

(编辑:东莞站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!