[#7187] Add List<T> DSLContext.fetchValues(Table<? extends Record1<T>>)

This commit is contained in:
lukaseder 2018-02-16 12:29:02 +01:00
parent 3895e4a0c2
commit 66d1f6be87
2 changed files with 29 additions and 0 deletions

View File

@ -10680,6 +10680,16 @@ public interface DSLContext extends Scope , AutoCloseable {
<R extends Record> Optional<R> fetchOptional(ResultQuery<R> query) throws DataAccessException, TooManyRowsException;
/**
* Fetch a single value from a single column table.
*
* @param table The table from which to fetch a value
* @return The value or <code>null</code>, if no record was found.
* @throws DataAccessException if something went wrong executing the query
* @throws TooManyRowsException if the query returned more than one record
*/
<T> T fetchValue(Table<? extends Record1<T>> table) throws DataAccessException, TooManyRowsException;
/**
* Execute a {@link ResultQuery} in the context of this
* <code>DSLContext</code> and return a single value.
@ -10740,6 +10750,15 @@ public interface DSLContext extends Scope , AutoCloseable {
<T> Optional<T> fetchOptionalValue(TableField<?, T> field) throws DataAccessException, TooManyRowsException, InvalidResultException;
/**
* Fetch all values from a single column table.
*
* @param table The table from which to fetch values
* @return The values. This will never be <code>null</code>.
* @throws DataAccessException if something went wrong executing the query
*/
<T> List<T> fetchValues(Table<? extends Record1<T>> table) throws DataAccessException;
/**
* Execute a {@link ResultQuery} in the context of this
* <code>DSLContext</code> and return all values for the only column.

View File

@ -4159,6 +4159,11 @@ public class DefaultDSLContext extends AbstractScope implements DSLContext, Seri
}
@Override
public <T> T fetchValue(Table<? extends Record1<T>> table) {
return fetchValue(selectFrom(table));
}
@Override
public <T, R extends Record1<T>> T fetchValue(ResultQuery<R> query) {
final Configuration previous = Tools.getConfiguration(query);
@ -4194,6 +4199,11 @@ public class DefaultDSLContext extends AbstractScope implements DSLContext, Seri
}
@Override
public <T> List<T> fetchValues(Table<? extends Record1<T>> table) throws DataAccessException {
return fetchValues(selectFrom(table));
}
@Override
public <T, R extends Record1<T>> List<T> fetchValues(ResultQuery<R> query) {
return (List) fetch(query).getValues(0);