Add fetchOne(RecordMapper) shortcut method to ResultQuery and implement it in implementing classes
This commit is contained in:
parent
59d8879aaf
commit
2fa50aeaf9
@ -457,6 +457,17 @@ public interface ResultQuery<R extends Record> extends Query, Iterable<R> {
|
||||
*/
|
||||
R fetchOne() throws DataAccessException, InvalidResultException;
|
||||
|
||||
/**
|
||||
* Execute the query and return at most one resulting value into a
|
||||
* custom mapper callback.
|
||||
*
|
||||
* @return The custom mapped record or <code>null</code> if the query returned no
|
||||
* records.
|
||||
* @throws DataAccessException if something went wrong executing the query
|
||||
* @throws InvalidResultException if the query returned more than one record
|
||||
*/
|
||||
<E> E fetchOne(RecordMapper<? super R, E> mapper) throws DataAccessException, InvalidResultException;
|
||||
|
||||
/**
|
||||
* Execute the query and return at most one resulting record as a name/value
|
||||
* map.
|
||||
|
||||
@ -440,6 +440,12 @@ abstract class AbstractResultQuery<R extends Record> extends AbstractQuery imple
|
||||
return Utils.fetchOne(fetchLazy());
|
||||
}
|
||||
|
||||
@Override
|
||||
public final <E> E fetchOne(RecordMapper<? super R, E> mapper) {
|
||||
R record = fetchOne();
|
||||
return record == null ? null : mapper.map(record);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Map<String, Object> fetchOneMap() {
|
||||
R record = fetchOne();
|
||||
|
||||
@ -2436,6 +2436,11 @@ class SelectImpl<R extends Record, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11,
|
||||
return getDelegate().fetchOne();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final <E> E fetchOne(RecordMapper<? super R, E> mapper) {
|
||||
return getDelegate().fetchOne(mapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Map<String, Object> fetchOneMap() {
|
||||
return getDelegate().fetchOneMap();
|
||||
|
||||
Loading…
Reference in New Issue
Block a user