Skip to content

Commit

Permalink
[#101] Correct annotations in SQLResultAdapter
Browse files Browse the repository at this point in the history
  • Loading branch information
zero88 committed Apr 10, 2022
1 parent 7a3a987 commit 32eac44
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ private void tweakDSLSetting() {
}

@Override
public <T, R> Future<R> execute(@NotNull Query query, @NotNull SQLResultAdapter<T, R> adapter) {
public <T, R> Future<@Nullable R> execute(@NotNull Query query, @NotNull SQLResultAdapter<T, R> adapter) {
return sqlClient().preparedQuery(preparedQuery().sql(dsl().configuration(), query))
.execute(preparedQuery().bindValues(query, typeMapperRegistry()))
.map(rs -> adapter.collect(rs, resultCollector(), dsl(), typeMapperRegistry()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.util.List;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jooq.DSLContext;
import org.jooq.Field;
import org.jooq.Record;
Expand All @@ -29,7 +30,7 @@
*/
public interface SQLResultAdapter<T, R> extends HasStrategy {

@SuppressWarnings({"rawtypes", "unchecked"})
@SuppressWarnings({ "rawtypes", "unchecked" })
static IdentityCollectorPart<JsonRecord<?>> byJson() {
return new IdentityCollectorPart<>((dsl, queryTbl) -> JsonRecord.create((TableLike<TableRecord>) queryTbl));
}
Expand Down Expand Up @@ -71,8 +72,8 @@ static <R extends Record, T extends TableLike<R>> IdentityCollectorPart<R> byTab
* @return an expected result
* @see DataTypeMapperRegistry
*/
@NotNull <RS> R collect(@NotNull RS resultSet, @NotNull SQLResultCollector<RS> collector, @NotNull DSLContext dsl,
@NotNull DataTypeMapperRegistry registry);
<RS> @Nullable R collect(@NotNull RS resultSet, @NotNull SQLResultCollector<RS> collector, @NotNull DSLContext dsl,
@NotNull DataTypeMapperRegistry registry);

/**
* Indicates select many row
Expand All @@ -84,7 +85,7 @@ interface SQLResultListAdapter<T, R> extends SQLResultAdapter<T, List<R>> {

@Override
@NotNull <RS> List<R> collect(@NotNull RS resultSet, @NotNull SQLResultCollector<RS> collector,
@NotNull DSLContext dsl, @NotNull DataTypeMapperRegistry registry);
@NotNull DSLContext dsl, @NotNull DataTypeMapperRegistry registry);

@Override
default @NotNull SelectStrategy strategy() {
Expand All @@ -107,8 +108,8 @@ interface SQLResultOneAdapter<T, R> extends SQLResultAdapter<T, R> {
}

@Override
@NotNull <RS> R collect(@NotNull RS resultSet, @NotNull SQLResultCollector<RS> collector,
@NotNull DSLContext dsl, @NotNull DataTypeMapperRegistry registry);
<RS> @Nullable R collect(@NotNull RS resultSet, @NotNull SQLResultCollector<RS> collector,
@NotNull DSLContext dsl, @NotNull DataTypeMapperRegistry registry);

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public SelectCount(@NotNull TableLike<Record1<Integer>> table) {
}

@Override
public <RS> @NotNull Integer collect(@NotNull RS resultSet, @NotNull SQLResultCollector<RS> collector,
public @NotNull <RS> Integer collect(@NotNull RS resultSet, @NotNull SQLResultCollector<RS> collector,
@NotNull DSLContext dsl, @NotNull DataTypeMapperRegistry registry) {
final SQLCollectorPart<JsonRecord<?>, Integer> part = SQLResultAdapter.byJson()
.andThen(r -> r.get(0, Integer.class));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public SelectExists(@NotNull TableLike<Record1<Integer>> table) {
}

@Override
public <RS> @NotNull Boolean collect(@NotNull RS resultSet, @NotNull SQLResultCollector<RS> collector,
public @NotNull <RS> Boolean collect(@NotNull RS resultSet, @NotNull SQLResultCollector<RS> collector,
@NotNull DSLContext dsl, @NotNull DataTypeMapperRegistry registry) {
return collector.collect(resultSet, initStrategy(dsl, registry,
SQLResultAdapter.byTable(table()).andThen(Objects::nonNull)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public SelectList(@NotNull T table, @NotNull SQLCollectorPart<R, I> collectorPar

@Override
public <RS> @NotNull List<I> collect(@NotNull RS resultSet, @NotNull SQLResultCollector<RS> collector,
@NotNull DSLContext dsl, @NotNull DataTypeMapperRegistry registry) {
@NotNull DSLContext dsl, @NotNull DataTypeMapperRegistry registry) {
return collector.collect(resultSet, createStrategy(registry, dsl));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.github.zero88.jooqx.adapter;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jooq.DSLContext;
import org.jooq.Record;
import org.jooq.TableLike;
Expand All @@ -26,8 +27,8 @@ public SelectOne(@NotNull T table, @NotNull SQLCollectorPart<R, I> collectorPart
}

@Override
public <RS> @NotNull I collect(@NotNull RS resultSet, @NotNull SQLResultCollector<RS> collector, @NotNull DSLContext dsl,
@NotNull DataTypeMapperRegistry registry) {
public <RS> @Nullable I collect(@NotNull RS resultSet, @NotNull SQLResultCollector<RS> collector,
@NotNull DSLContext dsl, @NotNull DataTypeMapperRegistry registry) {
return collector.collect(resultSet, createStrategy(registry, dsl)).stream().findFirst().orElse(null);
}

Expand Down

0 comments on commit 32eac44

Please sign in to comment.