Just to answer my question, not sure if its the recommended way to do stuff in iBatis.
> 1] The typeHandler java class, if not mistaken it should either extends off
> TypeHandlerCallback interface or TypeHandler, is this correct? Can't seems to find it
> int the docs, or did I just missed it.
type handler could be defined in sql-map xml file or sql-map-config xml file. Having the handler class extends off TypeHandlerCallback works, i guess TypeHandler should work as well, just that TypeHandler is an internal api, so might be better off using TypeHandlerCallback.
> 2] From the TypeHandlerCallback and TypeHandler interface, it looks like they are
> more towards a 1 to 1 conversion between the java object property and DB column.
> say, it would be possible to 'YES'/'NO' string to a boolean column type. Is it possible
> to convert say 'USD1.00' or maybe 'AUD2.00' to two columns in the db say USD in a
> column and 1.00 in the other?
One way would be to do something like,
<resultMap id="result_item" class="....Item" >
<result proprety="id" column="ID" ..../>
<result property="itemName" column="ITEM_NAME" ..... />
<result property="currency.currencyType" column="CURRENCY_TYPE" .... />
<result property="currency.amount" column="AMOUNT" ..... />
</resultMap>
<statement .... resultMap="result_item".>
SELECT
i.id as ID,
i.itemName as ITEM_NAME,
i.currencyType as CURRENCY_TYPE,
i.amount as AMOUNT
FROM
item as i
</statement>
assuming there's an Item object with have a Currency object that have properties "currencyType" and "amount" both as String. If for some reason the amount is store as an Amount object, then i guess we could use a typeHandler for that.
regards
> 1] The typeHandler java class, if not mistaken it should either extends off
> TypeHandlerCallback interface or TypeHandler, is this correct? Can't seems to find it
> int the docs, or did I just missed it.
type handler could be defined in sql-map xml file or sql-map-config xml file. Having the handler class extends off TypeHandlerCallback works, i guess TypeHandler should work as well, just that TypeHandler is an internal api, so might be better off using TypeHandlerCallback.
> 2] From the TypeHandlerCallback and TypeHandler interface, it looks like they are
> more towards a 1 to 1 conversion between the java object property and DB column.
> say, it would be possible to 'YES'/'NO' string to a boolean column type. Is it possible
> to convert say 'USD1.00' or maybe 'AUD2.00' to two columns in the db say USD in a
> column and 1.00 in the other?
One way would be to do something like,
<resultMap id="result_item" class="....Item" >
<result proprety="id" column="ID" ..../>
<result property="itemName" column="ITEM_NAME" ..... />
<result property="currency.currencyType" column="CURRENCY_TYPE" .... />
<result property="currency.amount" column="AMOUNT" ..... />
</resultMap>
<statement .... resultMap="result_item".>
SELECT
i.id as ID,
i.itemName as ITEM_NAME,
i.currencyType as CURRENCY_TYPE,
i.amount as AMOUNT
FROM
item as i
</statement>
assuming there's an Item object with have a Currency object that have properties "currencyType" and "amount" both as String. If for some reason the amount is store as an Amount object, then i guess we could use a typeHandler for that.
regards
----- Original Message ----
From: tm jee <[EMAIL PROTECTED]>
To: [email protected]
Sent: Saturday, 5 August, 2006 8:33:52 PM
Subject: iBatis TypeHandler
From: tm jee <[EMAIL PROTECTED]>
To: [email protected]
Sent: Saturday, 5 August, 2006 8:33:52 PM
Subject: iBatis TypeHandler
Hi guys,
Is it possible to do type conversion in iBatis, such that a particular object say for example a Price object can be persisted in two columns. Eg.
public class Price {
private String amount;
private String currencyType;
.... // getter/ setter
}
public class Item {
private String id;
private String itemName;
private Price price;
// getter/setter
}
<resultMap id="result_item">
<result proprety="id" column="ID" ..../>
<result property="itemName" column="ITEM_NAME" />
<result property="price" typeHandler="......" />
</resultMap>
<statement .... resultMap="result_item".>
SELECT
i.id as ID,
i.itemName as ITEM_NAME,
i.currencyType as CURRENCY_TYPE,
i.amount as AMOUNT
FROM
item as i
</statement>
1] The typeHandler java class, if not mistaken it should either extends off TypeHandlerCallback interface or TypeHandler, is this correct? Can't seems to find it int the docs, or did I just missed it.
2] From the TypeHandlerCallback and TypeHandler interface, it looks like they are more towards a 1 to 1 conversion between the java object property and DB column. say, it would be possible to 'YES'/'NO' string to a boolean column type. Is it possible to convert say 'USD1.00' or maybe 'AUD2.00' to two columns in the db say USD in a column and 1.00 in the other?
Thanks a lot. :-)
regards
Is it possible to do type conversion in iBatis, such that a particular object say for example a Price object can be persisted in two columns. Eg.
public class Price {
private String amount;
private String currencyType;
.... // getter/ setter
}
public class Item {
private String id;
private String itemName;
private Price price;
// getter/setter
}
<resultMap id="result_item">
<result proprety="id" column="ID" ..../>
<result property="itemName" column="ITEM_NAME" />
<result property="price" typeHandler="......" />
</resultMap>
<statement .... resultMap="result_item".>
SELECT
i.id as ID,
i.itemName as ITEM_NAME,
i.currencyType as CURRENCY_TYPE,
i.amount as AMOUNT
FROM
item as i
</statement>
1] The typeHandler java class, if not mistaken it should either extends off TypeHandlerCallback interface or TypeHandler, is this correct? Can't seems to find it int the docs, or did I just missed it.
2] From the TypeHandlerCallback and TypeHandler interface, it looks like they are more towards a 1 to 1 conversion between the java object property and DB column. say, it would be possible to 'YES'/'NO' string to a boolean column type. Is it possible to convert say 'USD1.00' or maybe 'AUD2.00' to two columns in the db say USD in a column and 1.00 in the other?
Thanks a lot. :-)
regards
