• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

jhannes / fluent-jdbc / #213

16 Jul 2026 05:43PM UTC coverage: 91.667% (+0.1%) from 91.572%
#213

push

jhannes
upgrade to JDK 17 in GitHub workflow to support latest junit

1221 of 1332 relevant lines covered (91.67%)

0.92 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

88.89
/src/main/java/org/fluentjdbc/DbContextStatement.java
1
package org.fluentjdbc;
2

3
import javax.annotation.CheckReturnValue;
4
import javax.annotation.Nonnull;
5
import java.sql.PreparedStatement;
6
import java.util.Collection;
7
import java.util.Collections;
8
import java.util.stream.Stream;
9

10
/**
11
 * Used to execute an arbitrary statement. Create with {@link DbContext#statement(String, Collection)}.
12
 *
13
 * <h2>Example</h2>
14
 *
15
 * <pre>
16
 * dbContext.statement(
17
 *      "update orders set quantity = quantity + 1 WHERE customer_id = ?",
18
 *      Arrays.asList(customerId)
19
 * ).executeUpdate();
20
 * </pre>
21
 */
22
public class DbContextStatement implements DbContextSelectResult {
23
    protected final DbContext dbContext;
24
    protected final DatabaseStatement statement;
25

26
    public DbContextStatement(DbContext dbContext, String statement, Collection<Object> parameters) {
1✔
27
        this.dbContext = dbContext;
1✔
28
        this.statement = dbContext.getStatementFactory().newStatement("*", "*", statement, parameters);
1✔
29
    }
1✔
30

31
    public DbContextStatement(DbContext dbContext, String statement) {
32
        this(dbContext, statement, Collections.emptyList());
1✔
33
    }
1✔
34

35
    /**
36
     * If the query returns no rows, returns {@link SingleRow#absent}, if exactly one row is returned, maps it and return it,
37
     * if more than one is returned, throws `IllegalStateException`
38
     *
39
     * @param mapper Function object to map a single returned row to an object
40
     * @return the mapped row if one row is returned, {@link SingleRow#absent} otherwise
41
     * @throws MultipleRowsReturnedException if more than one row was matched the query
42
     */
43
    @Nonnull
44
    @CheckReturnValue
45
    public <OBJECT> SingleRow<OBJECT> singleObject(DatabaseResult.RowMapper<OBJECT> mapper) {
46
        return statement.singleObject(dbContext.getThreadConnection(), mapper);
1✔
47
    }
48

49
    /**
50
     * Execute the query and map each return value over the {@link DatabaseResult.RowMapper} function to return a stream. Example:
51
     * <pre>
52
     *     table.where("status", status).stream(row -&gt; row.getInstant("created_at"))
53
     * </pre>
54
     */
55
    @CheckReturnValue
56
    public <OBJECT> Stream<OBJECT> stream(DatabaseResult.RowMapper<OBJECT> mapper) {
57
        return statement.stream(dbContext.getThreadConnection(), mapper);
1✔
58
    }
59

60
    /**
61
     * Calls prepareStatement(String) with the statement,
62
     * {@link DatabaseStatement#bindParameters(PreparedStatement, Collection)}, converting each parameter in the process
63
     * and executes the statement
64
     */
65
    public int executeUpdate() {
66
        return statement.executeUpdate(dbContext.getThreadConnection());
×
67
    }
68
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc