ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Sundar Sankar" <fatboys...@gmail.com>
Subject Re: stored proc call with list items in parameter
Date Tue, 15 Apr 2008 15:30:15 GMT
Use a type handler. Look at the example code below as a start.

public class StringArrayTypeHandler implements TypeHandlerCallback {

    /* (non-Javadoc)
     * @see
com.ibatis.sqlmap.client.extensions.TypeHandlerCallback#getResult(com.ibatis.sqlmap.client.extensions.ResultGetter)
     */
    public Object getResult(ResultGetter arg0) throws SQLException {
        // TODO Auto-generated method stub
        return null;
    }

    public void setParameter(ParameterSetter setter, Object parameter)
            throws SQLException {
        try {
            if (parameter instanceof ArrayList) {
                ArrayList arr = (ArrayList) parameter;
                Statement stmt = setter.getPreparedStatement();
                Connection conn = stmt.getConnection();
                ArrayDescriptor desc =
ArrayDescriptor.createDescriptor("STRARRAY", underLyingConnection); //
STRARRAY is the array in your stored proc
                parameter = new ARRAY(desc, conn, arr.toArray());
            }
            setter.setObject(parameter);
        } catch (Exception e) {
            logger.error(e, e);
            if (e instanceof SQLException)
                throw (SQLException)e;
            else throw new RuntimeException(e);
        }
    }

}

This one converts an arrayList of Strings to Oracle Array of Strings. Use a
similar one to suit your app. Hope this is what you needed.

-Sundar

On Tue, Jan 22, 2008 at 4:38 AM, Darren Davison <darren@davisononline.org>
wrote:

> hi,
>
> is it possible to refer to list items from a parameter class in a call
> to a stored proc?
>
> If I have a class as follows that I use as a paramaterClass:
>
> class Foo {
>  List<Bar> bar;
>  String name;
>
>  // getters/setters omitted
> }
>
> class Bar {
>  String name;
>  //getters/setters omitted
> }
>
>
> .. and a SP mapping as follows:
>
> <procedure id="testSP"
> parameterClass="com.example.Foo">
> { CALL my_pkg.odd_sp_using_foo (
>  #foo.name,mode=IN#,
>  #foo.bar[0].name,mode=IN#)
> }
> </procedure>
>
> obviously the above fails with;
> There is no READABLE property named 'bar[0]' in class
> com.example.Foo
>
> Is there a way to make this work so that I can refer to indexed elements
> in the list of Bar instances?
>
> Cheers,
>
> --
> Darren Davison
> Public Key: 0xE855B3EA
>
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.6 (GNU/Linux)
>
> iD8DBQFHldWdVgOfSOhVs+oRAmxtAKDAmtNWsEhO4m4r9je+ZJgkpJPBtACfWkjs
> YBTZqNX5UCQgqVirfD10N+w=
> =2Hc5
> -----END PGP SIGNATURE-----
>
>

Mime
View raw message