myBatis在Oracle中设置客户端标识符

myBatis在Oracle中设置客户端标识符

本文介绍了如何使用Spring/myBatis在Oracle中设置客户端标识符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何在Oracle中设置CLIENT_IDENTIFIER参数,以便在数据库调用期间使应用程序用户可用.我正在将Spring框架与myIbatis一起使用.

I'd like to know how to set the CLIENT_IDENTIFIER parameter in Oracle in order to have the application user available during invocations to the database. I'm using the Spring framework with myIbatis.

如果您能为我提供准确的操作方法说明,将不胜感激,因为我不是使用这些技术的专家.

I'll be very grateful if you can give me precise instructions on how to do that because I am not an expert using these technologies.

推荐答案

查看Oracle文档中的 setEndToEndMetrics ,了解较旧的版本;对于12c setClientInfo .

Check Oracle documentation for setEndToEndMetrics for older Versions; for 12csetClientInfo.

无论哪种情况,您都需要真实的连接,而不是代理.

In either case you need a real connection, not the proxy.

与调用DBMS_APPLICATION_INFO相比,使用此方法的优点是不需要往返数据库.信息将被传输并在下一个JDBC调用中设置.

The advantage of using this approach compared to a call of DBMS_APPLICATION_INFO is that it needs no roundtrip to the database. The information is transferred and set with the next JDBC call.

更新

以下是iBatis的简单示例.

A simple example for iBatis follows.

1)您必须取消连接获得真正的Oracle连接

1) You must unwind the connection to get the real Oracle connection

 Connection con = unwindConnection(sqlMapClient.getCurrentConnection());

2)定义E2E标识符-正如您在每个操作之前从池或事件请求连接后正确指出的那样

2) define the E2E identifiers - as you correct stated after requesting the connection from pool or event before each action

  String[] metrics = new String[OracleConnection.END_TO_END_STATE_INDEX_MAX];
 metrics[OracleConnection.END_TO_END_ACTION_INDEX] = 'myAction3';
 metrics[OracleConnection.END_TO_END_CLIENTID_INDEX] = 'myClient3';
 metrics[OracleConnection.END_TO_END_MODULE_INDEX] = 'myModule3';

 con.setEndToEndMetrics(metrics, (short) 0);

3)在下一次JDBC到DB的往返之后,设置了标识符

3) after the next JDBC roundtrip to DB the identifier are set

 select    ACTION, CLIENT_IDENTIFIER, MODULE
 from v$session where ....

 myAction3   myClient3   myModule3

这篇关于如何使用Spring/myBatis在Oracle中设置客户端标识符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-22 09:27