Type Handler for Single Primitive Result Type

classic Classic list List threaded Threaded
15 messages Options
Reply | Threaded
Open this post in threaded view
|

Type Handler for Single Primitive Result Type

Truth
We're trying to specify a Type Handler for a single primitive result,
without overriding the default type handler for all primitives of that
type.

For example, for the following style select statement, we want to
specify the type handler to be used:
<select resultType="boolean">

Our current work around is to wrap it in a simple class, and use a
result map - but this breaks our API.

Can someone point out how this is done?
Reply | Threaded
Open this post in threaded view
|

RE: Type Handler for Single Primitive Result Type

Poitras Christian
Try to use a resultMap.

<resultMap id="special_boolean" type="boolean">
  <constructor>
    <arg column="your_column" typeHandler="YourTypeHandler"/>
  </constructor>
</resultMap>

Christian

-----Message d'origine-----
De : [hidden email] [mailto:[hidden email]] De la part de Truth
Envoyé : February-21-11 5:22 PM
À : mybatis-user
Objet : Type Handler for Single Primitive Result Type

We're trying to specify a Type Handler for a single primitive result,
without overriding the default type handler for all primitives of that
type.

For example, for the following style select statement, we want to
specify the type handler to be used:
<select resultType="boolean">

Our current work around is to wrap it in a simple class, and use a
result map - but this breaks our API.

Can someone point out how this is done?

Reply | Threaded
Open this post in threaded view
|

Re: Type Handler for Single Primitive Result Type

Truth
Sorry it's taken us so long on this - things with workarounds tend to
get put lower priority.

The suggested solution didn't work for us, we always got a false
response regardless of input.
Throwing some debug tracing on, it seems with the resultMap type of
Boolean the typehandler we specify never gets called.

        <resultMap id="special_boolean" type="Boolean">
                <constructor>
                        <arg column="our_column" javaType="_boolean" typeHandler="OurTypeHandler"/>
                </constructor>
        </resultMap>

However on our own customer class, the typehandler still gets called:

        <resultMap id="special_boolean" type="BooleanContainer">
                <constructor>
                        <arg column="our_column" javaType="_boolean" typeHandler="OurTypeHandler"/>
                </constructor>
        </resultMap>

Is there some sort for automatic handler for a resultMap type of
Boolean that we cannot override?

--
Truth.

On 23 February 2011 02:39, Poitras Christian
<[hidden email]> wrote:

> Try to use a resultMap.
>
> <resultMap id="special_boolean" type="boolean">
>  <constructor>
>    <arg column="your_column" typeHandler="YourTypeHandler"/>
>  </constructor>
> </resultMap>
>
> Christian
>
> -----Message d'origine-----
> De : [hidden email] [mailto:[hidden email]] De la part de Truth
> Envoyé : February-21-11 5:22 PM
> À : mybatis-user
> Objet : Type Handler for Single Primitive Result Type
>
> We're trying to specify a Type Handler for a single primitive result,
> without overriding the default type handler for all primitives of that
> type.
>
> For example, for the following style select statement, we want to
> specify the type handler to be used:
> <select resultType="boolean">
>
> Our current work around is to wrap it in a simple class, and use a
> result map - but this breaks our API.
>
> Can someone point out how this is done?
Reply | Threaded
Open this post in threaded view
|

RE: Type Handler for Single Primitive Result Type

Poitras Christian
It's possible.

You can try either
SqlSessionFactory.getConfiguration().getTypeHandlerRegistry().register(Boolean.TYPE, YourTypeHandler);
Or register a JdbcType that match your data like
sqlSessionFactory.getConfiguration().getTypeHandlerRegistry().register(JdbcType.BIT, YourTypeHandler);
I haven't tried that for boolean.

You may also prefer to have a private special getter/setter/constructor that doesn't use boolean but another type that is easier to deal with.

Christian

-----Message d'origine-----
De : [hidden email] [mailto:[hidden email]] De la part de Truth
Envoyé : March-27-11 7:05 PM
À : [hidden email]
Objet : Re: Type Handler for Single Primitive Result Type

Sorry it's taken us so long on this - things with workarounds tend to
get put lower priority.

The suggested solution didn't work for us, we always got a false
response regardless of input.
Throwing some debug tracing on, it seems with the resultMap type of
Boolean the typehandler we specify never gets called.

        <resultMap id="special_boolean" type="Boolean">
                <constructor>
                        <arg column="our_column" javaType="_boolean" typeHandler="OurTypeHandler"/>
                </constructor>
        </resultMap>

However on our own customer class, the typehandler still gets called:

        <resultMap id="special_boolean" type="BooleanContainer">
                <constructor>
                        <arg column="our_column" javaType="_boolean" typeHandler="OurTypeHandler"/>
                </constructor>
        </resultMap>

Is there some sort for automatic handler for a resultMap type of
Boolean that we cannot override?

--
Truth.

On 23 February 2011 02:39, Poitras Christian
<[hidden email]> wrote:

> Try to use a resultMap.
>
> <resultMap id="special_boolean" type="boolean">
>  <constructor>
>    <arg column="your_column" typeHandler="YourTypeHandler"/>
>  </constructor>
> </resultMap>
>
> Christian
>
> -----Message d'origine-----
> De : [hidden email] [mailto:[hidden email]] De la part de Truth
> Envoyé : February-21-11 5:22 PM
> À : mybatis-user
> Objet : Type Handler for Single Primitive Result Type
>
> We're trying to specify a Type Handler for a single primitive result,
> without overriding the default type handler for all primitives of that
> type.
>
> For example, for the following style select statement, we want to
> specify the type handler to be used:
> <select resultType="boolean">
>
> Our current work around is to wrap it in a simple class, and use a
> result map - but this breaks our API.
>
> Can someone point out how this is done?
Reply | Threaded
Open this post in threaded view
|

Re: Type Handler for Single Primitive Result Type

Truth
Yes, but as in the OP, we don't want to change it for any other
Boolean's we're fetching - just this one.

Theoretically your previous suggestion should work, however when
MyBatis sees the resultMap type of Boolean, it doesn't process the
rest of the resultMap. It would appear the default handler for Boolean
overrides any custom resultMap specified for it.

The alternative I would have hoped for was the ability to set a
typeHandler for the result of a select where a resultType has been
specified.

At the moment for a work around, we've created our own
BooleanContainer custom type which we handling as per a normal
JavaBean - and inserting a dummy DAO layer between the actual DAO and
the Service call - that unwraps this BooleanContainer and returns a
boolean to match the API spec. However it seems a hack to hack to do
so, and the additional (minimal) overhead of another Bean being
managed.


Unless I've missed something it seems the default overriding the
resultMap for Boolean is a bug. And the lack of ability to specify a
typeHandler for a single result from a select statement a missing gap
in our functionality.

--
Truth.

On 29 March 2011 01:35, Poitras Christian <[hidden email]> wrote:

> It's possible.
>
> You can try either
> SqlSessionFactory.getConfiguration().getTypeHandlerRegistry().register(Boolean.TYPE, YourTypeHandler);
> Or register a JdbcType that match your data like
> sqlSessionFactory.getConfiguration().getTypeHandlerRegistry().register(JdbcType.BIT, YourTypeHandler);
> I haven't tried that for boolean.
>
> You may also prefer to have a private special getter/setter/constructor that doesn't use boolean but another type that is easier to deal with.
>
> Christian
>
> -----Message d'origine-----
> De : [hidden email] [mailto:[hidden email]] De la part de Truth
> Envoyé : March-27-11 7:05 PM
> À : [hidden email]
> Objet : Re: Type Handler for Single Primitive Result Type
>
> Sorry it's taken us so long on this - things with workarounds tend to
> get put lower priority.
>
> The suggested solution didn't work for us, we always got a false
> response regardless of input.
> Throwing some debug tracing on, it seems with the resultMap type of
> Boolean the typehandler we specify never gets called.
>
>        <resultMap id="special_boolean" type="Boolean">
>                <constructor>
>                        <arg column="our_column" javaType="_boolean" typeHandler="OurTypeHandler"/>
>                </constructor>
>        </resultMap>
>
> However on our own customer class, the typehandler still gets called:
>
>        <resultMap id="special_boolean" type="BooleanContainer">
>                <constructor>
>                        <arg column="our_column" javaType="_boolean" typeHandler="OurTypeHandler"/>
>                </constructor>
>        </resultMap>
>
> Is there some sort for automatic handler for a resultMap type of
> Boolean that we cannot override?
>
> --
> Truth.
>
> On 23 February 2011 02:39, Poitras Christian
> <[hidden email]> wrote:
>> Try to use a resultMap.
>>
>> <resultMap id="special_boolean" type="boolean">
>>  <constructor>
>>    <arg column="your_column" typeHandler="YourTypeHandler"/>
>>  </constructor>
>> </resultMap>
>>
>> Christian
>>
>> -----Message d'origine-----
>> De : [hidden email] [mailto:[hidden email]] De la part de Truth
>> Envoyé : February-21-11 5:22 PM
>> À : mybatis-user
>> Objet : Type Handler for Single Primitive Result Type
>>
>> We're trying to specify a Type Handler for a single primitive result,
>> without overriding the default type handler for all primitives of that
>> type.
>>
>> For example, for the following style select statement, we want to
>> specify the type handler to be used:
>> <select resultType="boolean">
>>
>> Our current work around is to wrap it in a simple class, and use a
>> result map - but this breaks our API.
>>
>> Can someone point out how this is done?
Reply | Threaded
Open this post in threaded view
|

Re: Type Handler for Single Primitive Result Type

Jackie Li
In reply to this post by Poitras Christian
Hi,

Just out of curiosity, what do you need a typehandler for a boolean type?

Cheers,
Jackie


On Tue, Feb 22, 2011 at 21:39, Poitras Christian <[hidden email]> wrote:
Try to use a resultMap.

<resultMap id="special_boolean" type="boolean">
 <constructor>
   <arg column="your_column" typeHandler="YourTypeHandler"/>
 </constructor>
</resultMap>

Christian

-----Message d'origine-----
De : [hidden email] [mailto:[hidden email]] De la part de Truth
Envoyé : February-21-11 5:22 PM
À : mybatis-user
Objet : Type Handler for Single Primitive Result Type

We're trying to specify a Type Handler for a single primitive result,
without overriding the default type handler for all primitives of that
type.

For example, for the following style select statement, we want to
specify the type handler to be used:
<select resultType="boolean">

Our current work around is to wrap it in a simple class, and use a
result map - but this breaks our API.

Can someone point out how this is done?


Reply | Threaded
Open this post in threaded view
|

Re: Type Handler for Single Primitive Result Type

Truth
Because in this case the values being stored are 'N' and 'Y'.
Existing database, and attached applications - so we can't change the
existing data.

It's somewhat annoying, but I was expecting that MyBatis would have a
simple solution. Or at least simpler than our current work-around.

--
Truth.

On 29 March 2011 15:46, lwpro <[hidden email]> wrote:

> Hi,
>
> Just out of curiosity, what do you need a typehandler for a boolean type?
>
> Cheers,
> Jackie
>
>
> On Tue, Feb 22, 2011 at 21:39, Poitras Christian
> <[hidden email]> wrote:
>>
>> Try to use a resultMap.
>>
>> <resultMap id="special_boolean" type="boolean">
>>  <constructor>
>>    <arg column="your_column" typeHandler="YourTypeHandler"/>
>>  </constructor>
>> </resultMap>
>>
>> Christian
>>
>> -----Message d'origine-----
>> De : [hidden email] [mailto:[hidden email]]
>> De la part de Truth
>> Envoyé : February-21-11 5:22 PM
>> À : mybatis-user
>> Objet : Type Handler for Single Primitive Result Type
>>
>> We're trying to specify a Type Handler for a single primitive result,
>> without overriding the default type handler for all primitives of that
>> type.
>>
>> For example, for the following style select statement, we want to
>> specify the type handler to be used:
>> <select resultType="boolean">
>>
>> Our current work around is to wrap it in a simple class, and use a
>> result map - but this breaks our API.
>>
>> Can someone point out how this is done?
Reply | Threaded
Open this post in threaded view
|

Re: Type Handler for Single Primitive Result Type

Jackie Li
if that's the case, you can achieve it by modifying your query.

select (flag = false) newFlag from myTable;

Cheers,
Jackie


On Tue, Mar 29, 2011 at 10:57, Truth <[hidden email]> wrote:
Because in this case the values being stored are 'N' and 'Y'.
Existing database, and attached applications - so we can't change the
existing data.

It's somewhat annoying, but I was expecting that MyBatis would have a
simple solution. Or at least simpler than our current work-around.

--
Truth.

On 29 March 2011 15:46, lwpro <[hidden email]> wrote:
> Hi,
>
> Just out of curiosity, what do you need a typehandler for a boolean type?
>
> Cheers,
> Jackie
>
>
> On Tue, Feb 22, 2011 at 21:39, Poitras Christian
> <[hidden email]> wrote:
>>
>> Try to use a resultMap.
>>
>> <resultMap id="special_boolean" type="boolean">
>>  <constructor>
>>    <arg column="your_column" typeHandler="YourTypeHandler"/>
>>  </constructor>
>> </resultMap>
>>
>> Christian
>>
>> -----Message d'origine-----
>> De : [hidden email] [mailto:[hidden email]]
>> De la part de Truth
>> Envoyé : February-21-11 5:22 PM
>> À : mybatis-user
>> Objet : Type Handler for Single Primitive Result Type
>>
>> We're trying to specify a Type Handler for a single primitive result,
>> without overriding the default type handler for all primitives of that
>> type.
>>
>> For example, for the following style select statement, we want to
>> specify the type handler to be used:
>> <select resultType="boolean">
>>
>> Our current work around is to wrap it in a simple class, and use a
>> result map - but this breaks our API.
>>
>> Can someone point out how this is done?

Reply | Threaded
Open this post in threaded view
|

Re: Type Handler for Single Primitive Result Type

Truth
If I put anything inside brackets in the column expression part of the
select query, I get an SQL error (Incorrect syntax).
I'm not quite sure what else you're trying to refer to here.

--
Truth.

On 29 March 2011 16:02, lwpro <[hidden email]> wrote:

> if that's the case, you can achieve it by modifying your query.
>
> select (flag = false) newFlag from myTable;
>
> Cheers,
> Jackie
>
>
> On Tue, Mar 29, 2011 at 10:57, Truth <[hidden email]> wrote:
>>
>> Because in this case the values being stored are 'N' and 'Y'.
>> Existing database, and attached applications - so we can't change the
>> existing data.
>>
>> It's somewhat annoying, but I was expecting that MyBatis would have a
>> simple solution. Or at least simpler than our current work-around.
>>
>> --
>> Truth.
>>
>> On 29 March 2011 15:46, lwpro <[hidden email]> wrote:
>> > Hi,
>> >
>> > Just out of curiosity, what do you need a typehandler for a boolean
>> > type?
>> >
>> > Cheers,
>> > Jackie
>> >
>> >
>> > On Tue, Feb 22, 2011 at 21:39, Poitras Christian
>> > <[hidden email]> wrote:
>> >>
>> >> Try to use a resultMap.
>> >>
>> >> <resultMap id="special_boolean" type="boolean">
>> >>  <constructor>
>> >>    <arg column="your_column" typeHandler="YourTypeHandler"/>
>> >>  </constructor>
>> >> </resultMap>
>> >>
>> >> Christian
>> >>
>> >> -----Message d'origine-----
>> >> De : [hidden email]
>> >> [mailto:[hidden email]]
>> >> De la part de Truth
>> >> Envoyé : February-21-11 5:22 PM
>> >> À : mybatis-user
>> >> Objet : Type Handler for Single Primitive Result Type
>> >>
>> >> We're trying to specify a Type Handler for a single primitive result,
>> >> without overriding the default type handler for all primitives of that
>> >> type.
>> >>
>> >> For example, for the following style select statement, we want to
>> >> specify the type handler to be used:
>> >> <select resultType="boolean">
>> >>
>> >> Our current work around is to wrap it in a simple class, and use a
>> >> result map - but this breaks our API.
>> >>
>> >> Can someone point out how this is done?
Reply | Threaded
Open this post in threaded view
|

Re: Type Handler for Single Primitive Result Type

Jackie Li
Hi,

I didn't run the query myself,
select (flag = false) newFlag from myTable;

Actually I am just trying to suggest to manipulate the query to negate the boolean value at database level, instead of using MyBatis typeHandler.

I think for oracle, we can use decode, or case function to negate the value, for example,
select case when group_id= 2 then 'true' else 'false' end as flag  from GTP_Group;
select decode (group_id, 2, 'true', 3, 'false') as flag from GTP_Group;
however, as you might know, if for oracle, actually it doesn't support boolean datatype.

I hope this clarifies. Sorry for the misunderstanding.

Cheers,
Jackie


On Tue, Mar 29, 2011 at 11:11, Truth <[hidden email]> wrote:
If I put anything inside brackets in the column expression part of the
select query, I get an SQL error (Incorrect syntax).
I'm not quite sure what else you're trying to refer to here.

--
Truth.

On 29 March 2011 16:02, lwpro <[hidden email]> wrote:
> if that's the case, you can achieve it by modifying your query.
>
> select (flag = false) newFlag from myTable;
>
> Cheers,
> Jackie
>
>
> On Tue, Mar 29, 2011 at 10:57, Truth <[hidden email]> wrote:
>>
>> Because in this case the values being stored are 'N' and 'Y'.
>> Existing database, and attached applications - so we can't change the
>> existing data.
>>
>> It's somewhat annoying, but I was expecting that MyBatis would have a
>> simple solution. Or at least simpler than our current work-around.
>>
>> --
>> Truth.
>>
>> On 29 March 2011 15:46, lwpro <[hidden email]> wrote:
>> > Hi,
>> >
>> > Just out of curiosity, what do you need a typehandler for a boolean
>> > type?
>> >
>> > Cheers,
>> > Jackie
>> >
>> >
>> > On Tue, Feb 22, 2011 at 21:39, Poitras Christian
>> > <[hidden email]> wrote:
>> >>
>> >> Try to use a resultMap.
>> >>
>> >> <resultMap id="special_boolean" type="boolean">
>> >>  <constructor>
>> >>    <arg column="your_column" typeHandler="YourTypeHandler"/>
>> >>  </constructor>
>> >> </resultMap>
>> >>
>> >> Christian
>> >>
>> >> -----Message d'origine-----
>> >> De : [hidden email]
>> >> [mailto:[hidden email]]
>> >> De la part de Truth
>> >> Envoyé : February-21-11 5:22 PM
>> >> À : mybatis-user
>> >> Objet : Type Handler for Single Primitive Result Type
>> >>
>> >> We're trying to specify a Type Handler for a single primitive result,
>> >> without overriding the default type handler for all primitives of that
>> >> type.
>> >>
>> >> For example, for the following style select statement, we want to
>> >> specify the type handler to be used:
>> >> <select resultType="boolean">
>> >>
>> >> Our current work around is to wrap it in a simple class, and use a
>> >> result map - but this breaks our API.
>> >>
>> >> Can someone point out how this is done?

Reply | Threaded
Open this post in threaded view
|

Re: Type Handler for Single Primitive Result Type

Truth
Hmm, I see what you mean. That's doable. Might be better than what
we've got - would need to test.

But I still think there should be a way of doing this, as is.

--
Truth.

On 29 March 2011 16:30, lwpro <[hidden email]> wrote:

> Hi,
>
> I didn't run the query myself,
> select (flag = false) newFlag from myTable;
>
> Actually I am just trying to suggest to manipulate the query to negate the
> boolean value at database level, instead of using MyBatis typeHandler.
>
> I think for oracle, we can use decode, or case function to negate the value,
> for example,
> select case when group_id= 2 then 'true' else 'false' end as flag  from
> GTP_Group;
> select decode (group_id, 2, 'true', 3, 'false') as flag from GTP_Group;
> however, as you might know, if for oracle, actually it doesn't support
> boolean datatype.
>
> I hope this clarifies. Sorry for the misunderstanding.
>
> Cheers,
> Jackie
>
>
> On Tue, Mar 29, 2011 at 11:11, Truth <[hidden email]> wrote:
>>
>> If I put anything inside brackets in the column expression part of the
>> select query, I get an SQL error (Incorrect syntax).
>> I'm not quite sure what else you're trying to refer to here.
>>
>> --
>> Truth.
>>
>> On 29 March 2011 16:02, lwpro <[hidden email]> wrote:
>> > if that's the case, you can achieve it by modifying your query.
>> >
>> > select (flag = false) newFlag from myTable;
>> >
>> > Cheers,
>> > Jackie
>> >
>> >
>> > On Tue, Mar 29, 2011 at 10:57, Truth <[hidden email]> wrote:
>> >>
>> >> Because in this case the values being stored are 'N' and 'Y'.
>> >> Existing database, and attached applications - so we can't change the
>> >> existing data.
>> >>
>> >> It's somewhat annoying, but I was expecting that MyBatis would have a
>> >> simple solution. Or at least simpler than our current work-around.
>> >>
>> >> --
>> >> Truth.
>> >>
>> >> On 29 March 2011 15:46, lwpro <[hidden email]> wrote:
>> >> > Hi,
>> >> >
>> >> > Just out of curiosity, what do you need a typehandler for a boolean
>> >> > type?
>> >> >
>> >> > Cheers,
>> >> > Jackie
>> >> >
>> >> >
>> >> > On Tue, Feb 22, 2011 at 21:39, Poitras Christian
>> >> > <[hidden email]> wrote:
>> >> >>
>> >> >> Try to use a resultMap.
>> >> >>
>> >> >> <resultMap id="special_boolean" type="boolean">
>> >> >>  <constructor>
>> >> >>    <arg column="your_column" typeHandler="YourTypeHandler"/>
>> >> >>  </constructor>
>> >> >> </resultMap>
>> >> >>
>> >> >> Christian
>> >> >>
>> >> >> -----Message d'origine-----
>> >> >> De : [hidden email]
>> >> >> [mailto:[hidden email]]
>> >> >> De la part de Truth
>> >> >> Envoyé : February-21-11 5:22 PM
>> >> >> À : mybatis-user
>> >> >> Objet : Type Handler for Single Primitive Result Type
>> >> >>
>> >> >> We're trying to specify a Type Handler for a single primitive
>> >> >> result,
>> >> >> without overriding the default type handler for all primitives of
>> >> >> that
>> >> >> type.
>> >> >>
>> >> >> For example, for the following style select statement, we want to
>> >> >> specify the type handler to be used:
>> >> >> <select resultType="boolean">
>> >> >>
>> >> >> Our current work around is to wrap it in a simple class, and use a
>> >> >> result map - but this breaks our API.
>> >> >>
>> >> >> Can someone point out how this is done?
Reply | Threaded
Open this post in threaded view
|

Re: Type Handler for Single Primitive Result Type

Jackie Li
Great if it would help.

I also think it's reasonable to have such functionality, enabling customised typeHandler for single return type. However, seems at least it's not common. And hope others could comment if there really is.

Cheers,
Jackie


On Tue, Mar 29, 2011 at 11:40, Truth <[hidden email]> wrote:
Hmm, I see what you mean. That's doable. Might be better than what
we've got - would need to test.

But I still think there should be a way of doing this, as is.

--
Truth.

On 29 March 2011 16:30, lwpro <[hidden email]> wrote:
> Hi,
>
> I didn't run the query myself,
> select (flag = false) newFlag from myTable;
>
> Actually I am just trying to suggest to manipulate the query to negate the
> boolean value at database level, instead of using MyBatis typeHandler.
>
> I think for oracle, we can use decode, or case function to negate the value,
> for example,
> select case when group_id= 2 then 'true' else 'false' end as flag  from
> GTP_Group;
> select decode (group_id, 2, 'true', 3, 'false') as flag from GTP_Group;
> however, as you might know, if for oracle, actually it doesn't support
> boolean datatype.
>
> I hope this clarifies. Sorry for the misunderstanding.
>
> Cheers,
> Jackie
>
>
> On Tue, Mar 29, 2011 at 11:11, Truth <[hidden email]> wrote:
>>
>> If I put anything inside brackets in the column expression part of the
>> select query, I get an SQL error (Incorrect syntax).
>> I'm not quite sure what else you're trying to refer to here.
>>
>> --
>> Truth.
>>
>> On 29 March 2011 16:02, lwpro <[hidden email]> wrote:
>> > if that's the case, you can achieve it by modifying your query.
>> >
>> > select (flag = false) newFlag from myTable;
>> >
>> > Cheers,
>> > Jackie
>> >
>> >
>> > On Tue, Mar 29, 2011 at 10:57, Truth <[hidden email]> wrote:
>> >>
>> >> Because in this case the values being stored are 'N' and 'Y'.
>> >> Existing database, and attached applications - so we can't change the
>> >> existing data.
>> >>
>> >> It's somewhat annoying, but I was expecting that MyBatis would have a
>> >> simple solution. Or at least simpler than our current work-around.
>> >>
>> >> --
>> >> Truth.
>> >>
>> >> On 29 March 2011 15:46, lwpro <[hidden email]> wrote:
>> >> > Hi,
>> >> >
>> >> > Just out of curiosity, what do you need a typehandler for a boolean
>> >> > type?
>> >> >
>> >> > Cheers,
>> >> > Jackie
>> >> >
>> >> >
>> >> > On Tue, Feb 22, 2011 at 21:39, Poitras Christian
>> >> > <[hidden email]> wrote:
>> >> >>
>> >> >> Try to use a resultMap.
>> >> >>
>> >> >> <resultMap id="special_boolean" type="boolean">
>> >> >>  <constructor>
>> >> >>    <arg column="your_column" typeHandler="YourTypeHandler"/>
>> >> >>  </constructor>
>> >> >> </resultMap>
>> >> >>
>> >> >> Christian
>> >> >>
>> >> >> -----Message d'origine-----
>> >> >> De : [hidden email]
>> >> >> [mailto:[hidden email]]
>> >> >> De la part de Truth
>> >> >> Envoyé : February-21-11 5:22 PM
>> >> >> À : mybatis-user
>> >> >> Objet : Type Handler for Single Primitive Result Type
>> >> >>
>> >> >> We're trying to specify a Type Handler for a single primitive
>> >> >> result,
>> >> >> without overriding the default type handler for all primitives of
>> >> >> that
>> >> >> type.
>> >> >>
>> >> >> For example, for the following style select statement, we want to
>> >> >> specify the type handler to be used:
>> >> >> <select resultType="boolean">
>> >> >>
>> >> >> Our current work around is to wrap it in a simple class, and use a
>> >> >> result map - but this breaks our API.
>> >> >>
>> >> >> Can someone point out how this is done?

Reply | Threaded
Open this post in threaded view
|

RE: Type Handler for Single Primitive Result Type

Poitras Christian
In reply to this post by Truth
As a side note:
You can specify a custom type handler for a single <result> easily even for Boolean, but it's much more difficult for a <resultMap>.

If you can set the Boolean as a <result> of another class, it would be very easy.
<resultMap id="someMap" type="SomeClass">
    <result property="my_boolean" column="our_column" typeHandler="OurTypeHandler"/>
</resultMap>

Christian

-----Message d'origine-----
De : [hidden email] [mailto:[hidden email]] De la part de Truth
Envoyé : March-28-11 4:59 PM
À : [hidden email]
Objet : Re: Type Handler for Single Primitive Result Type

Yes, but as in the OP, we don't want to change it for any other
Boolean's we're fetching - just this one.

Theoretically your previous suggestion should work, however when
MyBatis sees the resultMap type of Boolean, it doesn't process the
rest of the resultMap. It would appear the default handler for Boolean
overrides any custom resultMap specified for it.

The alternative I would have hoped for was the ability to set a
typeHandler for the result of a select where a resultType has been
specified.

At the moment for a work around, we've created our own
BooleanContainer custom type which we handling as per a normal
JavaBean - and inserting a dummy DAO layer between the actual DAO and
the Service call - that unwraps this BooleanContainer and returns a
boolean to match the API spec. However it seems a hack to hack to do
so, and the additional (minimal) overhead of another Bean being
managed.


Unless I've missed something it seems the default overriding the
resultMap for Boolean is a bug. And the lack of ability to specify a
typeHandler for a single result from a select statement a missing gap
in our functionality.

--
Truth.

On 29 March 2011 01:35, Poitras Christian <[hidden email]> wrote:

> It's possible.
>
> You can try either
> SqlSessionFactory.getConfiguration().getTypeHandlerRegistry().register(Boolean.TYPE, YourTypeHandler);
> Or register a JdbcType that match your data like
> sqlSessionFactory.getConfiguration().getTypeHandlerRegistry().register(JdbcType.BIT, YourTypeHandler);
> I haven't tried that for boolean.
>
> You may also prefer to have a private special getter/setter/constructor that doesn't use boolean but another type that is easier to deal with.
>
> Christian
>
> -----Message d'origine-----
> De : [hidden email] [mailto:[hidden email]] De la part de Truth
> Envoyé : March-27-11 7:05 PM
> À : [hidden email]
> Objet : Re: Type Handler for Single Primitive Result Type
>
> Sorry it's taken us so long on this - things with workarounds tend to
> get put lower priority.
>
> The suggested solution didn't work for us, we always got a false
> response regardless of input.
> Throwing some debug tracing on, it seems with the resultMap type of
> Boolean the typehandler we specify never gets called.
>
>        <resultMap id="special_boolean" type="Boolean">
>                <constructor>
>                        <arg column="our_column" javaType="_boolean" typeHandler="OurTypeHandler"/>
>                </constructor>
>        </resultMap>
>
> However on our own customer class, the typehandler still gets called:
>
>        <resultMap id="special_boolean" type="BooleanContainer">
>                <constructor>
>                        <arg column="our_column" javaType="_boolean" typeHandler="OurTypeHandler"/>
>                </constructor>
>        </resultMap>
>
> Is there some sort for automatic handler for a resultMap type of
> Boolean that we cannot override?
>
> --
> Truth.
>
> On 23 February 2011 02:39, Poitras Christian
> <[hidden email]> wrote:
>> Try to use a resultMap.
>>
>> <resultMap id="special_boolean" type="boolean">
>>  <constructor>
>>    <arg column="your_column" typeHandler="YourTypeHandler"/>
>>  </constructor>
>> </resultMap>
>>
>> Christian
>>
>> -----Message d'origine-----
>> De : [hidden email] [mailto:[hidden email]] De la part de Truth
>> Envoyé : February-21-11 5:22 PM
>> À : mybatis-user
>> Objet : Type Handler for Single Primitive Result Type
>>
>> We're trying to specify a Type Handler for a single primitive result,
>> without overriding the default type handler for all primitives of that
>> type.
>>
>> For example, for the following style select statement, we want to
>> specify the type handler to be used:
>> <select resultType="boolean">
>>
>> Our current work around is to wrap it in a simple class, and use a
>> result map - but this breaks our API.
>>
>> Can someone point out how this is done?
Reply | Threaded
Open this post in threaded view
|

Re: Type Handler for Single Primitive Result Type

Jackie Li
Hi Christian,

I agree. Actually I think (s)he has been using a BooleanContainer, which is another form of wrapper already. It for sure works.

However, it seems there might be a way to create custom typeHandler over single return result directly. Not sure if anyone have experience on this.

Cheers,
Jackie


On Tue, Mar 29, 2011 at 21:25, Poitras Christian <[hidden email]> wrote:
As a side note:
You can specify a custom type handler for a single <result> easily even for Boolean, but it's much more difficult for a <resultMap>.

If you can set the Boolean as a <result> of another class, it would be very easy.
<resultMap id="someMap" type="SomeClass">
   <result property="my_boolean" column="our_column" typeHandler="OurTypeHandler"/>
</resultMap>

Christian

-----Message d'origine-----
De : [hidden email] [mailto:[hidden email]] De la part de Truth
Envoyé : March-28-11 4:59 PM
À : [hidden email]
Objet : Re: Type Handler for Single Primitive Result Type

Yes, but as in the OP, we don't want to change it for any other
Boolean's we're fetching - just this one.

Theoretically your previous suggestion should work, however when
MyBatis sees the resultMap type of Boolean, it doesn't process the
rest of the resultMap. It would appear the default handler for Boolean
overrides any custom resultMap specified for it.

The alternative I would have hoped for was the ability to set a
typeHandler for the result of a select where a resultType has been
specified.

At the moment for a work around, we've created our own
BooleanContainer custom type which we handling as per a normal
JavaBean - and inserting a dummy DAO layer between the actual DAO and
the Service call - that unwraps this BooleanContainer and returns a
boolean to match the API spec. However it seems a hack to hack to do
so, and the additional (minimal) overhead of another Bean being
managed.


Unless I've missed something it seems the default overriding the
resultMap for Boolean is a bug. And the lack of ability to specify a
typeHandler for a single result from a select statement a missing gap
in our functionality.

--
Truth.

On 29 March 2011 01:35, Poitras Christian <[hidden email]> wrote:
> It's possible.
>
> You can try either
> SqlSessionFactory.getConfiguration().getTypeHandlerRegistry().register(Boolean.TYPE, YourTypeHandler);
> Or register a JdbcType that match your data like
> sqlSessionFactory.getConfiguration().getTypeHandlerRegistry().register(JdbcType.BIT, YourTypeHandler);
> I haven't tried that for boolean.
>
> You may also prefer to have a private special getter/setter/constructor that doesn't use boolean but another type that is easier to deal with.
>
> Christian
>
> -----Message d'origine-----
> De : [hidden email] [mailto:[hidden email]] De la part de Truth
> Envoyé : March-27-11 7:05 PM
> À : [hidden email]
> Objet : Re: Type Handler for Single Primitive Result Type
>
> Sorry it's taken us so long on this - things with workarounds tend to
> get put lower priority.
>
> The suggested solution didn't work for us, we always got a false
> response regardless of input.
> Throwing some debug tracing on, it seems with the resultMap type of
> Boolean the typehandler we specify never gets called.
>
>        <resultMap id="special_boolean" type="Boolean">
>                <constructor>
>                        <arg column="our_column" javaType="_boolean" typeHandler="OurTypeHandler"/>
>                </constructor>
>        </resultMap>
>
> However on our own customer class, the typehandler still gets called:
>
>        <resultMap id="special_boolean" type="BooleanContainer">
>                <constructor>
>                        <arg column="our_column" javaType="_boolean" typeHandler="OurTypeHandler"/>
>                </constructor>
>        </resultMap>
>
> Is there some sort for automatic handler for a resultMap type of
> Boolean that we cannot override?
>
> --
> Truth.
>
> On 23 February 2011 02:39, Poitras Christian
> <[hidden email]> wrote:
>> Try to use a resultMap.
>>
>> <resultMap id="special_boolean" type="boolean">
>>  <constructor>
>>    <arg column="your_column" typeHandler="YourTypeHandler"/>
>>  </constructor>
>> </resultMap>
>>
>> Christian
>>
>> -----Message d'origine-----
>> De : [hidden email] [mailto:[hidden email]] De la part de Truth
>> Envoyé : February-21-11 5:22 PM
>> À : mybatis-user
>> Objet : Type Handler for Single Primitive Result Type
>>
>> We're trying to specify a Type Handler for a single primitive result,
>> without overriding the default type handler for all primitives of that
>> type.
>>
>> For example, for the following style select statement, we want to
>> specify the type handler to be used:
>> <select resultType="boolean">
>>
>> Our current work around is to wrap it in a simple class, and use a
>> result map - but this breaks our API.
>>
>> Can someone point out how this is done?

Reply | Threaded
Open this post in threaded view
|

RE: Type Handler for Single Primitive Result Type

Poitras Christian

Maybe there is. I’ve never done this myself, so I’m not sure.

 

As for your suggestion to modify the select output, this is what I use to convert values like ‘N’ and ‘Y’ to boolean.

 

Christian

 

De : [hidden email] [mailto:[hidden email]] De la part de lwpro
Envoyé : March-29-11 9:32 AM
À : [hidden email]
Objet : Re: Type Handler for Single Primitive Result Type

 

Hi Christian,

I agree. Actually I think (s)he has been using a BooleanContainer, which is another form of wrapper already. It for sure works.

However, it seems there might be a way to create custom typeHandler over single return result directly. Not sure if anyone have experience on this.

Cheers,
Jackie

On Tue, Mar 29, 2011 at 21:25, Poitras Christian <[hidden email]> wrote:

As a side note:
You can specify a custom type handler for a single <result> easily even for Boolean, but it's much more difficult for a <resultMap>.

If you can set the Boolean as a <result> of another class, it would be very easy.
<resultMap id="someMap" type="SomeClass">
   <result property="my_boolean" column="our_column" typeHandler="OurTypeHandler"/>

</resultMap>

Christian

-----Message d'origine-----
De : [hidden email] [mailto:[hidden email]] De la part de Truth

Envoyé : March-28-11 4:59 PM

À : [hidden email]
Objet : Re: Type Handler for Single Primitive Result Type

Yes, but as in the OP, we don't want to change it for any other
Boolean's we're fetching - just this one.

Theoretically your previous suggestion should work, however when
MyBatis sees the resultMap type of Boolean, it doesn't process the
rest of the resultMap. It would appear the default handler for Boolean
overrides any custom resultMap specified for it.

The alternative I would have hoped for was the ability to set a
typeHandler for the result of a select where a resultType has been
specified.

At the moment for a work around, we've created our own
BooleanContainer custom type which we handling as per a normal
JavaBean - and inserting a dummy DAO layer between the actual DAO and
the Service call - that unwraps this BooleanContainer and returns a
boolean to match the API spec. However it seems a hack to hack to do
so, and the additional (minimal) overhead of another Bean being
managed.


Unless I've missed something it seems the default overriding the
resultMap for Boolean is a bug. And the lack of ability to specify a
typeHandler for a single result from a select statement a missing gap
in our functionality.

--
Truth.

On 29 March 2011 01:35, Poitras Christian <[hidden email]> wrote:


> It's possible.
>
> You can try either
> SqlSessionFactory.getConfiguration().getTypeHandlerRegistry().register(Boolean.TYPE, YourTypeHandler);
> Or register a JdbcType that match your data like
> sqlSessionFactory.getConfiguration().getTypeHandlerRegistry().register(JdbcType.BIT, YourTypeHandler);
> I haven't tried that for boolean.
>
> You may also prefer to have a private special getter/setter/constructor that doesn't use boolean but another type that is easier to deal with.
>
> Christian
>
> -----Message d'origine-----
> De : [hidden email] [mailto:[hidden email]] De la part de Truth
> Envoyé : March-27-11 7:05 PM
> À : [hidden email]
> Objet : Re: Type Handler for Single Primitive Result Type
>
> Sorry it's taken us so long on this - things with workarounds tend to
> get put lower priority.
>
> The suggested solution didn't work for us, we always got a false
> response regardless of input.
> Throwing some debug tracing on, it seems with the resultMap type of
> Boolean the typehandler we specify never gets called.
>
>        <resultMap id="special_boolean" type="Boolean">
>                <constructor>
>                        <arg column="our_column" javaType="_boolean" typeHandler="OurTypeHandler"/>
>                </constructor>
>        </resultMap>
>
> However on our own customer class, the typehandler still gets called:
>
>        <resultMap id="special_boolean" type="BooleanContainer">
>                <constructor>
>                        <arg column="our_column" javaType="_boolean" typeHandler="OurTypeHandler"/>
>                </constructor>
>        </resultMap>
>
> Is there some sort for automatic handler for a resultMap type of
> Boolean that we cannot override?
>
> --
> Truth.
>
> On 23 February 2011 02:39, Poitras Christian
> <[hidden email]> wrote:
>> Try to use a resultMap.
>>
>> <resultMap id="special_boolean" type="boolean">
>>  <constructor>
>>    <arg column="your_column" typeHandler="YourTypeHandler"/>
>>  </constructor>
>> </resultMap>
>>
>> Christian
>>
>> -----Message d'origine-----
>> De : [hidden email] [mailto:[hidden email]] De la part de Truth
>> Envoyé : February-21-11 5:22 PM
>> À : mybatis-user
>> Objet : Type Handler for Single Primitive Result Type
>>
>> We're trying to specify a Type Handler for a single primitive result,
>> without overriding the default type handler for all primitives of that
>> type.
>>
>> For example, for the following style select statement, we want to
>> specify the type handler to be used:
>> <select resultType="boolean">
>>
>> Our current work around is to wrap it in a simple class, and use a
>> result map - but this breaks our API.
>>
>> Can someone point out how this is done?