Announcement Announcement Module
Collapse
No announcement yet.
regarding webspherenativedataextractor Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • regarding webspherenativedataextractor

    Hi All,
    We want to use native connections using spring nativeconnectionextractor class. We are using websphere and to get native connection we have to use WebSphereNativeJdbcExtractor class but it is not recommended to use as it internally uses WSJdbcConnection.The connections obtained from this interface are not managed by WAS.
    So what I am planning to do is to create a customNativeJdbcExtractor class and in the getNativeconnection method I am planning to write the following code

    (OracleConnection)WSCallHelper.jdbcCall(OracleConn ectionWrapper.class,conn,"unwrap",null,null );

    Only thing I want to know is how spring handles native connections.. will it close it?
    As per my understanding native connections should not be closed. do I need to do anything in my code.

    In this class do I need to set true for all other methods like
    isNativeConnectionNecessaryForNativeStatements() {
    isNativeConnectionNecessaryForNativePreparedStatem ents
    isNativeConnectionNecessaryForNativeCallableStatem ents

    Can anyone please share their viewpoints here.

  • #2
    Consider trying SimpleNativeJdbcExtractor instead of implementing your custom NativeJdbcExtractor class.

    Spring implementation for OracleLOBHandler considers SimpleNativeJdbcExtractor as a choice for native connection unwrapping, a similar approach might help.

    http://static.springsource.org/sprin...JdbcExtractor)

    Comment


    • #3
      This is specific to websphere doesn't expose wrapped connections..and the recommended approach from IBM is to use WSCallHelper.
      I have created my own custom class like this

      private static final String WAS_NATIVE_CONNECTION_NAME = "com.ibm.websphere.rsadapter.WSCallHelper";
      private static final String JDBC_ADAPTER_EXTRACT_METHOD = "jdbcCall";

      @SuppressWarnings("rawtypes")
      private Class wrappedConnectionClass ;




      /**
      * This constructor retrieves WebSphere JDBC adapter classes,
      * so we can get the underlying vendor connection using reflection.
      */
      public WebSphereNativeJdbcExtractor() {
      try {
      this.wrappedConnectionClass = getClass().getClassLoader().loadClass(WAS_NATIVE_C ONNECTION_NAME);
      }
      catch (Exception ex) {
      throw new IllegalStateException(
      "Could not initialize WebSphereCustomNativeJdbcExtractor because WebSphere API classes are not available: " + ex);
      }
      }
      */
      protected Connection doGetNativeConnection(Connection con) throws SQLException {
      if (this.wrappedConnectionClass.isAssignableFrom(con. getClass())) {
      final java.lang.reflect.Method methodToInvoke = this.wrappedConnectionClass.getMethod(JDBC_ADAPTER _EXTRACT_METHOD, (Class[]) null);


      return (Connection) ReflectionUtils.invokeJdbcMethod(
      methodToInvoke, null, new Object[] {OracleConnectionWrapper.class,con,"unwrap",null,n ull});
      }
      return con;
      }

      Can anyone let me know if this is the correct way of doing it.

      One more doubt I am having.. if we inject this class into jdbctemplate for nativedataextractor then for all JDBC operations will native
      connections be used? I want to call native connections only when I am dealing with ARRAY or STRUCT constructs.

      Comment

      Working...
      X