
org.sfm.utils.conv.ArrayConverter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of simpleFlatMapper Show documentation
Show all versions of simpleFlatMapper Show documentation
Java library to map flat record - ResultSet, csv - to java object with minimum configuration and low footprint.
package org.sfm.utils.conv;
import org.sfm.reflect.Getter;
import java.sql.Array;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;
public class ArrayConverter implements Converter {
private final Class elementClass;
private final Getter elementGetter;
public ArrayConverter(Class elementClass, Getter elementGetter) {
this.elementClass = elementClass;
this.elementGetter = elementGetter;
}
@Override
public E[] convert(Array array) throws Exception {
List list = new ArrayList();
ResultSet rs = array.getResultSet();
try {
while(rs.next()) {
list.add(elementGetter.get(rs));
}
} finally {
rs.close();
}
@SuppressWarnings("unchecked")
E[] elements = (E[]) java.lang.reflect.Array.newInstance(elementClass, list.size());
return list.toArray(elements);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy