-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#115] Use collector when executing batch and routine
- Loading branch information
Showing
7 changed files
with
66 additions
and
110 deletions.
There are no files selected for viewing
23 changes: 21 additions & 2 deletions
23
core/src/main/java/io/github/zero88/jooqx/JooqxBatchCollector.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,40 @@ | ||
package io.github.zero88.jooqx; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import org.jetbrains.annotations.NotNull; | ||
|
||
import io.vertx.codegen.annotations.GenIgnore; | ||
import io.vertx.codegen.annotations.VertxGen; | ||
import io.vertx.sqlclient.Row; | ||
import io.vertx.sqlclient.RowSet; | ||
import io.vertx.sqlclient.SqlResult; | ||
|
||
/** | ||
* Represents for a collector that collects {@code Vert.x SQL batch result} to an expectation output | ||
* | ||
* @param <R> Type of each row in batch result | ||
* @see JooqxResultCollector | ||
* @since 2.0.0 | ||
*/ | ||
@VertxGen | ||
public interface JooqxBatchCollector extends JooqxResultCollector, SQLBatchCollector<RowSet<Row>, RowSet<Row>> { | ||
public interface JooqxBatchCollector<R> | ||
extends JooqxResultCollector, SQLBatchCollector<RowSet<Row>, SqlResult<List<R>>> { | ||
|
||
@Override | ||
int batchResultSize(@NotNull RowSet<Row> batchResult); | ||
default int batchResultSize(@NotNull SqlResult<List<R>> batchResult) { | ||
return reduce(batchResult).size(); | ||
} | ||
|
||
@GenIgnore | ||
default List<R> reduce(SqlResult<List<R>> batchResult) { | ||
final List<R> br = new ArrayList<>(); | ||
SqlResult<List<R>> res = batchResult; | ||
do { | ||
br.add(res.value().stream().findFirst().orElse(null)); | ||
} while ((res = res.next()) != null); | ||
return br; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 0 additions & 28 deletions
28
core/src/main/java/io/github/zero88/jooqx/SQLResultCollector.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,11 @@ | ||
package io.github.zero88.jooqx; | ||
|
||
import org.jetbrains.annotations.NotNull; | ||
import org.jooq.DSLContext; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import io.github.zero88.jooqx.adapter.SQLResultAdapter; | ||
import io.github.zero88.jooqx.adapter.SelectStrategy; | ||
import io.github.zero88.jooqx.datatype.DataTypeMapperRegistry; | ||
import io.vertx.codegen.annotations.GenIgnore; | ||
import io.vertx.codegen.annotations.Nullable; | ||
|
||
/** | ||
* Represents for a collector that collects and transforms {@code Vert.x SQL result} to an expectation output | ||
* | ||
* @param <RS> Type of Vertx SQL result set | ||
* @see LegacySQLCollector | ||
* @see JooqxResultCollector | ||
* @see JooqxBatchCollector | ||
* @since 1.0.0 | ||
*/ | ||
public interface SQLResultCollector<RS> { | ||
|
||
/** | ||
* Collect result set to an expectation result that defines in SQL result adapter | ||
* | ||
* @param <ROW> the type of jOOQ record of the reduction operation | ||
* @param <RESULT> the type of result after the reduction operation | ||
* @param resultSet result set | ||
* @return an expectation result | ||
* @see SQLResultAdapter | ||
* @see DataTypeMapperRegistry | ||
* @since 2.0.0 | ||
*/ | ||
@Nullable <ROW, RESULT> RESULT collect(@NotNull RS resultSet, @NotNull SQLResultAdapter<ROW, RESULT> adapter, | ||
@NotNull DSLContext dslContext, @NotNull DataTypeMapperRegistry registry); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters