oracle JBoss 数据库连接池自动提交行为
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3429417/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
JBoss database connection pool auto-commit behavior
提问by Erdem
We are using JBoss 4 and Oracle with a JNDI datasource configured via JBoss datasource XML file.
我们将 JBoss 4 和 Oracle 与通过 JBoss 数据源 XML 文件配置的 JNDI 数据源一起使用。
Recently realized that all connections acquired from the datasource by default has the auto-commit property set to true. However, we rely on Oracle stored procedures and want to control the commits within the stored procedures.
最近意识到默认情况下从数据源获取的所有连接都将自动提交属性设置为 true。但是,我们依赖 Oracle 存储过程并希望控制存储过程中的提交。
We use plain JDBC calls as well as Spring StoredProcedure wrapper to call stored procedures from JBoss. Trying to set the auto-commit from JBoss datasource XML did not really work.
我们使用普通的 JDBC 调用以及 Spring StoredProcedure 包装器从 JBoss 调用存储过程。尝试从 JBoss 数据源 XML 设置自动提交并没有真正起作用。
I can only see that for each connection we get from datasource we can set the auto-commit property to false, but does someone know how we could configure this in one place?
我只能看到对于我们从数据源获得的每个连接,我们可以将自动提交属性设置为 false,但是有人知道我们如何在一个地方配置它吗?
Edit: I am adding the datasource configuration we use:
编辑:我正在添加我们使用的数据源配置:
<local-tx-datasource>
<jndi-name>some name</jndi-name>
<connection-url>jdbc:oracle:thin:@(description=(address_list=(address=(protocol=tcp)(port=1521)(host=xxx))(address=(protocol=tcp)(port=1521)(host=xxx)))(load_balance = yes)(connect_data=(SERVICE_NAME=xxx)(SERVER=DEDICATED)))</connection-url>
<driver-class>oracle.jdbc.driver.OracleDriver</driver-class>
<user-name>xxxr</user-name>
<password>xxx</password>
<!-- Checks the Oracle error codes and messages for fatal errors -->
<exception-sorter-class-name>
org.jboss.resource.adapter.jdbc.vendor.OracleExceptionSorter
</exception-sorter-class-name>
<min-pool-size>5</min-pool-size>
<max-pool-size>25</max-pool-size>
<!-- corresponding type-mapping in the standardjbosscmp-jdbc.xml -->
<metadata>
<type-mapping>Oracle10g</type-mapping>
</metadata>
</local-tx-datasource>
We also used , but no change...
我们也用过,但没有变化...
回答by richj
There are three main types of datasource:
数据源主要有以下三种类型:
- <no-tx-datasource>
- <local-tx-datasource>
- <xa-datasource>
- <无交易数据源>
- <本地交易数据源>
- <xa-数据源>
JBoss Community ConfigDataSources
Your deploy/oracle-ds.xml file should use either <local-tx-datasource> or <xa-datasource> to get connections with auto-commit set to false.
您的 deploy/oracle-ds.xml 文件应使用 <local-tx-datasource> 或 <xa-datasource> 来获取自动提交设置为 false 的连接。
See the reply by Scott Stark in this post: How to Declaratively set autoCommit to falseor J2EETMConnector Architecture Specification Version 1.5section 15.5.3.1 for the original source.
请参阅 Scott Stark 在这篇文章中的回复:How to Declaratively set autoCommit to falseor J2EE TMConnector Architecture Specification Version 1.5section 15.5.3.1 section 15.5.3.1 for the original source。
回答by Romain Hippeau
You could create your own DataSource, which is subclassed from the one you are using. Store that in JNDI. The only method you would need to override is getConnection(), which would do:
您可以创建自己的数据源,它是您正在使用的数据源的子类。将其存储在 JNDI 中。您需要覆盖的唯一方法是 getConnection(),它将执行以下操作:
Connection public getConnection()
{
Connection conn = super.getConnection();
conn.setAutoCommit(true);
return conn;
}
回答by AntuanSoft
In my case I was using Jboss EAP 6 (AS7), and the solution for me was make a wrapper of the class WrapperDataSource and add the instruction:
就我而言,我使用的是 Jboss EAP 6 (AS7),而我的解决方案是制作 WrapperDataSource 类的包装器并添加指令:
wc.setAutoCommit(false);
in the getConnection methods, in order to set the auto-commit connection to false when my application get a connection from de JDBC pool.
在 getConnection 方法中,为了在我的应用程序从 de JDBC 池获取连接时将自动提交连接设置为 false。
This link explain how to do it
这个链接解释了如何做
http://antuansoft.blogspot.com.es/2017/01/jboss-datasources-set-autocommit-example.html
http://antuansoft.blogspot.com.es/2017/01/jboss-datasources-set-autocommit-example.html
Hope help anyone
希望帮助任何人