0
는
SQLite는JDBI resultsetmapper는 쿼리 결과 집합의 개체 목록을 만드시겠습니까? JPA와 Spring - 데이터 I에 대한 대안에 대한 수신 거부
저장소 코드
/**
* SQLite implementation of Foo Repository
*/
public class FooRepository implements FooRepository {
private final DBI connection;
/**
* The constructor initialises the connection to the local SQLite file
*
* @param dataSource jdbc connection string e.g. "jdbc:sqlite::resource:db/foo.db"
* @throws IllegalArgumentException when an invalid DB file is given
*/
public FooRepository(final SQLiteDataSource dataSource) {
checkNotNull(dataSource, "dataSource required");
connection = new DBI(dataSource);
}
/**
* Returns a list of Foo objects for a website locale in the DB
* @return List
* @throws SQLException error querying
*/
@Override
public List<Foo> getFoosByWebsiteLocale(f) throws SQLException {
checkNotNull(websiteLocale, "websiteLocale required");
final String fooQuery = query...
Handle queryHandler = connection.open();
final List<Foo> fooList = queryHandler.createQuery(fooQuery)
.map(FooMapper.class);
queryHandler.close();
return fooList;
}
}
매퍼
공용 클래스 FooMapper 구현과 함께 내 저장소 구현을위한 JDBI을 원했고 ResultSetMapper {
/**
* Construct a Foo object from a record in the result set
* @param index row number
* @param resultRow row
* @param ctx statementcontext
* @return Foo object
* @throws SQLException when accessing sql result set
*/
@Override
public Foo map(final int index, final ResultSet resultRow, final StatementContext ctx) throws SQLException {
return Foo.builder()
.name(resultRow.getString("foo_name"))
.type(resultRow.getString("foo_type"))
.build();
}
}
ResultSetMapper를 사용하여 Foo 객체 목록을 작성하는 방법을 이해하는 데 어려움을 겪고 있습니다.
JDBI 문서는 또한이 지역에 깨진 것으로 나타납니다
http://jdbi.org/maven_site/apidocs/org/skife/jdbi/v2/tweak/ResultSetMapper.html
도움말이이 일을 만드는 방법에 감상 할 수있다.
죄송합니다. 코드 솔루션을 제공 할 수 있습니까? – kaleeway
쿼리를 실행하는 코드 줄을 변경하십시오. final List fooList = queryHandler.createQuery (fooQuery) .map (FooMapper.class) .list(); –
jenarros