01: /*
02: * User: mrettig
03: * Date: Jun 26, 2002
04: * Time: 7:00:48 PM
05: */
06: package net.sourceforge.jaxor.example.mappers;
07:
08: import net.sourceforge.jaxor.MetaField;
09: import net.sourceforge.jaxor.mappers.MapperBase;
10: import net.sourceforge.jaxor.api.Mapper;
11: import net.sourceforge.jaxor.example.Money;
12:
13: import java.math.BigDecimal;
14: import java.sql.ResultSet;
15: import java.sql.SQLException;
16: import java.sql.Types;
17:
18: /**
19: * This class provides a Mapper instance to support the Money type.
20: * It provides a way to ensure that constant conversion between fixed
21: * precision values and the BigDecimal Java type is not necessary.
22: */
23:
24: public class MoneyMapper extends MapperBase {
25:
26: public Object getValueFromResultSet(ResultSet rs, MetaField field)
27: throws SQLException {
28: BigDecimal dec = rs.getBigDecimal(field.getColumn());
29: if (dec != null)
30: return new Money(dec);
31: return null;
32: }
33:
34: public int getSQLType() {
35: return Types.NUMERIC;
36: }
37:
38: public Object mapToSqlObject(Object obj) {
39: if (obj == null)
40: return null;
41: // else it is valid, return the amount
42: return ((Money) obj).getAmount();
43: }
44:
45: }
|