You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user-java@ibatis.apache.org by Martin Christian <Ma...@ffastfill.com> on 2010/03/03 18:19:23 UTC

Calling stored functions without hash map

Hi,

A similar question has actually already been asked by Sudhakar
Kanagarajan about a year ago. But there was no satisfying answer. Hence,
I'll ask again:

 

I've got a bean that's going to be stored in DB by a stored function:

 

public class Contract implements Serializable {

      private String code;

 

      public String getCode() {

            return code;

      }

 

      public void setCode(String code) {

            this.code = code;

      }

}

 

The stored function returns a result code. So what I do is, I create a
hash map store the whole bean in it and hand it over to iBatis:

 

      public void storeContract( Contract contract ) {

            SqlMapSession session = sessionFactory.openSession();

            Map<String, Object> params = new HashMap<String, Object>();

            params.put( "input", contract );

            try {

                  session.queryForObject( "storeContract", params );

                  Integer result = (Integer)params.get("result");

                  if ( result != 0 ) {

                        // do something

                  }

            } catch (SQLException e) {

                  // do something

            } finally {

                  session.close();

            }

      }

 

The iBatis mapping looks like that:

 

      <parameterMap id="ContractMap" class="java.util.Map">

            <parameter property="result" jdbcType="INTEGER"

                  javaType="java.lang.Integer" mode="OUT"/>

            <parameter property="input.code" jdbcType="VARCHAR"

                  javaType="java.lang.String" mode="IN" />

      </parameterMap>

      <procedure id="storeContract" parameterMap="ContractMap">

            {? = call pkg_some.import_contract( ? )}

      </procedure>

 

While this works, it's not quite beautiful. I'd rather define a
parameterClass=Contract and retrieve the return value of the function in
a separate Integer object. Is this possible? How?

 

A note about the solution above: The real bean has much more attributes
than this example. Hence, it would be a pain to create a prameter map
and add all attributes one by one to the parameter hash map in Java.
Also, having such a nice mechanism of serializing beans into DB, I don't
like the idea of pulling all attributes out of the bean, storing them in
a hash map before storing the object to DB. And the solution above
depends far too much on assumptions on the internal behaviour of
iBats/Spring.

 

Regards,

 

Martin.

 


_____________________________

16/02/2010 - FFastFill adds HSBC as new client for trading platform. For more information please visit www.ffastfill.com
_____________________________

FFastFill plc is a public limited company registered in England and Wales with details as follows; Registered Office: 35 Vine Street London EC3N 2AA; Company Number:3978346

This email and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed. If you have received this email in error please notify the sender immediately (+44 20 3002 1900)

This email has been scanned for viruses by the FFastFill Email Security System.
_____________________________