this.columnsInfo = columnsInfo;
this.columnTypeConverter = columnTypeConverter;
}
public Object process(ResultSet resultSet) throws SQLException {
IsoLog log = context.getLog();
IsoReflectionManager reflectionManager = context.getReflectionManager();
IsoBeanPropertyManager propertyManager = context
.getBeanPropertyManager();
log.debug("Processing: {0}", klass);
List<Object> list = new ArrayList<Object>();
ResultSetMetaData metaData = resultSet.getMetaData();
int columnCount = metaData.getColumnCount();
String[] columnNames = new String[columnCount];
for (int i = 0; i < columnCount; i++) {
String columnName = metaData.getColumnName(i + 1);
columnNames[i] = columnName;
log.trace("Catch of column: {0}", columnName);
}
while (resultSet.next()) {
Object bean = reflectionManager.newInstance(klass);
for (int i = 0; i < columnCount; i++) {
String columnName = columnNames[i];
IsoSQLResultSetProcessorColumnInfo columnInfo = columnsInfo
.get(columnName);
Object value;
Class<?> type;
switch (columnTypeConverter.getColumnType(columnInfo.getType())) {
case FLOAT:
value = Float.valueOf(resultSet.getFloat(i + 1));
type = Float.class;
break;
case DOUBLE:
value = Double.valueOf(resultSet.getDouble(i + 1));
type = Double.class;
break;
case STRING:
value = resultSet.getString(i + 1);
type = String.class;
break;
case INTEGER:
value = Integer.valueOf(resultSet.getInt(i + 1));
type = Integer.class;
break;
case LONG:
value = Long.valueOf(resultSet.getLong(i + 1));
type = Long.class;
break;
case DATE:
value = resultSet.getDate(i + 1);
type = Date.class;
break;
default:
continue;
}
propertyManager.setProperty(bean, type, columnInfo.getName(),
value);
}
list.add(bean);
}
log.debug("List size: {0}", Integer.valueOf(list.size()));
return list;
}