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 novotny <no...@gridsphere.org> on 2008/01/18 20:01:49 UTC

how to create custom TypeHandlerCallback to trim string whitespace

Hi,

 I'm using an informix database and querying for a map containing string
keys and integer values. The keys are stored as type CHAR in the database
and normally when I get them back they contain extar whitespace. I'm trying
to create a custom handler like so:

public class StringTypeHandlerCallback implements TypeHandlerCallback {


    public void setParameter(ParameterSetter parameterSetter, Object o)
throws SQLException {
        parameterSetter.setString(((String)o).trim());
    }

    public Object getResult(ResultGetter resultGetter) throws SQLException {
        return resultGetter.getString().trim();
    }

    public Object valueOf(String s) {
        return s.trim();
    }
}

and I added 

<typeHandler callback="StringTypeHandlerCallback" javaType="string"
jdbcType="CHAR"/>

but it doesn't seem to work-- the strings still have the whitespace.

Here was my query:

Map<String, Integer> m = sqlMapClient.queryForMap(QUERY, qwest, "sm_qwest",
"tm_id");

Any help is greatly appreciated!

Thanks, Jason
-- 
View this message in context: http://www.nabble.com/how-to-create-custom-TypeHandlerCallback-to-trim-string-whitespace-tp14956784p14956784.html
Sent from the iBATIS - User - Java mailing list archive at Nabble.com.


Re: how to create custom TypeHandlerCallback to trim string whitespace

Posted by Stephen Boyd <sw...@gmail.com>.
Can you use a db function to trim the value before it reaches ibatis?  I am
not familiar with informix, but in db2 I use the rtrim() function.  I am
sure there must be something similar.



On Jan 18, 2008 2:01 PM, novotny <no...@gridsphere.org> wrote:

>
> Hi,
>
>  I'm using an informix database and querying for a map containing string
> keys and integer values. The keys are stored as type CHAR in the database
> and normally when I get them back they contain extar whitespace. I'm
> trying
> to create a custom handler like so:
>
> public class StringTypeHandlerCallback implements TypeHandlerCallback {
>
>
>    public void setParameter(ParameterSetter parameterSetter, Object o)
> throws SQLException {
>        parameterSetter.setString(((String)o).trim());
>    }
>
>    public Object getResult(ResultGetter resultGetter) throws SQLException
> {
>        return resultGetter.getString().trim();
>    }
>
>    public Object valueOf(String s) {
>        return s.trim();
>    }
> }
>
> and I added
>
> <typeHandler callback="StringTypeHandlerCallback" javaType="string"
> jdbcType="CHAR"/>
>
> but it doesn't seem to work-- the strings still have the whitespace.
>
> Here was my query:
>
> Map<String, Integer> m = sqlMapClient.queryForMap(QUERY, qwest,
> "sm_qwest",
> "tm_id");
>
> Any help is greatly appreciated!
>
> Thanks, Jason
> --
> View this message in context:
> http://www.nabble.com/how-to-create-custom-TypeHandlerCallback-to-trim-string-whitespace-tp14956784p14956784.html
> Sent from the iBATIS - User - Java mailing list archive at Nabble.com.
>
>

RE: how to create custom TypeHandlerCallback to trim string whitespace

Posted by "Kezerashvili, Denis" <De...@gs.com>.
I take it back, you are defining callback for getting values out of the
db. Sorry for the misleading reply.

-----Original Message-----
From: novotny [mailto:novotny@gridsphere.org] 
Sent: Friday, January 18, 2008 2:02 PM
To: user-java@ibatis.apache.org
Subject: how to create custom TypeHandlerCallback to trim string
whitespace


Hi,

 I'm using an informix database and querying for a map containing string
keys and integer values. The keys are stored as type CHAR in the
database
and normally when I get them back they contain extar whitespace. I'm
trying
to create a custom handler like so:

public class StringTypeHandlerCallback implements TypeHandlerCallback {


    public void setParameter(ParameterSetter parameterSetter, Object o)
throws SQLException {
        parameterSetter.setString(((String)o).trim());
    }

    public Object getResult(ResultGetter resultGetter) throws
SQLException {
        return resultGetter.getString().trim();
    }

    public Object valueOf(String s) {
        return s.trim();
    }
}

and I added 

<typeHandler callback="StringTypeHandlerCallback" javaType="string"
jdbcType="CHAR"/>

but it doesn't seem to work-- the strings still have the whitespace.

Here was my query:

Map<String, Integer> m = sqlMapClient.queryForMap(QUERY, qwest,
"sm_qwest",
"tm_id");

Any help is greatly appreciated!

Thanks, Jason
-- 
View this message in context:
http://www.nabble.com/how-to-create-custom-TypeHandlerCallback-to-trim-s
tring-whitespace-tp14956784p14956784.html
Sent from the iBATIS - User - Java mailing list archive at Nabble.com.

RE: how to create custom TypeHandlerCallback to trim string whitespace

Posted by "Kezerashvili, Denis" <De...@gs.com>.
Have you tried the other thing that I have suggested: having the
callback class specified in the in the result tag in your result-map?

-----Original Message-----
From: novotny [mailto:novotny@gridsphere.org] 
Sent: Friday, January 18, 2008 5:23 PM
To: user-java@ibatis.apache.org
Subject: RE: how to create custom TypeHandlerCallback to trim string
whitespace



Well the database designer chose to use CHAR(6), so I wouldn't have this
problem if it were VARCHAR but since it's CHAR, I believe the informix
driver pads it with extra spacing hence the need for some kind of custom
handler which I can't get to work...

Thanks, Jason



Kezerashvili, Denis wrote:
> 
> I think the problem may be that you are specifying jdbsType="CHAR",
> should not it be jdbsType="VARCHAR". Aren't you dealing with strings
not
> just single characters. The call back is never invoked, since you get
> back a VARCHAR not CHAR.
> 
> Denis
> -----Original Message-----
> From: novotny [mailto:novotny@gridsphere.org] 
> Sent: Friday, January 18, 2008 2:02 PM
> To: user-java@ibatis.apache.org
> Subject: how to create custom TypeHandlerCallback to trim string
> whitespace
> 
> 
> Hi,
> 
>  I'm using an informix database and querying for a map containing
string
> keys and integer values. The keys are stored as type CHAR in the
> database
> and normally when I get them back they contain extar whitespace. I'm
> trying
> to create a custom handler like so:
> 
> public class StringTypeHandlerCallback implements TypeHandlerCallback
{
> 
> 
>     public void setParameter(ParameterSetter parameterSetter, Object
o)
> throws SQLException {
>         parameterSetter.setString(((String)o).trim());
>     }
> 
>     public Object getResult(ResultGetter resultGetter) throws
> SQLException {
>         return resultGetter.getString().trim();
>     }
> 
>     public Object valueOf(String s) {
>         return s.trim();
>     }
> }
> 
> and I added 
> 
> <typeHandler callback="StringTypeHandlerCallback" javaType="string"
> jdbcType="CHAR"/>
> 
> but it doesn't seem to work-- the strings still have the whitespace.
> 
> Here was my query:
> 
> Map<String, Integer> m = sqlMapClient.queryForMap(QUERY, qwest,
> "sm_qwest",
> "tm_id");
> 
> Any help is greatly appreciated!
> 
> Thanks, Jason
> -- 
> View this message in context:
>
http://www.nabble.com/how-to-create-custom-TypeHandlerCallback-to-trim-s
> tring-whitespace-tp14956784p14956784.html
> Sent from the iBATIS - User - Java mailing list archive at Nabble.com.
> 
> 

-- 
View this message in context:
http://www.nabble.com/how-to-create-custom-TypeHandlerCallback-to-trim-s
tring-whitespace-tp14956784p14961326.html
Sent from the iBATIS - User - Java mailing list archive at Nabble.com.

RE: how to create custom TypeHandlerCallback to trim stringwhitespace

Posted by Sundar Sankaranarayanan <Su...@phoenix.edu>.
Hi,
I had posted a way to insert a string array into oracle table. I am not
sure if that is gonna help you, but somehow feel you could use the
approach.

public void setParameter(ParameterSetter setter, Object parameter)
throws SQLException {

if (parameter instanceof ArrayList) {
ArrayList arr = (ArrayList)parameter;
Statement stmt = setter.getPreparedStatement();
Connection conn = stmt.getConnection();
ArrayDescriptor desc = ArrayDescriptor.createDescriptor("STRARRAY",
conn); // The STRARRAY is the name of the oracle type created as the
instance of table.
parameter = new ARRAY(desc, conn,arr.toArray());
}

setter.setObject(parameter);
}

The full class is available in the user list for subject  "Call stored
procedure with reference to a table as the input param.".  I feel that
your current type handler is not able to distinguish between char array
and string and you might wanna use char[](jdbctype=ARRAY) as a type in
your type handler and remove the last char of the array that comes out
as an output in the typehandler code. Not sure if it might work, but
feel that it could be well be tried out.

-S
-----Original Message-----
From: novotny [mailto:novotny@gridsphere.org] 
Sent: Friday, January 18, 2008 3:23 PM
To: user-java@ibatis.apache.org
Subject: RE: how to create custom TypeHandlerCallback to trim
stringwhitespace



Well the database designer chose to use CHAR(6), so I wouldn't have this
problem if it were VARCHAR but since it's CHAR, I believe the informix
driver pads it with extra spacing hence the need for some kind of custom
handler which I can't get to work...

Thanks, Jason



Kezerashvili, Denis wrote:
> 
> I think the problem may be that you are specifying jdbsType="CHAR", 
> should not it be jdbsType="VARCHAR". Aren't you dealing with strings 
> not just single characters. The call back is never invoked, since you 
> get back a VARCHAR not CHAR.
> 
> Denis
> -----Original Message-----
> From: novotny [mailto:novotny@gridsphere.org]
> Sent: Friday, January 18, 2008 2:02 PM
> To: user-java@ibatis.apache.org
> Subject: how to create custom TypeHandlerCallback to trim string 
> whitespace
> 
> 
> Hi,
> 
>  I'm using an informix database and querying for a map containing 
> string keys and integer values. The keys are stored as type CHAR in 
> the database and normally when I get them back they contain extar 
> whitespace. I'm trying to create a custom handler like so:
> 
> public class StringTypeHandlerCallback implements TypeHandlerCallback 
> {
> 
> 
>     public void setParameter(ParameterSetter parameterSetter, Object 
> o) throws SQLException {
>         parameterSetter.setString(((String)o).trim());
>     }
> 
>     public Object getResult(ResultGetter resultGetter) throws 
> SQLException {
>         return resultGetter.getString().trim();
>     }
> 
>     public Object valueOf(String s) {
>         return s.trim();
>     }
> }
> 
> and I added
> 
> <typeHandler callback="StringTypeHandlerCallback" javaType="string"
> jdbcType="CHAR"/>
> 
> but it doesn't seem to work-- the strings still have the whitespace.
> 
> Here was my query:
> 
> Map<String, Integer> m = sqlMapClient.queryForMap(QUERY, qwest, 
> "sm_qwest", "tm_id");
> 
> Any help is greatly appreciated!
> 
> Thanks, Jason
> --
> View this message in context:
> http://www.nabble.com/how-to-create-custom-TypeHandlerCallback-to-trim
> -s tring-whitespace-tp14956784p14956784.html
> Sent from the iBATIS - User - Java mailing list archive at Nabble.com.
> 
> 

--
View this message in context:
http://www.nabble.com/how-to-create-custom-TypeHandlerCallback-to-trim-s
tring-whitespace-tp14956784p14961326.html
Sent from the iBATIS - User - Java mailing list archive at Nabble.com.


RE: how to create custom TypeHandlerCallback to trim string whitespace

Posted by novotny <no...@gridsphere.org>.

Well the database designer chose to use CHAR(6), so I wouldn't have this
problem if it were VARCHAR but since it's CHAR, I believe the informix
driver pads it with extra spacing hence the need for some kind of custom
handler which I can't get to work...

Thanks, Jason



Kezerashvili, Denis wrote:
> 
> I think the problem may be that you are specifying jdbsType="CHAR",
> should not it be jdbsType="VARCHAR". Aren't you dealing with strings not
> just single characters. The call back is never invoked, since you get
> back a VARCHAR not CHAR.
> 
> Denis
> -----Original Message-----
> From: novotny [mailto:novotny@gridsphere.org] 
> Sent: Friday, January 18, 2008 2:02 PM
> To: user-java@ibatis.apache.org
> Subject: how to create custom TypeHandlerCallback to trim string
> whitespace
> 
> 
> Hi,
> 
>  I'm using an informix database and querying for a map containing string
> keys and integer values. The keys are stored as type CHAR in the
> database
> and normally when I get them back they contain extar whitespace. I'm
> trying
> to create a custom handler like so:
> 
> public class StringTypeHandlerCallback implements TypeHandlerCallback {
> 
> 
>     public void setParameter(ParameterSetter parameterSetter, Object o)
> throws SQLException {
>         parameterSetter.setString(((String)o).trim());
>     }
> 
>     public Object getResult(ResultGetter resultGetter) throws
> SQLException {
>         return resultGetter.getString().trim();
>     }
> 
>     public Object valueOf(String s) {
>         return s.trim();
>     }
> }
> 
> and I added 
> 
> <typeHandler callback="StringTypeHandlerCallback" javaType="string"
> jdbcType="CHAR"/>
> 
> but it doesn't seem to work-- the strings still have the whitespace.
> 
> Here was my query:
> 
> Map<String, Integer> m = sqlMapClient.queryForMap(QUERY, qwest,
> "sm_qwest",
> "tm_id");
> 
> Any help is greatly appreciated!
> 
> Thanks, Jason
> -- 
> View this message in context:
> http://www.nabble.com/how-to-create-custom-TypeHandlerCallback-to-trim-s
> tring-whitespace-tp14956784p14956784.html
> Sent from the iBATIS - User - Java mailing list archive at Nabble.com.
> 
> 

-- 
View this message in context: http://www.nabble.com/how-to-create-custom-TypeHandlerCallback-to-trim-string-whitespace-tp14956784p14961326.html
Sent from the iBATIS - User - Java mailing list archive at Nabble.com.


RE: how to create custom TypeHandlerCallback to trim string whitespace

Posted by "Kezerashvili, Denis" <De...@gs.com>.
I think the problem may be that you are specifying jdbsType="CHAR",
should not it be jdbsType="VARCHAR". Aren't you dealing with strings not
just single characters. The call back is never invoked, since you get
back a VARCHAR not CHAR.

Denis
-----Original Message-----
From: novotny [mailto:novotny@gridsphere.org] 
Sent: Friday, January 18, 2008 2:02 PM
To: user-java@ibatis.apache.org
Subject: how to create custom TypeHandlerCallback to trim string
whitespace


Hi,

 I'm using an informix database and querying for a map containing string
keys and integer values. The keys are stored as type CHAR in the
database
and normally when I get them back they contain extar whitespace. I'm
trying
to create a custom handler like so:

public class StringTypeHandlerCallback implements TypeHandlerCallback {


    public void setParameter(ParameterSetter parameterSetter, Object o)
throws SQLException {
        parameterSetter.setString(((String)o).trim());
    }

    public Object getResult(ResultGetter resultGetter) throws
SQLException {
        return resultGetter.getString().trim();
    }

    public Object valueOf(String s) {
        return s.trim();
    }
}

and I added 

<typeHandler callback="StringTypeHandlerCallback" javaType="string"
jdbcType="CHAR"/>

but it doesn't seem to work-- the strings still have the whitespace.

Here was my query:

Map<String, Integer> m = sqlMapClient.queryForMap(QUERY, qwest,
"sm_qwest",
"tm_id");

Any help is greatly appreciated!

Thanks, Jason
-- 
View this message in context:
http://www.nabble.com/how-to-create-custom-TypeHandlerCallback-to-trim-s
tring-whitespace-tp14956784p14956784.html
Sent from the iBATIS - User - Java mailing list archive at Nabble.com.

Re: how to create custom TypeHandlerCallback to trim string whitespace

Posted by Stephen Boyd <sw...@gmail.com>.
Hmm....  Did you try TRIM(trailing ' ' from sm_issue_symbol)?

On Jan 22, 2008 4:59 PM, novotny <no...@gridsphere.org> wrote:

>
>
> Hi,
>
> That's what I wanted to but for whatever reason maybe because it's CHAR or
> maybe because it's informix, but it doesn't trim the string so I still get
> whitespace padding... :-(
>
> Jason
>
>
>
> Stephen Boyd-3 wrote:
> >
> > Why don't you change your select clause to this?
> >
> >    select *trim(sm_issue_symbol) as sm_issue_symbol*,
> >           tm_id
> >    from
> >            sec_master,
> >            category_security,
> >            tier_mast
> >        where sm_secid = cs_secid
> >            and cs_tierid = tm_id
> >            and sm_issue_symbol is not NULL
> >            and sm_issue_symbol != " "
> >        order by 1, 2;
> >
> > On Jan 22, 2008 3:59 PM, novotny <no...@gridsphere.org> wrote:
> >
> >>
> >> Hi,
> >>
> >> I'm not quite sure what you mean-- this is what I have in my
> >> sql-ibatis.xml
> >> file:
> >>
> >> <select id="GetAllSecTiers" resultClass="java.util.HashMap">
> >>        select
> >>            sm_issue_symbol,
> >>            tm_id
> >>        from
> >>            sec_master,
> >>            category_security,
> >>            tier_mast
> >>        where sm_secid = cs_secid
> >>            and cs_tierid = tm_id
> >>            and sm_issue_symbol is not NULL
> >>            and sm_issue_symbol != " "
> >>        order by 1, 2;
> >>    </select>
> >>
> >> So my resultMap is just a generic HashMap where the keys consist of the
> >> sm_issue_symbol that I want trimmed and the values are the integers
> from
> >> the
> >> tm_id column.
> >> What would the property attribute in the result element need to be set
> >> to?
> >>
> >> Thanks, Jason
> >>
> >>
> >>
> >> Kezerashvili, Denis wrote:
> >> >
> >> > One more point, you need the following in your sql mapping xml file,
> in
> >> > you result map, for the column you want to trim:
> >> >
> >> >
> >> > <result property="[propertyToSet]" column="[columnNameToUse]"
> >> > javaType="StringTypeHandlerCallback" jdbcType="VARCHAR"/>
> >> >
> >> > Replace things in [] with correct values for your use.
> >> >
> >> > Make sure the StringTypeHandlerCallback is either fully qualified
> name
> >> > of defined in the typeAlias.
> >> >
> >> > Denis
> >> >
> >> > -----Original Message-----
> >> > From: novotny [mailto:novotny@gridsphere.org]
> >> > Sent: Friday, January 18, 2008 2:02 PM
> >> > To: user-java@ibatis.apache.org
> >> > Subject: how to create custom TypeHandlerCallback to trim string
> >> > whitespace
> >> >
> >> >
> >> > Hi,
> >> >
> >> >  I'm using an informix database and querying for a map containing
> >> string
> >> > keys and integer values. The keys are stored as type CHAR in the
> >> > database
> >> > and normally when I get them back they contain extar whitespace. I'm
> >> > trying
> >> > to create a custom handler like so:
> >> >
> >> > public class StringTypeHandlerCallback implements TypeHandlerCallback
> {
> >> >
> >> >
> >> >     public void setParameter(ParameterSetter parameterSetter, Object
> o)
> >> > throws SQLException {
> >> >         parameterSetter.setString(((String)o).trim());
> >> >     }
> >> >
> >> >     public Object getResult(ResultGetter resultGetter) throws
> >> > SQLException {
> >> >         return resultGetter.getString().trim();
> >> >     }
> >> >
> >> >     public Object valueOf(String s) {
> >> >         return s.trim();
> >> >     }
> >> > }
> >> >
> >> > and I added
> >> >
> >> > <typeHandler callback="StringTypeHandlerCallback" javaType="string"
> >> > jdbcType="CHAR"/>
> >> >
> >> > but it doesn't seem to work-- the strings still have the whitespace.
> >> >
> >> > Here was my query:
> >> >
> >> > Map<String, Integer> m = sqlMapClient.queryForMap(QUERY, qwest,
> >> > "sm_qwest",
> >> > "tm_id");
> >> >
> >> > Any help is greatly appreciated!
> >> >
> >> > Thanks, Jason
> >> > --
> >> > View this message in context:
> >> >
> >>
> http://www.nabble.com/how-to-create-custom-TypeHandlerCallback-to-trim-s
> >> > tring-whitespace-tp14956784p14956784.html
> >> > Sent from the iBATIS - User - Java mailing list archive at Nabble.com
> .
> >> >
> >> >
> >>
> >> --
> >> View this message in context:
> >>
> http://www.nabble.com/how-to-create-custom-TypeHandlerCallback-to-trim-string-whitespace-tp14956784p15028271.html
> >> Sent from the iBATIS - User - Java mailing list archive at Nabble.com.
> >>
> >>
> >
> >
>
> --
> View this message in context:
> http://www.nabble.com/how-to-create-custom-TypeHandlerCallback-to-trim-string-whitespace-tp14956784p15029467.html
> Sent from the iBATIS - User - Java mailing list archive at Nabble.com.
>
>

Re: how to create custom TypeHandlerCallback to trim string whitespace

Posted by novotny <no...@gridsphere.org>.

Hi,

That's what I wanted to but for whatever reason maybe because it's CHAR or
maybe because it's informix, but it doesn't trim the string so I still get
whitespace padding... :-(

Jason



Stephen Boyd-3 wrote:
> 
> Why don't you change your select clause to this?
> 
>    select *trim(sm_issue_symbol) as sm_issue_symbol*,
>           tm_id
>    from
>            sec_master,
>            category_security,
>            tier_mast
>        where sm_secid = cs_secid
>            and cs_tierid = tm_id
>            and sm_issue_symbol is not NULL
>            and sm_issue_symbol != " "
>        order by 1, 2;
> 
> On Jan 22, 2008 3:59 PM, novotny <no...@gridsphere.org> wrote:
> 
>>
>> Hi,
>>
>> I'm not quite sure what you mean-- this is what I have in my
>> sql-ibatis.xml
>> file:
>>
>> <select id="GetAllSecTiers" resultClass="java.util.HashMap">
>>        select
>>            sm_issue_symbol,
>>            tm_id
>>        from
>>            sec_master,
>>            category_security,
>>            tier_mast
>>        where sm_secid = cs_secid
>>            and cs_tierid = tm_id
>>            and sm_issue_symbol is not NULL
>>            and sm_issue_symbol != " "
>>        order by 1, 2;
>>    </select>
>>
>> So my resultMap is just a generic HashMap where the keys consist of the
>> sm_issue_symbol that I want trimmed and the values are the integers from
>> the
>> tm_id column.
>> What would the property attribute in the result element need to be set
>> to?
>>
>> Thanks, Jason
>>
>>
>>
>> Kezerashvili, Denis wrote:
>> >
>> > One more point, you need the following in your sql mapping xml file, in
>> > you result map, for the column you want to trim:
>> >
>> >
>> > <result property="[propertyToSet]" column="[columnNameToUse]"
>> > javaType="StringTypeHandlerCallback" jdbcType="VARCHAR"/>
>> >
>> > Replace things in [] with correct values for your use.
>> >
>> > Make sure the StringTypeHandlerCallback is either fully qualified name
>> > of defined in the typeAlias.
>> >
>> > Denis
>> >
>> > -----Original Message-----
>> > From: novotny [mailto:novotny@gridsphere.org]
>> > Sent: Friday, January 18, 2008 2:02 PM
>> > To: user-java@ibatis.apache.org
>> > Subject: how to create custom TypeHandlerCallback to trim string
>> > whitespace
>> >
>> >
>> > Hi,
>> >
>> >  I'm using an informix database and querying for a map containing
>> string
>> > keys and integer values. The keys are stored as type CHAR in the
>> > database
>> > and normally when I get them back they contain extar whitespace. I'm
>> > trying
>> > to create a custom handler like so:
>> >
>> > public class StringTypeHandlerCallback implements TypeHandlerCallback {
>> >
>> >
>> >     public void setParameter(ParameterSetter parameterSetter, Object o)
>> > throws SQLException {
>> >         parameterSetter.setString(((String)o).trim());
>> >     }
>> >
>> >     public Object getResult(ResultGetter resultGetter) throws
>> > SQLException {
>> >         return resultGetter.getString().trim();
>> >     }
>> >
>> >     public Object valueOf(String s) {
>> >         return s.trim();
>> >     }
>> > }
>> >
>> > and I added
>> >
>> > <typeHandler callback="StringTypeHandlerCallback" javaType="string"
>> > jdbcType="CHAR"/>
>> >
>> > but it doesn't seem to work-- the strings still have the whitespace.
>> >
>> > Here was my query:
>> >
>> > Map<String, Integer> m = sqlMapClient.queryForMap(QUERY, qwest,
>> > "sm_qwest",
>> > "tm_id");
>> >
>> > Any help is greatly appreciated!
>> >
>> > Thanks, Jason
>> > --
>> > View this message in context:
>> >
>> http://www.nabble.com/how-to-create-custom-TypeHandlerCallback-to-trim-s
>> > tring-whitespace-tp14956784p14956784.html
>> > Sent from the iBATIS - User - Java mailing list archive at Nabble.com.
>> >
>> >
>>
>> --
>> View this message in context:
>> http://www.nabble.com/how-to-create-custom-TypeHandlerCallback-to-trim-string-whitespace-tp14956784p15028271.html
>> Sent from the iBATIS - User - Java mailing list archive at Nabble.com.
>>
>>
> 
> 

-- 
View this message in context: http://www.nabble.com/how-to-create-custom-TypeHandlerCallback-to-trim-string-whitespace-tp14956784p15029467.html
Sent from the iBATIS - User - Java mailing list archive at Nabble.com.


Re: how to create custom TypeHandlerCallback to trim string whitespace

Posted by Stephen Boyd <sw...@gmail.com>.
Why don't you change your select clause to this?

   select *trim(sm_issue_symbol) as sm_issue_symbol*,
          tm_id
   from
           sec_master,
           category_security,
           tier_mast
       where sm_secid = cs_secid
           and cs_tierid = tm_id
           and sm_issue_symbol is not NULL
           and sm_issue_symbol != " "
       order by 1, 2;

On Jan 22, 2008 3:59 PM, novotny <no...@gridsphere.org> wrote:

>
> Hi,
>
> I'm not quite sure what you mean-- this is what I have in my
> sql-ibatis.xml
> file:
>
> <select id="GetAllSecTiers" resultClass="java.util.HashMap">
>        select
>            sm_issue_symbol,
>            tm_id
>        from
>            sec_master,
>            category_security,
>            tier_mast
>        where sm_secid = cs_secid
>            and cs_tierid = tm_id
>            and sm_issue_symbol is not NULL
>            and sm_issue_symbol != " "
>        order by 1, 2;
>    </select>
>
> So my resultMap is just a generic HashMap where the keys consist of the
> sm_issue_symbol that I want trimmed and the values are the integers from
> the
> tm_id column.
> What would the property attribute in the result element need to be set to?
>
> Thanks, Jason
>
>
>
> Kezerashvili, Denis wrote:
> >
> > One more point, you need the following in your sql mapping xml file, in
> > you result map, for the column you want to trim:
> >
> >
> > <result property="[propertyToSet]" column="[columnNameToUse]"
> > javaType="StringTypeHandlerCallback" jdbcType="VARCHAR"/>
> >
> > Replace things in [] with correct values for your use.
> >
> > Make sure the StringTypeHandlerCallback is either fully qualified name
> > of defined in the typeAlias.
> >
> > Denis
> >
> > -----Original Message-----
> > From: novotny [mailto:novotny@gridsphere.org]
> > Sent: Friday, January 18, 2008 2:02 PM
> > To: user-java@ibatis.apache.org
> > Subject: how to create custom TypeHandlerCallback to trim string
> > whitespace
> >
> >
> > Hi,
> >
> >  I'm using an informix database and querying for a map containing string
> > keys and integer values. The keys are stored as type CHAR in the
> > database
> > and normally when I get them back they contain extar whitespace. I'm
> > trying
> > to create a custom handler like so:
> >
> > public class StringTypeHandlerCallback implements TypeHandlerCallback {
> >
> >
> >     public void setParameter(ParameterSetter parameterSetter, Object o)
> > throws SQLException {
> >         parameterSetter.setString(((String)o).trim());
> >     }
> >
> >     public Object getResult(ResultGetter resultGetter) throws
> > SQLException {
> >         return resultGetter.getString().trim();
> >     }
> >
> >     public Object valueOf(String s) {
> >         return s.trim();
> >     }
> > }
> >
> > and I added
> >
> > <typeHandler callback="StringTypeHandlerCallback" javaType="string"
> > jdbcType="CHAR"/>
> >
> > but it doesn't seem to work-- the strings still have the whitespace.
> >
> > Here was my query:
> >
> > Map<String, Integer> m = sqlMapClient.queryForMap(QUERY, qwest,
> > "sm_qwest",
> > "tm_id");
> >
> > Any help is greatly appreciated!
> >
> > Thanks, Jason
> > --
> > View this message in context:
> > http://www.nabble.com/how-to-create-custom-TypeHandlerCallback-to-trim-s
> > tring-whitespace-tp14956784p14956784.html
> > Sent from the iBATIS - User - Java mailing list archive at Nabble.com.
> >
> >
>
> --
> View this message in context:
> http://www.nabble.com/how-to-create-custom-TypeHandlerCallback-to-trim-string-whitespace-tp14956784p15028271.html
> Sent from the iBATIS - User - Java mailing list archive at Nabble.com.
>
>

RE: how to create custom TypeHandlerCallback to trim string whitespace

Posted by novotny <no...@gridsphere.org>.
Hi,

I'm not quite sure what you mean-- this is what I have in my sql-ibatis.xml
file:

<select id="GetAllSecTiers" resultClass="java.util.HashMap">
        select
            sm_issue_symbol,
            tm_id
        from
            sec_master,
            category_security,
            tier_mast
        where sm_secid = cs_secid
            and cs_tierid = tm_id
            and sm_issue_symbol is not NULL
            and sm_issue_symbol != " "
        order by 1, 2;
    </select>

So my resultMap is just a generic HashMap where the keys consist of the
sm_issue_symbol that I want trimmed and the values are the integers from the
tm_id column.
What would the property attribute in the result element need to be set to?

Thanks, Jason



Kezerashvili, Denis wrote:
> 
> One more point, you need the following in your sql mapping xml file, in
> you result map, for the column you want to trim:
>  
> 
> <result property="[propertyToSet]" column="[columnNameToUse]"
> javaType="StringTypeHandlerCallback" jdbcType="VARCHAR"/>
> 
> Replace things in [] with correct values for your use.
> 
> Make sure the StringTypeHandlerCallback is either fully qualified name
> of defined in the typeAlias.
> 
> Denis
> 
> -----Original Message-----
> From: novotny [mailto:novotny@gridsphere.org] 
> Sent: Friday, January 18, 2008 2:02 PM
> To: user-java@ibatis.apache.org
> Subject: how to create custom TypeHandlerCallback to trim string
> whitespace
> 
> 
> Hi,
> 
>  I'm using an informix database and querying for a map containing string
> keys and integer values. The keys are stored as type CHAR in the
> database
> and normally when I get them back they contain extar whitespace. I'm
> trying
> to create a custom handler like so:
> 
> public class StringTypeHandlerCallback implements TypeHandlerCallback {
> 
> 
>     public void setParameter(ParameterSetter parameterSetter, Object o)
> throws SQLException {
>         parameterSetter.setString(((String)o).trim());
>     }
> 
>     public Object getResult(ResultGetter resultGetter) throws
> SQLException {
>         return resultGetter.getString().trim();
>     }
> 
>     public Object valueOf(String s) {
>         return s.trim();
>     }
> }
> 
> and I added 
> 
> <typeHandler callback="StringTypeHandlerCallback" javaType="string"
> jdbcType="CHAR"/>
> 
> but it doesn't seem to work-- the strings still have the whitespace.
> 
> Here was my query:
> 
> Map<String, Integer> m = sqlMapClient.queryForMap(QUERY, qwest,
> "sm_qwest",
> "tm_id");
> 
> Any help is greatly appreciated!
> 
> Thanks, Jason
> -- 
> View this message in context:
> http://www.nabble.com/how-to-create-custom-TypeHandlerCallback-to-trim-s
> tring-whitespace-tp14956784p14956784.html
> Sent from the iBATIS - User - Java mailing list archive at Nabble.com.
> 
> 

-- 
View this message in context: http://www.nabble.com/how-to-create-custom-TypeHandlerCallback-to-trim-string-whitespace-tp14956784p15028271.html
Sent from the iBATIS - User - Java mailing list archive at Nabble.com.


RE: how to create custom TypeHandlerCallback to trim string whitespace

Posted by "Kezerashvili, Denis" <De...@gs.com>.
One more point, you need the following in your sql mapping xml file, in
you result map, for the column you want to trim:
 

<result property="[propertyToSet]" column="[columnNameToUse]"
javaType="StringTypeHandlerCallback" jdbcType="VARCHAR"/>

Replace things in [] with correct values for your use.

Make sure the StringTypeHandlerCallback is either fully qualified name
of defined in the typeAlias.

Denis

-----Original Message-----
From: novotny [mailto:novotny@gridsphere.org] 
Sent: Friday, January 18, 2008 2:02 PM
To: user-java@ibatis.apache.org
Subject: how to create custom TypeHandlerCallback to trim string
whitespace


Hi,

 I'm using an informix database and querying for a map containing string
keys and integer values. The keys are stored as type CHAR in the
database
and normally when I get them back they contain extar whitespace. I'm
trying
to create a custom handler like so:

public class StringTypeHandlerCallback implements TypeHandlerCallback {


    public void setParameter(ParameterSetter parameterSetter, Object o)
throws SQLException {
        parameterSetter.setString(((String)o).trim());
    }

    public Object getResult(ResultGetter resultGetter) throws
SQLException {
        return resultGetter.getString().trim();
    }

    public Object valueOf(String s) {
        return s.trim();
    }
}

and I added 

<typeHandler callback="StringTypeHandlerCallback" javaType="string"
jdbcType="CHAR"/>

but it doesn't seem to work-- the strings still have the whitespace.

Here was my query:

Map<String, Integer> m = sqlMapClient.queryForMap(QUERY, qwest,
"sm_qwest",
"tm_id");

Any help is greatly appreciated!

Thanks, Jason
-- 
View this message in context:
http://www.nabble.com/how-to-create-custom-TypeHandlerCallback-to-trim-s
tring-whitespace-tp14956784p14956784.html
Sent from the iBATIS - User - Java mailing list archive at Nabble.com.

RE: how to create custom TypeHandlerCallback to trim string whitespace

Posted by "Kezerashvili, Denis" <De...@gs.com>.
You have only defined it for storing to the db. You need to include the
following in your sql mapping file 
#columnToTrim,handler=StringTypeHandlerCallback#

Denis

-----Original Message-----
From: novotny [mailto:novotny@gridsphere.org] 
Sent: Friday, January 18, 2008 2:02 PM
To: user-java@ibatis.apache.org
Subject: how to create custom TypeHandlerCallback to trim string
whitespace


Hi,

 I'm using an informix database and querying for a map containing string
keys and integer values. The keys are stored as type CHAR in the
database
and normally when I get them back they contain extar whitespace. I'm
trying
to create a custom handler like so:

public class StringTypeHandlerCallback implements TypeHandlerCallback {


    public void setParameter(ParameterSetter parameterSetter, Object o)
throws SQLException {
        parameterSetter.setString(((String)o).trim());
    }

    public Object getResult(ResultGetter resultGetter) throws
SQLException {
        return resultGetter.getString().trim();
    }

    public Object valueOf(String s) {
        return s.trim();
    }
}

and I added 

<typeHandler callback="StringTypeHandlerCallback" javaType="string"
jdbcType="CHAR"/>

but it doesn't seem to work-- the strings still have the whitespace.

Here was my query:

Map<String, Integer> m = sqlMapClient.queryForMap(QUERY, qwest,
"sm_qwest",
"tm_id");

Any help is greatly appreciated!

Thanks, Jason
-- 
View this message in context:
http://www.nabble.com/how-to-create-custom-TypeHandlerCallback-to-trim-s
tring-whitespace-tp14956784p14956784.html
Sent from the iBATIS - User - Java mailing list archive at Nabble.com.