使用Oracle JDBC驱动程序隐式缓存功能 [英] using Oracle JDBC driver implicit caching feature

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

问题描述

我很确定其他人已经问过这个问题,但是我仍然找不到满意的答案. 因此,这是我的情况:我想使用Oracle的JDBC驱动程序隐式语句缓存(在此处记录:

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.

在连接上调用setImplicitCachingEnabled(true) 或者 使用ImplicitCachingEnabled调用OracleDataSource.getConnection 属性设置为true.您可以通过调用设置ImplicitCachingEnabled OracleDataSource.setImplicitCachingEnabled(true)

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.

除了调用这些方法之一之外,您还需要调用 物理连接上的OracleConnection.setStatementCacheSize.这 您提供的参数是高速缓存中的最大语句数. 参数0表示不缓存.

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.

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内存管理表示

11.2驱动程序还添加了一个新属性来启用隐式语句缓存.

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

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驱动程序隐式缓存功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆