diff --git a/jOOQ-manual/src/main/resources/org/jooq/web/manual-3.10.xml b/jOOQ-manual/src/main/resources/org/jooq/web/manual-3.10.xml index 797c494c91..30ee02e1b6 100644 --- a/jOOQ-manual/src/main/resources/org/jooq/web/manual-3.10.xml +++ b/jOOQ-manual/src/main/resources/org/jooq/web/manual-3.10.xml @@ -8518,12 +8518,20 @@ book.setAuthorId(1); book.setPublishedIn(1970); book.setLanguageId(1); -Result books = +// Using the explicit condition() API +Result books1 = DSL.using(configuration) .selectFrom(BOOK) .where(condition(book)) - .fetch();]]> - + .fetch(); + +// Using the convenience API on DSLContext +Result books2 = DSL.using(configuration).fetchByExample(book);]]> + +

+ The latter API call makes use of the convenience API . +

+ diff --git a/jOOQ/src/main/java/org/jooq/DSLContext.java b/jOOQ/src/main/java/org/jooq/DSLContext.java index 0c72c1f49f..6aca6db0d4 100644 --- a/jOOQ/src/main/java/org/jooq/DSLContext.java +++ b/jOOQ/src/main/java/org/jooq/DSLContext.java @@ -9249,7 +9249,7 @@ public interface DSLContext extends Scope , AutoCloseable { > List fetchValues(ResultQuery query) throws DataAccessException; /** - * Fetch all values in a given {@link Table}'s {@link TableField} + * Fetch all values in a given {@link Table}'s {@link TableField}. * * @param field The field for which to fetch all values. * @return The values. This will never be null. @@ -9257,6 +9257,16 @@ public interface DSLContext extends Scope , AutoCloseable { */ List fetchValues(TableField field) throws DataAccessException; + /** + * Execute a "Query by Example" (QBE) based on an example record. + * + * @param example The example record + * @return The resulting records matching the example record. + * @throws DataAccessException if something went wrong executing the query + * @see DSL#condition(Record) + */ + > Result fetchByExample(R example) throws DataAccessException; + /** * Execute a {@link Select} query in the context of this DSLContext and return * a COUNT(*) value. diff --git a/jOOQ/src/main/java/org/jooq/impl/DefaultDSLContext.java b/jOOQ/src/main/java/org/jooq/impl/DefaultDSLContext.java index eafa9cca3a..5a25b72712 100644 --- a/jOOQ/src/main/java/org/jooq/impl/DefaultDSLContext.java +++ b/jOOQ/src/main/java/org/jooq/impl/DefaultDSLContext.java @@ -37,6 +37,7 @@ package org.jooq.impl; import static org.jooq.conf.ParamType.INLINED; import static org.jooq.conf.ParamType.NAMED; import static org.jooq.conf.ParamType.NAMED_OR_INLINED; +import static org.jooq.impl.DSL.condition; import static org.jooq.impl.DSL.field; import static org.jooq.impl.DSL.name; import static org.jooq.impl.DSL.schema; @@ -3628,6 +3629,13 @@ public class DefaultDSLContext extends AbstractScope implements DSLContext, Seri return record.value1(); } + @Override + public > Result fetchByExample(R example) { + return selectFrom(example.getTable()) + .where(condition(example)) + .fetch(); + } + @Override public int fetchCount(Select query) { return new FetchCount(configuration(), query).fetchOne().value1();