Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DOCS: 4.x DB Client/Data Guide #6450

Closed
5 tasks done
ljamen opened this issue Mar 22, 2023 · 0 comments · Fixed by #7874
Closed
5 tasks done

DOCS: 4.x DB Client/Data Guide #6450

ljamen opened this issue Mar 22, 2023 · 0 comments · Fixed by #7874
Assignees
Labels
4.x Version 4.x DB client Helidon DB Client docs
Milestone

Comments

@ljamen
Copy link
Contributor

ljamen commented Mar 22, 2023

Problem Description

We need to update docs for 4.x

  • update dbclient.adoc for SE
  • update guides/dbclient.adoc for SE

Guidelines

  • Make sure any fixes from 3.x are forward ported to 4.x DOCS: SE Diffs 3.x to Main *.adoc  #7515
  • Make sure any fixes from MP 3.x are forward ported to 4.x
  • Initial focus is on correctness
  • Record migration impact in this issue

Migration Impact

See #6991 for the initial notes and discussions on the API changes made in 4.x.
The notes below describe the bulk of the changes.

DbExecute

In 3.x the DbExecute interface was like this:

interface DbExecute {
    // factory methods are omitted
    Multi<DbRow> namedQuery(String statementName, Object... parameters);
    Multi<DbRow> query(String statement, Object... parameters);
    Single<Optional<DbRow>> namedGet(String statementName, Object... parameters);
    Single<Optional<DbRow>> get(String statement, Object... parameters);
    Single<Long> namedInsert(String statementName, Object... parameters);
    Single<Long> insert(String statement, Object... parameters);
    Single<Long> namedUpdate(String statementName, Object... parameters);
    Single<Long> update(String statement, Object... parameters);
    Single<Long> namedDelete(String statementName, Object... parameters);
    Single<Long> namedDml(String statementName, Object... parameters);
    Single<Long> dml(String statement, Object... parameters);
    <C> Single<C> unwrap(Class<C> cls);
}

In 4.x the DbExecute interface looks like this:

interface DbExecute;
    // factory methods are omitted
    Stream<DbRow> namedQuery(String statementName, Object... parameters);
    Stream<DbRow> query(String statement, Object... parameters);
    Optional<DbRow> namedGet(String statementName, Object... parameters);
    Optional<DbRow> get(String statement, Object... parameters);
    long namedInsert(String statementName, Object... parameters);
    long insert(String statement, Object... parameters);
    long namedUpdate(String statementName, Object... parameters);
    long update(String statement, Object... parameters);
    long namedDelete(String statementName, Object... parameters);
    long delete(String statement, Object... parameters);
    long namedDml(String statementName, Object... parameters);
    long dml(String statement, Object... parameters);
    <C> C unwrap(Class<C> var1);
}

The API was changed to be blocking instead of reactive:

  • Single<DbRow> has been replaced with Optional<DbRow>
  • Multi<DbRow> has been replaced with Stream<DbRow>
  • Single<Long> has been replaced with long

In 4.x, onComplete is achieved by the next statement.

List<String> names = exec.query("SELECT * FROM names").toList();
System.out.println("done");

onError is achieved by a try-catch block:

try {
    List<String> names = exec.query("SELECT * FROM names").toList();
    System.out.println("done");
} catch (DbClientException dce) {
    // ugh-oh
}

Closing of the underlying ResultSet

Single query statements are closed right away (all methods except the ones that return Stream<DbRow>).

When operating on a Stream<DbRow> the underlying result set is closed on terminal operations, or if the underlying result set is drained.

Stream.close() can be used to manually close the underlying result set. This is not required, and if fact would reflect a mis-usage of the Stream API, E.g. a terminal operation wasn't called.

Transactions

In 3.x transactions were implemented by supplying a Function<DbTransaction, T>, changes made by the function were automatically committed at the end of the execution of the function, or automatically rolled-backed if an error occurred during the execution of the function.

E.g. A transaction In 3.x:

dbClient.inTransaction(tx -> {
    tx.namedDelete("delete-statement");
    tx.namedInsert("insert-statement");
    return 0L;
})
.onError(ex -> System.err.println("tx err: " + ex.getMessage))
.forSingle(count -> System.out.println("tx ok"));

In 4.x, inTransaction has been renamed to transaction. Transactions are not implemented with a user supplied function, instead the user is responsible for invoking commit() and rollback():

E.g. A transaction in 4.x:

DbTransaction tx = dbClient.transaction();
try {
    tx.namedDelete("delete-statement");
    tx.namedInsert("insert-statement");
    tx.commit();
} catch (Throwable t) {
    tx.rollback();
    throw t;
}

Note that both the commit() and rollback() methods are new additions to DbTransaction in 4.x:

interface DbTransaction extends DbExecute {
    void commit();
    void rollback();
}

DbClientService

In 3.x DbClientService looked like this:

interface DbClientService {
    Single<DbClientServiceContext> statement(DbClientServiceContext context);
}

Example of an implementation:

DbClientService service = context -> {
    System.out.println("Statement: " + context.statement());
    context.statementFuture().thenRun(() -> System.out.println("After statement"));
    return Single.just(context);
};

In 4.x DbClientService looks like this:

interface DbClientService {
    DbClientServiceContext statement(DbClientServiceContext context);
}

Example of an implementation:

DbClientService service = context -> {
    System.out.println("Statement: " + context.statement());
    context.statementFuture().thenRun(() -> System.out.println("After statement"));
    return context;
};
@ljamen ljamen added docs DB client Helidon DB Client 4.x Version 4.x labels Mar 22, 2023
@ljamen ljamen added this to the 4.0.0-RC1 milestone Mar 22, 2023
@ljamen ljamen self-assigned this Mar 22, 2023
@ljamen ljamen modified the milestones: 4.0.0-M2, 4.0.0 Aug 31, 2023
romain-grecourt added a commit to romain-grecourt/helidon that referenced this issue Oct 21, 2023
- Refresh docs/se/dbclient.adoc
- Refresh docs/se/guides/dbclient.adoc
- Remove left-over file: examples/dbclient/pokemons/src/main/resources/Pokemons.json

Fixes helidon-io#6450
@romain-grecourt romain-grecourt linked a pull request Oct 21, 2023 that will close this issue
barchetta pushed a commit that referenced this issue Oct 21, 2023
- Refresh docs/se/dbclient.adoc
- Refresh docs/se/guides/dbclient.adoc
- Remove left-over file: examples/dbclient/pokemons/src/main/resources/Pokemons.json

Fixes #6450
@m0mus m0mus added this to Backlog Aug 12, 2024
@m0mus m0mus moved this to Closed in Backlog Aug 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
4.x Version 4.x DB client Helidon DB Client docs
Projects
Archived in project
Archived in project
Development

Successfully merging a pull request may close this issue.

4 participants