[jOOQ/jOOQ#11902] Deprecate RecordHandler

This commit is contained in:
Lukas Eder 2021-05-19 14:25:17 +02:00
parent 8d39ea9f3f
commit 9cb8781445
8 changed files with 31 additions and 33 deletions

View File

@ -43,6 +43,7 @@ import java.sql.Statement;
import java.util.Iterator;
import java.util.List;
import java.util.Optional;
import java.util.function.Consumer;
import java.util.stream.Collector;
import java.util.stream.Stream;
@ -146,7 +147,10 @@ public interface Cursor<R extends Record> extends Fields, Iterable<R>, Formattab
* @param handler The handler callback
* @return Convenience result, returning the parameter handler itself
* @throws DataAccessException if something went wrong executing the query
* @deprecated - 3.15.0 - [#11902] - Use {@link Iterable#forEach(Consumer)}
* based methods, instead.
*/
@Deprecated
@NotNull
<H extends RecordHandler<? super R>> H fetchInto(H handler) throws DataAccessException;
@ -208,6 +212,8 @@ public interface Cursor<R extends Record> extends Fields, Iterable<R>, Formattab
/**
* @deprecated - 3.10 - [#6363] - Use {@link #fetchNextInto(RecordHandler)} instead.
* @deprecated - 3.15.0 - [#11902] - Use {@link Iterable#forEach(Consumer)}
* based methods, instead.
*/
@NotNull
@Deprecated
@ -257,7 +263,10 @@ public interface Cursor<R extends Record> extends Fields, Iterable<R>, Formattab
* @param handler The handler callback
* @return Convenience result, returning the parameter handler itself
* @throws DataAccessException if something went wrong executing the query
* @deprecated - 3.15.0 - [#11902] - Use {@link Iterable#forEach(Consumer)}
* based methods, instead.
*/
@Deprecated
@NotNull
<H extends RecordHandler<? super R>> H fetchNextInto(H handler) throws DataAccessException;

View File

@ -37,18 +37,27 @@
*/
package org.jooq;
import java.util.function.Consumer;
/**
* A <code>RecordHandler</code> is a handler that can receive {@link Record}
* objects, when fetching data from the database.
*
* @author Lukas Eder
* @deprecated - 3.15.0 - [#11902] - Use {@link Iterable#forEach(Consumer)}
* based methods, instead.
*/
@Deprecated
@FunctionalInterface
public interface RecordHandler<R extends Record> {
public interface RecordHandler<R extends Record> extends Consumer<R> {
/**
* A callback method indicating that the next record has been fetched.
*/
void next(R record);
@Override
default void accept(R record) {
next(record);
}
}

View File

@ -43,6 +43,7 @@ import java.sql.Statement;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.function.Consumer;
import java.util.stream.Collector;
import java.util.stream.Stream;
@ -2816,7 +2817,10 @@ public interface Result<R extends Record> extends Fields, List<R>, Attachable, F
*
* @param handler The handler callback
* @return Convenience result, returning the parameter handler itself
* @deprecated - 3.15.0 - [#11902] - Use {@link Iterable#forEach(Consumer)}
* based methods, instead.
*/
@Deprecated
@NotNull
<H extends RecordHandler<? super R>> H into(H handler);

View File

@ -4188,7 +4188,10 @@ public interface ResultQuery<R extends Record> extends Query, Iterable<R>, Publi
* @param handler The handler callback
* @return Convenience result, returning the parameter handler itself
* @throws DataAccessException if something went wrong executing the query
* @deprecated - 3.15.0 - [#11902] - Use {@link Iterable#forEach(Consumer)}
* based methods, instead.
*/
@Deprecated
@NotNull
<H extends RecordHandler<? super R>> H fetchInto(H handler) throws DataAccessException;

View File

@ -185,9 +185,7 @@ abstract class AbstractCursor<R extends Record> extends AbstractResult<R> implem
@Override
public final <H extends RecordHandler<? super R>> H fetchInto(H handler) {
while (hasNext())
fetchNextInto(handler);
forEach(handler);
return handler;
}

View File

@ -13333,10 +13333,6 @@ public class DSL {
* <td>Fetch records into a custom POJO (optionally annotated with JPA
* annotations)</td>
* </tr>
* <tr>
* <td> {@link ResultQuery#fetchInto(RecordHandler)}</td>
* <td>Fetch records into a custom callback (similar to Spring's RowMapper)</td>
* </tr>
* </table>
* <p>
* Example (Postgres):
@ -13382,10 +13378,6 @@ public class DSL {
* <td>Fetch records into a custom POJO (optionally annotated with JPA
* annotations)</td>
* </tr>
* <tr>
* <td> {@link ResultQuery#fetchInto(RecordHandler)}</td>
* <td>Fetch records into a custom callback (similar to Spring's RowMapper)</td>
* </tr>
* </table>
* <p>
* Example (Postgres):
@ -13432,10 +13424,6 @@ public class DSL {
* <td>Fetch records into a custom POJO (optionally annotated with JPA
* annotations)</td>
* </tr>
* <tr>
* <td> {@link ResultQuery#fetchInto(RecordHandler)}</td>
* <td>Fetch records into a custom callback (similar to Spring's RowMapper)</td>
* </tr>
* </table>
* <p>
* Example (Postgres):

View File

@ -960,9 +960,7 @@ final class ResultImpl<R extends Record> extends AbstractResult<R> implements Re
@Override
public final <H extends RecordHandler<? super R>> H into(H handler) {
for (R record : this)
handler.next(record);
forEach(handler);
return handler;
}

View File

@ -311,21 +311,9 @@ interface ResultQueryTrait<R extends Record> extends QueryPartInternal, ResultQu
if (fetchIntermediateResult(Tools.configuration(this)))
return fetch().stream();
AtomicReference<Cursor<R>> r = new AtomicReference<>();
// [#11895] Don't use the Stream.of(1).flatMap(i -> fetchLazy().stream())
// trick, because flatMap() will consume the entire result set
return StreamSupport.stream(
() -> {
Cursor<R> c = fetchLazy();
r.set(c);
return c.spliterator();
},
Spliterator.IMMUTABLE | Spliterator.NONNULL | Spliterator.ORDERED,
false
).onClose(() -> {
safeClose(r.get());
});
return fetchLazy().stream();
}
@Override
@ -1406,7 +1394,8 @@ interface ResultQueryTrait<R extends Record> extends QueryPartInternal, ResultQu
@Override
default <H extends RecordHandler<? super R>> H fetchInto(H handler) {
return fetch().into(handler);
forEach(handler);
return handler;
}
@Override