01: /*
02: * User: mrettig
03: * Date: Jun 26, 2002
04: * Time: 6:51:36 PM
05: */
06: package net.sourceforge.jaxor.mappers;
07:
08: import net.sourceforge.jaxor.MetaField;
09: import net.sourceforge.jaxor.api.Mapper;
10: import net.sourceforge.jaxor.util.SystemException;
11:
12: import java.sql.ResultSet;
13: import java.sql.SQLException;
14: import java.sql.Types;
15:
16: public class StringMapper extends MapperBase {
17:
18: public Object getValueFromResultSet(ResultSet rs, MetaField field)
19: throws SQLException {
20: return rs.getString(field.getColumn());
21: }
22:
23: public void validate(Object obj, MetaField field) {
24: String val = (String) obj;
25: if (val != null && val.equals("") && !field.canBeNull())
26: throw new SystemException(
27: "Cannot insert empty string into non-nullable column: "
28: + field.getColumn());
29: }
30:
31: public int getSQLType() {
32: return Types.VARCHAR;
33: }
34: }
|