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

torand / FasterSQL / 12888686285

21 Jan 2025 02:07PM UTC coverage: 50.829%. Remained the same
12888686285

push

github

torand
refactor: use instanceof variables

104 of 304 branches covered (34.21%)

Branch coverage included in aggregate %.

0 of 14 new or added lines in 1 file covered. (0.0%)

601 of 1083 relevant lines covered (55.49%)

2.91 hits per line

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

0.0
/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.*;
26
import java.time.Instant;
27
import java.time.LocalDate;
28
import java.time.LocalDateTime;
29
import java.util.List;
30
import java.util.UUID;
31

32
/**
33
 * Builder for creating PreparedStatement with a Connection.
34
 */
35
public class PreparedStatementBuilder {
36
    private static final Logger LOGGER = LoggerFactory.getLogger(PreparedStatementBuilder.class);
×
37
    private final Connection connection;
38

39
    public static PreparedStatementBuilder using(Connection connection) {
40
        return new PreparedStatementBuilder(connection);
×
41
    }
42

43
    private PreparedStatementBuilder(Connection connection) {
×
44
        this.connection = connection;
×
45
    }
×
46

47
    public PreparedStatement prepare(PreparableStatement statement) throws SQLException {
48
        LOGGER.debug("Preparing SQL statement: {}", statement);
×
49

50
        Context context = Context.of(Dialect.fromConnection(connection));
×
51
        String sql = statement.sql(context);
×
52
        List<Object> params = statement.params(context);
×
53

54
        PreparedStatement stmt = connection.prepareStatement(sql);
×
55
        int i = 1;
×
56
        for (Object param : params) {
×
NEW
57
            if (param instanceof Instant instant) {
×
NEW
58
                stmt.setTimestamp(i, Timestamp.from(instant));
×
NEW
59
            } else if (param instanceof LocalDateTime localDateTime) {
×
NEW
60
                stmt.setTimestamp(i, Timestamp.valueOf(localDateTime));
×
NEW
61
            } else if (param instanceof LocalDate localDate) {
×
NEW
62
                stmt.setDate(i, Date.valueOf(localDate));
×
NEW
63
            } else if (param instanceof UUID uuid) {
×
NEW
64
                stmt.setObject(i, uuid.toString());
×
NEW
65
            } else if (param instanceof URI uri) {
×
NEW
66
                stmt.setObject(i, uri.toString());
×
NEW
67
            } else if (param instanceof Enum enumValue) {
×
NEW
68
                stmt.setObject(i, enumValue.name());
×
NEW
69
            } else if (param instanceof InputStream inputStream) {
×
NEW
70
                stmt.setBinaryStream(i, inputStream);
×
71
            } else {
72
                stmt.setObject(i, param);
×
73
            }
74

75
            i++;
×
76
        }
×
77

78
        return stmt;
×
79
    }
80
}
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