[#3983] Add <T> List<T> DSLContext.fetchValues(TableField<?, T>)

This commit is contained in:
lukaseder 2015-01-25 13:02:53 +01:00
parent 236da42743
commit 77beb6dd8d
2 changed files with 15 additions and 0 deletions

View File

@ -5877,6 +5877,15 @@ public interface DSLContext extends Scope {
*/
<T, R extends Record1<T>> List<T> fetchValues(ResultQuery<R> query) throws DataAccessException;
/**
* Fetch all values in a given {@link Table}'s {@link TableField}
*
* @param field The field for which to fetch all values.
* @return The values.
* @throws DataAccessException if something went wrong executing the query
*/
<T> List<T> fetchValues(TableField<?, T> field) throws DataAccessException;
/**
* Execute a {@link Select} query in the context of this <code>DSLContext</code> and return
* a <code>COUNT(*)</code> value.

View File

@ -187,6 +187,7 @@ import org.jooq.SelectSelectStep;
import org.jooq.SelectWhereStep;
import org.jooq.Sequence;
import org.jooq.Table;
import org.jooq.TableField;
import org.jooq.TableLike;
import org.jooq.TableRecord;
import org.jooq.TransactionProvider;
@ -2201,6 +2202,11 @@ public class DefaultDSLContext extends AbstractScope implements DSLContext, Seri
return (List) fetch(query).getValues(0);
}
@Override
public <T> List<T> fetchValues(TableField<?, T> field) {
return fetchValues(select(field).from(field.getTable()));
}
private final <T, R extends Record1<T>> T value1(R record) {
if (record == null)
return null;