[#6195] Add DSLContext.fetchByExample(TableRecord)
This commit is contained in:
parent
11ef2849ff
commit
00aafce1ab
@ -8518,12 +8518,20 @@ book.setAuthorId(1);
|
||||
book.setPublishedIn(1970);
|
||||
book.setLanguageId(1);
|
||||
|
||||
Result<BookRecord> books =
|
||||
// Using the explicit condition() API
|
||||
Result<BookRecord> books1 =
|
||||
DSL.using(configuration)
|
||||
.selectFrom(BOOK)
|
||||
.where(condition(book))
|
||||
.fetch();]]></java>
|
||||
</content>
|
||||
.fetch();
|
||||
|
||||
// Using the convenience API on DSLContext
|
||||
Result<BookRecord> books2 = DSL.using(configuration).fetchByExample(book);]]></java><html>
|
||||
|
||||
<p>
|
||||
The latter API call makes use of the convenience API <reference class="org.jooq.DSLContext" title="DSLContext.fetchByExample(TableRecord)" anchor="#fetchByExample-org.jooq.TableRecord-"/>.
|
||||
</p>
|
||||
</html></content>
|
||||
</section>
|
||||
</sections>
|
||||
</section>
|
||||
|
||||
@ -9249,7 +9249,7 @@ public interface DSLContext extends Scope , AutoCloseable {
|
||||
<T, R extends Record1<T>> List<T> fetchValues(ResultQuery<R> 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 <code>null</code>.
|
||||
@ -9257,6 +9257,16 @@ public interface DSLContext extends Scope , AutoCloseable {
|
||||
*/
|
||||
<T> List<T> fetchValues(TableField<?, T> 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)
|
||||
*/
|
||||
<R extends TableRecord<R>> Result<R> fetchByExample(R example) throws DataAccessException;
|
||||
|
||||
/**
|
||||
* Execute a {@link Select} query in the context of this <code>DSLContext</code> and return
|
||||
* a <code>COUNT(*)</code> value.
|
||||
|
||||
@ -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 <R extends TableRecord<R>> Result<R> fetchByExample(R example) {
|
||||
return selectFrom(example.getTable())
|
||||
.where(condition(example))
|
||||
.fetch();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int fetchCount(Select<?> query) {
|
||||
return new FetchCount(configuration(), query).fetchOne().value1();
|
||||
|
||||
Loading…
Reference in New Issue
Block a user