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

jhannes / fluent-jdbc / #172

01 Aug 2024 07:53PM UTC coverage: 94.146% (-1.3%) from 95.478%
#172

push

jhannes
DatabaseUpdatable.setField with expression allows to insert and update rows with calculated column values

41 of 45 new or added lines in 7 files covered. (91.11%)

32 existing lines in 12 files now uncovered.

1174 of 1247 relevant lines covered (94.15%)

0.94 hits per line

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

75.0
/src/main/java/org/fluentjdbc/DatabaseListableQueryBuilder.java
1
package org.fluentjdbc;
2

3
import javax.annotation.CheckReturnValue;
4
import javax.annotation.Nonnull;
5
import java.sql.Connection;
6
import java.util.List;
7
import java.util.stream.Collectors;
8
import java.util.stream.Stream;
9

10
/**
11
 * Interface to execute terminal operations for <code>SELECT</code>-statements. Usage:
12
 *
13
 * <pre>
14
 * table.where...().list(connection, row -&gt; row.getUUID("column"));
15
 * table.where...().single(connection, row -&gt; row.getLocalDate("column"));
16
 * </pre>
17
 */
18
public interface DatabaseListableQueryBuilder<T extends DatabaseListableQueryBuilder<T>> {
19

20
    /**
21
     * Adds <code>ORDER BY ...</code> clause to the <code>SELECT</code> statement
22
     */
23
    @CheckReturnValue
24
    T orderBy(String orderByClause);
25

26
    /**
27
     * Adds <code>FETCH ... ROWS ONLY</code> clause to the <code>SELECT</code> statement.
28
     * FETCH FIRST was introduced in
29
     * <a href="https://en.wikipedia.org/wiki/Select_%28SQL%29#Limiting_result_rows">SQL:2008</a>
30
     * and is supported by Postgresql 8.4, Oracle 12c, IBM DB2, HSQLDB, H2, and SQL Server 2012.
31
     */
32
    @CheckReturnValue
33
    default T limit(int rowCount) {
UNCOV
34
        return skipAndLimit(0, rowCount);
×
35
    }
36

37
    /**
38
     * Adds <code>OFFSET ... ROWS FETCH ... ROWS ONLY</code> clause to the <code>SELECT</code>
39
     * statement. FETCH FIRST was introduced in
40
     * <a href="https://en.wikipedia.org/wiki/Select_%28SQL%29#Limiting_result_rows">SQL:2008</a>
41
     * and is supported by Postgresql 8.4, Oracle 12c, IBM DB2, HSQLDB, H2, and SQL Server 2012.
42
     */
43
    @CheckReturnValue
44
    T skipAndLimit(int offset, int rowCount);
45

46
    /**
47
     * If the query returns no rows, returns {@link SingleRow#absent}, if exactly one row is returned, maps it and return it,
48
     * if more than one is returned, throws `IllegalStateException`
49
     *
50
     * @param connection Database connection
51
     * @param mapper Function object to map a single returned row to a object
52
     * @return the mapped row if one row is returned, Optional.empty otherwise
53
     * @throws IllegalStateException if more than one row was matched the the query
54
     */
55
    @Nonnull
56
    @CheckReturnValue
57
    <OBJECT> SingleRow<OBJECT> singleObject(Connection connection, DatabaseResult.RowMapper<OBJECT> mapper);
58

59
    /**
60
     * Execute the query and map each return value over the {@link DatabaseResult.RowMapper} function to return a stream. Example:
61
     * <pre>
62
     *     table.where("status", status).stream(connection, row -&gt; row.getInstant("created_at"))
63
     * </pre>
64
     */
65
    @CheckReturnValue
66
    <OBJECT> Stream<OBJECT> stream(@Nonnull Connection connection, DatabaseResult.RowMapper<OBJECT> mapper);
67

68
    /**
69
     * Execute the query and map each return value over the {@link DatabaseResult.RowMapper} function to return a list. Example:
70
     * <pre>
71
     *     List&lt;Instant&gt; creationTimes = table.where("status", status).list(row -&gt; row.getInstant("created_at"))
72
     * </pre>
73
     */
74
    @CheckReturnValue
75
    default <OBJECT> List<OBJECT> list(Connection connection, DatabaseResult.RowMapper<OBJECT> mapper) {
76
        return stream(connection, mapper).collect(Collectors.toList());
1✔
77
    }
78

79
    /**
80
     * Executes the <code>SELECT * FROM ...</code> statement and calls back to
81
     * {@link org.fluentjdbc.DatabaseResult.RowConsumer} for each returned row
82
     */
83
    void forEach(Connection connection, DatabaseResult.RowConsumer consumer);
84

85
    /**
86
     * Executes <code>SELECT count(*) FROM ...</code> on the query and returns the result
87
     */
88
    @CheckReturnValue
89
    int getCount(Connection connection);
90

91
    /**
92
     * Executes <code>SELECT count(*) FROM ...</code> on the query and returns the result
93
     */
94
    @CheckReturnValue
95
    default List<Long> listLongs(Connection connection, final String fieldName) {
96
        return list(connection, row -> row.getLong(fieldName));
1✔
97
    }
98

99
    /**
100
     * Executes <code>SELECT count(*) FROM ...</code> on the query and returns the result
101
     */
102
    @CheckReturnValue
103
    default List<String> listStrings(Connection connection, final String fieldName) {
104
        return list(connection, row -> row.getString(fieldName));
1✔
105
    }
106

107
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc