public Object mapRow(ResultSet rs, int rowNumber) throws SQLException {
Object result;
try {
result = defaultConstruct.newInstance(null);
} catch (IllegalAccessException e) {
throw new DataAccessResourceFailureException("Failed to load class " + mappedClass.getName(), e);
} catch (InvocationTargetException e) {
throw new DataAccessResourceFailureException("Failed to load class " + mappedClass.getName(), e);
} catch (InstantiationException e) {
throw new DataAccessResourceFailureException("Failed to load class " + mappedClass.getName(), e);
}
ResultSetMetaData meta = rs.getMetaData();
int columns = meta.getColumnCount();
Map mappedColumns = new HashMap(10);
Map unmappedColumns = new HashMap(10);
for (int x = 1; x <= columns; x++) {
String field = meta.getColumnName(x).toLowerCase();
PersistentField fieldMeta = (PersistentField)persistentObject.getPersistentFields().get(field);
if (fieldMeta != null) {
Object value = null;
Method m = null;
try {
if (fieldMeta.getJavaType().equals(String.class)) {
m = result.getClass().getMethod(ActiveMapperUtils.setterName(fieldMeta.getColumnName()), new Class[] {String.class});
value = rs.getString(x);
}
else if (fieldMeta.getJavaType().equals(Byte.class)) {
m = result.getClass().getMethod(ActiveMapperUtils.setterName(fieldMeta.getColumnName()), new Class[] {Byte.class});
value = new Byte(rs.getByte(x));
}
else if (fieldMeta.getJavaType().equals(Short.class)) {
m = result.getClass().getMethod(ActiveMapperUtils.setterName(fieldMeta.getColumnName()), new Class[] {Short.class});
value = new Short(rs.getShort(x));
}
else if (fieldMeta.getJavaType().equals(Integer.class)) {
m = result.getClass().getMethod(ActiveMapperUtils.setterName(fieldMeta.getColumnName()), new Class[] {Integer.class});
value = new Integer(rs.getInt(x));
}
else if (fieldMeta.getJavaType().equals(Long.class)) {
m = result.getClass().getMethod(ActiveMapperUtils.setterName(fieldMeta.getColumnName()), new Class[] {Long.class});
value = new Long(rs.getLong(x));
}
else if (fieldMeta.getJavaType().equals(Float.class)) {
m = result.getClass().getMethod(ActiveMapperUtils.setterName(fieldMeta.getColumnName()), new Class[] {Float.class});
value = new Float(rs.getFloat(x));
}
else if (fieldMeta.getJavaType().equals(Double.class)) {
m = result.getClass().getMethod(ActiveMapperUtils.setterName(fieldMeta.getColumnName()), new Class[] {Double.class});
value = new Double(rs.getDouble(x));
}
else if (fieldMeta.getJavaType().equals(BigDecimal.class)) {
m = result.getClass().getMethod(ActiveMapperUtils.setterName(fieldMeta.getColumnName()), new Class[] {BigDecimal.class});
value = rs.getBigDecimal(x);
}
else if (fieldMeta.getJavaType().equals(Boolean.class)) {
m = result.getClass().getMethod(ActiveMapperUtils.setterName(fieldMeta.getColumnName()), new Class[] {Boolean.class});
value = (rs.getBoolean(x)) ? Boolean.TRUE : Boolean.FALSE;
}
else if (fieldMeta.getJavaType().equals(Date.class)) {
m = result.getClass().getMethod(ActiveMapperUtils.setterName(fieldMeta.getColumnName()), new Class[] {Date.class});
if (fieldMeta.getSqlType() == Types.DATE) {
value = rs.getDate(x);
}
else if (fieldMeta.getSqlType() == Types.TIME) {
value = rs.getTime(x);
}
else {
value = rs.getTimestamp(x);
}
}
else {
unmappedColumns.put(fieldMeta.getColumnName(), fieldMeta);
}
if (m != null) {
m.invoke(result , new Object[] {value});
mappedColumns.put(meta.getColumnName(x), meta);
}
} catch (NoSuchMethodException e) {
throw new DataAccessResourceFailureException(new StringBuffer().append("Failed to map field ").append(fieldMeta.getFieldName()).append(".").toString(), e);
} catch (IllegalAccessException e) {
throw new DataAccessResourceFailureException(new StringBuffer().append("Failed to map field ").append(fieldMeta.getFieldName()).append(".").toString(), e);
} catch (InvocationTargetException e) {
throw new DataAccessResourceFailureException(new StringBuffer().append("Failed to map field ").append(fieldMeta.getFieldName()).append(".").toString(), e);
}
}
else {
unmappedColumns.put(meta.getColumnName(x), meta);
}