Hi gang,
 
I found a temp fix to my problem. In case anyone is interested, all I did was
modify MonetaryAmount.java as below
 
private BigDecimal value;
private Currency currency;
 
private boolean valueFlag = true;
private boolean currencyFlag = true;
 

/**
 * Required by iBatis
 * @param currency
 */
public void setCurrency(Currency currency) {
 if ( currencyFlag ){
  this.currency = currency;
  currencyFlag = false;
 }
}
 
/**
 * Required by iBatis
 * @param value
 */
public void setValue(BigDecimal value) {
 if ( valueFlag ){
  this.value = value;
  valueFlag = false;
 }
}
 
public Currency getCurrency() {
 return Currency.getInstance( currency.getCurrencyCode() );
}
 
public BigDecimal getValue() {
 return new BigDecimal( value.doubleValue() );
}
 
Not pretty but at least security still maintained. And now I can use
 
 
Sam,
 
----- Original Message -----
From: Dodo
Sent: Saturday, July 08, 2006 3:45 PM
Subject: TypeHandlerCallback problem

Hi,
 
If I have an Item.java class that has a complex object
, MonetaryAmount.java as its field. Now for security reason,
fields of MonetaryAmount class has private final fields and
getter methods only, setter methods are empty.
 
Now you can see I have problem using TypeHandlerCallback
to return MonetaryAmount's private final field as setter
method for Currency needs to be empty
 
E.g.
 
public class Item {
 
 private Monetary initialPrice;
 
 // setter and getter for initialPrice
 ....
 
}
 
  and
 
public class MonetaryAmount implements Serializable {
 
 private final BigDecimal value;
 private final Currency currency;
 
 public MonetaryAmount(BigDecimal value, Currency currency) {
  this.value = value;
  this.currency = currency;
 }
 
 public Currency getCurrency() {
  return currency;
 }
 
 public BigDecimal getValue() {
  return value;
 }
    .........
 
 public void setCurrency(Currency currency) {
 }
 
 public void setValue(BigDecimal value) {
 }
 
}
 
so mapping file will look like
 
 <typeAlias alias="item" type="org.auctionfuse.model.Item"/>
 
    <resultMap id="itemResult" class="item">
        <result property="id" column="item_id"/>
  ..
  <!-- initialPrice is MonetaryAmount field -->
        <result property="initialPrice.value" column="initial_price"/> 
        <result property="initialPrice.currency" column="currency"
         typeHandler= "org.auctionfuse.ibatis.typehandler.CurrencyTypeHandler" /> 
  ...   
    </resultMap>
 
where CurrencyTypeHandler implements TypeHandlerCallback and tries to converts
string retrieved from database to Currency object
 
but the problem is setter methods of MonetaryAmount.java simply does nothing
 
I was wandering if anyone has elegant solution in iBatis.
 
Thanks,
 
Sam

Reply via email to