[#4426] Add <T> T DSLContext.fetchValue(TableField<?, T> field)

This commit is contained in:
lukaseder 2015-07-24 15:09:14 +02:00
parent 2bd1123491
commit 9ad9474b09
2 changed files with 36 additions and 0 deletions

View File

@ -6706,6 +6706,19 @@ public interface DSLContext extends Scope {
<T, R extends Record1<T>> T fetchValue(ResultQuery<R> query)
throws DataAccessException, TooManyRowsException, InvalidResultException;
/**
* xecute a {@link ResultQuery} in the context of this
* <code>DSLContext</code> and return a single value.
*
* @param field The field for which to fetch a single value.
* @return The value.
* @throws DataAccessException if something went wrong executing the query
* @throws TooManyRowsException if the query returned more than one record
* @throws InvalidResultException if the query returned a record with more
* than one value
*/
<T> T fetchValue(TableField<?, T> field) throws DataAccessException, TooManyRowsException, InvalidResultException;
/* [java-8] */
/**
* Execute a {@link ResultQuery} in the context of this
@ -6719,6 +6732,19 @@ public interface DSLContext extends Scope {
* than one value
*/
<T, R extends Record1<T>> Optional<T> fetchOptionalValue(ResultQuery<R> query) throws DataAccessException, TooManyRowsException, InvalidResultException;
/**
* Execute a {@link ResultQuery} in the context of this
* <code>DSLContext</code> and return a single value.
*
* @param field The field for which to fetch a single value.
* @return The value.
* @throws DataAccessException if something went wrong executing the query
* @throws TooManyRowsException if the query returned more than one record
* @throws InvalidResultException if the query returned a record with more
* than one value
*/
<T> Optional<T> fetchOptionalValue(TableField<?, T> field) throws DataAccessException, TooManyRowsException, InvalidResultException;
/* [/java-8] */
/**

View File

@ -2472,11 +2472,21 @@ public class DefaultDSLContext extends AbstractScope implements DSLContext, Seri
}
}
@Override
public <T> T fetchValue(TableField<?, T> field) {
return fetchValue(select(field).from(field.getTable()));
}
/* [java-8] */
@Override
public <T, R extends Record1<T>> Optional<T> fetchOptionalValue(ResultQuery<R> query) {
return Optional.ofNullable(fetchValue(query));
}
@Override
public <T> Optional<T> fetchOptionalValue(TableField<?, T> field) {
return Optional.ofNullable(fetchValue(field));
}
/* [/java-8] */
@Override