org.simpleflatmapper.jdbc.converter.SqlArrayToListConverter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of sfm-jdbc Show documentation
Show all versions of sfm-jdbc Show documentation
Java library to map flat record - ResultSet, csv - to java object with minimum configuration and low footprint.
package org.simpleflatmapper.jdbc.converter;
import org.simpleflatmapper.converter.Context;
import org.simpleflatmapper.converter.ContextualConverter;
import org.simpleflatmapper.reflect.Getter;
import java.sql.Array;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;
public class SqlArrayToListConverter implements ContextualConverter> {
private final Getter super ResultSet, ? extends T> getter;
@SuppressWarnings("unchecked")
public SqlArrayToListConverter(Getter super ResultSet, ? extends T> getter) {
this.getter = getter;
}
@Override
public List convert(Array in, Context context) throws Exception {
if (in == null) return null;
List list = new ArrayList();
ResultSet rs = in.getResultSet();
try {
while(rs.next()) {
list.add(getter.get(rs));
}
} finally {
rs.close();
}
return list;
}
}