[#4312] Add various fetchOptional() methods
This commit is contained in:
parent
3bcdc15ab8
commit
2dce62d61d
@ -45,6 +45,7 @@ import java.sql.ResultSet;
|
||||
import java.sql.Statement;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.jooq.conf.Settings;
|
||||
import org.jooq.exception.DataAccessException;
|
||||
@ -155,6 +156,65 @@ public interface Cursor<R extends Record> extends Iterable<R> {
|
||||
*/
|
||||
Result<R> fetch(int number) throws DataAccessException;
|
||||
|
||||
/**
|
||||
* Fetch results into a custom handler callback.
|
||||
* <p>
|
||||
* The resulting records are attached to the original {@link Configuration}
|
||||
* by default. Use {@link Settings#isAttachRecords()} to override this
|
||||
* behaviour.
|
||||
*
|
||||
* @param handler The handler callback
|
||||
* @return Convenience result, returning the parameter handler itself
|
||||
* @throws DataAccessException if something went wrong executing the query
|
||||
*/
|
||||
<H extends RecordHandler<? super R>> H fetchInto(H handler) throws DataAccessException;
|
||||
|
||||
/**
|
||||
* Fetch results into a custom mapper callback.
|
||||
*
|
||||
* @param mapper The mapper callback
|
||||
* @return The custom mapped records
|
||||
* @throws DataAccessException if something went wrong executing the query
|
||||
*/
|
||||
<E> List<E> fetch(RecordMapper<? super R, E> mapper) throws DataAccessException;
|
||||
|
||||
/**
|
||||
* Map resulting records onto a custom type.
|
||||
* <p>
|
||||
* This is the same as calling <code>fetch().into(type)</code>. See
|
||||
* {@link Record#into(Class)} for more details
|
||||
*
|
||||
* @param <E> The generic entity type.
|
||||
* @param type The entity type.
|
||||
* @see Record#into(Class)
|
||||
* @see Result#into(Class)
|
||||
* @throws DataAccessException if something went wrong executing the query
|
||||
* @throws MappingException wrapping any reflection or data type conversion
|
||||
* exception that might have occurred while mapping records
|
||||
* @see DefaultRecordMapper
|
||||
*/
|
||||
<E> List<E> fetchInto(Class<? extends E> type) throws DataAccessException, MappingException;
|
||||
|
||||
/**
|
||||
* Map resulting records onto a custom record.
|
||||
* <p>
|
||||
* This is the same as calling <code>fetch().into(table)</code>. See
|
||||
* {@link Record#into(Class)} for more details
|
||||
* <p>
|
||||
* The result and its contained records are attached to the original
|
||||
* {@link Configuration} by default. Use {@link Settings#isAttachRecords()}
|
||||
* to override this behaviour.
|
||||
*
|
||||
* @param <Z> The generic table record type.
|
||||
* @param table The table type.
|
||||
* @see Record#into(Class)
|
||||
* @see Result#into(Class)
|
||||
* @throws DataAccessException if something went wrong executing the query
|
||||
* @throws MappingException wrapping any reflection or data type conversion
|
||||
* exception that might have occurred while mapping records
|
||||
*/
|
||||
<Z extends Record> Result<Z> fetchInto(Table<Z> table) throws DataAccessException, MappingException;
|
||||
|
||||
/**
|
||||
* Fetch the next record from the cursor.
|
||||
* <p>
|
||||
@ -187,40 +247,6 @@ public interface Cursor<R extends Record> extends Iterable<R> {
|
||||
*/
|
||||
<H extends RecordHandler<? super R>> H fetchOneInto(H handler) throws DataAccessException;
|
||||
|
||||
/**
|
||||
* Fetch results into a custom handler callback.
|
||||
* <p>
|
||||
* The resulting records are attached to the original {@link Configuration}
|
||||
* by default. Use {@link Settings#isAttachRecords()} to override this
|
||||
* behaviour.
|
||||
*
|
||||
* @param handler The handler callback
|
||||
* @return Convenience result, returning the parameter handler itself
|
||||
* @throws DataAccessException if something went wrong executing the query
|
||||
*/
|
||||
<H extends RecordHandler<? super R>> H fetchInto(H handler) throws DataAccessException;
|
||||
|
||||
/**
|
||||
* Fetch the next record into a custom mapper callback.
|
||||
* <p>
|
||||
* This will conveniently close the <code>Cursor</code>, after the last
|
||||
* <code>Record</code> was fetched.
|
||||
*
|
||||
* @param mapper The mapper callback
|
||||
* @return The custom mapped record
|
||||
* @throws DataAccessException if something went wrong executing the query
|
||||
*/
|
||||
<E> E fetchOne(RecordMapper<? super R, E> mapper) throws DataAccessException;
|
||||
|
||||
/**
|
||||
* Fetch results into a custom mapper callback.
|
||||
*
|
||||
* @param mapper The mapper callback
|
||||
* @return The custom mapped records
|
||||
* @throws DataAccessException if something went wrong executing the query
|
||||
*/
|
||||
<E> List<E> fetch(RecordMapper<? super R, E> mapper) throws DataAccessException;
|
||||
|
||||
/**
|
||||
* Map the next resulting record onto a custom type.
|
||||
* <p>
|
||||
@ -239,21 +265,16 @@ public interface Cursor<R extends Record> extends Iterable<R> {
|
||||
<E> E fetchOneInto(Class<? extends E> type) throws DataAccessException, MappingException;
|
||||
|
||||
/**
|
||||
* Map resulting records onto a custom type.
|
||||
* Fetch the next record into a custom mapper callback.
|
||||
* <p>
|
||||
* This is the same as calling <code>fetch().into(type)</code>. See
|
||||
* {@link Record#into(Class)} for more details
|
||||
* This will conveniently close the <code>Cursor</code>, after the last
|
||||
* <code>Record</code> was fetched.
|
||||
*
|
||||
* @param <E> The generic entity type.
|
||||
* @param type The entity type.
|
||||
* @see Record#into(Class)
|
||||
* @see Result#into(Class)
|
||||
* @param mapper The mapper callback
|
||||
* @return The custom mapped record
|
||||
* @throws DataAccessException if something went wrong executing the query
|
||||
* @throws MappingException wrapping any reflection or data type conversion
|
||||
* exception that might have occurred while mapping records
|
||||
* @see DefaultRecordMapper
|
||||
*/
|
||||
<E> List<E> fetchInto(Class<? extends E> type) throws DataAccessException, MappingException;
|
||||
<E> E fetchOne(RecordMapper<? super R, E> mapper) throws DataAccessException;
|
||||
|
||||
/**
|
||||
* Map the next resulting record onto a custom record.
|
||||
@ -275,15 +296,60 @@ public interface Cursor<R extends Record> extends Iterable<R> {
|
||||
*/
|
||||
<Z extends Record> Z fetchOneInto(Table<Z> table) throws DataAccessException, MappingException;
|
||||
|
||||
/* [java-8] */
|
||||
/**
|
||||
* Map resulting records onto a custom record.
|
||||
* Fetch the next record from the cursor.
|
||||
* <p>
|
||||
* This is the same as calling <code>fetch().into(table)</code>. See
|
||||
* This will conveniently close the <code>Cursor</code>, after the last
|
||||
* <code>Record</code> was fetched.
|
||||
* <p>
|
||||
* The resulting record is attached to the original {@link Configuration} by
|
||||
* default. Use {@link Settings#isAttachRecords()} to override this
|
||||
* behaviour.
|
||||
*
|
||||
* @return The next record from the cursor
|
||||
* @throws DataAccessException if something went wrong executing the query
|
||||
*/
|
||||
Optional<R> fetchOptional() throws DataAccessException;
|
||||
|
||||
/**
|
||||
* Map the next resulting record onto a custom type.
|
||||
* <p>
|
||||
* This is the same as calling <code>fetchOne().into(type)</code>. See
|
||||
* {@link Record#into(Class)} for more details
|
||||
*
|
||||
* @param <E> The generic entity type.
|
||||
* @param type The entity type.
|
||||
* @see Record#into(Class)
|
||||
* @see Result#into(Class)
|
||||
* @throws DataAccessException if something went wrong executing the query
|
||||
* @throws MappingException wrapping any reflection or data type conversion
|
||||
* exception that might have occurred while mapping records
|
||||
* @see DefaultRecordMapper
|
||||
*/
|
||||
<E> Optional<E> fetchOptionalInto(Class<? extends E> type) throws DataAccessException, MappingException;
|
||||
|
||||
/**
|
||||
* Fetch the next record into a custom mapper callback.
|
||||
* <p>
|
||||
* This will conveniently close the <code>Cursor</code>, after the last
|
||||
* <code>Record</code> was fetched.
|
||||
*
|
||||
* @param mapper The mapper callback
|
||||
* @return The custom mapped record
|
||||
* @throws DataAccessException if something went wrong executing the query
|
||||
*/
|
||||
<E> Optional<E> fetchOptional(RecordMapper<? super R, E> mapper) throws DataAccessException;
|
||||
|
||||
/**
|
||||
* Map the next resulting record onto a custom record.
|
||||
* <p>
|
||||
* This is the same as calling <code>fetchOne().into(table)</code>. See
|
||||
* {@link Record#into(Class)} for more details
|
||||
* <p>
|
||||
* The result and its contained records are attached to the original
|
||||
* {@link Configuration} by default. Use {@link Settings#isAttachRecords()}
|
||||
* to override this behaviour.
|
||||
* The resulting record is attached to the original {@link Configuration} by
|
||||
* default. Use {@link Settings#isAttachRecords()} to override this
|
||||
* behaviour.
|
||||
*
|
||||
* @param <Z> The generic table record type.
|
||||
* @param table The table type.
|
||||
@ -293,7 +359,8 @@ public interface Cursor<R extends Record> extends Iterable<R> {
|
||||
* @throws MappingException wrapping any reflection or data type conversion
|
||||
* exception that might have occurred while mapping records
|
||||
*/
|
||||
<Z extends Record> Result<Z> fetchInto(Table<Z> table) throws DataAccessException, MappingException;
|
||||
<Z extends Record> Optional<Z> fetchOptionalInto(Table<Z> table) throws DataAccessException, MappingException;
|
||||
/* [/java-8] */
|
||||
|
||||
/**
|
||||
* Explicitly close the underlying {@link PreparedStatement} and
|
||||
|
||||
@ -42,6 +42,7 @@ package org.jooq;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.jooq.conf.Settings;
|
||||
import org.jooq.exception.DataAccessException;
|
||||
@ -259,6 +260,22 @@ public interface DAO<R extends TableRecord<R>, P, T> {
|
||||
*/
|
||||
<Z> P fetchOne(Field<Z> field, Z value) throws DataAccessException;
|
||||
|
||||
/* [java-8] */
|
||||
/**
|
||||
* Find a unique record by a given field and a value.
|
||||
*
|
||||
* @param field The field to compare value against
|
||||
* @param value The accepted value
|
||||
* @return A record fulfilling <code>field = value</code>
|
||||
* @throws DataAccessException This exception is thrown
|
||||
* <ul>
|
||||
* <li>if something went wrong executing the query</li>
|
||||
* <li>if the query returned more than one value</li>
|
||||
* </ul>
|
||||
*/
|
||||
<Z> Optional<P> fetchOptional(Field<Z> field, Z value) throws DataAccessException;
|
||||
/* [/java-8] */
|
||||
|
||||
/**
|
||||
* Get the underlying table
|
||||
*/
|
||||
|
||||
@ -69,6 +69,7 @@ import java.sql.Statement;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
import javax.annotation.Generated;
|
||||
|
||||
@ -799,6 +800,96 @@ public interface DSLContext extends Scope {
|
||||
@PlainSQL
|
||||
Record fetchOne(String sql, QueryPart... parts) throws DataAccessException, TooManyRowsException;
|
||||
|
||||
/* [java-8] */
|
||||
/**
|
||||
* Execute a new query holding plain SQL.
|
||||
* <p>
|
||||
* Example (Postgres):
|
||||
* <p>
|
||||
* <code><pre>
|
||||
* String sql = "FETCH ALL IN \"<unnamed cursor 1>\"";</pre></code> Example
|
||||
* (SQLite):
|
||||
* <p>
|
||||
* <code><pre>
|
||||
* String sql = "pragma table_info('my_table')";</pre></code>
|
||||
* <p>
|
||||
* <b>NOTE</b>: When inserting plain SQL into jOOQ objects, you must
|
||||
* guarantee syntax integrity. You may also create the possibility of
|
||||
* malicious SQL injection. Be sure to properly use bind variables and/or
|
||||
* escape literals when concatenated into SQL clauses!
|
||||
*
|
||||
* @param sql The SQL
|
||||
* @return The results from the executed query
|
||||
* @throws DataAccessException if something went wrong executing the query
|
||||
* @throws TooManyRowsException if the query returned more than one record
|
||||
*/
|
||||
@Support
|
||||
@PlainSQL
|
||||
Optional<Record> fetchOptional(String sql) throws DataAccessException, TooManyRowsException;
|
||||
|
||||
/**
|
||||
* Execute a new query holding plain SQL.
|
||||
* <p>
|
||||
* There must be as many bind variables contained in the SQL, as passed in
|
||||
* the bindings parameter
|
||||
* <p>
|
||||
* Example (Postgres):
|
||||
* <p>
|
||||
* <code><pre>
|
||||
* String sql = "FETCH ALL IN \"<unnamed cursor 1>\"";</pre></code> Example
|
||||
* (SQLite):
|
||||
* <p>
|
||||
* <code><pre>
|
||||
* String sql = "pragma table_info('my_table')";</pre></code>
|
||||
* <p>
|
||||
* <b>NOTE</b>: When inserting plain SQL into jOOQ objects, you must
|
||||
* guarantee syntax integrity. You may also create the possibility of
|
||||
* malicious SQL injection. Be sure to properly use bind variables and/or
|
||||
* escape literals when concatenated into SQL clauses!
|
||||
*
|
||||
* @param sql The SQL
|
||||
* @param bindings The bindings
|
||||
* @return The results from the executed query
|
||||
* @throws DataAccessException if something went wrong executing the query
|
||||
* @throws TooManyRowsException if the query returned more than one record
|
||||
*/
|
||||
@Support
|
||||
@PlainSQL
|
||||
Optional<Record> fetchOptional(String sql, Object... bindings) throws DataAccessException, TooManyRowsException;
|
||||
|
||||
/**
|
||||
* Execute a new query holding plain SQL.
|
||||
* <p>
|
||||
* Unlike {@link #fetchOne(String, Object...)}, the SQL passed to this
|
||||
* method should not contain any bind variables. Instead, you can pass
|
||||
* {@link QueryPart} objects to the method which will be rendered at indexed
|
||||
* locations of your SQL string as such: <code><pre>
|
||||
* // The following query
|
||||
* fetchOne("select {0}, {1} from {2}", val(1), inline("test"), name("DUAL"));
|
||||
*
|
||||
* // Will execute this SQL on an Oracle database with RenderNameStyle.QUOTED:
|
||||
* select ?, 'test' from "DUAL"
|
||||
* </pre></code>
|
||||
* <p>
|
||||
* <b>NOTE</b>: When inserting plain SQL into jOOQ objects, you must
|
||||
* guarantee syntax integrity. You may also create the possibility of
|
||||
* malicious SQL injection. Be sure to properly use bind variables and/or
|
||||
* escape literals when concatenated into SQL clauses! One way to escape
|
||||
* literals is to use {@link DSL#name(String...)} and similar methods
|
||||
*
|
||||
* @param sql The SQL clause, containing {numbered placeholders} where query
|
||||
* parts can be injected
|
||||
* @param parts The {@link QueryPart} objects that are rendered at the
|
||||
* {numbered placeholder} locations
|
||||
* @return The results from the executed query
|
||||
* @throws DataAccessException if something went wrong executing the query
|
||||
* @throws TooManyRowsException if the query returned more than one record
|
||||
*/
|
||||
@Support
|
||||
@PlainSQL
|
||||
Optional<Record> fetchOptional(String sql, QueryPart... parts) throws DataAccessException, TooManyRowsException;
|
||||
/* [/java-8] */
|
||||
|
||||
/**
|
||||
* Execute a new query holding plain SQL.
|
||||
* <p>
|
||||
@ -896,6 +987,102 @@ public interface DSLContext extends Scope {
|
||||
@PlainSQL
|
||||
Object fetchValue(String sql, QueryPart... parts) throws DataAccessException, TooManyRowsException, InvalidResultException;
|
||||
|
||||
/* [java-8] */
|
||||
/**
|
||||
* Execute a new query holding plain SQL.
|
||||
* <p>
|
||||
* Example (Postgres):
|
||||
* <p>
|
||||
* <code><pre>
|
||||
* String sql = "FETCH ALL IN \"<unnamed cursor 1>\"";</pre></code> Example
|
||||
* (SQLite):
|
||||
* <p>
|
||||
* <code><pre>
|
||||
* String sql = "pragma table_info('my_table')";</pre></code>
|
||||
* <p>
|
||||
* <b>NOTE</b>: When inserting plain SQL into jOOQ objects, you must
|
||||
* guarantee syntax integrity. You may also create the possibility of
|
||||
* malicious SQL injection. Be sure to properly use bind variables and/or
|
||||
* escape literals when concatenated into SQL clauses!
|
||||
*
|
||||
* @param sql The SQL
|
||||
* @return The result value from the executed query
|
||||
* @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
|
||||
*/
|
||||
@Support
|
||||
@PlainSQL
|
||||
Optional<?> fetchOptionalValue(String sql) throws DataAccessException, TooManyRowsException, InvalidResultException;
|
||||
|
||||
/**
|
||||
* Execute a new query holding plain SQL.
|
||||
* <p>
|
||||
* There must be as many bind variables contained in the SQL, as passed in
|
||||
* the bindings parameter
|
||||
* <p>
|
||||
* Example (Postgres):
|
||||
* <p>
|
||||
* <code><pre>
|
||||
* String sql = "FETCH ALL IN \"<unnamed cursor 1>\"";</pre></code> Example
|
||||
* (SQLite):
|
||||
* <p>
|
||||
* <code><pre>
|
||||
* String sql = "pragma table_info('my_table')";</pre></code>
|
||||
* <p>
|
||||
* <b>NOTE</b>: When inserting plain SQL into jOOQ objects, you must
|
||||
* guarantee syntax integrity. You may also create the possibility of
|
||||
* malicious SQL injection. Be sure to properly use bind variables and/or
|
||||
* escape literals when concatenated into SQL clauses!
|
||||
*
|
||||
* @param sql The SQL
|
||||
* @param bindings The bindings
|
||||
* @return The results from the executed query
|
||||
* @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
|
||||
*/
|
||||
@Support
|
||||
@PlainSQL
|
||||
Optional<?> fetchOptionalValue(String sql, Object... bindings) throws DataAccessException, TooManyRowsException, InvalidResultException;
|
||||
|
||||
/**
|
||||
* Execute a new query holding plain SQL.
|
||||
* <p>
|
||||
* Unlike {@link #fetchValue(String, Object...)}, the SQL passed to this
|
||||
* method should not contain any bind variables. Instead, you can pass
|
||||
* {@link QueryPart} objects to the method which will be rendered at indexed
|
||||
* locations of your SQL string as such: <code><pre>
|
||||
* // The following query
|
||||
* fetchOne("select {0}, {1} from {2}", val(1), inline("test"), name("DUAL"));
|
||||
*
|
||||
* // Will execute this SQL on an Oracle database with RenderNameStyle.QUOTED:
|
||||
* select ?, 'test' from "DUAL"
|
||||
* </pre></code>
|
||||
* <p>
|
||||
* <b>NOTE</b>: When inserting plain SQL into jOOQ objects, you must
|
||||
* guarantee syntax integrity. You may also create the possibility of
|
||||
* malicious SQL injection. Be sure to properly use bind variables and/or
|
||||
* escape literals when concatenated into SQL clauses! One way to escape
|
||||
* literals is to use {@link DSL#name(String...)} and similar methods
|
||||
*
|
||||
* @param sql The SQL clause, containing {numbered placeholders} where query
|
||||
* parts can be injected
|
||||
* @param parts The {@link QueryPart} objects that are rendered at the
|
||||
* {numbered placeholder} locations
|
||||
* @return The results from the executed query
|
||||
* @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
|
||||
*/
|
||||
@Support
|
||||
@PlainSQL
|
||||
Optional<?> fetchOptionalValue(String sql, QueryPart... parts) throws DataAccessException, TooManyRowsException, InvalidResultException;
|
||||
/* [/java-8] */
|
||||
|
||||
/**
|
||||
* Execute a new query holding plain SQL.
|
||||
* <p>
|
||||
@ -1329,6 +1516,80 @@ public interface DSLContext extends Scope {
|
||||
@Support
|
||||
Record fetchOne(ResultSet rs, Class<?>... types) throws DataAccessException, TooManyRowsException;
|
||||
|
||||
/* [java-8] */
|
||||
/**
|
||||
* Fetch a record from a JDBC {@link ResultSet} and transform it to a jOOQ
|
||||
* {@link Record}.
|
||||
* <p>
|
||||
* This will internally fetch all records and throw an exception if there
|
||||
* was more than one resulting record.
|
||||
*
|
||||
* @param rs The JDBC ResultSet to fetch data from
|
||||
* @return The resulting jOOQ record
|
||||
* @throws DataAccessException if something went wrong executing the query
|
||||
* @throws TooManyRowsException if the query returned more than one record
|
||||
*/
|
||||
@Support
|
||||
Optional<Record> fetchOptional(ResultSet rs) throws DataAccessException, TooManyRowsException;
|
||||
|
||||
/**
|
||||
* Fetch a record from a JDBC {@link ResultSet} and transform it to a jOOQ
|
||||
* {@link Record}.
|
||||
* <p>
|
||||
* This will internally fetch all records and throw an exception if there
|
||||
* was more than one resulting record.
|
||||
* <p>
|
||||
* The additional <code>fields</code> argument is used by jOOQ to coerce
|
||||
* field names and data types to the desired output
|
||||
*
|
||||
* @param rs The JDBC ResultSet to fetch data from
|
||||
* @param fields The fields to use in the desired output
|
||||
* @return The resulting jOOQ record
|
||||
* @throws DataAccessException if something went wrong executing the query
|
||||
* @throws TooManyRowsException if the query returned more than one record
|
||||
*/
|
||||
@Support
|
||||
Optional<Record> fetchOptional(ResultSet rs, Field<?>... fields) throws DataAccessException, TooManyRowsException;
|
||||
|
||||
/**
|
||||
* Fetch a record from a JDBC {@link ResultSet} and transform it to a jOOQ
|
||||
* {@link Record}.
|
||||
* <p>
|
||||
* This will internally fetch all records and throw an exception if there
|
||||
* was more than one resulting record.
|
||||
* <p>
|
||||
* The additional <code>types</code> argument is used by jOOQ to coerce data
|
||||
* types to the desired output
|
||||
*
|
||||
* @param rs The JDBC ResultSet to fetch data from
|
||||
* @param types The data types to use in the desired output
|
||||
* @return The resulting jOOQ record
|
||||
* @throws DataAccessException if something went wrong executing the query
|
||||
* @throws TooManyRowsException if the query returned more than one record
|
||||
*/
|
||||
@Support
|
||||
Optional<Record> fetchOptional(ResultSet rs, DataType<?>... types) throws DataAccessException, TooManyRowsException;
|
||||
|
||||
/**
|
||||
* Fetch a record from a JDBC {@link ResultSet} and transform it to a jOOQ
|
||||
* {@link Record}.
|
||||
* <p>
|
||||
* This will internally fetch all records and throw an exception if there
|
||||
* was more than one resulting record.
|
||||
* <p>
|
||||
* The additional <code>types</code> argument is used by jOOQ to coerce data
|
||||
* types to the desired output
|
||||
*
|
||||
* @param rs The JDBC ResultSet to fetch data from
|
||||
* @param types The data types to use in the desired output
|
||||
* @return The resulting jOOQ record
|
||||
* @throws DataAccessException if something went wrong executing the query
|
||||
* @throws TooManyRowsException if the query returned more than one record
|
||||
*/
|
||||
@Support
|
||||
Optional<Record> fetchOptional(ResultSet rs, Class<?>... types) throws DataAccessException, TooManyRowsException;
|
||||
/* [/java-8] */
|
||||
|
||||
/**
|
||||
* Fetch a record from a JDBC {@link ResultSet} and return the only
|
||||
* contained value.
|
||||
@ -1409,6 +1670,88 @@ public interface DSLContext extends Scope {
|
||||
@Support
|
||||
<T> T fetchValue(ResultSet rs, Class<T> type) throws DataAccessException, TooManyRowsException, InvalidResultException;
|
||||
|
||||
/* [java-8] */
|
||||
/**
|
||||
* Fetch a record from a JDBC {@link ResultSet} and return the only
|
||||
* contained value.
|
||||
* <p>
|
||||
* This will internally fetch all records and throw an exception if there
|
||||
* was more than one resulting record.
|
||||
*
|
||||
* @param rs The JDBC ResultSet to fetch data from
|
||||
* @return The resulting 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
|
||||
*/
|
||||
@Support
|
||||
Optional<?> fetchOptionalValue(ResultSet rs) throws DataAccessException, TooManyRowsException, InvalidResultException;
|
||||
|
||||
/**
|
||||
* Fetch a record from a JDBC {@link ResultSet} and return the only
|
||||
* contained value.
|
||||
* <p>
|
||||
* This will internally fetch all records and throw an exception if there
|
||||
* was more than one resulting record.
|
||||
* <p>
|
||||
* The additional <code>field</code> argument is used by jOOQ to coerce
|
||||
* field names and data types to the desired output
|
||||
*
|
||||
* @param rs The JDBC ResultSet to fetch data from
|
||||
* @param field The field to use in the desired output
|
||||
* @return The resulting 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
|
||||
*/
|
||||
@Support
|
||||
<T> Optional<T> fetchOptionalValue(ResultSet rs, Field<T> field) throws DataAccessException, TooManyRowsException, InvalidResultException;
|
||||
|
||||
/**
|
||||
* Fetch a record from a JDBC {@link ResultSet} and return the only
|
||||
* contained value.
|
||||
* <p>
|
||||
* This will internally fetch all records and throw an exception if there
|
||||
* was more than one resulting record.
|
||||
* <p>
|
||||
* The additional <code>type</code> argument is used by jOOQ to coerce data
|
||||
* types to the desired output
|
||||
*
|
||||
* @param rs The JDBC ResultSet to fetch data from
|
||||
* @param type The data type to use in the desired output
|
||||
* @return The resulting 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
|
||||
*/
|
||||
@Support
|
||||
<T> Optional<T> fetchOptionalValue(ResultSet rs, DataType<T> type) throws DataAccessException, TooManyRowsException, InvalidResultException;
|
||||
|
||||
/**
|
||||
* Fetch a record from a JDBC {@link ResultSet} and return the only
|
||||
* contained value.
|
||||
* <p>
|
||||
* This will internally fetch all records and throw an exception if there
|
||||
* was more than one resulting record.
|
||||
* <p>
|
||||
* The additional <code>type</code> argument is used by jOOQ to coerce data
|
||||
* types to the desired output
|
||||
*
|
||||
* @param rs The JDBC ResultSet to fetch data from
|
||||
* @param type The data types to use in the desired output
|
||||
* @return The resulting 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
|
||||
*/
|
||||
@Support
|
||||
<T> Optional<T> fetchOptionalValue(ResultSet rs, Class<T> type) throws DataAccessException, TooManyRowsException, InvalidResultException;
|
||||
/* [/java-8] */
|
||||
|
||||
/**
|
||||
* Fetch a result from a JDBC {@link ResultSet} and return the only
|
||||
* contained column's values.
|
||||
@ -6105,6 +6448,20 @@ public interface DSLContext extends Scope {
|
||||
*/
|
||||
<R extends Record> R fetchOne(ResultQuery<R> query) throws DataAccessException, TooManyRowsException;
|
||||
|
||||
/* [java-8] */
|
||||
/**
|
||||
* Execute a {@link ResultQuery} in the context of this <code>DSLContext</code> and return
|
||||
* a record.
|
||||
*
|
||||
* @param query The query to execute
|
||||
* @return The record
|
||||
* @throws DataAccessException if something went wrong executing the query
|
||||
* @throws TooManyRowsException if the query returned more than one record
|
||||
* @see ResultQuery#fetchOptional()
|
||||
*/
|
||||
<R extends Record> Optional<R> fetchOptional(ResultQuery<R> query) throws DataAccessException, TooManyRowsException;
|
||||
/* [/java-8] */
|
||||
|
||||
/**
|
||||
* Execute a {@link ResultQuery} in the context of this
|
||||
* <code>DSLContext</code> and return a single value.
|
||||
@ -6116,7 +6473,23 @@ public interface DSLContext extends Scope {
|
||||
* @throws InvalidResultException if the query returned a record with more
|
||||
* than one value
|
||||
*/
|
||||
<T, R extends Record1<T>> T fetchValue(ResultQuery<R> query) throws DataAccessException, TooManyRowsException, InvalidResultException;
|
||||
<T, R extends Record1<T>> T fetchValue(ResultQuery<R> query)
|
||||
throws DataAccessException, TooManyRowsException, InvalidResultException;
|
||||
|
||||
/* [java-8] */
|
||||
/**
|
||||
* Execute a {@link ResultQuery} in the context of this
|
||||
* <code>DSLContext</code> and return a single value.
|
||||
*
|
||||
* @param query The query to execute
|
||||
* @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, R extends Record1<T>> Optional<T> fetchOptionalValue(ResultQuery<R> query) throws DataAccessException, TooManyRowsException, InvalidResultException;
|
||||
/* [/java-8] */
|
||||
|
||||
/**
|
||||
* Execute a {@link ResultQuery} in the context of this
|
||||
@ -6296,6 +6669,38 @@ public interface DSLContext extends Scope {
|
||||
@Support
|
||||
<R extends Record> R fetchOne(Table<R> table, Condition condition) throws DataAccessException, TooManyRowsException;
|
||||
|
||||
/* [java-8] */
|
||||
/**
|
||||
* Execute and return zero or one record for
|
||||
* <code><pre>SELECT * FROM [table]</pre></code>.
|
||||
* <p>
|
||||
* The resulting record is attached to this {@link Configuration} by
|
||||
* default. Use {@link Settings#isAttachRecords()} to override this
|
||||
* behaviour.
|
||||
*
|
||||
* @return The record
|
||||
* @throws DataAccessException if something went wrong executing the query
|
||||
* @throws TooManyRowsException if the query returned more than one record
|
||||
*/
|
||||
@Support
|
||||
<R extends Record> Optional<R> fetchOptional(Table<R> table) throws DataAccessException, TooManyRowsException;
|
||||
|
||||
/**
|
||||
* Execute and return zero or one record for
|
||||
* <code><pre>SELECT * FROM [table] WHERE [condition] </pre></code>.
|
||||
* <p>
|
||||
* The resulting record is attached to this {@link Configuration} by
|
||||
* default. Use {@link Settings#isAttachRecords()} to override this
|
||||
* behaviour.
|
||||
*
|
||||
* @return The record
|
||||
* @throws DataAccessException if something went wrong executing the query
|
||||
* @throws TooManyRowsException if the query returned more than one record
|
||||
*/
|
||||
@Support
|
||||
<R extends Record> Optional<R> fetchOptional(Table<R> table, Condition condition) throws DataAccessException, TooManyRowsException;
|
||||
/* [/java-8] */
|
||||
|
||||
/**
|
||||
* Execute and return zero or one record for
|
||||
* <code><pre>SELECT * FROM [table] LIMIT 1</pre></code>.
|
||||
|
||||
@ -44,6 +44,8 @@ package org.jooq;
|
||||
import static org.jooq.SQLDialect.FIREBIRD;
|
||||
import static org.jooq.SQLDialect.POSTGRES;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import org.jooq.exception.DataAccessException;
|
||||
|
||||
/**
|
||||
@ -71,7 +73,7 @@ public interface DeleteResultStep<R extends Record> extends Delete<R> {
|
||||
|
||||
/**
|
||||
* The result holding returned values as specified by the
|
||||
* {@link UpdateReturningStep}
|
||||
* {@link UpdateReturningStep}.
|
||||
*
|
||||
* @return The returned values as specified by the
|
||||
* {@link UpdateReturningStep}. Note:
|
||||
@ -89,7 +91,7 @@ public interface DeleteResultStep<R extends Record> extends Delete<R> {
|
||||
|
||||
/**
|
||||
* The record holding returned values as specified by the
|
||||
* {@link UpdateReturningStep}
|
||||
* {@link UpdateReturningStep}.
|
||||
*
|
||||
* @return The returned value as specified by the
|
||||
* {@link UpdateReturningStep}. This may return <code>null</code> in
|
||||
@ -100,4 +102,18 @@ public interface DeleteResultStep<R extends Record> extends Delete<R> {
|
||||
*/
|
||||
@Support({ FIREBIRD, POSTGRES })
|
||||
R fetchOne() throws DataAccessException;
|
||||
|
||||
/* [java-8] */
|
||||
/**
|
||||
* The record holding returned values as specified by the
|
||||
* {@link UpdateReturningStep}.
|
||||
*
|
||||
* @return The returned value as specified by the
|
||||
* {@link UpdateReturningStep}
|
||||
* @throws DataAccessException if something went wrong executing the query
|
||||
* @see UpdateQuery#getReturnedRecord()
|
||||
*/
|
||||
@Support({ FIREBIRD, POSTGRES })
|
||||
Optional<R> fetchOptional() throws DataAccessException;
|
||||
/* [/java-8] */
|
||||
}
|
||||
|
||||
@ -40,6 +40,8 @@
|
||||
*/
|
||||
package org.jooq;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import org.jooq.exception.DataAccessException;
|
||||
|
||||
/**
|
||||
@ -78,7 +80,7 @@ public interface InsertResultStep<R extends Record> extends Insert<R> {
|
||||
|
||||
/**
|
||||
* The result holding returned values as specified by the
|
||||
* {@link InsertReturningStep}
|
||||
* {@link InsertReturningStep}.
|
||||
*
|
||||
* @return The returned values as specified by the
|
||||
* {@link InsertReturningStep}. Note:
|
||||
@ -96,7 +98,7 @@ public interface InsertResultStep<R extends Record> extends Insert<R> {
|
||||
|
||||
/**
|
||||
* The record holding returned values as specified by the
|
||||
* {@link InsertReturningStep}
|
||||
* {@link InsertReturningStep}.
|
||||
*
|
||||
* @return The returned value as specified by the
|
||||
* {@link InsertReturningStep}. This may return <code>null</code> in
|
||||
@ -107,4 +109,18 @@ public interface InsertResultStep<R extends Record> extends Insert<R> {
|
||||
*/
|
||||
@Support
|
||||
R fetchOne() throws DataAccessException;
|
||||
|
||||
/* [java-8] */
|
||||
/**
|
||||
* The record holding returned values as specified by the
|
||||
* {@link InsertReturningStep}.
|
||||
*
|
||||
* @return The returned value as specified by the
|
||||
* {@link InsertReturningStep}
|
||||
* @throws DataAccessException if something went wrong executing the query
|
||||
* @see InsertQuery#getReturnedRecord()
|
||||
*/
|
||||
@Support
|
||||
Optional<R> fetchOptional() throws DataAccessException;
|
||||
/* [/java-8] */
|
||||
}
|
||||
|
||||
@ -48,6 +48,7 @@ import java.sql.Statement;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
|
||||
@ -625,6 +626,249 @@ public interface ResultQuery<R extends Record> extends Query, Iterable<R> {
|
||||
*/
|
||||
<Z extends Record> Z fetchOneInto(Table<Z> table) throws DataAccessException, TooManyRowsException;
|
||||
|
||||
/* [java-8] */
|
||||
/**
|
||||
* Execute the query and return at most one resulting value for a
|
||||
* field from the generated result.
|
||||
* <p>
|
||||
* This is the same as calling {@link #fetchOptional()} and then
|
||||
* {@link Record#getValue(Field)}
|
||||
*
|
||||
* @return The resulting value
|
||||
* @throws DataAccessException if something went wrong executing the query
|
||||
* @throws TooManyRowsException if the query returned more than one record
|
||||
*/
|
||||
<T> Optional<T> fetchOptional(Field<T> field) throws DataAccessException, TooManyRowsException;
|
||||
|
||||
/**
|
||||
* Execute the query and return at most one resulting value for a
|
||||
* field from the generated result.
|
||||
* <p>
|
||||
* This is the same as calling {@link #fetchOptional()} and then
|
||||
* {@link Record#getValue(Field, Class)}
|
||||
*
|
||||
* @return The resulting value
|
||||
* @throws DataAccessException if something went wrong executing the query
|
||||
* @throws TooManyRowsException if the query returned more than one record
|
||||
*/
|
||||
<T> Optional<T> fetchOptional(Field<?> field, Class<? extends T> type) throws DataAccessException, TooManyRowsException;
|
||||
|
||||
/**
|
||||
* Execute the query and return at most one resulting value for a
|
||||
* field from the generated result.
|
||||
* <p>
|
||||
* This is the same as calling {@link #fetchOptional()} and then
|
||||
* {@link Record#getValue(Field, Converter)}
|
||||
*
|
||||
* @return The resulting value
|
||||
* @throws DataAccessException if something went wrong executing the query
|
||||
* @throws TooManyRowsException if the query returned more than one record
|
||||
*/
|
||||
<T, U> Optional<U> fetchOptional(Field<T> field, Converter<? super T, U> converter) throws DataAccessException, TooManyRowsException;
|
||||
|
||||
/**
|
||||
* Execute the query and return at most one resulting value for a
|
||||
* field index from the generated result.
|
||||
* <p>
|
||||
* This is the same as calling {@link #fetchOptional()} and then
|
||||
* {@link Record#getValue(int)}
|
||||
*
|
||||
* @return The resulting value
|
||||
* @throws DataAccessException if something went wrong executing the query
|
||||
* @throws TooManyRowsException if the query returned more than one record
|
||||
*/
|
||||
Optional<?> fetchOptional(int fieldIndex) throws DataAccessException, TooManyRowsException;
|
||||
|
||||
/**
|
||||
* Execute the query and return at most one resulting value for a
|
||||
* field index from the generated result.
|
||||
* <p>
|
||||
* This is the same as calling {@link #fetchOptional()} and then
|
||||
* {@link Record#getValue(int, Class)}
|
||||
*
|
||||
* @return The resulting value
|
||||
* @throws DataAccessException if something went wrong executing the query
|
||||
* @throws TooManyRowsException if the query returned more than one record
|
||||
*/
|
||||
<T> Optional<T> fetchOptional(int fieldIndex, Class<? extends T> type) throws DataAccessException, TooManyRowsException;
|
||||
|
||||
/**
|
||||
* Execute the query and return at most one resulting value for a
|
||||
* field index from the generated result.
|
||||
* <p>
|
||||
* This is the same as calling {@link #fetchOptional()} and then
|
||||
* {@link Record#getValue(int, Converter)}
|
||||
*
|
||||
* @return The resulting value
|
||||
* @throws DataAccessException if something went wrong executing the query
|
||||
* @throws TooManyRowsException if the query returned more than one record
|
||||
*/
|
||||
<U> Optional<U> fetchOptional(int fieldIndex, Converter<?, U> converter) throws DataAccessException, TooManyRowsException;
|
||||
|
||||
/**
|
||||
* Execute the query and return at most one resulting value for a
|
||||
* field name from the generated result.
|
||||
* <p>
|
||||
* This is the same as calling {@link #fetchOptional()} and then
|
||||
* {@link Record#getValue(String)}
|
||||
*
|
||||
* @return The resulting value
|
||||
* @throws DataAccessException if something went wrong executing the query
|
||||
* @throws TooManyRowsException if the query returned more than one record
|
||||
*/
|
||||
Optional<?> fetchOptional(String fieldName) throws DataAccessException, TooManyRowsException;
|
||||
|
||||
/**
|
||||
* Execute the query and return at most one resulting value for a
|
||||
* field name from the generated result.
|
||||
* <p>
|
||||
* This is the same as calling {@link #fetchOptional()} and then
|
||||
* {@link Record#getValue(String, Class)}
|
||||
*
|
||||
* @return The resulting value
|
||||
* @throws DataAccessException if something went wrong executing the query
|
||||
* @throws TooManyRowsException if the query returned more than one record
|
||||
*/
|
||||
<T> Optional<T> fetchOptional(String fieldName, Class<? extends T> type) throws DataAccessException, TooManyRowsException;
|
||||
|
||||
/**
|
||||
* Execute the query and return at most one resulting value for a
|
||||
* field name from the generated result.
|
||||
* <p>
|
||||
* This is the same as calling {@link #fetchOptional()} and then
|
||||
* {@link Record#getValue(String, Converter)}
|
||||
*
|
||||
* @return The resulting value
|
||||
* @throws DataAccessException if something went wrong executing the query
|
||||
* @throws TooManyRowsException if the query returned more than one record
|
||||
*/
|
||||
<U> Optional<U> fetchOptional(String fieldName, Converter<?, U> converter) throws DataAccessException, TooManyRowsException;
|
||||
|
||||
/**
|
||||
* Execute the query and return at most one resulting value for a
|
||||
* field name from the generated result.
|
||||
* <p>
|
||||
* This is the same as calling {@link #fetchOptional()} and then
|
||||
* {@link Record#getValue(Name)}
|
||||
*
|
||||
* @return The resulting value
|
||||
* @throws DataAccessException if something went wrong executing the query
|
||||
* @throws TooManyRowsException if the query returned more than one record
|
||||
*/
|
||||
Optional<?> fetchOptional(Name fieldName) throws DataAccessException, TooManyRowsException;
|
||||
|
||||
/**
|
||||
* Execute the query and return at most one resulting value for a
|
||||
* field name from the generated result.
|
||||
* <p>
|
||||
* This is the same as calling {@link #fetchOptional()} and then
|
||||
* {@link Record#getValue(Name, Class)}
|
||||
*
|
||||
* @return The resulting value
|
||||
* @throws DataAccessException if something went wrong executing the query
|
||||
* @throws TooManyRowsException if the query returned more than one record
|
||||
*/
|
||||
<T> Optional<T> fetchOptional(Name fieldName, Class<? extends T> type) throws DataAccessException, TooManyRowsException;
|
||||
|
||||
/**
|
||||
* Execute the query and return at most one resulting value for a
|
||||
* field name from the generated result.
|
||||
* <p>
|
||||
* This is the same as calling {@link #fetchOptional()} and then
|
||||
* {@link Record#getValue(Name, Converter)}
|
||||
*
|
||||
* @return The resulting value
|
||||
* @throws DataAccessException if something went wrong executing the query
|
||||
* @throws TooManyRowsException if the query returned more than one record
|
||||
*/
|
||||
<U> Optional<U> fetchOptional(Name fieldName, Converter<?, U> converter) throws DataAccessException, TooManyRowsException;
|
||||
|
||||
/**
|
||||
* Execute the query and return at most one resulting record.
|
||||
* <p>
|
||||
* The resulting record is attached to the original {@link Configuration} by
|
||||
* default. Use {@link Settings#isAttachRecords()} to override this
|
||||
* behaviour.
|
||||
*
|
||||
* @return The resulting record
|
||||
* @throws DataAccessException if something went wrong executing the query
|
||||
* @throws TooManyRowsException if the query returned more than one record
|
||||
*/
|
||||
Optional<R> fetchOptional() throws DataAccessException, TooManyRowsException;
|
||||
|
||||
/**
|
||||
* Execute the query and return at most one resulting value into a
|
||||
* custom mapper callback.
|
||||
*
|
||||
* @return The custom mapped record
|
||||
* @throws DataAccessException if something went wrong executing the query
|
||||
* @throws TooManyRowsException if the query returned more than one record
|
||||
*/
|
||||
<E> Optional<E> fetchOptional(RecordMapper<? super R, E> mapper) throws DataAccessException, TooManyRowsException;
|
||||
|
||||
/**
|
||||
* Execute the query and return at most one resulting record as a name/value
|
||||
* map.
|
||||
*
|
||||
* @return The resulting record
|
||||
* @throws DataAccessException if something went wrong executing the query
|
||||
* @throws TooManyRowsException if the query returned more than one record
|
||||
* @see Result#intoMaps()
|
||||
* @see Record#intoMap()
|
||||
*/
|
||||
Optional<Map<String, Object>> fetchOptionalMap() throws DataAccessException, TooManyRowsException;
|
||||
|
||||
/**
|
||||
* Execute the query and return at most one resulting record as an array.
|
||||
*
|
||||
* @return The resulting record
|
||||
* @throws DataAccessException if something went wrong executing the query
|
||||
* @throws TooManyRowsException if the query returned more than one record
|
||||
*/
|
||||
Optional<Object[]> fetchOptionalArray() throws DataAccessException, TooManyRowsException;
|
||||
|
||||
/**
|
||||
* Map resulting records onto a custom type.
|
||||
* <p>
|
||||
* This is the same as calling <code><pre>
|
||||
* Optional<E> result = q.fetchOptional().map(r -> r.into(type));
|
||||
* </pre></code>. See {@link Record#into(Class)} for more details
|
||||
*
|
||||
* @param <E> The generic entity type.
|
||||
* @param type The entity type.
|
||||
* @return The resulting record
|
||||
* @see Record#into(Class)
|
||||
* @see Result#into(Class)
|
||||
* @throws DataAccessException if something went wrong executing the query
|
||||
* @throws MappingException wrapping any reflection or data type conversion
|
||||
* exception that might have occurred while mapping records
|
||||
* @throws TooManyRowsException if the query returned more than one record
|
||||
* @see DefaultRecordMapper
|
||||
*/
|
||||
<E> Optional<E> fetchOptionalInto(Class<? extends E> type) throws DataAccessException, MappingException, TooManyRowsException;
|
||||
|
||||
/**
|
||||
* Map resulting records onto a custom record.
|
||||
* <p>
|
||||
* This is the same as calling <code><pre>
|
||||
* Optional<Z> result = q.fetchOptional().map(r -> r.into(table));
|
||||
* </pre></code>. See {@link Record#into(Table)} for more details
|
||||
* <p>
|
||||
* The resulting record is attached to the original {@link Configuration} by
|
||||
* default. Use {@link Settings#isAttachRecords()} to override this
|
||||
* behaviour.
|
||||
*
|
||||
* @param <Z> The generic table record type.
|
||||
* @param table The table type.
|
||||
* @return The resulting record
|
||||
* @see Record#into(Table)
|
||||
* @see Result#into(Table)
|
||||
* @throws DataAccessException if something went wrong executing the query
|
||||
* @throws TooManyRowsException if the query returned more than one record
|
||||
*/
|
||||
<Z extends Record> Optional<Z> fetchOptionalInto(Table<Z> table) throws DataAccessException, TooManyRowsException;
|
||||
/* [/java-8] */
|
||||
|
||||
/**
|
||||
* Execute the query and return at most one resulting value for a
|
||||
* field from the generated result.
|
||||
|
||||
@ -44,6 +44,8 @@ package org.jooq;
|
||||
import static org.jooq.SQLDialect.FIREBIRD;
|
||||
import static org.jooq.SQLDialect.POSTGRES;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import org.jooq.exception.DataAccessException;
|
||||
|
||||
/**
|
||||
@ -74,7 +76,7 @@ public interface UpdateResultStep<R extends Record> extends Update<R> {
|
||||
|
||||
/**
|
||||
* The result holding returned values as specified by the
|
||||
* {@link UpdateReturningStep}
|
||||
* {@link UpdateReturningStep}.
|
||||
*
|
||||
* @return The returned values as specified by the
|
||||
* {@link UpdateReturningStep}. Note:
|
||||
@ -92,7 +94,7 @@ public interface UpdateResultStep<R extends Record> extends Update<R> {
|
||||
|
||||
/**
|
||||
* The record holding returned values as specified by the
|
||||
* {@link UpdateReturningStep}
|
||||
* {@link UpdateReturningStep}.
|
||||
*
|
||||
* @return The returned value as specified by the
|
||||
* {@link UpdateReturningStep}. This may return <code>null</code> in
|
||||
@ -103,4 +105,18 @@ public interface UpdateResultStep<R extends Record> extends Update<R> {
|
||||
*/
|
||||
@Support({ FIREBIRD, POSTGRES })
|
||||
R fetchOne() throws DataAccessException;
|
||||
|
||||
/* [java-8] */
|
||||
/**
|
||||
* The record holding returned values as specified by the
|
||||
* {@link UpdateReturningStep}.
|
||||
*
|
||||
* @return The returned value as specified by the
|
||||
* {@link UpdateReturningStep}.
|
||||
* @throws DataAccessException if something went wrong executing the query
|
||||
* @see UpdateQuery#getReturnedRecord()
|
||||
*/
|
||||
@Support({ FIREBIRD, POSTGRES })
|
||||
Optional<R> fetchOptional() throws DataAccessException;
|
||||
/* [/java-8] */
|
||||
}
|
||||
|
||||
@ -58,6 +58,7 @@ import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
@ -508,6 +509,98 @@ abstract class AbstractResultQuery<R extends Record> extends AbstractQuery imple
|
||||
return record == null ? null : record.into(table);
|
||||
}
|
||||
|
||||
/* [java-8] */
|
||||
@Override
|
||||
public final <T> Optional<T> fetchOptional(Field<T> field) {
|
||||
return Optional.ofNullable(fetchOne(field));
|
||||
}
|
||||
|
||||
@Override
|
||||
public final <T> Optional<T> fetchOptional(Field<?> field, Class<? extends T> type) {
|
||||
return Optional.ofNullable(fetchOne(field, type));
|
||||
}
|
||||
|
||||
@Override
|
||||
public final <T, U> Optional<U> fetchOptional(Field<T> field, Converter<? super T, U> converter) {
|
||||
return Optional.ofNullable(fetchOne(field, converter));
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Optional<?> fetchOptional(int fieldIndex) {
|
||||
return Optional.ofNullable(fetchOne(fieldIndex));
|
||||
}
|
||||
|
||||
@Override
|
||||
public final <T> Optional<T> fetchOptional(int fieldIndex, Class<? extends T> type) {
|
||||
return Optional.ofNullable(fetchOne(fieldIndex, type));
|
||||
}
|
||||
|
||||
@Override
|
||||
public final <U> Optional<U> fetchOptional(int fieldIndex, Converter<?, U> converter) {
|
||||
return Optional.ofNullable(fetchOne(fieldIndex, converter));
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Optional<?> fetchOptional(String fieldName) {
|
||||
return Optional.ofNullable(fetchOne(fieldName));
|
||||
}
|
||||
|
||||
@Override
|
||||
public final <T> Optional<T> fetchOptional(String fieldName, Class<? extends T> type) {
|
||||
return Optional.ofNullable(fetchOne(fieldName, type));
|
||||
}
|
||||
|
||||
@Override
|
||||
public final <U> Optional<U> fetchOptional(String fieldName, Converter<?, U> converter) {
|
||||
return Optional.ofNullable(fetchOne(fieldName, converter));
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Optional<?> fetchOptional(Name fieldName) {
|
||||
return Optional.ofNullable(fetchOne(fieldName));
|
||||
}
|
||||
|
||||
@Override
|
||||
public final <T> Optional<T> fetchOptional(Name fieldName, Class<? extends T> type) {
|
||||
return Optional.ofNullable(fetchOne(fieldName, type));
|
||||
}
|
||||
|
||||
@Override
|
||||
public final <U> Optional<U> fetchOptional(Name fieldName, Converter<?, U> converter) {
|
||||
return Optional.ofNullable(fetchOne(fieldName, converter));
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Optional<R> fetchOptional() {
|
||||
return Optional.ofNullable(fetchOne());
|
||||
}
|
||||
|
||||
@Override
|
||||
public final <E> Optional<E> fetchOptional(RecordMapper<? super R, E> mapper) {
|
||||
return Optional.ofNullable(fetchOne(mapper));
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Optional<Map<String, Object>> fetchOptionalMap() {
|
||||
return Optional.ofNullable(fetchOneMap());
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Optional<Object[]> fetchOptionalArray() {
|
||||
return Optional.ofNullable(fetchOneArray());
|
||||
}
|
||||
|
||||
@Override
|
||||
public final <E> Optional<E> fetchOptionalInto(Class<? extends E> type) {
|
||||
return Optional.ofNullable(fetchOneInto(type));
|
||||
}
|
||||
|
||||
@Override
|
||||
public final <Z extends Record> Optional<Z> fetchOptionalInto(Table<Z> table) {
|
||||
return Optional.ofNullable(fetchOneInto(table));
|
||||
}
|
||||
/* [/java-8] */
|
||||
|
||||
@Override
|
||||
public final <T> T fetchAny(Field<T> field) {
|
||||
R record = fetchAny();
|
||||
|
||||
@ -68,6 +68,7 @@ import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.jooq.BindingGetResultSetContext;
|
||||
import org.jooq.Cursor;
|
||||
@ -83,6 +84,7 @@ import org.jooq.Result;
|
||||
import org.jooq.Row;
|
||||
import org.jooq.Table;
|
||||
import org.jooq.exception.ControlFlowSignal;
|
||||
import org.jooq.exception.DataAccessException;
|
||||
import org.jooq.tools.JooqLogger;
|
||||
import org.jooq.tools.jdbc.JDBC41ResultSet;
|
||||
import org.jooq.tools.jdbc.JDBCUtils;
|
||||
@ -202,6 +204,28 @@ class CursorImpl<R extends Record> implements Cursor<R> {
|
||||
return null;
|
||||
}
|
||||
|
||||
/* [java-8] */
|
||||
@Override
|
||||
public final Optional<R> fetchOptional() throws DataAccessException {
|
||||
return Optional.ofNullable(fetchOne());
|
||||
}
|
||||
|
||||
@Override
|
||||
public final <E> Optional<E> fetchOptionalInto(Class<? extends E> type) {
|
||||
return Optional.ofNullable(fetchOneInto(type));
|
||||
}
|
||||
|
||||
@Override
|
||||
public final <E> Optional<E> fetchOptional(RecordMapper<? super R, E> mapper) {
|
||||
return Optional.ofNullable(fetchOne(mapper));
|
||||
}
|
||||
|
||||
@Override
|
||||
public final <Z extends Record> Optional<Z> fetchOptionalInto(Table<Z> table) {
|
||||
return Optional.ofNullable(fetchOneInto(table));
|
||||
}
|
||||
/* [/java-8] */
|
||||
|
||||
@Override
|
||||
public final Result<R> fetch(int number) {
|
||||
// [#1157] This invokes listener.fetchStart(ctx), which has to be called
|
||||
|
||||
@ -69,6 +69,7 @@ import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Optional;
|
||||
|
||||
import javax.annotation.Generated;
|
||||
import javax.sql.DataSource;
|
||||
@ -551,6 +552,23 @@ public class DefaultDSLContext extends AbstractScope implements DSLContext, Seri
|
||||
return resultQuery(sql, parts).fetchOne();
|
||||
}
|
||||
|
||||
/* [java-8] */
|
||||
@Override
|
||||
public Optional<Record> fetchOptional(String sql) {
|
||||
return Optional.ofNullable(fetchOne(sql));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<Record> fetchOptional(String sql, Object... bindings) {
|
||||
return Optional.ofNullable(fetchOne(sql, bindings));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<Record> fetchOptional(String sql, QueryPart... parts) {
|
||||
return Optional.ofNullable(fetchOne(sql, parts));
|
||||
}
|
||||
/* [/java-8] */
|
||||
|
||||
@Override
|
||||
public Object fetchValue(String sql) {
|
||||
return fetchValue((ResultQuery) resultQuery(sql));
|
||||
@ -566,6 +584,23 @@ public class DefaultDSLContext extends AbstractScope implements DSLContext, Seri
|
||||
return fetchValue((ResultQuery) resultQuery(sql, parts));
|
||||
}
|
||||
|
||||
/* [java-8] */
|
||||
@Override
|
||||
public Optional<?> fetchOptionalValue(String sql) {
|
||||
return Optional.ofNullable(fetchValue(sql));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<?> fetchOptionalValue(String sql, Object... bindings) {
|
||||
return Optional.ofNullable(fetchValue(sql, bindings));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<?> fetchOptionalValue(String sql, QueryPart... parts) {
|
||||
return Optional.ofNullable(fetchValue(sql, parts));
|
||||
}
|
||||
/* [/java-8] */
|
||||
|
||||
@Override
|
||||
public List<?> fetchValues(String sql) {
|
||||
return fetchValues((ResultQuery) resultQuery(sql));
|
||||
@ -655,6 +690,28 @@ public class DefaultDSLContext extends AbstractScope implements DSLContext, Seri
|
||||
return Utils.fetchOne(fetchLazy(rs, types));
|
||||
}
|
||||
|
||||
/* [java-8] */
|
||||
@Override
|
||||
public Optional<Record> fetchOptional(ResultSet rs) {
|
||||
return Optional.ofNullable(fetchOne(rs));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<Record> fetchOptional(ResultSet rs, Field<?>... fields) {
|
||||
return Optional.ofNullable(fetchOne(rs, fields));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<Record> fetchOptional(ResultSet rs, DataType<?>... types) {
|
||||
return Optional.ofNullable(fetchOne(rs, types));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<Record> fetchOptional(ResultSet rs, Class<?>... types) {
|
||||
return Optional.ofNullable(fetchOne(rs, types));
|
||||
}
|
||||
/* [/java-8] */
|
||||
|
||||
@Override
|
||||
public Object fetchValue(ResultSet rs) {
|
||||
return value1((Record1) fetchOne(rs));
|
||||
@ -675,6 +732,28 @@ public class DefaultDSLContext extends AbstractScope implements DSLContext, Seri
|
||||
return (T) value1((Record1) fetchOne(rs, type));
|
||||
}
|
||||
|
||||
/* [java-8] */
|
||||
@Override
|
||||
public Optional<?> fetchOptionalValue(ResultSet rs) {
|
||||
return Optional.ofNullable(fetchValue(rs));
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> Optional<T> fetchOptionalValue(ResultSet rs, Field<T> field) {
|
||||
return Optional.ofNullable(fetchValue(rs, field));
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> Optional<T> fetchOptionalValue(ResultSet rs, DataType<T> type) {
|
||||
return Optional.ofNullable(fetchValue(rs, type));
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> Optional<T> fetchOptionalValue(ResultSet rs, Class<T> type) {
|
||||
return Optional.ofNullable(fetchValue(rs, type));
|
||||
}
|
||||
/* [/java-8] */
|
||||
|
||||
@Override
|
||||
public List<?> fetchValues(ResultSet rs) {
|
||||
return fetch(rs).getValues(0);
|
||||
@ -2323,6 +2402,13 @@ public class DefaultDSLContext extends AbstractScope implements DSLContext, Seri
|
||||
}
|
||||
}
|
||||
|
||||
/* [java-8] */
|
||||
@Override
|
||||
public <R extends Record> Optional<R> fetchOptional(ResultQuery<R> query) {
|
||||
return Optional.ofNullable(fetchOne(query));
|
||||
}
|
||||
/* [/java-8] */
|
||||
|
||||
@Override
|
||||
public <T, R extends Record1<T>> T fetchValue(ResultQuery<R> query) {
|
||||
final Configuration previous = Utils.getConfiguration(query);
|
||||
@ -2336,6 +2422,13 @@ public class DefaultDSLContext extends AbstractScope implements DSLContext, Seri
|
||||
}
|
||||
}
|
||||
|
||||
/* [java-8] */
|
||||
@Override
|
||||
public <T, R extends Record1<T>> Optional<T> fetchOptionalValue(ResultQuery<R> query) {
|
||||
return Optional.ofNullable(fetchValue(query));
|
||||
}
|
||||
/* [/java-8] */
|
||||
|
||||
@Override
|
||||
public <T, R extends Record1<T>> List<T> fetchValues(ResultQuery<R> query) {
|
||||
return (List) fetch(query).getValues(0);
|
||||
@ -2423,6 +2516,18 @@ public class DefaultDSLContext extends AbstractScope implements DSLContext, Seri
|
||||
return Utils.fetchOne(fetchLazy(table, condition));
|
||||
}
|
||||
|
||||
/* [java-8] */
|
||||
@Override
|
||||
public <R extends Record> Optional<R> fetchOptional(Table<R> table) {
|
||||
return Optional.ofNullable(fetchOne(table));
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R extends Record> Optional<R> fetchOptional(Table<R> table, Condition condition) {
|
||||
return Optional.ofNullable(fetchOne(table, condition));
|
||||
}
|
||||
/* [/java-8] */
|
||||
|
||||
@Override
|
||||
public <R extends Record> R fetchAny(Table<R> table) {
|
||||
return Utils.filterOne(selectFrom(table).limit(1).fetch());
|
||||
|
||||
@ -45,6 +45,7 @@ import static org.jooq.impl.DSL.exists;
|
||||
import static org.jooq.impl.DSL.notExists;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.jooq.Condition;
|
||||
import org.jooq.Configuration;
|
||||
@ -243,4 +244,9 @@ class DeleteImpl<R extends Record>
|
||||
getDelegate().execute();
|
||||
return getDelegate().getReturnedRecord();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Optional<R> fetchOptional() {
|
||||
return Optional.ofNullable(fetchOne());
|
||||
}
|
||||
}
|
||||
|
||||
@ -44,6 +44,7 @@ import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
import javax.annotation.Generated;
|
||||
|
||||
@ -663,4 +664,9 @@ class InsertImpl<R extends Record, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11,
|
||||
getDelegate().execute();
|
||||
return getDelegate().getReturnedRecord();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Optional<R> fetchOptional() {
|
||||
return Optional.ofNullable(fetchOne());
|
||||
}
|
||||
}
|
||||
|
||||
@ -51,6 +51,7 @@ import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
|
||||
@ -2524,6 +2525,96 @@ class SelectImpl<R extends Record, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11,
|
||||
return getDelegate().fetchOneInto(table);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final <T> Optional<T> fetchOptional(Field<T> field) {
|
||||
return getDelegate().fetchOptional(field);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final <T> Optional<T> fetchOptional(Field<?> field, Class<? extends T> type) {
|
||||
return getDelegate().fetchOptional(field, type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final <T, U> Optional<U> fetchOptional(Field<T> field, Converter<? super T, U> converter) {
|
||||
return getDelegate().fetchOptional(field, converter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Optional<?> fetchOptional(int fieldIndex) {
|
||||
return getDelegate().fetchOptional(fieldIndex);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final <T> Optional<T> fetchOptional(int fieldIndex, Class<? extends T> type) {
|
||||
return getDelegate().fetchOptional(fieldIndex, type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final <U> Optional<U> fetchOptional(int fieldIndex, Converter<?, U> converter) {
|
||||
return getDelegate().fetchOptional(fieldIndex, converter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Optional<?> fetchOptional(String fieldName) {
|
||||
return getDelegate().fetchOptional(fieldName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final <T> Optional<T> fetchOptional(String fieldName, Class<? extends T> type) {
|
||||
return getDelegate().fetchOptional(fieldName, type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final <U> Optional<U> fetchOptional(String fieldName, Converter<?, U> converter) {
|
||||
return getDelegate().fetchOptional(fieldName, converter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Optional<?> fetchOptional(Name fieldName) {
|
||||
return getDelegate().fetchOptional(fieldName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final <T> Optional<T> fetchOptional(Name fieldName, Class<? extends T> type) {
|
||||
return getDelegate().fetchOptional(fieldName, type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final <U> Optional<U> fetchOptional(Name fieldName, Converter<?, U> converter) {
|
||||
return getDelegate().fetchOptional(fieldName, converter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Optional<R> fetchOptional() {
|
||||
return getDelegate().fetchOptional();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final <E> Optional<E> fetchOptional(RecordMapper<? super R, E> mapper) {
|
||||
return getDelegate().fetchOptional(mapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Optional<Map<String, Object>> fetchOptionalMap() {
|
||||
return getDelegate().fetchOptionalMap();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Optional<Object[]> fetchOptionalArray() {
|
||||
return getDelegate().fetchOptionalArray();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final <E> Optional<E> fetchOptionalInto(Class<? extends E> type) {
|
||||
return getDelegate().fetchOptionalInto(type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final <Z extends Record> Optional<Z> fetchOptionalInto(Table<Z> table) {
|
||||
return getDelegate().fetchOptionalInto(table);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final <T> T fetchAny(Field<T> field) {
|
||||
return getDelegate().fetchAny(field);
|
||||
|
||||
@ -47,6 +47,7 @@ import static org.jooq.impl.DSL.table;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
import javax.annotation.Generated;
|
||||
|
||||
@ -672,4 +673,9 @@ final class UpdateImpl<R extends Record>
|
||||
getDelegate().execute();
|
||||
return getDelegate().getReturnedRecord();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Optional<R> fetchOptional() {
|
||||
return Optional.ofNullable(fetchOne());
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user