Support for Oracle "OPAQUE"
---------------------------

                 Key: IBATIS-397
                 URL: https://issues.apache.org/jira/browse/IBATIS-397
             Project: iBatis for Java
          Issue Type: Improvement
          Components: SQL Maps
    Affects Versions: 2.3.0, 2.2.0
            Reporter: Jan Vissers


Based on the custom type handler described in: 
http://opensource.atlassian.com/confluence/oss/display/IBATIS/XMLTypeHandlerCallback.java
 we tried to use this handler not only for "regular select" statements but also 
for "callable statements". As it turns out the current iBatis codebase doesn't 
allow us to use and/or extend the type handler to fully support Oracle's RDBMS 
XMLType datatype.

I've experimented a bit and suggest the following solution:

1) Modify the JdbcTypeRegistry class in order for it to contain the 
ORACLEOPAQUE (much like the ORACLECURSOR already specified)

{code:title=com.ibatis.sqlmap.engine.type.JdbcTypeRegistry}
       setType("ORACLEOPAQUE", 2007);
{code}

2) Modify the CallableStatementResultSet class to have it expose its decorated 
"CallableStatement" instance:

{code:title=com.ibatis.sqlmap.engine.type.CallableStatementResultSet}
       public CallableStatement getCs() {
           return cs;
       }
{code}

With these two modifications we can declare the mapping as follows:

{code:xml}
     <parameter property="doc" jdbcType="ORACLEOPAQUE" mode="OUT"
          typeHandler="XMLTypeHandlerCallback" typeName="SYS.XMLTYPE"/>
{code:xml}

We have to change the XMLTypeHandlerCallback (referenced at the top) in order 
for the getResult() to determine whether to perform work for a 
CallableStatementResultSet or an OracleResultSet, like so:

{code:title=com.yourpackage.XMLTypeHandlerCallback}

    //The handler getResult
    public Object getResult(ResultGetter getter) throws SQLException {
        if (getter.getResultSet() instanceof CallableStatementResultSet) {
            if (((CallableStatementResultSet) getter.getResultSet()).getCs() 
instanceof OracleCallableStatement) {
                OracleCallableStatement ocsmt = (OracleCallableStatement) 
((CallableStatementResultSet) getter.getResultSet()).getCs();
                // go to work
            } else {
                throw new UnsupportedOperationException("XMLType mapping only 
supported for Oracle RDBMS");
            }
        } else if (getter.getResultSet() instanceof OracleResultSet) {
          // go to work 
        } else {
            throw new UnsupportedOperationException("XMLType mapping only 
supported for Oracle RDBMS");
        }
    }

{code}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to