Also see the previous page in the documentation, which shows how to associate your Handle or DBI with mappers.
Essentially, you need a mapper to convert a ResultSet into your desired object and interface to access the mapper.
Assume a minimal example. A cartographer must first be provided:
public class CustomizedObjectMapper implements ResultSetMapper<customizedObject> { @Override public customizedObject map(int index, ResultSet r, StatementContext ctx) throws SQLException { return new customizedObject(r.getString("uuid"), r.getString("other_column")); } }
Then we need an interface to determine which request provides the data that is passed to the mapper class. One line of results leads to one call to CustomizedObjectMapper.map(...) :
@RegisterMapper(CustomizeObjectMapper.class) public interface CustomizeObjectQuery { @SqlQuery("Select uuid, other_column from schema.relation") List<customizedObject> get(); }
Finally, the objects can be obtained: List<customizedObject> test = dbi.open(CustomizeObjectQuery.class).get() .
You can also combine components on an individual basis and omit the interface: dbi.open().createQuery("Select uuid, other_colum from schema.relation").map(new EventMapper()).list()
Augustus kling
source share