From 9ad9474b09b69608ac55aefae5e3c52935dca211 Mon Sep 17 00:00:00 2001 From: lukaseder Date: Fri, 24 Jul 2015 15:09:14 +0200 Subject: [PATCH] [#4426] Add T DSLContext.fetchValue(TableField field) --- jOOQ/src/main/java/org/jooq/DSLContext.java | 26 +++++++++++++++++++ .../java/org/jooq/impl/DefaultDSLContext.java | 10 +++++++ 2 files changed, 36 insertions(+) diff --git a/jOOQ/src/main/java/org/jooq/DSLContext.java b/jOOQ/src/main/java/org/jooq/DSLContext.java index ac78768484..3ee6f8b917 100644 --- a/jOOQ/src/main/java/org/jooq/DSLContext.java +++ b/jOOQ/src/main/java/org/jooq/DSLContext.java @@ -6706,6 +6706,19 @@ public interface DSLContext extends Scope { > T fetchValue(ResultQuery query) throws DataAccessException, TooManyRowsException, InvalidResultException; + /** + * xecute a {@link ResultQuery} in the context of this + * DSLContext 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 fetchValue(TableField 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 */ > Optional fetchOptionalValue(ResultQuery query) throws DataAccessException, TooManyRowsException, InvalidResultException; + + /** + * Execute a {@link ResultQuery} in the context of this + * DSLContext 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 + */ + Optional fetchOptionalValue(TableField field) throws DataAccessException, TooManyRowsException, InvalidResultException; /* [/java-8] */ /** diff --git a/jOOQ/src/main/java/org/jooq/impl/DefaultDSLContext.java b/jOOQ/src/main/java/org/jooq/impl/DefaultDSLContext.java index 0976e8618a..9c4e16b219 100644 --- a/jOOQ/src/main/java/org/jooq/impl/DefaultDSLContext.java +++ b/jOOQ/src/main/java/org/jooq/impl/DefaultDSLContext.java @@ -2472,11 +2472,21 @@ public class DefaultDSLContext extends AbstractScope implements DSLContext, Seri } } + @Override + public T fetchValue(TableField field) { + return fetchValue(select(field).from(field.getTable())); + } + /* [java-8] */ @Override public > Optional fetchOptionalValue(ResultQuery query) { return Optional.ofNullable(fetchValue(query)); } + + @Override + public Optional fetchOptionalValue(TableField field) { + return Optional.ofNullable(fetchValue(field)); + } /* [/java-8] */ @Override