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

torand / FasterSQL / 13316820294

13 Feb 2025 08:49PM UTC coverage: 56.762% (+11.0%) from 45.739%
13316820294

push

github

web-flow
Merge pull request #8 from torand/testcontainers

feat: misc additions

143 of 336 branches covered (42.56%)

Branch coverage included in aggregate %.

97 of 171 new or added lines in 34 files covered. (56.73%)

6 existing lines in 6 files now uncovered.

772 of 1276 relevant lines covered (60.5%)

3.21 hits per line

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

73.47
/src/main/java/io/github/torand/fastersql/statement/PreparedStatementBuilder.java
1
/*
2
 * Copyright (c) 2024 Tore Eide Andersen
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *      http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16
package io.github.torand.fastersql.statement;
17

18
import io.github.torand.fastersql.Context;
19
import io.github.torand.fastersql.dialect.Dialect;
20
import org.slf4j.Logger;
21
import org.slf4j.LoggerFactory;
22

23
import java.io.InputStream;
24
import java.net.URI;
25
import java.sql.Connection;
26
import java.sql.Date;
27
import java.sql.PreparedStatement;
28
import java.sql.SQLException;
29
import java.sql.Timestamp;
30
import java.time.Instant;
31
import java.time.LocalDate;
32
import java.time.LocalDateTime;
33
import java.util.List;
34
import java.util.UUID;
35

36
/**
37
 * Builder for creating PreparedStatement with a Connection.
38
 */
39
public class PreparedStatementBuilder {
40
    private static final Logger LOGGER = LoggerFactory.getLogger(PreparedStatementBuilder.class);
4✔
41
    private final Connection connection;
42
    private final Dialect dialect;
43

44
    public static PreparedStatementBuilder using(Connection connection) {
NEW
45
        return new PreparedStatementBuilder(connection, Dialect.fromConnection(connection));
×
46
    }
47

48
    public static PreparedStatementBuilder using(Connection connection, Dialect dialect) {
49
        return new PreparedStatementBuilder(connection, dialect);
6✔
50
    }
51

52
    private PreparedStatementBuilder(Connection connection, Dialect dialect) {
2✔
53
        this.connection = connection;
3✔
54
        this.dialect = dialect;
3✔
55
    }
1✔
56

57
    public PreparedStatement prepare(PreparableStatement statement) throws SQLException {
58
        LOGGER.debug("Preparing SQL statement (ANSI/ISO SQL): {}", statement);
4✔
59

60
        Context context = Context.of(dialect);
4✔
61

62
        String sql = statement.sql(context);
4✔
63
        LOGGER.debug("Generated {} SQL statement: {}", context.getDialect().getProductName(), sql);
7✔
64
        List<Object> params = statement.params(context);
4✔
65

66
        PreparedStatement stmt = connection.prepareStatement(sql);
5✔
67
        int i = 1;
2✔
68
        for (Object param : params) {
9✔
69
            if (param instanceof Instant instant) {
3!
70
                stmt.setTimestamp(i, Timestamp.from(instant));
×
71
            } else if (param instanceof LocalDateTime localDateTime) {
6✔
72
                stmt.setTimestamp(i, Timestamp.valueOf(localDateTime));
6✔
73
            } else if (param instanceof LocalDate localDate) {
3!
74
                stmt.setDate(i, Date.valueOf(localDate));
×
75
            } else if (param instanceof UUID uuid) {
3!
76
                stmt.setObject(i, uuid.toString());
×
77
            } else if (param instanceof URI uri) {
3!
78
                stmt.setObject(i, uri.toString());
×
79
            } else if (param instanceof Enum enumValue) {
3!
80
                stmt.setObject(i, enumValue.name());
×
81
            } else if (param instanceof InputStream inputStream) {
3!
82
                stmt.setBinaryStream(i, inputStream);
×
83
            } else {
84
                stmt.setObject(i, param);
4✔
85
            }
86

87
            i++;
1✔
88
        }
1✔
89

90
        return stmt;
2✔
91
    }
92
}
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