Announcement Announcement Module
Collapse
No announcement yet.
How to get handle to the current Connection being used? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to get handle to the current Connection being used?

    Hello All,

    Currently in our project we are using Spring's iBatis Support API for accessing Database tables.

    We have created a class called "DatabaseService" extending
    org.springframework.orm.ibatis.support.SqlMapClien tDaoSupport.

    The configurations to datasource in spring xml files.

    We are using declarative transactions and we use:
    org.springframework.transaction.jta.WebLogicJtaTra nsactionManager
    Transaction Manager class.

    Code Snippet for simple insert statement call looks like:
    Object resultObject = getSqlMapClientTemplate().insert("statement_client _insert", parameterObject);
    where parameterObject contains the client java bean.
    The insertion works fine and is also transaction managed properly.

    Note: We do not have calls to start / commit or rollback the transacations. This is taken care by the declarative transaction. Please find the attached file.

    I have a requirement to get the Connection object that is being used for the Transaction. I used the API call:

    Connection connection = DataSourceUtils.getConnection (dataSource);

    but this returns a different connection object than the one which is being used for Transaction.

    Any help or pointers to API / reference materials would be of great help.

    Thanks and regards,
    Paz

  • #2
    Originally posted by pazhanikanthan View Post
    I have a requirement to get the Connection object that is being used for the Transaction. I used the API call:

    Connection connection = DataSourceUtils.getConnection (dataSource);

    but this returns a different connection object than the one which is being used for Transaction.
    Are you sure it's not only a handle for the physical connection? In JTA environment you hardly get access to the latter, it's often wrapped few times, e.g. to avoid closing of the physical connection instead of its handle. What for exactly do you need it?

    Joerg

    Comment


    • #3
      Originally posted by Jörg Heinicke View Post
      Are you sure it's not only a handle for the physical connection? In JTA environment you hardly get access to the latter, it's often wrapped few times, e.g. to avoid closing of the physical connection instead of its handle. What for exactly do you need it?
      Joerg
      Hello Joerg,

      I have a strange requirement to set the Client Identifier ID tied to the User who is accessing the website.

      For example :
      OracleConnection oracleconnection = (OracleConnection) connection;
      oracleconnection.setClientIdentifier (identifier);

      where OracleConnection is >>> weblogic.jdbc.vendor.oracle.OracleConnection which extends OracleConnection from Oracle JDBC classes.

      Thanks
      Paz

      Comment


      • #4
        Originally posted by pazhanikanthan View Post
        I have a strange requirement to set the Client Identifier ID tied to the User who is accessing the website.
        I understand your requirement, it's not THAT strange The easiest would be if DataSourceUtils.getTargetConnection(Connection) works. Otherwise you might need to provide a wrapper for the Oracle DataSource in which you set the identifier on getConnection().

        Joerg

        Comment


        • #5
          You could also have a look at this.
          http://www.springframework.org/docs/...ataSource.html

          Comment


          • #6
            Hello,

            I would like to know if this thread has beed solved. I'm facing the similar issue, in that I would like to test the OracleConnection.setEndToEndMetrics method. For that, I need to get the connection used in the current transaction.

            Currently, I'm searching information about NativeJdbcExtractor and SimpleNativeJdbcExtractor without knowing if it is a right way. But, I'm learning !

            Thanks for answers,
            Sebastien.

            Comment

            Working...
            X